:root {
  /* Colores corporativos: index.php los sobrescribe con los de config.php */
  --brand-cfg: #002b75;
  --accent-cfg: #00c9a1;

  --brand: var(--brand-cfg);       /* botones, enlaces, pestaña activa */
  --on-brand: #ffffff;             /* texto sobre --brand */
  --accent: var(--accent-cfg);     /* energía: indicador de potencia, gráficos */
  --bg: #f2f5fa;
  --card: #ffffff;
  --text: #0f1f3d;
  --muted: #5d6b82;
  --line: #e1e7f0;
  --soft: #edf1f7;
  --ok: #007f68;                   /* turquesa oscurecido para texto legible */
  --warn: #b86e00;
  --danger: #d92d20;
  --info: #1d4fa8;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 30, 80, .05), 0 4px 16px rgba(0, 30, 80, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: var(--accent-cfg);
    --on-brand: var(--brand-cfg);
    --bg: #071226;
    --card: #0f1e3a;
    --text: #e8eef8;
    --muted: #93a3bd;
    --line: #1e3058;
    --soft: #172a4d;
    --ok: #2fdcb6;
    --info: #7aa7ff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.splash { min-height: 100vh; display: grid; place-items: center; }
.splash img { width: 72px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.94); } }

/* ---------- estructura */
.appbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 14px;
  background: var(--brand-cfg);
  box-shadow: 0 2px 12px rgba(0, 20, 60, .18);
}
.appbar .side { display: flex; gap: 8px; align-items: center; }
.appbar .side.right { justify-content: flex-end; }
.appbar-logo { display: block; line-height: 0; }
.appbar-logo img { height: 40px; width: auto; }
.appbar .icon-btn { background: rgba(255, 255, 255, .14); color: #fff; box-shadow: none; }
.appbar .icon-btn:hover { background: rgba(255, 255, 255, .22); }
.pagehead { max-width: 640px; margin: 0 auto; padding: 18px 20px 4px; }
.pagehead h1 { font-size: 24px; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--card);
  display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow); flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
main.page { max-width: 640px; margin: 0 auto; padding: 4px 16px calc(env(safe-area-inset-bottom) + 96px); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 160px; padding: 9px 4px 10px; text-align: center; text-decoration: none;
  color: var(--muted); font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabs a svg { width: 22px; height: 22px; }
.tabs a.active { color: var(--brand); font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid.three { grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 519px) {
  .grid.three .stat { padding: 12px 10px; }
  .grid.three .stat .value { font-size: 18px; }
  .grid.three .stat .label { font-size: 12px; }
}
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; min-width: 0; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 2px; }

/* ---------- botones y formularios */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; cursor: pointer;
  background: var(--brand); color: var(--on-brand); text-decoration: none; min-height: 46px;
}
.btn.block { width: 100%; }
.btn.big { min-height: 58px; font-size: 18px; border-radius: 16px; }
.btn.secondary { background: var(--soft); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--brand); padding: 8px 10px; min-height: 0; }
.btn.small { padding: 7px 12px; min-height: 0; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 20px; height: 20px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], input[type=tel], select {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); min-height: 46px;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); border-color: var(--brand); }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }

.days { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.days label { flex: 1; min-width: 38px; }
.days input { position: absolute; opacity: 0; pointer-events: none; }
.days span { display: block; text-align: center; padding: 9px 0; border-radius: 10px; background: var(--soft); cursor: pointer; font-size: 14px; font-weight: 600; }
.days input:checked + span { background: var(--brand); color: var(--on-brand); }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 22px; }
.login .brand { text-align: center; margin-bottom: 24px; }
.login .brand h1 { font-size: 24px; }

/* ---------- lista de cargadores */
.charger-item { display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit; }
.charger-item .dot { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; flex: none; background: var(--soft); color: var(--muted); }
.charger-item .dot svg { width: 24px; height: 24px; }
.charger-item .info { flex: 1; min-width: 0; }
.charger-item .info strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.charger-item .chev { color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: var(--soft); color: var(--muted); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-charging { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.st-plugged, .st-waiting, .st-paused { color: var(--info); background: color-mix(in srgb, var(--info) 12%, transparent); }
.st-finished { color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.st-fault, .st-offline { color: var(--danger); background: color-mix(in srgb, var(--danger) 11%, transparent); }
.charger-item .dot.st-charging, .charger-item .dot.st-finished { color: var(--ok); }
.charger-item .dot.st-plugged, .charger-item .dot.st-waiting, .charger-item .dot.st-paused { color: var(--info); }
.charger-item .dot.st-fault, .charger-item .dot.st-offline { color: var(--danger); }
.charger-item .dot[class*=st-]:not(.st-available):not(.st-unknown) { background: color-mix(in srgb, currentColor 13%, transparent); }

/* ---------- pantalla de estado */
.hero { text-align: center; padding: 22px 16px 18px; }
.gauge { position: relative; width: 220px; max-width: 70vw; aspect-ratio: 1; margin: 6px auto 14px; }
.gauge svg { width: 100%; height: 100%; transform: rotate(135deg); }
.gauge .track { stroke: var(--soft); }
.gauge .bar { stroke: var(--accent); transition: stroke-dashoffset .8s ease; }
.gauge .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge .kw { font-size: 46px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.gauge .kw-label { color: var(--muted); font-size: 14px; margin-top: -4px; }
.charging .gauge .bar { animation: glow 2s ease-in-out infinite; }
@keyframes glow { 50% { opacity: .65; } }
.hero .hint { color: var(--muted); font-size: 14px; margin: 10px 0 0; }

.amps { display: flex; align-items: center; gap: 12px; }
.amps .val { flex: 1; text-align: center; font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.amps .val small { font-size: 16px; color: var(--muted); font-weight: 500; }
.amps .icon-btn { width: 52px; height: 52px; font-size: 26px; background: var(--soft); box-shadow: none; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 14px 0 2px; }
.range-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.alert { border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 12px; background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--text); }
.alert.error { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.alert.info { background: color-mix(in srgb, var(--info) 10%, transparent); }

/* ---------- listas */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .main { flex: 1; min-width: 0; }
.list .main strong { display: block; }
.list .side { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---------- gráfico */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 8px; }
.chart .b { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; opacity: .9; }
.chart .b.zero { background: var(--soft); opacity: 1; }
.chart .b:hover { opacity: 1; }
.chart-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- tabla de mapeo */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td code { font-size: 13px; word-break: break-all; }

/* ---------- modal y avisos */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(480px, calc(100vw - 24px));
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25);
  max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgba(10, 15, 20, .45); }
dialog .modal-body { padding: 22px 20px 18px; }
dialog h2 { font-size: 19px; margin-bottom: 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translate(-50%, 20px);
  background: #0f1f3d; color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); }

.spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .7s linear infinite; display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }
.mock-banner { background: var(--warn); color: #fff; text-align: center; font-size: 13px; padding: 4px 8px; }

/* ---------- logotipo */
.wordmark { display: block; height: 30px; width: auto; }
.wordmark.dark { display: none; }
.login .wordmark { height: 64px; margin: 0 auto 14px; }
@media (prefers-color-scheme: dark) {
  .wordmark.light { display: none; }
  .wordmark.dark { display: block; }
}
.charger-item .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
