:root {
  color-scheme: light dark;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--surface, #0f172a);
  color: var(--text, #e2e8f0);
  --surface: #0f172a;
  --surface-alt: #111c34;
  --surface-panel: rgba(15, 23, 42, 0.85);
  --border: rgba(148, 163, 184, 0.2);
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --danger: #f97316;
  --muted: #94a3b8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1e293b 0%, #0f172a 60%, #020617 100%);
  padding: 24px;
}

.app-header {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 12px;
  margin-bottom: 24px;
}

.header-text {
  text-align: center;
  margin: 0 auto;
}

.header-meta {
  display: flex;
  justify-content: center;
  margin-top: 4px;
}

.header-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 auto 24px;
}

.nav-button {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, border 0.2s ease;
}

.nav-button:hover {
  transform: translateY(-1px);
  border-color: rgba(34, 197, 94, 0.45);
}

.nav-button:disabled,
.nav-button.is-disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.nav-button.active {
  background: linear-gradient(135deg, var(--accent) 0%, #15803d 100%);
  border-color: rgba(34, 197, 94, 0.6);
  color: #0f172a;
}

.token-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.token-modal.active {
  display: flex;
}

.token-card {
  width: min(420px, 92vw);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
}

.token-card input {
  width: 100%;
  margin-top: 8px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.5vw, 2.2rem);
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 92vw);
  background: var(--surface-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

.auth-card h1 {
  margin: 0 0 8px;
}

.auth-error {
  color: #f97316;
  margin-top: 10px;
}

#user-title {
  color: #9CE802;
  font-style: italic;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.status-pill {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.status-pill.valid {
  background: rgba(34, 197, 94, 0.2);
  color: #9ce802;
  border: 1px solid rgba(34, 197, 94, 0.5);
}

.status-pill.expired {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.6);
}

.brand-highlight {
  color: #9CE802;
}

.brand-word {
  font-style: italic;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  max-width: 480px;
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent);
  font-size: 0.85rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 480px) minmax(520px, 1fr);
  gap: 24px;
  width: min(1600px, calc(100vw - 48px));
  max-width: 100%;
  margin: 0 auto;
  align-items: flex-start;
}

.layout-single {
  grid-template-columns: minmax(360px, 1fr);
}

.view.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.header-text {
  flex: 1;
  text-align: center;
}

.tickets-panel,
.form-panel {
  background: var(--surface-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  backdrop-filter: blur(12px);
}

.tickets-panel.users-panel {
  border: 1px dashed #FF7A01;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 0;
}

.ticket-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
  margin: 0;
}

.tickets-load-more {
  margin-top: 12px;
  width: 100%;
}

.ticket-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ticket-card h3 {
  margin: 0;
  font-size: 1rem;
}

.ticket-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
  margin: 0;
}

.user-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-card h3 {
  margin: 0;
  font-size: 1rem;
}

.user-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.user-token {
  font-size: 0.85rem;
  color: var(--accent);
}

.ticket-actions {
  display: flex;
  gap: 8px;
}

.ticket-status-control {
  margin: 4px 0 8px;
}

.tickets-panel .ticket-status-control {
  display: none;
}

.ticket-status-control label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.ticket-status-select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(15, 23, 42, 0.55);
  color: var(--text);
  font-size: 0.9rem;
}

.ticket-status-control--busy .ticket-status-select {
  opacity: 0.65;
  pointer-events: none;
}

button {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.2s ease;
}

button.primary {
  background: linear-gradient(135deg, var(--accent) 0%, #15803d 100%);
  color: #0f172a;
}

button.secondary {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text);
}

.button.is-loading,
button.is-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.75;
}

.button.is-loading::after,
button.is-loading::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: rgba(255, 255, 255, 0.9);
  animation: spin 0.8s linear infinite;
  transform: translateY(-50%);
}

@keyframes spin {
  to {
    transform: translateY(-50%) rotate(360deg);
  }
}

button.danger {
  background: rgba(249, 115, 22, 0.15);
  color: #f97316;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:active {
  transform: translateY(0);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

input,
textarea,
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.55);
  color: var(--text);
  font-size: 0.95rem;
}

input[type="datetime-local"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(34, 197, 94, 0.4);
  outline-offset: -2px;
}

input.leg-odds::-webkit-outer-spin-button,
input.leg-odds::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input.leg-odds {
  -moz-appearance: textfield;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.checkbox input {
  width: auto;
  accent-color: var(--accent);
}

.legs-fieldset,
.ticket-fieldset {
  border: 1px dashed #FF7A01;
  border-radius: 12px;
  padding: 16px;
  margin: 20px 0;
}

.legs-fieldset legend,
.ticket-fieldset legend {
  padding: 0 8px;
  color: #9CE802;
}

.settings-panel {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.settings-fieldset {
  border: 1px dashed #FF7A01;
  border-radius: 12px;
  padding: 20px;
  margin: 20px 0;
}

.settings-fieldset legend {
  padding: 0 8px;
  color: #9CE802;
}

.settings-fieldset label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  color: var(--muted);
}

.settings-fieldset input {
  border-radius: 10px;
  padding: 10px 12px;
}

.settings-file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.settings-fieldset label.file-upload {
  border: 1px dashed rgba(255, 122, 1, 0.4);
  border-radius: 10px;
  padding: 12px;
  background: rgba(255, 122, 1, 0.04);
  color: inherit;
}

.settings-fieldset label.file-upload input[type="file"] {
  padding: 0;
}

.current-file {
  font-size: 0.8rem;
  color: var(--muted);
}

.settings-actions {
  justify-content: flex-end;
}

.images-actions {
  margin-top: 8px;
  justify-content: flex-start;
}

.settings-view {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 16px;
  margin-top: -16px;
}

.ticket-fieldset > label {
  margin-bottom: 16px;
}

.helper-text {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.legs-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.leg-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(15, 23, 42, 0.45);
}

.leg-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 12px;
}

.leg-grid .leg-field {
  width: 100%;
  min-width: 0;
}

.leg-grid .leg-field input,
.leg-grid .leg-field select {
  width: 100%;
  min-width: 0;
}

.leg-start-time {
  min-width: 0;
}

.leg-grid .leg-results-field {
  grid-column-start: 6;
  grid-column-end: span 1;
}

.leg-field--match-time {
  grid-column-start: 7;
  grid-column-end: span 2;
}

.leg-field--full {
  grid-column: span 3;
}

.leg-footer {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-top: 12px;
  flex-wrap: wrap;
}

.leg-results-field {
  flex: 1;
  min-width: 0;
}

.leg-footer .leg-results-field {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.leg-footer .leg-actions {
  margin-top: 0;
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
}

.leg-footer .leg-actions button {
  width: 100%;
  height: 100%;
}

.leg-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.ticket-status-hidden {
  display: none !important;
}

.placeholder-card {
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: 16px;
  padding: 24px;
  background: rgba(15, 23, 42, 0.6);
  color: var(--muted);
  text-align: center;
  grid-column: 1 / -1;
}

.placeholder-card h2 {
  margin-top: 0;
  margin-bottom: 8px;
  color: var(--text);
}

#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: rgba(34, 197, 94, 0.18);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(34, 197, 94, 0.45);
  min-width: 180px;
  text-align: center;
  transform: translateY(120%);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  backdrop-filter: blur(10px);
}

#toast.visible {
  transform: translateY(0);
  opacity: 1;
}

#toast.error {
  background: rgba(248, 113, 113, 0.18);
  border-color: rgba(248, 113, 113, 0.45);
}

@media (max-width: 960px) {
  body {
    padding: 16px;
  }

  .layout {
    display: flex;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .form-panel {
    order: 1;
    width: 100%;
    max-width: 100%;
  }

  .tickets-panel {
    order: 2;
    width: 100%;
    max-width: 100%;
  }

  .app-header {
    flex-direction: column;
    text-align: center;
  }

  .form-actions {
    flex-direction: column;
  }

  .ticket-actions {
    flex-direction: column;
  }

  .leg-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .leg-grid .leg-field {
    grid-column: span 2 !important;
  }

  .leg-grid .leg-field:nth-child(5),
  .leg-grid .leg-field:nth-child(6) {
    grid-column: span 1 !important;
    min-width: 0;
    width: 100%;
  }

  .leg-grid .leg-field:nth-child(5),
  .leg-grid .leg-field:nth-child(6) {
    justify-self: stretch;
  }

  .leg-field--match-time {
    grid-column: span 2 !important;
    width: 100%;
    justify-self: stretch;
  }

  .leg-field--match-time .leg-start-time {
    min-width: 0;
  }

  .leg-footer {
    flex-wrap: nowrap;
    align-items: stretch;
  }

  .leg-footer .leg-actions {
    width: auto;
  }

  .ticket-fieldset > label,
  .ticket-fieldset .form-grid label {
    width: 100%;
  }

  .ticket-fieldset .form-grid {
    grid-template-columns: 1fr;
  }


  .header-nav {
    gap: 8px;
  }

  .nav-button {
    flex: 1 1 calc(50% - 8px);
    max-width: calc(50% - 8px);
    min-width: 140px;
  }

  .settings-view {
    align-items: flex-start;
    min-height: auto;
    margin-top: 0;
  }
}
/* First row: expand Home/Away/League */
.leg-grid .leg-field:nth-child(1) {
  grid-column: span 3;
}

.leg-grid .leg-field:nth-child(2) {
  grid-column: span 3;
}

.leg-grid .leg-field:nth-child(3) {
  grid-column: span 2;
}

/* Second row: detail columns */
.leg-grid .leg-field:nth-child(4) {
  grid-column-start: 1;
  grid-column-end: span 3;
}

.leg-grid .leg-field:nth-child(5) {
  grid-column-start: 4;
  grid-column-end: span 1;
}

.leg-grid .leg-field:nth-child(6) {
  grid-column-start: 5;
  grid-column-end: span 1;
}

.leg-grid .leg-field:nth-child(7) {
  grid-column-start: 6;
  grid-column-end: span 1;
}

.leg-grid .leg-field:nth-child(8) {
  grid-column-start: 7;
  grid-column-end: span 2;
}
