:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #475467;
  --text-3: #98a2b3;
  --accent: #111827;
  --accent-text: #ffffff;
  --green: #12b76a;
  --green-bg: #ecfdf3;
  --green-text: #067647;
  --grey: #98a2b3;
  --grey-bg: #f2f4f7;
  --grey-text: #475467;
  --amber: #f79009;
  --amber-bg: #fffaeb;
  --amber-text: #b54708;
  --red: #f04438;
  --red-bg: #fef3f2;
  --red-text: #b42318;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d12; --surface: #13161d; --surface-2: #1a1e27; --border: #242a35; --border-strong: #333a47;
    --text: #eef1f6; --text-2: #a4adbd; --text-3: #6b7485; --accent: #eef1f6; --accent-text: #0b0d12;
    --green-bg: rgba(18,183,106,.12); --green-text: #4ade80; --grey-bg: rgba(152,162,179,.12); --grey-text: #b4bccb;
    --amber-bg: rgba(247,144,9,.12); --amber-text: #fdb022; --red-bg: rgba(240,68,56,.12); --red-text: #fd8077;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 16px 40px -8px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d12; --surface: #13161d; --surface-2: #1a1e27; --border: #242a35; --border-strong: #333a47;
  --text: #eef1f6; --text-2: #a4adbd; --text-3: #6b7485; --accent: #eef1f6; --accent-text: #0b0d12;
  --green-bg: rgba(18,183,106,.12); --green-text: #4ade80; --grey-bg: rgba(152,162,179,.12); --grey-text: #b4bccb;
  --amber-bg: rgba(247,144,9,.12); --amber-text: #fdb022; --red-bg: rgba(240,68,56,.12); --red-text: #fd8077;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 16px 40px -8px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 0 24px; }
@media (max-width: 640px) { .wrap { padding: 0 16px; } }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 68px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); display: grid; align-content: center; gap: 3px; padding: 0 9px; flex: none; }
.logo span { height: 3px; border-radius: 2px; background: var(--accent-text); }
.logo span:first-child { background: var(--green); }
.logo span:nth-child(2) { width: 70%; }
.logo span:nth-child(3) { width: 85%; opacity: .5; }
h1 { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.sub { margin: 0; font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.user-chip { font-size: 12.5px; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); padding: 5px 10px; border-radius: 999px; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.user-chip b { font-weight: 600; color: var(--text); }
@media (max-width: 760px) { .user-chip { display: none; } .btn span { display: none; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); cursor: pointer; font-weight: 500; font-size: 13.5px; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #d92d20; border-color: #d92d20; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); opacity: .9; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text-2); }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Banner */
.banner { margin-top: 20px; padding: 12px 16px; border-radius: 12px; font-size: 13.5px; border: 1px solid; }
.banner.info { background: var(--amber-bg); color: var(--amber-text); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.banner.error { background: var(--red-bg); color: var(--red-text); border-color: color-mix(in srgb, var(--red) 30%, transparent); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 24px 0 20px; }
@media (max-width: 960px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.stat:hover { border-color: var(--border-strong); }
.stat.on { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.stat-label { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 7px; font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--grey); display: inline-block; flex: none; }
.stat-active .dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.stat-disabled .dot { background: var(--grey); }
.stat-unset .dot { background: var(--amber); }
.stat-alert .dot { background: var(--red); }
.stat-alert.has-issues { border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.stat-alert.has-issues .stat-value { color: var(--red-text); }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.search { flex: 1 1 280px; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--text-3); box-shadow: var(--shadow); }
.search:focus-within { border-color: var(--text-2); }
.search input { flex: 1; border: 0; outline: 0; background: transparent; min-width: 0; color: var(--text); }
.search kbd { font: 11px/1 ui-monospace, monospace; border: 1px solid var(--border); border-radius: 5px; padding: 3px 6px; color: var(--text-3); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 500; font-size: 13px; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg-icons button { padding: 0 8px; display: grid; place-items: center; }
.tool-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select { height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); padding: 0 10px; cursor: pointer; box-shadow: var(--shadow); font-size: 13.5px; }
@media (max-width: 640px) { #filterSeg { width: 100%; overflow-x: auto; } }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; padding-bottom: 48px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s, opacity .2s; position: relative; min-width: 0; }
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.card.is-disabled { background: color-mix(in srgb, var(--surface) 70%, var(--bg)); }
.card.is-disabled .card-title { color: var(--text-2); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-title { font-size: 15px; font-weight: 600; margin: 0; line-height: 1.35; letter-spacing: -.005em; word-break: break-word; }
.url { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); min-width: 0; }
.url a { text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.url a:hover { color: var(--text); text-decoration: underline; }
.url .muted { color: var(--text-3); font-style: italic; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; color: var(--text-2); cursor: pointer; max-width: 100%; }
.tag span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11.5px; }
.tag:hover { color: var(--text); border-color: var(--border-strong); }
.tag b { font-weight: 500; color: var(--text-3); font-family: Inter, sans-serif; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.card-actions { display: flex; align-items: center; gap: 6px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.act { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border); background: transparent; font-size: 12.5px; font-weight: 500; text-decoration: none; cursor: pointer; color: var(--text-2); white-space: nowrap; }
.act:hover { color: var(--text); background: var(--surface-2); }
.act[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.footnote { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Status pill */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; flex: none; }
.pill .dot { width: 6px; height: 6px; }
.pill.active { background: var(--green-bg); color: var(--green-text); }
.pill.active .dot { background: var(--green); animation: pulse 2s infinite; }
.pill.disabled { background: var(--grey-bg); color: var(--grey-text); }
.pill.unset, .pill.unknown { background: var(--amber-bg); color: var(--amber-text); }
.pill.unset .dot, .pill.unknown .dot { background: var(--amber); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(18,183,106,.5); } 50% { box-shadow: 0 0 0 4px rgba(18,183,106,0); } }

/* Health */
.health { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 500; white-space: nowrap; flex: none; }
.health.ok { color: var(--green-text); }
.health.bad { color: var(--red-text); }
.health.checking { color: var(--text-3); }
.health .dot { width: 6px; height: 6px; }
.health.ok .dot { background: var(--green); }
.health.bad .dot { background: var(--red); }
.card.has-issue { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }

/* Toggle */
.toggle { margin-left: auto; display: inline-flex; padding: 4px; border: 0; background: transparent; cursor: pointer; border-radius: 999px; }
.track { width: 36px; height: 20px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background .2s; flex: none; }
.track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.toggle[aria-checked="true"] .track { background: var(--green); }
.toggle[aria-checked="true"] .track::after { transform: translateX(16px); }
.toggle:focus-visible { outline: 0; }
.toggle:focus-visible .track { outline: 2px solid var(--text); outline-offset: 2px; }
.toggle.busy { opacity: .5; pointer-events: none; }

/* List view */
.grid.list { grid-template-columns: 1fr; gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); padding-bottom: 0; margin-bottom: 48px; }
.grid.list .card { flex-direction: row; align-items: center; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; box-shadow: none; padding: 12px 16px; gap: 16px; }
.grid.list .card:last-child { border-bottom: 0; }
.grid.list .card:hover { background: var(--surface-2); box-shadow: none; }
.grid.list .card-main { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.grid.list .card-head { order: -1; }
.grid.list .meta { flex: 0 1 240px; min-width: 0; }
.grid.list .card-actions { border: 0; padding: 0; margin: 0; flex: none; }
.grid.list .footnote { display: none; }
.grid.list .card-title { font-size: 14px; }
@media (max-width: 860px) {
  .grid.list .card { flex-wrap: wrap; }
  .grid.list .card-main { flex-basis: 100%; }
  .grid.list .card-actions { width: 100%; }
}
.card-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

/* Skeleton */
.skeleton { height: 180px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Empty */
.empty { text-align: center; padding: 64px 16px; color: var(--text-2); }
.empty-title { font-weight: 600; font-size: 15px; color: var(--text); margin: 0 0 4px; }
.empty-sub { margin: 0; }

/* Dialog */
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 24px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(16, 24, 40, .45); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 8px; font-size: 17px; }
dialog p { margin: 0 0 20px; color: var(--text-2); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--accent); color: var(--accent-text); padding: 10px 14px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow-lg); animation: rise .2s ease-out; }
.toast.error { background: var(--red); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
