:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #64717f;
  --line: #dbe2ea;
  --primary: #1864ab;
  --primary-dark: #124f86;
  --accent: #2f9e44;
  --danger: #b42318;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(420px, calc(100vw - 32px));
}

.login-panel,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  font-weight: 700;
}

h1, h2, p { margin-top: 0; }
p { color: var(--muted); }

.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
input, select, button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
}
button {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  cursor: pointer;
}
button:hover { background: var(--primary-dark); }
button.secondary {
  background: white;
  color: var(--primary);
}
button.secondary:hover { background: #eef6ff; }
button.small-btn {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
}
button.danger-btn {
  background: var(--danger);
  border-color: var(--danger);
}
.row-actions {
  display: flex;
  gap: 6px;
}
.error { min-height: 20px; color: var(--danger); }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
}

.mobile-topbar,
.sidebar-overlay {
  display: none;
}

.sidebar {
  background: #18212b;
  color: white;
  padding: 18px 12px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.brand {
  font-size: 20px;
  font-weight: 700;
  padding: 8px 10px 18px;
}

.nav {
  background: transparent;
  color: #d7dee8;
  border: 0;
  text-align: left;
}
.nav.active,
.nav:hover {
  background: #243447;
  color: white;
}
.nav.muted { margin-top: 18px; color: #aeb8c5; }

.main { padding: 22px; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}
.topbar h1 { margin-bottom: 4px; font-size: 28px; }
.badge {
  border: 1px solid var(--line);
  background: white;
  padding: 8px 10px;
  border-radius: 6px;
}

.view { display: none; }
.view.active { display: block; }
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.metric {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.metric b { display: block; font-size: 28px; margin-top: 8px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar input,
.toolbar select { min-width: 160px; }
.panel { margin-bottom: 12px; }
.dashboard-filters {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1.25fr) minmax(320px, 0.75fr);
  gap: 12px;
}
.chart-panel h2,
.dashboard-layout h2 {
  font-size: 16px;
  margin-bottom: 12px;
}
.bar-chart {
  display: grid;
  gap: 8px;
}
.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 190px) 1fr 44px;
  gap: 8px;
  align-items: center;
  min-height: 24px;
}
.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.bar-track {
  height: 16px;
  background: #eef2f6;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: #2f9e44;
}
.bar-value {
  text-align: right;
  font-weight: 700;
  font-size: 13px;
}
.daily-chart {
  min-height: 178px;
  display: flex;
  gap: 6px;
  align-items: end;
  overflow-x: auto;
  padding-top: 8px;
}
.day-bar {
  min-width: 34px;
  display: grid;
  justify-items: center;
  gap: 4px;
}
.day-value {
  font-size: 11px;
  color: var(--muted);
}
.day-fill {
  width: 22px;
  background: #1864ab;
  border-radius: 4px 4px 0 0;
}
.day-label {
  font-size: 11px;
  color: var(--muted);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
.empty-state {
  color: var(--muted);
  padding: 12px 0;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.settings-panel {
  max-width: 760px;
}
.settings-panel .form-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-items: end;
}
.settings-panel label input {
  width: 100%;
}
.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  color: var(--text);
}
.inline-check input {
  width: 16px;
  height: 16px;
}
.status-line {
  min-height: 18px;
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--accent);
}
.status-line.error { color: var(--danger); }

.table-wrap {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
th { background: #eef2f6; color: #344152; }
.group-row td {
  background: #dfeaf5;
  color: #124f86;
  font-weight: 700;
  font-size: 15px;
}
.subtotal-row td {
  background: #f7f9fb;
  color: #2f3b47;
  font-weight: 700;
  border-bottom: 2px solid #cbd5df;
}
.late-time {
  color: var(--danger);
  font-weight: 700;
}
.late-minutes {
  display: inline-block;
  margin-left: 6px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}
pre {
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
}

@media print {
  .sidebar,
  .topbar,
  .toolbar,
  .view:not(#query8) {
    display: none !important;
  }
  body { background: white; }
  .app-shell { display: block; }
  .main { padding: 0; }
  #query8 { display: block !important; }
  .table-wrap { border: 0; overflow: visible; }
  th, td { white-space: normal; font-size: 11px; padding: 5px; }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
    padding-top: 56px;
  }
  .mobile-topbar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 8;
    height: 56px;
    display: grid;
    grid-template-columns: 44px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 8px 12px;
    background: #18212b;
    color: white;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18);
  }
  .menu-button {
    width: 40px;
    height: 40px;
    display: grid;
    place-content: center;
    gap: 5px;
    padding: 0;
    border-color: rgba(255, 255, 255, 0.22);
    background: #243447;
    border-radius: 6px;
  }
  .menu-button span {
    width: 18px;
    height: 2px;
    background: white;
    border-radius: 2px;
  }
  .mobile-brand {
    font-size: 18px;
    font-weight: 700;
  }
  .mobile-user {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #d7dee8;
    font-size: 12px;
  }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    width: min(280px, 82vw);
    display: grid;
    grid-template-columns: 1fr;
    align-content: start;
    transform: translateX(-105%);
    transition: transform 160ms ease;
    box-shadow: 14px 0 30px rgba(15, 23, 42, 0.22);
  }
  body.menu-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 9;
    display: none;
    background: rgba(15, 23, 42, 0.45);
  }
  body.menu-open .sidebar-overlay {
    display: block;
  }
  .dashboard-layout { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: minmax(80px, 120px) 1fr 36px; }
  .main { padding: 14px; }
  .topbar {
    align-items: flex-start;
    margin-bottom: 12px;
  }
  .topbar h1 { font-size: 24px; }
  .topbar .badge { display: none; }
  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .toolbar input,
  .toolbar select,
  .toolbar button,
  .form-grid input,
  .form-grid select,
  .form-grid button {
    width: 100%;
    min-width: 0;
  }
  .panel {
    padding: 14px;
  }
  .overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .metric {
    padding: 12px;
  }
  .metric b {
    font-size: 22px;
  }
  table {
    min-width: 680px;
    font-size: 13px;
  }
  th,
  td {
    padding: 8px;
  }
  .login-body {
    align-items: start;
    padding-top: 44px;
  }
  .login-panel {
    padding: 18px;
  }
}

@media (max-width: 420px) {
  .overview-grid {
    grid-template-columns: 1fr;
  }
  .topbar {
    display: block;
  }
}
