:root {
  --bg: #f6f7f9;
  --ink: #1b1f24;
  --muted: #667085;
  --line: #d8dee7;
  --panel: #ffffff;
  --accent: #16735f;
  --warn: #b15c00;
  --bad: #b42318;
  --sidebar-bg: #11181f;
  --sidebar-ink: #eef2f7;
  --sidebar-muted: #aeb8c4;
  --sidebar-active: #22313d;
  
  --success: #027a48;
  --warning: #b54708;
  --danger: #b42318;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --ink: #c9d1d9;
  --muted: #8b949e;
  --line: #30363d;
  --panel: #161b22;
  --accent: #2ea043;
  --warn: #d29922;
  --bad: #da3633;
  --sidebar-bg: #0b1218;
  --sidebar-ink: #f1f5f9;
  --sidebar-muted: #9aa3af;
  --sidebar-active: #1f2a37;
  
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  display: grid;
  grid-template-columns: 260px 1fr;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body.kiosk-mode {
  grid-template-columns: 1fr;
}

#sidebar, .sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  padding: 22px;
  min-height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 32px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #37b38f;
  display: grid;
  place-items: center;
  color: #092018;
  font-weight: 800;
}
.brand small { display: block; color: var(--sidebar-muted); margin-top: 2px; }
nav { display: grid; gap: 8px; }
.nav, button {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 10px 13px;
  font: inherit;
  cursor: pointer;
}
.nav { text-align: left; background: transparent; color: var(--sidebar-muted); }
.nav.active, .nav:hover { background: var(--sidebar-active); color: var(--sidebar-ink); }

main { padding: 24px; overflow: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
h1, h2, p { margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }
#clock { color: var(--muted); margin-top: 4px; }
.top-banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(178, 35, 24, 0.12), rgba(22, 115, 95, 0.08));
  color: var(--ink);
  font-weight: 700;
}
.top-banner.info { border-color: rgba(22, 115, 95, 0.25); }
.top-banner.warn { border-color: rgba(177, 92, 0, 0.35); }
.top-banner.error { border-color: rgba(180, 35, 24, 0.35); background: linear-gradient(90deg, rgba(180, 35, 24, 0.18), rgba(180, 35, 24, 0.08)); }
.status-pill {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--accent);
  font-weight: 700;
}
.view { display: none; }
.view.active { display: block; }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.metric { padding: 18px; }
.metric span { color: var(--muted); }
.metric strong { display: block; font-size: 36px; margin-top: 8px; }
.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, .8fr);
  gap: 16px;
}
.panel { padding: 18px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
button {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
button:hover { filter: brightness(.94); }
button.secondary { background: #405261; }
button.danger { background: var(--bad); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 700; font-size: 13px; }
.status-badge {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
}
.status-badge.on_time { background: #daf8ec; color: #12664f; }
.status-badge.late { background: #fff1d6; color: var(--warn); }
.status-badge.not_come { background: #fee4e2; color: var(--bad); }
.badge { padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.badge.on_time { background: #daf8ec; color: #12664f; }
.badge.late { background: #fff1d6; color: var(--warn); }
.badge.not_come { background: #fee4e2; color: var(--bad); }
.event-log { display: grid; gap: 8px; max-height: 480px; overflow: auto; }
.event {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--panel);
  color: var(--ink);
}
.scanner-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 360px;
  gap: 16px;
  max-width: 1040px;
  margin: 0 auto;
}
.camera-panel {
  background: #101820;
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 12px;
}
video {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 6px;
  object-fit: cover;
}
canvas { display: none; }
.scan-actions, .inline-action, .segmented, .button-row, .inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
select, input, textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  font: inherit;
  background: var(--panel);
  color: var(--ink);
}
textarea {
  min-height: 96px;
  resize: vertical;
}
.result-box {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  min-height: 120px;
}
.form-grid { display: grid; gap: 10px; }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 700; }
label input, label select { color: var(--ink); font-weight: 400; }
.check { display: flex; align-items: center; gap: 8px; }
.cards { display: grid; gap: 10px; }
.employee-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.employee-card small { color: var(--muted); display: block; margin-top: 3px; }
.inline-action { margin-top: 14px; }
.inline-action input { flex: 1; min-width: 220px; }
.whatsapp-grid {
  display: grid;
  grid-template-columns: minmax(320px, .9fr) minmax(360px, 1.1fr);
  gap: 16px;
}
.wide-panel { grid-column: 1 / -1; }
.connection-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.connection-details div {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--panel);
  min-width: 0;
}
.connection-details span { display: block; color: var(--muted); font-size: 12px; }
.connection-details strong { display: block; overflow-wrap: anywhere; margin-top: 4px; }
.qr-box, .pairing-box {
  margin-top: 14px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  min-height: 72px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}
.qr-box img { max-width: 240px; width: 100%; height: auto; }
.pairing-code {
  font-size: 28px;
  letter-spacing: 0;
  color: var(--ink);
}
.table-list, .route-list {
  display: grid;
  gap: 8px;
}
.table-row, .route-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}
.route-row {
  grid-template-columns: minmax(160px, 1fr) minmax(220px, 1fr) repeat(5, auto) auto;
}
.table-row small, .route-row small { color: var(--muted); overflow-wrap: anywhere; }
.route-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
}
.compact-log { max-height: 260px; }
pre {
  white-space: pre-wrap;
  background: #11181f;
  color: #e8eef5;
  border-radius: 8px;
  padding: 16px;
  min-height: 420px;
  overflow: auto;
}
.settings-panel { max-width: 760px; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 12px;
}
.cal-day {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  min-height: 60px;
  padding: 4px;
  position: relative;
  font-size: 11px;
}
.cal-header {
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding: 8px 0;
}
.cal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  position: absolute;
  bottom: 6px;
  right: 6px;
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
  nav { grid-template-columns: repeat(2, 1fr); }
  .metric-grid, .two-col, .scanner-layout, .whatsapp-grid, .connection-details, .table-row, .route-row { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; gap: 12px; flex-direction: column; }
}

@media (max-width: 720px) {
  table.responsive thead {
    display: none;
  }
  table.responsive,
  table.responsive tbody,
  table.responsive tr,
  table.responsive td {
    display: block;
    width: 100%;
  }
  table.responsive tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: var(--panel);
  }
  table.responsive td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border: none;
  }
  table.responsive td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
  }
}
