* { box-sizing: border-box; }

:root {
  --bg: #f6f7fb;
  --text: #121826;
  --muted: #64748b;
  --topbar-bg: #0f172a;
  --topbar-text: #ffffff;
  --topbar-sub: #b7c3df;
  --panel-bg: #ffffff;
  --panel-border: #e4e9f3;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e5e9f2;
  --tab-bg: #eef2ff;
  --tab-text: #1e293b;
  --tab-active-bg: #2563eb;
  --tab-active-text: #ffffff;
  --input-bg: #ffffff;
  --input-border: #d0d7e2;
  --table-head-bg: #f8fafc;
  --table-row-alt: #fcfdff;
  --table-hover: #f1f5ff;
  --day-bg: #fefefe;
  --blank-bg: #f3f6fb;
  --blank-border: #e6ecf5;
  --primary: #2563eb;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --text: #e5e7eb;
  --muted: #9aa7bd;
  --topbar-bg: #020617;
  --topbar-text: #e2e8f0;
  --topbar-sub: #94a3b8;
  --panel-bg: #0f172a;
  --panel-border: #1e293b;
  --sidebar-bg: #0f172a;
  --sidebar-border: #1e293b;
  --tab-bg: #172036;
  --tab-text: #cbd5e1;
  --tab-active-bg: #3b82f6;
  --tab-active-text: #eaf2ff;
  --input-bg: #0b1220;
  --input-border: #334155;
  --table-head-bg: #111827;
  --table-row-alt: #101a2d;
  --table-hover: #1a2740;
  --day-bg: #0b1326;
  --blank-bg: #0c1425;
  --blank-border: #1f2a3f;
  --primary: #60a5fa;
}

body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); }

button, input, select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
}

button {
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
}
button:hover { opacity: .92; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
}
.topbar h1 { margin: 0; font-size: 22px; }
.topbar p { margin: 4px 0 0; color: var(--topbar-sub); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.sync-status {
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid #334155;
  border-radius: 999px;
  padding: 4px 10px;
}

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 84px); }
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tab { text-align: left; background: var(--tab-bg); color: var(--tab-text); }
.sidebar .tab { width: 100%; }
.tab.active { background: var(--tab-active-bg); color: var(--tab-active-text); }
.content { padding: 14px; }
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.kpi { background: color-mix(in oklab, var(--panel-bg) 90%, #5b7dbd 10%); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px; }
.kpi h4 { margin: 0; font-size: 12px; color: var(--muted); }
.kpi strong { font-size: 22px; }

.table-wrap { overflow: auto; border: 1px solid var(--panel-border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
th, td { padding: 9px; border-bottom: 1px solid var(--panel-border); text-align: left; }
th { font-weight: 700; color: var(--text); background: var(--table-head-bg); position: sticky; top: 0; z-index: 1; }
tbody tr:nth-child(even) { background: var(--table-row-alt); }
tbody tr:hover { background: var(--table-hover); }

.inline-controls { margin: 0 0 12px 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-controls label { font-size: 13px; color: var(--muted); }
#weekly-stats { margin-bottom: 12px; }

.weekly-nav {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px 0;
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: color-mix(in oklab, var(--panel-bg) 88%, #6da5ff 12%);
}
.week-arrow {
  width: 40px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  color: var(--primary);
  font-weight: 700;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}
.week-arrow:hover { background: var(--table-hover); }
.week-label { text-align: center; font-weight: 700; color: var(--text); letter-spacing: 0.2px; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.weekday-cell {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 6px 4px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: color-mix(in oklab, var(--panel-bg) 92%, #5678aa 8%);
}
.day-cell { min-height: 94px; border: 1px solid var(--panel-border); border-radius: 10px; background: var(--day-bg); padding: 6px; font-size: 12px; }
.day-cell.good { background: #dcfce7; color: #14532d; }
.day-cell.mid { background: #fef3c7; color: #78350f; }
.day-cell.bad { background: #fee2e2; color: #7f1d1d; }
html[data-theme="dark"] .day-cell.good { background: #133b2a; color: #b8ffd7; }
html[data-theme="dark"] .day-cell.mid { background: #3f3111; color: #ffe6a7; }
html[data-theme="dark"] .day-cell.bad { background: #3f1b1b; color: #ffc9c9; }
.day-cell.blank {
  background: var(--blank-bg);
  border-style: dashed;
  border-color: var(--blank-border);
  min-height: 70px;
}
.day-num { font-weight: 700; margin-bottom: 4px; }
.day-total { font-size: 11px; margin-bottom: 4px; }
.day-lines { display: grid; gap: 2px; max-height: 90px; overflow: auto; padding-right: 2px; }
.day-line { font-size: 11px; line-height: 1.25; }
.day-empty { color: var(--muted); font-style: italic; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stack-form { display: grid; gap: 8px; margin-bottom: 12px; }
.stack-form input,
.stack-form select { width: 100%; }
.stack-form button { justify-self: start; width: auto; min-width: 160px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list li { border: 1px solid var(--panel-border); background: var(--panel-bg); border-radius: 10px; padding: 8px; }

.alert-item { border-left: 5px solid #94a3b8 !important; background: #ffffff !important; }
.alert-item.high { border-left-color: #dc2626 !important; background: #fef2f2 !important; }
.alert-item.medium { border-left-color: #d97706 !important; background: #fff7ed !important; }
.alert-item.low { border-left-color: #2563eb !important; background: #eff6ff !important; }
html[data-theme="dark"] .alert-item { background: #0f172a !important; color: #e5e7eb; }
html[data-theme="dark"] .alert-item.high { background: #3d1d1d !important; }
html[data-theme="dark"] .alert-item.medium { background: #3f2f16 !important; }
html[data-theme="dark"] .alert-item.low { background: #152a45 !important; }
.alert-top { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.alert-account { font-weight: 800; color: var(--text); }
.alert-date { font-size: 12px; color: var(--muted); background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: 999px; padding: 2px 8px; }
.alert-severity { font-size: 11px; font-weight: 800; border-radius: 999px; padding: 2px 8px; }
.alert-severity.high { background: #fee2e2; color: #991b1b; }
.alert-severity.medium { background: #ffedd5; color: #9a3412; }
.alert-severity.low { background: #dbeafe; color: #1e3a8a; }
.alert-message { color: var(--text); font-weight: 600; line-height: 1.35; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; }
.badge.on_track { background: #dcfce7; color: #166534; }
.badge.at_risk { background: #fef3c7; color: #854d0e; }
.badge.missed { background: #fee2e2; color: #991b1b; }
html[data-theme="dark"] .badge.on_track { background: #143927; color: #bcf7cf; }
html[data-theme="dark"] .badge.at_risk { background: #3f3111; color: #ffe6a7; }
html[data-theme="dark"] .badge.missed { background: #3f1b1b; color: #ffd1d1; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.login-theme-toggle-wrap { position: fixed; top: 12px; right: 12px; z-index: 5; }
.login-card {
  width: min(420px, 96vw);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  display: grid;
  gap: 8px;
}
.error { color: #ef4444; font-size: 13px; }

pre { white-space: pre-wrap; max-height: 260px; overflow: auto; background: #0b1220; color: #dbeafe; padding: 10px; border-radius: 8px; }

dialog {
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  color: var(--text);
  border-radius: 12px;
  padding: 16px;
  width: min(680px, 96vw);
}
.hidden { display: none !important; }

.progress-wrap { display: grid; gap: 6px; }
.progress-label { font-size: 12px; color: var(--muted); }
.progress-bar { width: 100%; height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
html[data-theme="dark"] .progress-bar { background: #1f2d44; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #3b82f6, #2563eb); transition: width .25s ease; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    border-right: 0;
    border-bottom: 1px solid var(--sidebar-border);
  }
  .tab { white-space: nowrap; }
  .sidebar .tab { width: auto; flex: 0 0 auto; }
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .top-actions {
    justify-content: flex-start;
  }
  .content {
    padding: 10px;
  }
  .panel {
    padding: 10px;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .calendar-grid {
    gap: 6px;
  }
  .weekday-cell {
    font-size: 11px;
    padding: 4px 2px;
  }
  .day-cell {
    min-height: 84px;
    padding: 5px;
    font-size: 11px;
  }
}

@media (max-width: 420px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .top-actions > * {
    width: 100%;
  }
}
