:root {
  --bg-deep: #070504;
  --bg-surface: #120d0a;
  --bg-elevated: #1b130e;
  --bg-hover: #261b14;
  --border: rgba(255, 255, 255, 0.09);
  --border-gold: rgba(229, 152, 67, 0.42);
  --gold: #e59843;
  --gold-light: #fbd38d;
  --gold-dark: #b96b1c;
  --cyan: #38bdf8;
  --cyan-bg: rgba(56, 189, 248, 0.16);
  --text-main: #f8fafc;
  --text-muted: #a39e99;
  --emerald: #10b981;
  --emerald-bg: rgba(16, 185, 129, 0.15);
  --crimson: #ef4444;
  --crimson-bg: rgba(239, 68, 68, 0.16);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.16);
  --blue: #38bdf8;
  --blue-bg: rgba(56, 189, 248, 0.16);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(circle at 15% 0%, #261308 0%, #0d1522 45%, var(--bg-deep) 80%);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--gold-light);
  text-decoration: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 0.95rem;
}

.hidden {
  display: none !important;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 55%, var(--gold-dark) 100%);
  color: #090c14;
  box-shadow: 0 4px 18px rgba(226, 185, 75, 0.28);
}

.btn-gold:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(226, 185, 75, 0.4);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-main);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-emerald {
  background: var(--emerald);
  color: #04130d;
  font-weight: 700;
}

.btn-danger {
  background: var(--crimson-bg);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.28);
}

.btn-sm {
  padding: 0.4rem 0.72rem;
  font-size: 0.82rem;
  border-radius: 7px;
}

/* --- Inputs --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  margin-bottom: 0.9rem;
}

.form-group label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.input, select.input, textarea.input {
  background: rgba(7, 9, 15, 0.72);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.68rem 0.88rem;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(226, 185, 75, 0.16);
}

/* --- Auth Card --- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--bg-surface);
  border: 1px solid var(--border-gold);
  border-radius: 20px;
  padding: 2.2rem 2rem;
  box-shadow: var(--shadow);
}

.brand-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: rgba(226, 185, 75, 0.12);
  border: 1px solid var(--border-gold);
  color: var(--gold-light);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.9rem;
}

/* --- Layout & Header --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(16px);
  background: rgba(10, 14, 24, 0.86);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.5rem;
}

.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
  color: #090c14;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 1.2rem;
  box-shadow: 0 4px 15px rgba(226, 185, 75, 0.25);
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* --- KPI Grid --- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.35rem;
  position: relative;
  overflow: hidden;
}

.kpi-card.gold-accent {
  border-color: var(--border-gold);
}

.kpi-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 800;
  margin-top: 0.25rem;
}

.kpi-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.progress-track {
  width: 100%;
  height: 7px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.65rem;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--emerald), #34d399);
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* --- Main Grid --- */
.workspace-grid {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 1.35rem;
  align-items: start;
}

@media (max-width: 1040px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}

.panel-title {
  font-size: 1.02rem;
  font-weight: 700;
}

.tabs {
  display: flex;
  background: rgba(7, 9, 15, 0.65);
  padding: 0.25rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 0.7rem;
  border-radius: 7px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--bg-elevated);
  color: var(--gold-light);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.24rem 0.62rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.badge-valid {
  background: var(--emerald-bg);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-consumed {
  background: var(--blue-bg);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.32);
}

.badge-revoked {
  background: var(--crimson-bg);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.32);
}

.badge-cat-apesiste {
  background: rgba(229, 152, 67, 0.18);
  color: #fbd38d;
  border: 1px solid rgba(229, 152, 67, 0.45);
}

.badge-cat-iaviste {
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.42);
}

.poster-banner-card {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border-gold);
  margin-bottom: 1.35rem;
  position: relative;
  background: #080504;
  display: grid;
  grid-template-columns: 320px 1fr;
  align-items: center;
  box-shadow: var(--shadow);
}

.poster-banner-card img {
  width: 100%;
  height: 100%;
  max-height: 175px;
  object-fit: cover;
  display: block;
}

.poster-banner-info {
  padding: 1.15rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

@media (max-width: 820px) {
  .poster-banner-card {
    grid-template-columns: 1fr;
  }
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-gold);
  border-radius: 18px;
  max-width: 780px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.ticket-preview-img {
  width: 100%;
  max-width: 720px;
  display: block;
  margin: 0.75rem auto;
  border-radius: 14px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.7);
  border: 1px solid var(--border-gold);
}

/* --- Filter Bar & Table --- */
.filter-bar {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-bar .input {
  flex: 1;
  min-width: 190px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 11px;
}

table.tickets-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.tickets-table th {
  text-align: left;
  padding: 0.78rem 0.9rem;
  background: rgba(7, 9, 15, 0.6);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.77rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.tickets-table td {
  padding: 0.82rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tickets-table tr:last-child td {
  border-bottom: none;
}

.tickets-table tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

.mono-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold-light);
  font-size: 0.84rem;
}

.row-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* --- Live Scan Feed --- */
.live-feed {
  max-height: 290px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.feed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 9px;
  background: rgba(7, 9, 15, 0.55);
  border-left: 3px solid var(--border);
  font-size: 0.82rem;
}

.feed-item.ok {
  border-left-color: var(--emerald);
}

.feed-item.err {
  border-left-color: var(--crimson);
}

/* --- Modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(3, 5, 10, 0.82);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-gold);
  color: var(--text-main);
  padding: 0.75rem 1.05rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 600;
}

/* --- Print Stylesheet for PDF Ticket Sheet --- */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }
  .no-print {
    display: none !important;
  }
  #printSheet {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    padding: 10px;
  }
  #printSheet img {
    width: 100%;
    page-break-inside: avoid;
    border: 1px solid #ccc;
    border-radius: 10px;
  }
}
