/* Yetfix Ops — shared styles. Dark default, light via [data-theme="light"]. */

:root {
  color-scheme: dark;
  --bg: #0f1012;
  --surface-1: #17181b;
  --surface-2: #1e1f23;
  --surface-3: #26272c;
  --border: #2c2d33;
  --border-strong: #3a3b42;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8d8c85;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --series-1: #3987e5;
  --series-2: #d95926;
  --grid: rgba(255, 255, 255, 0.07);
  --axis: rgba(255, 255, 255, 0.16);
  --ok: #2fb67c;
  --ok-bg: rgba(47, 182, 124, 0.14);
  --warn: #e0a321;
  --warn-bg: rgba(224, 163, 33, 0.15);
  --crit: #ec5b5b;
  --crit-bg: rgba(236, 91, 91, 0.15);
  --info: #7aa7e8;
  --info-bg: rgba(122, 167, 232, 0.14);
  --neutral-bg: rgba(255, 255, 255, 0.07);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.18);
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --sidebar-w: 220px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f3f3f1;
  --surface-3: #ebebe8;
  --border: #e2e1dd;
  --border-strong: #cfcec9;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: rgba(0, 0, 0, 0.07);
  --axis: rgba(0, 0, 0, 0.18);
  --ok: #138a55;
  --ok-bg: rgba(19, 138, 85, 0.11);
  --warn: #a96d00;
  --warn-bg: rgba(214, 145, 0, 0.14);
  --crit: #c62f2f;
  --crit-bg: rgba(198, 47, 47, 0.1);
  --info: #2a62b3;
  --info-bg: rgba(42, 98, 179, 0.1);
  --neutral-bg: rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 6px 18px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- buttons & inputs ---------- */
button, .btn {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: var(--surface-3); border-color: var(--border-strong); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); border-color: var(--border); }
button:disabled { opacity: 0.6; cursor: default; }
button.icon { padding: 7px; width: 34px; height: 34px; justify-content: center; }
button svg, .nav svg { width: 16px; height: 16px; flex: none; }

label { display: block; font-weight: 500; margin: 0 0 6px; color: var(--text-secondary); font-size: 13px; }
input[type="text"], input[type="password"] {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
input:focus { border-color: var(--accent); outline: none; }
.field { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.form-error { color: var(--crit); background: var(--crit-bg); border-radius: var(--radius-sm); padding: 9px 12px; margin-bottom: 14px; font-size: 13px; }
.form-ok { color: var(--ok); background: var(--ok-bg); border-radius: var(--radius-sm); padding: 9px 12px; margin-bottom: 14px; font-size: 13px; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px 24px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 20px; margin: 14px 0 4px; }
.auth-card p.lead { margin: 0 0 22px; color: var(--text-secondary); }
.auth-card button.primary { width: 100%; justify-content: center; padding: 11px; font-size: 15px; margin-top: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--series-1), #6250d6);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
}
.auth-foot { text-align: center; margin-top: 16px; font-size: 12px; color: var(--text-muted); }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  border-right: 1px solid var(--border); background: var(--surface-1);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 18px;
}
.sidebar .brand { padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; }
.nav a.active { background: var(--surface-3); color: var(--text-primary); }
.nav .count { margin-left: auto; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--crit-bg); color: var(--crit); font-weight: 600; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--text-muted); padding: 0 8px; }

.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { display: none; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.topbar .host { color: var(--text-muted); font-size: 13px; }
.topbar .spacer { flex: 1; }
.conn { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex: none; }
.conn.live .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.conn.stale .dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.conn.down .dot { background: var(--crit); box-shadow: 0 0 0 3px var(--crit-bg); }
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 6px; z-index: 30;
}
.menu-pop .who { padding: 6px 10px 8px; font-size: 12px; color: var(--text-muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-pop button { width: 100%; background: transparent; border-color: transparent; justify-content: flex-start; }
.menu-pop button:hover { background: var(--surface-2); }

.content { padding: 20px 24px 48px; max-width: 1480px; }
.section { margin-bottom: 30px; scroll-margin-top: 72px; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 15px; margin: 0; font-weight: 650; }
.section-head .meta { color: var(--text-muted); font-size: 12.5px; }
.section-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.unavailable {
  padding: 18px; border: 1px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--text-muted); text-align: center; background: var(--surface-1);
}
.empty { padding: 18px; color: var(--text-muted); text-align: center; }

/* ---------- overview ---------- */
.grid-cards { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stat .label { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 12.5px; font-weight: 500; }
.stat .label .badge { margin-left: auto; }
.stat .value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin-top: 6px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--text-secondary); letter-spacing: 0; margin-left: 2px; }
.stat .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .value.compact { font-size: 20px; }
.bar { height: 6px; border-radius: 3px; background: var(--neutral-bg); margin-top: 12px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 3px; background: var(--ok); width: 0; transition: width 0.4s ease; }
.bar.warn > span { background: var(--warn); }
.bar.critical > span { background: var(--crit); }
.load-row { display: flex; gap: 14px; margin-top: 6px; align-items: baseline; }
.load-row div { display: flex; flex-direction: column; }
.load-row b { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.load-row span { font-size: 11px; color: var(--text-muted); }
.net-row { display: flex; gap: 18px; margin-top: 6px; }
.net-row div { display: flex; flex-direction: column; }
.net-row b { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.net-row span { font-size: 11.5px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.swatch.s1 { background: var(--series-1); }
.swatch.s2 { background: var(--series-2); }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--neutral-bg); color: var(--text-secondary); white-space: nowrap; line-height: 1.5;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.critical { background: var(--crit-bg); color: var(--crit); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.plain::before { display: none; }

/* ---------- charts ---------- */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 6px; font-size: 12.5px; color: var(--text-secondary); }
.seg button:hover { background: var(--surface-3); }
.seg button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,0.2); font-weight: 600; }
.grid-charts { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.chart-card h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.chart-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.chart-head .now { margin-left: auto; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 14px; height: 3px; }
.chart-box { position: relative; height: 180px; }
.chart-box canvas { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: var(--shadow); padding: 7px 10px; font-size: 12px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chart-tip .t { color: var(--text-muted); margin-bottom: 3px; }
.chart-tip .row { display: flex; align-items: center; gap: 7px; color: var(--text-primary); }
.chart-tip .row .k { color: var(--text-secondary); }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); font-size: 12.5px; pointer-events: none; }

/* ---------- lists / tables ---------- */
.list { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.svc-row {
  display: grid; grid-template-columns: minmax(180px, 1.6fr) 110px minmax(150px, 1.3fr) 110px 90px;
  gap: 12px; align-items: center; padding: 11px 16px; border-top: 1px solid var(--border);
}
.svc-row:first-child { border-top: 0; }
.svc-row.head { background: var(--surface-2); color: var(--text-muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding-top: 8px; padding-bottom: 8px; }
.svc-name { font-weight: 600; min-width: 0; }
.svc-name .unit { display: block; font-weight: 400; font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-row .cell-label { display: none; }

.table-wrap { overflow-x: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: top; }
thead th { border-top: 0; background: var(--surface-2); color: var(--text-muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .cmd { display: block; font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 520px; }
td .err { color: var(--crit); font-size: 12px; display: block; max-width: 360px; overflow-wrap: anywhere; }
.grid-2 { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.sub-title { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin: 0 0 8px; }

/* ---------- sites ---------- */
.grid-sites { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.site-head { display: flex; align-items: center; gap: 8px; }
.site-head .host { font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-head .badge { margin-left: auto; }
.site-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
.site-metrics div { display: flex; flex-direction: column; min-width: 0; }
.site-metrics span { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.site-metrics b { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.warn-text { color: var(--warn); }
.critical-text { color: var(--crit); }
.site-cert { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-secondary); flex-wrap: wrap; }
.site-err { color: var(--crit); font-size: 12px; margin-top: 6px; overflow-wrap: anywhere; }
.spark-box { position: relative; height: 34px; margin-top: 12px; }
.spark-box canvas { display: block; width: 100%; height: 100%; }
.spark-cap { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-top: 4px; min-height: 16px; }

/* ---------- activity ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { padding: 4px 11px; border-radius: 999px; font-size: 12.5px; color: var(--text-secondary); }
.chips button[aria-pressed="true"] { background: var(--text-primary); color: var(--bg); border-color: var(--text-primary); }
.events { list-style: none; margin: 0; padding: 0; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); max-height: 560px; overflow-y: auto; }
.events li { display: grid; grid-template-columns: 128px 74px 1fr; gap: 12px; padding: 9px 16px; border-top: 1px solid var(--border); align-items: baseline; font-size: 13px; }
.events li:first-child { border-top: 0; }
.events .when { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 12.5px; white-space: nowrap; }
.events .msg { overflow-wrap: anywhere; }
.events .lv { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--text-muted); vertical-align: 1px; }
.events .lv.ok { background: var(--ok); }
.events .lv.warn { background: var(--warn); }
.events .lv.critical { background: var(--crit); }
.events .lv.info { background: var(--info); }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(420px, calc(100vw - 32px));
  background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog form { padding: 22px; }
dialog h2 { margin: 0 0 16px; font-size: 17px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 57px; z-index: 15; height: auto; flex-direction: row; padding: 8px 12px;
    border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; gap: 0;
    background: color-mix(in srgb, var(--surface-1) 92%, transparent);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar > .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav a { white-space: nowrap; padding: 6px 10px; font-size: 13px; }
  .nav a svg { display: none; }
  .shell { display: flex; flex-direction: column; }
  .main { display: contents; }
  .topbar { order: -1; padding: 10px 16px; }
  .topbar .brand { display: flex; }
  .topbar h1, .topbar .host { display: none; }
  .content { padding: 16px 14px 40px; }
  .section { scroll-margin-top: 112px; }
}
@media (max-width: 760px) {
  .svc-row.head { display: none; }
  .svc-row { grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 14px; }
  .svc-row .svc-name { grid-column: 1; }
  .svc-row .svc-badge { grid-column: 2; grid-row: 1; justify-self: end; }
  .svc-row .svc-since, .svc-row .svc-mem, .svc-row .svc-pid { grid-column: 1 / -1; font-size: 12.5px; color: var(--text-secondary); }
  .svc-row .cell-label { display: inline; color: var(--text-muted); margin-right: 6px; }
  .grid-2, .grid-charts { grid-template-columns: 1fr; }
  .events li { grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 14px; }
  .events .when { grid-column: 1; grid-row: 1; }
  .events .type { grid-column: 2; grid-row: 1; justify-self: end; }
  .events .msg { grid-column: 1 / -1; }
  td .cmd { max-width: 58vw; }
  .proc-table .hide-sm { display: none; }
}
@media (max-width: 520px) {
  .grid-cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid-cards .card { padding: 12px; }
  .stat .value { font-size: 22px; }
  .stat .value.compact { font-size: 16px; }
  .stat .label .badge { display: none; }
  .stat .label .badge.critical, .stat .label .badge.warn { display: inline-flex; }
  .load-row b { font-size: 17px; }
  .load-row { gap: 10px; }
  .net-row { flex-direction: column; gap: 6px; }
  .net-row b { font-size: 16px; }
  .conn .label { display: none; }
  .updated { font-size: 12px; }
  .chart-box { height: 160px; }
  .stat .label { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (forced-colors: active) {
  .badge::before, .events .lv { forced-color-adjust: none; }
}
