:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #0f1b2d;
  --ink-2: #4a5568;
  --muted: #8a94a6;
  --line: #e4e8ee;
  --side: #0f1b2d;
  --side-2: #18263c;
  --brand: #f5a524;
  --primary: #1e5eff;
  --primary-2: #1648c9;
  --libre: #12a150;
  --libre-bg: #e6f6ed;
  --ocupada: #d93838;
  --ocupada-bg: #fdecec;
  --warn: #c77700;
  --warn-bg: #fff4e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 4px 16px rgba(15, 27, 45, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
a { color: var(--primary); }

/* ---------- Marca ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; color: #fff; font-weight: 500; }
.brand b { color: var(--brand); font-weight: 800; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: var(--side); display: grid; place-items: center; font-weight: 900; font-size: 20px; }
.brand-lg { font-size: 28px; color: var(--ink); justify-content: center; }
.brand-lg .brand-mark { width: 44px; height: 44px; font-size: 26px; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #24395a 0, var(--side) 55%); }
.login-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 18px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-sub { text-align: center; color: var(--ink-2); margin: 8px 0 24px; }
.login-card form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
input, select, textarea { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: #fff; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(30, 94, 255, .35); border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }
.form-error { color: var(--ocupada); font-size: 14px; min-height: 1em; margin: 0; }
.demo-users { margin-top: 22px; border-top: 1px dashed var(--line); padding-top: 16px; display: grid; gap: 8px; }
.demo-users p { margin: 0 0 2px; font-size: 13px; color: var(--muted); }
.demo-users button { display: flex; flex-wrap: wrap; gap: 2px 10px; justify-content: space-between; align-items: center; border: 1px solid var(--line); background: #fafbfc; border-radius: 9px; padding: 9px 12px; text-align: left; }
.demo-users button:hover { border-color: var(--primary); background: #f3f7ff; }
.demo-users span { color: var(--muted); font-size: 13px; }
.sim-note { margin: 18px 0 0; font-size: 12px; color: var(--warn); text-align: center; }

/* ---------- Botones ---------- */
.btn { border: 1px solid transparent; border-radius: 9px; padding: 9px 16px; font-weight: 600; background: #eef1f5; color: var(--ink); transition: background .15s, border-color .15s; }
.btn:hover { background: #e3e7ed; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-danger { background: var(--ocupada-bg); color: var(--ocupada); }
.btn-danger:hover { background: #fadada; }
.btn-ghost { background: transparent; color: #c6d0e0; border-color: #2c3d58; }
.btn-ghost:hover { background: var(--side-2); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { border: 0; background: transparent; font-size: 20px; padding: 6px 10px; border-radius: 8px; color: inherit; }
.icon-btn:hover { background: rgba(0,0,0,.06); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; background: linear-gradient(90deg, var(--side) 250px, var(--bg) 250px); }
.sidebar { background: var(--side); color: #c6d0e0; display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 0 8px 22px; }
#nav { display: grid; gap: 2px; flex: 1; overflow-y: auto; align-content: start; }
#nav .nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b7d99; padding: 14px 10px 6px; }
#nav a { display: flex; align-items: center; gap: 10px; color: #c6d0e0; text-decoration: none; padding: 9px 10px; border-radius: 8px; font-size: 15px; }
#nav a:hover { background: var(--side-2); color: #fff; }
#nav a.active { background: var(--primary); color: #fff; }
#nav a .ico { width: 20px; text-align: center; }
#nav a .count { margin-left: auto; background: var(--ocupada); color: #fff; font-size: 11px; border-radius: 99px; padding: 1px 7px; font-weight: 700; }
.sidebar-foot { border-top: 1px solid #22324c; padding-top: 14px; display: grid; gap: 12px; }
.user-chip { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.user-chip b { display: block; color: #fff; font-size: 14px; }
.user-chip span { font-size: 12px; color: #8ea0bd; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: var(--side); display: grid; place-items: center; font-weight: 800; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 28px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 21px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
#menu-toggle { display: none; }
.live { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); }
.live i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.live.on i { background: var(--libre); box-shadow: 0 0 0 0 rgba(18,161,80,.6); animation: pulse 1.8s infinite; }
.live.off i { background: var(--ocupada); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(18,161,80,0); } 100% { box-shadow: 0 0 0 0 rgba(18,161,80,0); } }
.badge-sim { font-size: 12px; font-weight: 700; color: var(--warn); background: var(--warn-bg); padding: 4px 10px; border-radius: 99px; }

.view { padding: 24px 28px 48px; display: grid; gap: 20px; align-content: start; }

/* ---------- Tarjetas ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.kpi span { font-size: 13px; color: var(--ink-2); }
.kpi b { display: block; font-size: 28px; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi.libre b { color: var(--libre); }
.kpi.ocupada b { color: var(--ocupada); }
.kpi.alerta b { color: var(--warn); }

.suggest { display: flex; align-items: center; gap: 16px; background: linear-gradient(90deg, var(--side), #1f3456); color: #fff; border-radius: var(--radius); padding: 16px 20px; }
.suggest .big { font-size: 34px; }
.suggest b { color: var(--brand); }
.suggest p { margin: 2px 0 0; color: #b8c4d8; font-size: 14px; }
.suggest .right { margin-left: auto; text-align: right; font-size: 13px; color: #b8c4d8; }

/* ---------- Gráficos ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 12px; fill: var(--ink-2); }
.chart .axis { stroke: var(--line); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- Zonas / mapa ---------- */
.zone-rows { display: grid; gap: 14px; }
.zone-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center; }
.zone-row .bar { grid-column: 1 / -1; grid-row: 2; }
.zone-row .right { text-align: right; display: flex; gap: 8px; align-items: center; }
.zone-row .name { font-weight: 600; font-size: 14px; }
.zone-row .name small { display: block; color: var(--muted); font-weight: 400; }
.bar { height: 14px; background: var(--libre-bg); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--ocupada); border-radius: 99px; transition: width .4s; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.pill.baja, .pill.libre, .pill.Cerrada, .pill.entrada-ok { background: var(--libre-bg); color: var(--libre); }
.pill.media, .pill.En-proceso { background: var(--warn-bg); color: var(--warn); }
.pill.alta, .pill.ocupada, .pill.Abierta, .pill.rechazado { background: var(--ocupada-bg); color: var(--ocupada); }
.pill.duplicado, .pill.gris { background: #eef1f5; color: var(--ink-2); }
.pill.entrada { background: #e8efff; color: var(--primary); }
.pill.salida { background: var(--libre-bg); color: var(--libre); }

.map-zone { margin-bottom: 4px; }
.map-zone h3 { font-size: 15px; display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.map-zone h3 small { color: var(--muted); font-weight: 400; }
.spots { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 10px; }
.spot { border: 2px solid; border-radius: 10px; padding: 10px 6px; text-align: center; font-size: 13px; font-weight: 700; background: #fff; transition: transform .2s, background .3s; position: relative; }
.spot .ico { display: block; font-size: 20px; margin-bottom: 2px; }
.spot small { display: block; font-weight: 600; font-size: 11px; }
.spot.libre { border-color: var(--libre); color: var(--libre); background: var(--libre-bg); }
.spot.ocupada { border-color: var(--ocupada); color: var(--ocupada); background: var(--ocupada-bg); }
.spot.inactiva { border-color: var(--line); color: var(--muted); background: #f6f7f9; border-style: dashed; }
.spot.flash { transform: scale(1.08); }
button.spot:hover { box-shadow: 0 0 0 3px rgba(30,94,255,.25); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfd; }
tr.new { animation: newrow 1.2s; }
@keyframes newrow { from { background: #fff7df; } to { background: transparent; } }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filters label { font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }

.switch { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; color: var(--ink); cursor: pointer; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 99px; background: #cfd6e0; position: relative; padding: 0; border: 0; cursor: pointer; transition: background .2s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--libre); }
.switch input:checked::after { left: 21px; }

.result-box { border-radius: 10px; padding: 16px; display: flex; align-items: center; gap: 16px; }
.result-box.ok { background: var(--libre-bg); color: var(--libre); }
.result-box.fail { background: var(--ocupada-bg); color: var(--ocupada); }
.result-box b { font-size: 30px; }

.stars { color: var(--brand); letter-spacing: 2px; }
.note { font-size: 13px; color: var(--ink-2); background: #f6f8fb; border-left: 3px solid var(--primary); padding: 10px 12px; border-radius: 6px; }
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.timeline li { border-left: 3px solid var(--line); padding: 2px 0 2px 12px; font-size: 14px; }
.timeline li small { color: var(--muted); display: block; }

/* ---------- Modal y toasts ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,27,45,.5); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-card { background: #fff; border-radius: 16px; max-width: 620px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 24px; position: relative; }
.modal-close { position: absolute; top: 12px; right: 12px; }
.modal-card h2 { font-size: 19px; margin-bottom: 4px; padding-right: 30px; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 360px; font-size: 14px; animation: toastin .25s; }
.toast.error { background: var(--ocupada); }
.toast.alerta { background: var(--warn); }
.toast.ok { background: var(--libre); }
@keyframes toastin { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 980px) {
  .grid-2, .grid-3-1 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(15,27,45,.45); }
  #menu-toggle { display: inline-block; }
  .topbar { padding: 12px 16px; }
  .view { padding: 16px 14px 40px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .layout { background: var(--bg); }
  .form-grid { grid-template-columns: 1fr; }
  .badge-sim { display: none; }
  .suggest .right { display: none; }
}
