:root {
  --bg: #f2f4f3;
  --surface: #ffffff;
  --ink: #1a2421;
  --muted: #5c6b66;
  --line: #e2e8e5;
  --accent: #0c7568;
  --accent-ink: #f4fffc;
  --ok: #1a7a46;
  --warn: #8a5a00;
  --danger: #a33b3b;
  --shadow: 0 1px 2px rgba(16, 28, 24, 0.04), 0 8px 24px rgba(16, 28, 24, 0.04);
  --sidebar: #10211e;
  --sidebar-ink: #e7f1ee;
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e1412;
  --surface: #171f1c;
  --ink: #e7eeeb;
  --muted: #9aada6;
  --line: #2a3833;
  --accent: #3cbeae;
  --accent-ink: #06211d;
  --ok: #8ed4ae;
  --warn: #e6c27a;
  --danger: #f0a8a8;
  --shadow: none;
  --sidebar: #0c1211;
  --sidebar-ink: #e7f1ee;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: 1rem; top: -4rem; }
.skip:focus { top: 1rem; background: var(--surface); padding: 0.4rem 0.7rem; z-index: 40; }

.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px; height: 100vh; position: sticky; top: 0;
  background: var(--sidebar); color: var(--sidebar-ink);
  padding: 1.15rem 0.85rem; display: flex; flex-direction: column; gap: 1.35rem;
}
.brand { display: flex; gap: 0.7rem; align-items: center; padding: 0.2rem 0.45rem; }
.brand strong { display: block; font-size: 0.98rem; font-weight: 700; }
.brand small { color: #b7c7c2; font-size: 0.75rem; }
.mark {
  width: 16px; height: 16px; flex: 0 0 16px; border: 2px solid #8fd0c8; border-radius: 50%;
  box-shadow: inset 0 0 0 3px var(--sidebar), 0 0 0 3px rgba(242, 212, 138, 0.25);
  background: #f2d48a;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.2rem; }
.sidebar a {
  text-decoration: none; min-height: 40px; padding: 0.45rem 0.75rem; border-radius: 10px;
  color: #d7e6e1; font-weight: 500; display: flex; align-items: center;
}
.sidebar a:hover { background: rgba(255, 255, 255, 0.06); }
.sidebar a[aria-current="page"] {
  background: rgba(60, 190, 174, 0.16); color: #fff;
  box-shadow: inset 3px 0 0 #3cbeae;
}

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 0.55rem 1rem;
  min-height: 64px; padding: 0.6rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.top-start, .top-actions, .time-form { display: flex; align-items: center; gap: 0.5rem; }
.top-start { flex: 1 1 16rem; min-width: 0; }
.top-actions { margin-inline-start: auto; }
.time-form { flex-wrap: wrap; min-width: 0; }
.time-form select { width: auto; min-width: 11rem; }
.who {
  color: var(--muted); font-size: 0.82rem; border: 1px solid var(--line);
  border-radius: 999px; padding: 0.2rem 0.7rem; line-height: 1.6;
}
#menu-btn { display: none; }
.burger, .burger::before, .burger::after {
  display: block; width: 16px; height: 2px; background: currentColor; border-radius: 2px; position: relative;
}
.burger::before, .burger::after { content: ""; position: absolute; left: 0; }
.burger::before { top: -5px; }
.burger::after { top: 5px; }

main {
  width: min(1180px, 100%);
  margin-inline: auto;
  padding: 1.35rem 1.5rem 2.5rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.page-head {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; gap: 0.8rem 1.25rem;
}
.page-head h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.page-head p, .muted { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.9rem; }
h2 { margin: 0; font-size: 1rem; font-weight: 650; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; justify-content: flex-end; }

input, select {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.45rem 0.65rem; min-height: 2.45rem; width: 100%;
}
select[multiple] { min-height: 9.5rem; }
.btn, .icon-btn {
  border: 1px solid transparent; background: var(--accent); color: var(--accent-ink);
  border-radius: 10px; padding: 0.42rem 0.85rem; cursor: pointer; min-height: 2.45rem;
  font-weight: 600; font-size: 0.9rem; white-space: nowrap;
}
.btn.ghost, .icon-btn { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.danger {
  background: transparent; color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost:hover, .icon-btn:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); filter: none; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); filter: none; }
.btn:focus-visible, .icon-btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
#modal-ok.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }

.cards, .split { display: grid; gap: 0.75rem; }
.cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card, .stat, .filters, .table-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 1rem 1rem 0.9rem; }
.card header { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.card .table-wrap { border: 0; box-shadow: none; border-radius: 0; background: transparent; }
.stat {
  padding: 0.85rem 1rem 0.8rem;
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem;
}
.stat-label { color: var(--muted); font-size: 0.8rem; font-weight: 500; }
.stat-value {
  display: block; font-size: 1.32rem; font-weight: 700; line-height: 1.3;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.stat-value .pill { font-size: 0.82rem; font-weight: 600; letter-spacing: 0; }
.stat-hint { color: var(--muted); font-size: 0.78rem; min-height: 1.15em; }
.token {
  direction: ltr; unicode-bidi: isolate; display: block; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.95rem; font-weight: 650; letter-spacing: 0;
}
.chart-box { height: 280px; position: relative; }
.state { color: var(--muted); font-size: 0.9rem; }
.state:empty, .state[hidden] { display: none; }
.state.error { color: var(--danger); }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
.card table, .split table { min-width: 0; }
th, td { text-align: left; padding: 0.72rem 0.85rem; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th {
  color: var(--muted); font-weight: 600; font-size: 0.78rem; white-space: nowrap;
  background: color-mix(in srgb, var(--bg) 65%, var(--surface));
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
td .btn { min-height: 2rem; padding: 0.15rem 0.65rem; font-size: 0.8rem; }
td.num, .ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; text-align: left; }
main a { color: var(--accent); text-decoration: none; font-weight: 600; }
main a:hover { text-decoration: underline; }

.pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  border-radius: 999px; padding: 0.12rem 0.6rem; font-size: 0.78rem; font-weight: 600;
  background: var(--bg); line-height: 1.5;
}
.pill::before { content: ""; width: 0.42rem; height: 0.42rem; border-radius: 50%; background: currentColor; }
.pill.online { color: var(--ok); }
.pill.offline { color: var(--warn); }
.pill.disabled, .pill.resolved { color: var(--muted); }
.pill.open, .pill.critical { color: var(--danger); }

.filters { padding: 0.85rem; display: grid; gap: 0.7rem; }
.filter-primary, .filter-grid {
  display: grid; gap: 0.65rem; align-items: end;
}
.filter-primary { grid-template-columns: minmax(160px, 1.5fr) repeat(3, minmax(120px, 1fr)) auto; }
.alert-primary { grid-template-columns: minmax(160px, 240px) auto; justify-content: start; }
.compare-primary { grid-template-columns: 180px minmax(0, 1fr) auto; }
.filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 0.7rem; }
.filters label, .login-card label, .dialog label {
  display: flex; flex-direction: column; gap: 0.28rem; font-size: 0.78rem; color: var(--muted); font-weight: 500;
}
.filter-more summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; width: fit-content; }
.filter-primary .btn, .filter-grid .btn, .filters > .btn { width: auto; justify-self: start; align-self: end; }
.pager { color: var(--muted); font-size: 0.85rem; }

.feed { display: flex; flex-direction: column; }
.feed-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: 0.62rem 0; border-bottom: 1px solid var(--line); font-size: 0.92rem;
}
.feed-item:last-child { border-bottom: 0; padding-bottom: 0.15rem; }
.feed-item time { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.empty { color: var(--muted); margin: 0; padding: 0.25rem 0; }

.seg { display: flex; gap: 0.25rem; background: var(--bg); padding: 0.18rem; border-radius: 10px; }
.seg button {
  background: transparent; border: 0; border-radius: 8px; padding: 0.28rem 0.7rem;
  cursor: pointer; color: var(--muted); font-weight: 600;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.time-form label.custom-only { display: none; }
.time-form.custom label.custom-only {
  display: flex; flex-direction: row; align-items: center; gap: 0.35rem;
  width: auto; font-size: 0.75rem; color: var(--muted);
}
.time-form.custom label.custom-only input { width: 11.25rem; min-width: 0; max-width: 100%; }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(ellipse at top, color-mix(in srgb, var(--accent) 18%, transparent), transparent 52%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 1.6rem 1.45rem 1.35rem; display: grid; gap: 0.7rem;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 1.3rem; }
.login-card .mark { box-shadow: inset 0 0 0 3px var(--surface), 0 0 0 3px rgba(242, 212, 138, 0.35); }
.login-card .btn { margin-top: 0.25rem; }
.form-error { color: var(--danger); margin: 0; font-size: 0.88rem; }

.modal { position: fixed; inset: 0; background: rgba(8, 14, 12, 0.48); display: grid; place-items: center; padding: 1rem; z-index: 40; }
.modal[hidden] { display: none; }
.dialog { width: min(460px, 100%); background: var(--surface); border-radius: 16px; padding: 1.15rem 1.15rem 1rem; border: 1px solid var(--line); }
.dialog.wide { width: min(720px, 100%); }
.install-command {
  direction: ltr; text-align: left; unicode-bidi: isolate;
  white-space: pre-wrap; word-break: break-all; overflow-wrap: anywhere;
  background: var(--bg); border-radius: 10px; padding: 0.75rem; margin: 0.75rem 0 0;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.82rem; line-height: 1.45;
}
.install-command:empty { display: none; }
.dialog p { margin: 0.45rem 0 0; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-start; gap: 0.45rem; margin-top: 1rem; }
.key-box { direction: ltr; text-align: left; background: var(--bg); padding: 0.75rem; border-radius: 10px; word-break: break-all; margin-top: 0.7rem; font-size: 0.92rem; }
#toast {
  position: fixed; bottom: 1rem; inset-inline-end: 1rem; z-index: 50;
  background: var(--ink); color: var(--bg); padding: 0.7rem 0.9rem; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: min(360px, calc(100% - 2rem));
}
#toast.show { opacity: 1; }
body[data-page="settings"] .time-form { display: none; }
#settings-form { display: flex; flex-direction: column; gap: 1rem; }
.card > .btn { margin-top: 0.85rem; }
.startup-card { padding: 0.9rem 1rem; }
.startup-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.45rem 1rem; margin: 0.7rem 0 0; }
.startup-list div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line); padding-bottom: 0.35rem; }
.startup-list dt { color: var(--muted); font-size: 0.8rem; }
.startup-list dd { margin: 0; font-size: 0.88rem; direction: ltr; unicode-bidi: isolate; text-align: left; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem 1rem; }
.settings-grid small { font-weight: 400; line-height: 1.45; }
.settings-save { align-self: flex-start; }
.backdrop { position: fixed; inset: 0; background: rgba(8, 14, 12, 0.45); z-index: 20; }
.backdrop[hidden] { display: none; }

.compare-primary { align-items: start; }
@media (max-width: 1100px) {
  .filter-primary, .filter-grid { grid-template-columns: 1fr 1fr; }
  .compare-primary { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; right: auto; z-index: 30;
    transform: translateX(-100%); transition: transform 0.18s ease; height: 100vh;
  }
  .sidebar.open { transform: none; }
  #menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 2.45rem; padding: 0; }
  .topbar, .top-start { align-items: flex-start; }
  .top-actions { margin-top: 0.15rem; }
  .split, .page-head { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
  main { padding: 1rem; }
  .topbar { padding-inline: 0.85rem; }
  .who { display: none; }
}
@media (max-width: 800px) {
  .settings-grid, .startup-list { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .cards, .filter-primary, .filter-grid { grid-template-columns: 1fr; }
  .time-form select { min-width: 0; }
}
