:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --fg: #1a1d29;
  --muted: #667085;
  --border: #e5e8f0;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0fd;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a24;
    --fg: #edeef2;
    --muted: #9aa0b4;
    --border: #2a2e3d;
    --accent: #818cf8;
    --accent-hover: #a5b0fb;
    --accent-soft: #23253a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1rem; margin: 0 0 0.5rem; }
a { color: var(--accent); }

/* --- Topbar --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.85rem 1.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--fg);
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.user-email { margin-left: auto; color: var(--muted); font-size: 0.85rem; }
.btn-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.3rem 0.1rem;
  transition: color 0.15s ease;
}
.btn-link:hover { color: var(--accent); }

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

.header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; gap: 1rem; flex-wrap: wrap; }
.header-row h1 { margin: 0; }

/* --- Buttons --- */
.btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }

/* --- Cards / panels --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.banner-warning {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}
.banner-warning h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.banner-warning ul { margin: 0; padding-left: 1.2rem; }
.estado-perfil { white-space: normal; min-width: 13rem; }
.estado-perfil .hint, .estado-perfil .estado-aviso { font-size: 0.78rem; }
.estado-aviso { color: #b45309; font-weight: 600; }
.banner-info {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.5rem;
}
.banner-info h3 { margin: 0 0 0.3rem; font-size: 0.88rem; }
.banner-info ul { margin: 0; padding-left: 1.2rem; font-size: 0.85rem; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 2rem; }
table { width: 100%; border-collapse: collapse; }
.table-wrap table { margin-bottom: 0; }
th, td { text-align: left; padding: 0.7rem 1rem; font-size: 0.88rem; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border); }
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s ease; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--accent-soft); }
td a { font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }

/* fallback for pages not yet wrapped in .table-wrap */
table:not(.table-wrap table) { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 2rem; }

.badge { display: inline-block; border: none; border-radius: 999px; padding: 0.25rem 0.75rem; font-size: 0.78rem; font-weight: 600; cursor: pointer; }
.badge-on { background: #dcfce7; color: #15803d; }
.badge-off { background: #fee2e2; color: #b91c1c; }
@media (prefers-color-scheme: dark) {
  .badge-on { background: #103822; color: #4ade80; }
  .badge-off { background: #3a1414; color: #f87171; }
}

/* --- Login --- */
.login-box {
  max-width: 380px;
  margin: 4.5rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 2rem 1.75rem;
}
.login-box h1 { text-align: center; margin-bottom: 1.5rem; }

/* --- Forms --- */
form label { display: block; margin-bottom: 1rem; font-size: 0.9rem; font-weight: 500; }
form input[type=text], form input[type=email], form input[type=password],
form input[type=number], form input[type=date], form input[type=time], form select {
  display: block; width: 100%; padding: 0.6rem 0.7rem; margin-top: 0.35rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--fg);
  font-size: 0.92rem; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
form input:focus, form select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
form label.checkbox { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; }
form label.checkbox input { width: auto; margin: 0; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1.25rem; padding: 1.25rem 1.5rem; background: var(--surface); box-shadow: var(--shadow); }
legend { padding: 0 0.5rem; font-weight: 700; font-size: 0.95rem; color: var(--accent); }
.weekdays { display: flex; flex-wrap: wrap; gap: 0.9rem; margin-bottom: 1rem; }
.hint { color: var(--muted); font-size: 0.85rem; }

/* --- Filters --- */
.filters {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: end;
  margin-bottom: 1.5rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.25rem;
}
.filters label { display: flex; flex-direction: column; font-size: 0.82rem; font-weight: 500; gap: 0.3rem; color: var(--muted); }
.filters input, .filters select { padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--fg); }

/* --- Stat cards --- */
.stats-row { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.9rem 1.4rem; flex: 1; min-width: 130px;
}
.stat-card .value { font-size: 1.5rem; font-weight: 700; }
.stat-card .label { color: var(--muted); font-size: 0.78rem; margin-top: 0.15rem; }

.segment-block { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--surface); padding: 1.1rem 1.4rem; margin-bottom: 1.25rem; }
.segment-block h3 { margin-top: 0.25rem; color: var(--accent); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }
.segment-block p { margin: 0.35rem 0; }

.help { cursor: help; color: var(--accent); font-size: 0.8rem; margin-left: 0.3rem; }
.codes-help { margin: -0.5rem 0 1.25rem; font-size: 0.85rem; color: var(--muted); background: var(--accent-soft); border-radius: 8px; padding: 0.6rem 1rem; }
.codes-help summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.codes-help ul, .codes-help ol { margin: 0.5rem 0 0; padding-left: 1.2rem; }
.codes-help code { background: rgba(128,128,128,0.15); padding: 0.05rem 0.3rem; border-radius: 4px; }

.error { color: #b91c1c; font-weight: 500; }
.ok { color: #15803d; font-weight: 500; }

@media (max-width: 640px) {
  .topbar { padding: 0.75rem 1rem; gap: 0.75rem; flex-wrap: wrap; }
  .user-email { display: none; }
  .container { padding: 1.25rem 1rem 3rem; }
  fieldset { padding: 1rem; }
}

/* --- Consumo de servicios --- */
.barra-cuota { width: 10rem; height: 0.5rem; background: var(--border); border-radius: 999px; overflow: hidden; margin: 0.3rem 0 0.15rem; }
.barra-cuota-relleno { height: 100%; background: #16a34a; }
.barra-cuota-relleno.alto { background: #d97706; }
.barra-cuota-relleno.lleno { background: #dc2626; }
.btn-link-inline { background: none; border: none; padding: 0 0 0 0.6rem; color: var(--accent); cursor: pointer; font: inherit; }
.btn-link-inline:hover { text-decoration: underline; }

/* --- Destinos --- */
.filtro-destinos { width: 100%; max-width: 24rem; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; margin-bottom: 1rem; }

/* --- Grafico de evolucion del precio --- */
.grafico-precio { position: relative; height: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; margin-bottom: 0.4rem; }
