:root {
  /* Colores tomados del logo de Gelato Feliz */
  --grape: #5b3a86;
  --grape-700: #4a2d70;
  --grape-900: #2c1a45;
  --lilac: #b48fd9;
  --lilac-300: #d3bdeb;
  --lilac-100: #f2eafa;
  --lilac-50: #faf6fd;
  --ink: #1d1724;
  --ink-2: #5d5468;
  --ink-3: #958ca0;
  --line: #ece4f4;
  --card: #ffffff;
  --bg: #f8f4fb;

  /* Sabores (métodos) */
  --c-fingerprint: #5b3a86;
  --c-rfid: #b48fd9;
  --c-pin: #ef9fc0;
  --c-manual: #7ccbb8;

  --ok: #2f9e6e;
  --ok-bg: #e6f6ee;
  --warn: #d98a1c;
  --warn-bg: #fdf3e2;
  --err: #d3455b;
  --err-bg: #fce9ec;
  --info: #7a5bb0;
  --info-bg: #f1ebfa;

  --radius: 18px;
  --shadow: 0 1px 2px rgba(44, 26, 69, .04), 0 8px 24px rgba(44, 26, 69, .06);
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; }
html { height: 100%; }
body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  display: flex;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--grape); }
.muted { color: var(--ink-2); }
.tiny { font-size: 12px; color: var(--ink-3); }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 250px; flex-shrink: 0; height: 100vh; position: sticky; top: 0;
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 16px;
}
.brand { padding: 4px 8px 18px; border-bottom: 1px dashed var(--line); margin-bottom: 14px; }
.brand img { width: 100%; max-width: 170px; display: block; margin: 0 auto; }
#nav { display: flex; flex-direction: column; gap: 4px; }
#nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
  text-decoration: none; color: var(--ink-2); font-weight: 700; transition: background .15s, color .15s;
}
#nav a svg { width: 20px; height: 20px; flex-shrink: 0; }
#nav a:hover { background: var(--lilac-50); color: var(--grape); }
#nav a.active { background: var(--lilac-100); color: var(--grape); }
#nav a .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; padding-top: 14px; }

/* ---------- Main ---------- */
main { flex: 1; min-width: 0; padding: 26px 34px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.topbar h1 { font-family: var(--display); font-size: 32px; margin: 0; color: var(--grape-900); letter-spacing: -.01em; }
.topbar p { margin: 4px 0 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.clock { text-align: right; line-height: 1.1; }
.clock span { font-size: 26px; font-weight: 800; color: var(--grape); font-variant-numeric: tabular-nums; }
.clock small { display: block; color: var(--ink-3); font-weight: 600; }

.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Pills, badges, chips ---------- */
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-on { background: var(--ok-bg); color: var(--ok); }
.pill-on .dot { animation: pulse 1.8s infinite; }
.pill-off { background: var(--err-bg); color: var(--err); }
.conn { padding: 9px 16px 9px 13px; font-size: 14.5px; font-weight: 800; gap: 10px; cursor: default; transition: background .3s, color .3s; }
.conn .dot { width: 10px; height: 10px; box-shadow: 0 0 0 4px rgba(255,255,255,.65); }
.conn.pill-on .dot { animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(47,158,110,.5); } 70% { box-shadow: 0 0 0 7px rgba(47,158,110,0); } 100% { box-shadow: 0 0 0 0 rgba(47,158,110,0); } }

.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--grape); color: #fff; font-size: 12px; font-weight: 800; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.chip svg { width: 14px; height: 14px; }
.chip-fingerprint { background: #ece4f6; color: var(--c-fingerprint); }
.chip-rfid { background: #f3ecfb; color: #8a63bd; }
.chip-pin { background: #fdeef4; color: #c4527f; }
.chip-manual { background: #e7f6f2; color: #2f8a74; }
.chip-in { background: var(--ok-bg); color: var(--ok); }
.chip-out { background: #f0edf3; color: var(--ink-2); }
.chip-late { background: var(--warn-bg); color: var(--warn); }
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-info { background: var(--info-bg); color: var(--info); }
.chip-warn { background: var(--warn-bg); color: var(--warn); }
.chip-error { background: var(--err-bg); color: var(--err); }
.chip-ghost { background: var(--lilac-50); color: var(--ink-3); border: 1px dashed var(--lilac-300); }

/* ---------- Cards & grid ---------- */
.grid { display: grid; gap: 20px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-12 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.mt { margin-top: 20px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; border: 1px solid rgba(236, 228, 244, .6); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 16px; font-weight: 800; color: var(--grape-900); }
.card-head .tiny { font-weight: 600; }

/* Hero */
.hero {
  position: relative; overflow: hidden; border-radius: 24px; padding: 28px 30px; color: #fff;
  background: radial-gradient(120% 140% at 100% 0%, #8b63c0 0%, var(--grape) 45%, var(--grape-900) 100%);
  display: flex; align-items: center; justify-content: space-between; gap: 20px; box-shadow: 0 14px 34px rgba(74, 45, 112, .28);
}
.hero h2 { font-family: var(--display); font-size: 30px; margin: 0 0 6px; }
.hero p { margin: 0; opacity: .85; font-weight: 600; }
.hero .big { font-size: 54px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.hero .big small { font-size: 20px; opacity: .7; font-weight: 700; }
.hero-stat { text-align: right; position: relative; z-index: 1; }
.hero-stat .tiny { color: rgba(255,255,255,.75); font-size: 13px; font-weight: 700; }
.sprinkle { position: absolute; border-radius: 999px; opacity: .55; }

/* KPI */
.kpi { display: flex; align-items: center; gap: 16px; }
.kpi-icon { width: 50px; height: 50px; border-radius: 15px; display: grid; place-items: center; flex-shrink: 0; }
.kpi-icon svg { width: 24px; height: 24px; }
.kpi-val { font-size: 30px; font-weight: 800; line-height: 1; color: var(--grape-900); font-variant-numeric: tabular-nums; }
.kpi-lbl { color: var(--ink-2); font-weight: 700; font-size: 13.5px; margin-top: 4px; }
.kpi-sub { font-size: 12px; color: var(--ink-3); font-weight: 600; }

/* Listas */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); min-width: 0; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 12.5px; color: var(--ink-3); font-weight: 600; }
.row .time { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--grape-900); }
.row.new { animation: flash 1.6s ease; }
@keyframes flash { 0% { background: var(--lilac-100); } 100% { background: transparent; } }
.scroll { max-height: 380px; overflow: auto; margin: 0 -6px; padding: 0 6px; }

.avatar { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; color: #fff; flex-shrink: 0; font-size: 14px; letter-spacing: .02em; }
.avatar.lg { width: 64px; height: 64px; border-radius: 20px; font-size: 22px; }
.avatar.sm { width: 32px; height: 32px; border-radius: 10px; font-size: 12px; }

.empty { text-align: center; padding: 34px 10px; color: var(--ink-3); font-weight: 600; }
.empty .emoji { width: 52px; height: 52px; border-radius: 16px; background: var(--lilac-100); color: var(--grape); display: grid; place-items: center; margin: 0 auto 12px; }
.empty .emoji svg { width: 24px; height: 24px; }
.hint-ico { width: 42px; height: 42px; border-radius: 13px; background: #fff; color: var(--grape); display: grid; place-items: center; flex-shrink: 0; }
.hint-ico svg { width: 22px; height: 22px; }

/* Gráficos */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-family: var(--font); fill: var(--ink-3); font-size: 11px; font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.donut-wrap { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 18px 22px; }
.donut-wrap .legend { flex: 1 1 140px; min-width: 0; max-width: 220px; }
.donut-wrap .legend { flex-direction: column; gap: 10px; }
.donut-wrap .legend b { margin-left: auto; color: var(--grape-900); padding-left: 14px; }
.donut-wrap .legend div { display: flex; align-items: center; }

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid transparent; background: var(--grape); color: #fff; font-weight: 800;
  cursor: pointer; transition: transform .08s, background .15s, box-shadow .15s; white-space: nowrap; text-decoration: none; font-size: 14px;
}
.btn:hover { background: var(--grape-700); box-shadow: 0 6px 16px rgba(91, 58, 134, .25); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn svg { width: 17px; height: 17px; }
.btn-soft { background: var(--lilac-100); color: var(--grape); }
.btn-soft:hover { background: #e8dcf6; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { background: var(--lilac-50); box-shadow: none; color: var(--grape); }
.btn-danger { background: var(--err-bg); color: var(--err); }
.btn-danger:hover { background: #f8d6dc; box-shadow: none; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 10px; }
.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 10px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 12.5px; font-weight: 800; color: var(--ink-2); }
.input, select.input, textarea.input {
  padding: 10px 13px; border-radius: 12px; border: 1px solid var(--line); background: #fff; outline: none;
  transition: border .15s, box-shadow .15s; min-width: 0; width: 100%;
}
.input:focus { border-color: var(--lilac); box-shadow: 0 0 0 4px var(--lilac-100); }
textarea.input { resize: vertical; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; color: var(--ink-3); }
.search .input { padding-left: 38px; width: 260px; }

.seg { display: inline-flex; background: var(--lilac-100); padding: 4px; border-radius: 13px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 10px; font-weight: 800; color: var(--ink-2); cursor: pointer; font-size: 13.5px; }
.seg button.on { background: #fff; color: var(--grape); box-shadow: 0 1px 4px rgba(44,26,69,.1); }

.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #ddd3e8; cursor: pointer; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--grape); }
.switch input:checked + span::before { transform: translateX(18px); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; margin: 0 -22px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 800; padding: 10px 22px; border-bottom: 1px solid var(--line); background: var(--lilac-50); white-space: nowrap; }
td { padding: 11px 22px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fcfaff; }
td .person { display: flex; align-items: center; gap: 10px; font-weight: 800; }

/* ---------- Empleados ---------- */
.emp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 18px; }
.emp-card { cursor: pointer; transition: transform .15s, box-shadow .15s; display: flex; flex-direction: column; gap: 14px; }
.emp-card:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(44, 26, 69, .1); }
.emp-card.inactive { opacity: .55; }
.emp-top { display: flex; align-items: center; gap: 12px; }
.emp-top .grow { flex: 1; min-width: 0; }
.emp-top .name { font-weight: 800; font-size: 16px; }
.emp-creds { display: flex; flex-wrap: wrap; gap: 6px; }
.emp-foot { display: flex; align-items: center; justify-content: space-between; border-top: 1px dashed var(--line); padding-top: 12px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

.cred-box { border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.cred-box h4 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
.cred-box h4 .ico { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; }
.cred-box h4 .ico svg { width: 17px; height: 17px; }
.cred-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--lilac-50); border-radius: 10px; padding: 6px 6px 6px 12px; font-weight: 700; font-size: 13.5px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline .input { flex: 1; }
.waiting { display: flex; align-items: center; gap: 10px; background: var(--info-bg); color: var(--info); border-radius: 12px; padding: 10px 12px; font-weight: 700; font-size: 13px; }
.spinner { width: 16px; height: 16px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Dispositivos ---------- */
.dev-card { display: flex; flex-direction: column; gap: 14px; }
.dev-head { display: flex; align-items: center; gap: 12px; }
.dev-head .ico { width: 48px; height: 48px; border-radius: 15px; background: var(--lilac-100); color: var(--grape); display: grid; place-items: center; }
.dev-head .ico svg { width: 26px; height: 26px; }
.dev-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.dev-stats div { background: var(--lilac-50); border-radius: 12px; padding: 10px 12px; }
.dev-stats b { display: block; font-size: 15px; color: var(--grape-900); }
.dev-stats span { font-size: 12px; color: var(--ink-3); font-weight: 700; }
.motion { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 13.5px; color: var(--ink-2); }
.motion .radar { width: 12px; height: 12px; border-radius: 50%; background: #d8cfe2; }
.motion.live .radar { background: var(--c-pin); animation: radar 1.2s infinite; }
@keyframes radar { 0% { box-shadow: 0 0 0 0 rgba(239,159,192,.7); } 100% { box-shadow: 0 0 0 14px rgba(239,159,192,0); } }

/* ---------- Eventos ---------- */
.ev { display: grid; grid-template-columns: 76px 92px 1fr auto; gap: 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.ev:last-child { border-bottom: 0; }
.ev .when { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 13px; color: var(--ink-2); }
.ev .msg { font-weight: 700; min-width: 0; }
.ev .msg small { display: block; font-weight: 600; color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev pre { grid-column: 1 / -1; margin: 0; background: var(--grape-900); color: #e9ddf8; padding: 12px 14px; border-radius: 12px; overflow: auto; font-size: 12.5px; }
.ev.new { animation: flash 1.6s ease; }

/* ---------- Simulador ---------- */
.code {
  background: var(--grape-900); color: #eadff8; border-radius: 14px; padding: 14px 16px; font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12.5px; white-space: pre-wrap; word-break: break-all; position: relative; margin: 0;
}
.code .k { color: #f3a9c8; }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0 6px; font-size: 12px; font-weight: 800; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.topic { background: var(--lilac-100); color: var(--grape); padding: 8px 12px; border-radius: 10px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; font-weight: 700; word-break: break-all; }
.sim-card { display: flex; flex-direction: column; gap: 12px; }
.sim-card .btn { align-self: flex-start; }
.hint { background: var(--lilac-50); border: 1px dashed var(--lilac-300); border-radius: 14px; padding: 12px 14px; font-size: 13.5px; color: var(--ink-2); font-weight: 600; }
.hint b { color: var(--grape); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(44, 26, 69, .38); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fadein .15s; }
@keyframes fadein { from { opacity: 0; } }
.modal { background: #fff; border-radius: 24px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 30px 60px rgba(44,26,69,.25); animation: pop .2s ease; }
.modal.wide { max-width: 820px; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.modal-head h3 { margin: 0; font-family: var(--display); font-size: 22px; color: var(--grape-900); }
.modal-body { padding: 18px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 24px 22px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast { display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 16px; padding: 12px 16px 12px 12px; box-shadow: 0 14px 34px rgba(44,26,69,.18); min-width: 280px; max-width: 380px; animation: slide .3s ease; border-left: 4px solid var(--grape); }
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--err); }
.toast .t-title { font-weight: 800; }
.toast .t-sub { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.toast.out { opacity: 0; transform: translateX(20px); transition: .3s; }
@keyframes slide { from { opacity: 0; transform: translateX(30px); } }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .g-21 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .g-12 { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 20; flex-direction: row; align-items: center; padding: 10px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { border: 0; margin: 0; padding: 0; }
  .brand img { width: 74px; }
  #nav { flex-direction: row; overflow-x: auto; flex: 1; }
  #nav a { padding: 9px 11px; }
  #nav a span.lbl { display: none; }
  main { padding: 20px 16px 50px; }
  .g-21, .g-12, .g-2, .g-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .g-4 { grid-template-columns: minmax(0, 1fr); }
  .hero { flex-direction: column; align-items: flex-start; }
  .hero-stat { text-align: left; }
  .topbar h1 { font-size: 26px; }
  .clock { display: none; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .search .input { width: 100%; }
  .ev { grid-template-columns: 64px 1fr; }
  .ev > :nth-child(2), .ev > :nth-child(4) { display: none; }
}
