:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --track: #efeee9;
  --accent: #2a78d6;
  --series-cpu: #2a78d6;
  --series-mem: #eb6834;
  --series-disk: #1baf7a;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --good-text: #006300;
  --warning-text: #8a5a00;
  --critical-text: #b42f2f;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --track: #2c2c2a;
    --accent: #3987e5;
    --series-cpu: #3987e5;
    --series-mem: #d95926;
    --series-disk: #199e70;
    --good-text: #0ca30c;
    --warning-text: #fab219;
    --critical-text: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --track: #2c2c2a;
  --accent: #3987e5;
  --series-cpu: #3987e5;
  --series-mem: #d95926;
  --series-disk: #199e70;
  --good-text: #0ca30c;
  --warning-text: #fab219;
  --critical-text: #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

button, input { font: inherit; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login {
  width: 100%;
  max-width: 360px;
  padding: 32px 28px;
}

.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { margin: 0 0 24px; color: var(--text-2); }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  color: var(--text);
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn-primary {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }

.error {
  display: none;
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--critical-text);
  border: 1px solid var(--critical);
}

/* ---------- Dashboard ---------- */

.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}
.topbar h1 { font-size: 22px; margin: 0; }
.topbar .sub { color: var(--text-2); font-size: 14px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.live.offline .live-dot { background: var(--critical); }

.btn-ghost {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); background: var(--track); }

.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.tile { padding: 20px; }
.tile-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tile-label { font-size: 14px; color: var(--text-2); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tile-value { font-size: 36px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.tile-value small { font-size: 18px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.tile-detail { font-size: 13px; color: var(--text-2); margin-top: 4px; min-height: 19px; }

.meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; margin-top: 14px; }
.meter-fill { height: 100%; border-radius: 3px; width: 0; transition: width 0.4s ease; }

.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.status svg { width: 14px; height: 14px; }
.status.good { color: var(--good-text); }
.status.warning { color: var(--warning-text); }
.status.critical { color: var(--critical-text); }

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-head h2 { font-size: 16px; margin: 0; }

.ranges { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.ranges button {
  padding: 6px 14px;
  border: 0;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.ranges button:last-child { border-right: 0; }
.ranges button:hover { color: var(--text); background: var(--track); }
.ranges button[aria-pressed="true"] { color: #fff; background: var(--accent); font-weight: 600; }

.charts { display: grid; gap: 16px; }
.chart-card { padding: 16px 20px 12px; }
.chart-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.chart-title h3 { font-size: 14px; margin: 0; display: flex; align-items: center; gap: 8px; }
.chart-title .stats { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.chart-box { position: relative; height: 220px; }
.empty {
  position: absolute; inset: 0;
  display: none; place-items: center;
  color: var(--muted); font-size: 14px;
}

.footer-info { margin-top: 24px; font-size: 13px; color: var(--muted); }

@media (max-width: 860px) {
  .tiles { grid-template-columns: 1fr; }
  .chart-box { height: 180px; }
}

.ranges button { white-space: nowrap; }

@media (max-width: 520px) {
  .ranges { display: flex; width: 100%; }
  .ranges button { flex: 1; padding: 6px 4px; font-size: 14px; }
}

/* ---------- Projects ---------- */

:root {
  --cat-1: #2a78d6; --cat-2: #eb6834; --cat-3: #1baf7a; --cat-4: #eda100;
  --cat-5: #e87ba4; --cat-6: #008300; --cat-7: #4a3aa7; --cat-8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500;
    --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9; --cat-8: #e66767;
  }
}
:root[data-theme="dark"] {
  --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500;
  --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9; --cat-8: #e66767;
}

#projects-section { margin-bottom: 24px; }

.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }

table.projects { width: 100%; border-collapse: collapse; font-size: 14px; }
.projects th, .projects td { padding: 12px 14px; text-align: left; white-space: nowrap; vertical-align: top; }
.projects th {
  font-size: 12px; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.projects td { border-bottom: 1px solid var(--border); }
.projects tr:last-child td { border-bottom: 0; }
.projects .num { text-align: right; font-variant-numeric: tabular-nums; }
.projects .name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.projects .sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.projects .sub a { color: inherit; }
.projects .muted { color: var(--muted); }
.projects .commit { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.badge {
  font-size: 11px; font-weight: 600; color: var(--text-2);
  border: 1px solid var(--border); border-radius: 4px; padding: 0 5px;
}

.section-head.sticky {
  position: sticky; top: 0; z-index: 5;
  background: var(--page);
  padding: 10px 0; margin-bottom: 2px;
}

.group-title { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 8px 0 0; text-transform: uppercase; letter-spacing: 0.04em; }
.project-charts { margin-top: 16px; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 8px; font-size: 13px; color: var(--text-2); }
.legend:empty { display: none; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  margin: -8px 0 24px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  color: var(--text-2);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.tab-alert { display: inline-flex; color: var(--critical-text); }
.tab-alert svg { width: 14px; height: 14px; }

/* ---------- Project view ---------- */

.project-head { margin-bottom: 16px; }
.project-head h2 { font-size: 20px; margin: 0; display: flex; align-items: center; gap: 10px; }
.project-head .swatch { width: 12px; height: 12px; }
.project-head .sub { color: var(--text-2); font-size: 14px; margin-top: 4px; }
.project-head .sub a { color: inherit; }

.tiles-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile.compact { padding: 16px 18px; }
.tile.compact .tile-value { font-size: 26px; min-height: 29px; }
.tile.compact .tile-value small { font-size: 15px; }
.tile.compact .tile-detail { font-size: 12px; }
.tile-line { margin-top: 6px; }
.commit-title {
  display: block;
  font-size: 15px; font-weight: 600; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding-top: 6px;
}

.projects a.name { color: var(--text); text-decoration: none; }
.projects a.name:hover { text-decoration: underline; }
.projects .sub .badge { margin-right: 4px; }

@media (max-width: 1000px) {
  .tiles-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .tiles-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile.compact { padding: 12px 14px; }
  .tile.compact .tile-value { font-size: 22px; }
}
