:root {
  --bg: #f5f6f8; --panel: #ffffff; --text: #1d2330; --muted: #6b7385; --border: #e3e6ec;
  --primary: #1a73e8; --primary-ink: #fff; --side: #111827; --side-text: #c9d1e0; --side-active: #1f2937;
  --ok: #188038; --ok-bg: #e6f4ea; --bad: #c5221f; --bad-bg: #fce8e6; --warn: #b06000; --warn-bg: #fef7e0;
  --info-bg: #e8f0fe; --code-bg: #f1f3f4; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --panel: #171b23; --text: #e6e9ef; --muted: #9aa3b5; --border: #2a303c;
    --side: #0b0d12; --side-active: #1b2130; --ok-bg: #12301d; --bad-bg: #3a1615; --warn-bg: #3a2c0c;
    --info-bg: #13243f; --code-bg: #0b0e13; --ok: #5bd17d; --bad: #ff7a73; --warn: #f0b44c;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
a { color: var(--primary); }
code, pre, textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
pre { background: var(--code-bg); padding: 12px; border-radius: 8px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 8px 0; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; font-size: 16px; padding: 0 8px; }
.brand.big { color: var(--text); font-size: 20px; padding: 0; }
.logo { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-weight: 800;
  background: conic-gradient(#4285f4 0 25%, #34a853 0 50%, #fbbc05 0 75%, #ea4335 0); }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a { color: var(--side-text); text-decoration: none; padding: 9px 12px; border-radius: 8px; }
nav a:hover { background: var(--side-active); color: #fff; }
nav a.active { background: var(--primary); color: #fff; }
main { padding: 24px 28px 60px; max-width: 1400px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid.two { grid-template-columns: 1fr 1fr; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--info-bg); }

.btn { border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 7px 13px; border-radius: 8px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.ghost { background: transparent; color: inherit; border-color: #374151; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: wait; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--code-bg); color: var(--muted); }
.badge.active, .badge.healthy, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.suspended, .badge.pending, .badge.unknown, .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.failed, .badge.cancelled, .badge.unhealthy, .badge.bad { background: var(--bad-bg); color: var(--bad); }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--info-bg); margin: 2px 2px 0 0; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: var(--bad); position: relative; transition: .15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { left: 19px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; font-weight: 400; }
textarea { min-height: 70px; resize: vertical; }
textarea.code { min-height: 110px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label.inline { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; color: var(--text); }
label.inline input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.kv-row { display: grid; grid-template-columns: 1fr 1.6fr auto; gap: 6px; margin-bottom: 6px; }

details.op { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--panel); }
details.op > summary { padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: center; list-style: none; }
details.op > summary::-webkit-details-marker { display: none; }
details.op[open] > summary { border-bottom: 1px solid var(--border); }
details.op .body { padding: 12px; }

.modal-back { position: fixed; inset: 0; background: rgba(10, 14, 22, .55); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--panel); border-radius: 12px; width: min(720px, 100%); max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.wide { width: min(1000px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--side); color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: 0 8px 20px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.error-text { color: var(--bad); font-size: 13px; min-height: 18px; }
.key-box { display: flex; gap: 8px; align-items: center; background: var(--warn-bg); padding: 12px; border-radius: 8px; word-break: break-all; }
.callout { background: var(--info-bg); border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.callout.warn { background: var(--warn-bg); }
.empty { text-align: center; padding: 30px; color: var(--muted); }
.provider-card { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.provider-card .name { font-weight: 700; font-size: 15px; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  nav { flex-direction: row; flex-wrap: wrap; }
  main { padding: 16px; }
  .grid.two { grid-template-columns: 1fr; }
}
