:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #222636;
  --border:    #2d3148;
  --accent:    #6366f1;
  --accent-h:  #4f52d8;
  --text:      #e2e8f0;
  --muted:     #8892a4;
  --success:   #10b981;
  --warning:   #f59e0b;
  --danger:    #ef4444;
  --civ:       #818cf8;
  --via:       #fbbf24;
  --web:       #34d399;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

.logo { font-size: 17px; font-weight: 700; letter-spacing: -.4px; }
.logo em { color: var(--accent); font-style: normal; }

.sync-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: 20px;
  letter-spacing: .3px;
  transition: all .3s;
  white-space: nowrap;
}
.sync-ok      { background: rgba(16,185,129,.15); color: var(--success); }
.sync-pending { background: rgba(245,158,11,.15);  color: var(--warning); }
.sync-offline { background: rgba(239,68,68,.12);   color: var(--danger); }
.sync-loading { background: var(--surface2);        color: var(--muted); }

nav { display: flex; gap: 4px; flex-shrink: 0; }

.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  transition: all .18s;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: rgba(99,102,241,.15); color: var(--accent); }

/* ── Layout ───────────────────────────────────── */
main { max-width: 920px; margin: 0 auto; padding: 36px 24px 60px; }

.view { display: none; }
.view.active { display: block; }

.section-title {
  font-size: 21px;
  font-weight: 700;
  margin-bottom: 24px;
}

/* ── Card ─────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  margin-bottom: 20px;
}

/* ── Form ─────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}

input, select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 13px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color .18s;
  -moz-appearance: textfield;
}
input::-webkit-inner-spin-button { display: none; }
input:focus, select:focus { border-color: var(--accent); }
select option { background: var(--surface2); }

/* ── PAX sources ──────────────────────────────── */
.pax-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
}

.source-tag {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Preview ──────────────────────────────────── */
.preview {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-top: 22px;
}

.preview-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 14px;
}

.preview-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.preview-cell { text-align: center; }

.preview-val {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 3px;
}

.preview-lbl {
  font-size: 11px;
  color: var(--muted);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.preview-totals {
  display: flex;
  justify-content: space-between;
}

.total-block { text-align: center; }
.total-lbl { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.total-val { font-size: 18px; font-weight: 700; }

/* colour helpers */
.c-civ  { color: var(--civ); }
.c-via  { color: var(--via); }
.c-web  { color: var(--web); }
.c-acc  { color: var(--accent); }
.c-ok   { color: var(--success); }
.c-err  { color: var(--danger); }
.c-warn { color: var(--warning); }

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 22px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .18s;
}
.btn:hover { background: var(--accent-h); }
.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--border); }
.btn-icon {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 5px 9px;
  font-size: 13px;
}
.btn-icon:hover { color: var(--danger); border-color: var(--danger); background: rgba(239,68,68,.08); }
.btn-sm { padding: 7px 14px; font-size: 12.5px; border-radius: 7px; }
.btn-full { width: 100%; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

/* ── History controls ─────────────────────────── */
.hist-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 5px 8px;
}
.month-nav button {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 18px;
  line-height: 1;
  transition: background .15s;
}
.month-nav button:hover { background: var(--surface2); }
.month-label {
  font-weight: 600;
  font-size: 14px;
  min-width: 140px;
  text-align: center;
}

/* ── Summary cards ────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.sum-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 16px 14px;
  text-align: center;
}
.sum-val {
  font-size: 21px;
  font-weight: 700;
  margin-bottom: 4px;
}
.sum-lbl {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Table ────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  background: var(--surface2);
  padding: 11px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
}

tbody tr {
  border-top: 1px solid var(--border);
  transition: background .12s;
}
tbody tr:hover { background: rgba(99,102,241,.05); }
tbody td { padding: 11px 14px; vertical-align: middle; }

tfoot td {
  padding: 11px 14px;
  font-weight: 700;
  border-top: 2px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-am { background: rgba(129,140,248,.15); color: var(--civ); }
.badge-pm { background: rgba(251,191,36,.15);  color: var(--via); }

.sub { font-size: 11px; color: var(--muted); }

.td-actions { display: flex; gap: 5px; align-items: center; }

.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 38px; margin-bottom: 12px; }
.empty-msg  { font-size: 14px; }

/* ── Modal ────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
}
.modal-title { font-size: 17px; font-weight: 700; }
.close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 5px;
  transition: color .15s;
}
.close-btn:hover { color: var(--text); }

/* ── Toast ────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--success);
  color: #fff;
  padding: 11px 20px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(16px);
  transition: all .3s;
  z-index: 500;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── History tabs ────────────────────────────── */
.hist-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 5px;
  margin-bottom: 20px;
  width: fit-content;
}
.hist-tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 7px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  transition: all .18s;
}
.hist-tab:hover  { background: var(--surface2); color: var(--text); }
.hist-tab.active { background: rgba(99,102,241,.15); color: var(--accent); }

/* ── Period filter ────────────────────────────── */
.period-filter {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 14px;
  align-items: end;
}

.period-info {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}
.period-info strong { color: var(--text); }

.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.breakdown-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 18px 14px;
  text-align: center;
}
.breakdown-val {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.breakdown-lbl {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Config view ──────────────────────────────── */
.config-section { margin-bottom: 28px; }
.config-section:last-child { margin-bottom: 0; }

.config-section-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}
.config-section-desc {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 16px;
}

.config-col-labels {
  display: grid;
  gap: 8px;
  margin-bottom: 6px;
  padding: 0 2px;
}
.config-col-labels.platforms { grid-template-columns: 1fr 100px 38px; }
.config-col-labels.schedules { grid-template-columns: 1fr 90px 38px; }
.config-col-labels label { margin: 0; font-size: 10.5px; }

.config-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }

.config-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.config-item .cfg-name { flex: 1; }
.config-item .cfg-rate { width: 100px; flex-shrink: 0; }
.config-item .cfg-tour { flex: 1; }
.config-item .cfg-time { width: 90px; flex-shrink: 0; }

.config-add-btn {
  background: none;
  border: 1px dashed var(--border);
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  transition: all .18s;
  text-align: left;
}
.config-add-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Login screen ────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.4px;
  margin-bottom: 8px;
}
.login-logo em { color: var(--accent); font-style: normal; }

.login-subtitle {
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 32px;
}

.login-error {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--danger);
  min-height: 18px;
}

.login-toggle {
  margin-top: 20px;
  font-size: 13px;
  color: var(--muted);
}
.login-toggle button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-decoration: underline;
  padding: 0;
}

/* Botón cerrar sesión en header */
.btn-signout {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  transition: all .18s;
  white-space: nowrap;
}
.btn-signout:hover { border-color: var(--danger); color: var(--danger); }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-greeting {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Responsive ───────────────────────────────── */
@media (max-width: 640px) {

  /* Header: logo+header-right row 1, nav full-width row 2 */
  header {
    height: auto;
    flex-wrap: wrap;
    padding: 0;
    justify-content: flex-start;
  }
  .logo {
    flex: 0 0 auto;
    padding: 14px 16px;
    font-size: 16px;
  }
  .header-right {
    flex: 1;
    justify-content: flex-end;
    gap: 6px;
    padding-right: 12px;
  }
  #header-greeting {
    font-size: 12px;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #sync-status {
    font-size: 10px;
    padding: 3px 8px;
  }
  nav {
    width: 100%;
    order: 3;
    border-top: 1px solid var(--border);
  }
  .nav-btn {
    flex: 1;
    border-radius: 0;
    padding: 13px 8px;
    font-size: 13px;
    text-align: center;
  }

  /* Layout */
  main { padding: 20px 14px 90px; }
  .section-title { font-size: 18px; margin-bottom: 16px; }
  .card { padding: 18px 15px; }

  /* Inputs: 16px evita zoom en iOS */
  input, select { font-size: 16px; padding: 12px 13px; }

  /* Touch targets mínimos */
  .btn         { min-height: 48px; }
  .btn-sm      { min-height: 44px; padding: 8px 14px; }
  .btn-icon    { min-height: 44px; min-width: 44px; padding: 8px 12px; }
  button       { -webkit-tap-highlight-color: transparent; }

  /* Form */
  .form-grid { grid-template-columns: 1fr; gap: 14px; }
  .pax-row { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
  .source-tag { font-size: 10px; }

  /* Preview */
  .preview { padding: 14px 12px; }
  .preview-row {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
  }
  .preview-val { font-size: 17px; }
  .preview-totals { flex-direction: column; gap: 10px; }
  .total-val { font-size: 16px; }
  .total-lbl { font-size: 11px; }

  /* Form actions: columna, botón principal arriba */
  .form-actions { flex-direction: column; gap: 8px; }
  .form-actions .btn { width: 100%; text-align: center; }

  /* History tabs: ancho completo */
  .hist-tabs { width: 100%; }
  .hist-tab { flex: 1; text-align: center; padding: 9px 6px; font-size: 13px; }

  /* History controls: columna */
  .hist-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .month-nav { justify-content: space-between; }
  .month-label { min-width: 0; flex: 1; font-size: 15px; }
  .hist-controls .btn-ghost { text-align: center; }
  .hist-controls span:empty { display: none; }

  /* Summary / breakdown: 2 columnas fijas en móvil */
  .summary-grid   { grid-template-columns: 1fr 1fr; gap: 10px; }
  .breakdown-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .sum-val        { font-size: 18px; }
  .sum-card       { padding: 13px 10px; }
  .breakdown-val  { font-size: 18px; }
  .breakdown-card { padding: 13px 10px; }

  /* Period filter */
  .period-filter { grid-template-columns: 1fr 1fr; }
  .period-filter .btn { grid-column: 1 / -1; }

  /* Table: padding compacto */
  thead th  { padding: 10px 9px; font-size: 10.5px; }
  tbody td  { padding: 10px 9px; font-size: 12.5px; }
  tfoot td  { padding: 10px 9px; font-size: 12px; }
  .td-actions { flex-direction: column; gap: 4px; align-items: flex-start; }
  .td-actions .btn-sm  { padding: 6px 10px; font-size: 11.5px; }
  .td-actions .btn-icon { min-width: 36px; min-height: 36px; }

  /* Modal: slide-up desde el fondo */
  .overlay { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: 18px 18px 0 0;
    max-height: 90vh;
    padding: 22px 18px 32px;
  }
  .modal .form-grid { grid-template-columns: 1fr; }
  .modal .pax-row   { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }

  /* Toast: ancho completo centrado */
  .toast {
    left: 14px;
    right: 14px;
    bottom: 14px;
    text-align: center;
  }

  /* Login */
  .login-card { padding: 32px 22px; }
  .btn-signout { font-size: 11px; padding: 4px 9px; }

  /* Config */
  .config-col-labels.platforms { grid-template-columns: 1fr 80px 38px; }
  .config-col-labels.schedules { grid-template-columns: 1fr 74px 38px; }
  .config-item .cfg-rate { width: 80px; }
  .config-item .cfg-time { width: 74px; }

  /* Historial — columna Tour truncada en mobile */
  .td-tour {
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ═══════════════ LOADING SCREEN ══════════════ */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
