:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --border: #e3e6eb;
  --text: #1c2230;
  --muted: #6b7385;
  --accent: #4f6bed;
  --accent-text: #ffffff;
  --accent-soft: #eef1fe;
  --ok: #1f9d55;
  --ok-soft: #e6f6ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --err: #d64545;
  --err-soft: #fdecec;
  --info: #2f80ed;
  --info-soft: #e8f1fd;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --panel: #171b23;
    --panel-2: #1c212b;
    --border: #2a303c;
    --text: #e6e9ef;
    --muted: #949cad;
    --accent: #7088f5;
    --accent-text: #0f1218;
    --accent-soft: #232a45;
    --ok: #4cc38a;
    --ok-soft: #173326;
    --warn: #e0a84a;
    --warn-soft: #3a2e17;
    --err: #f07272;
    --err-soft: #3d1f22;
    --info: #6aa7f5;
    --info-soft: #1b2a40;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ───── layout ───── */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; padding: 4px 8px 16px; }
.brand-logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: var(--accent-text); font-size: 15px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--text);
}
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .me { font-size: 13px; color: var(--muted); padding: 8px 10px; border-top: 1px solid var(--border); }
.main { padding: 24px 28px 60px; max-width: 1200px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .grow { flex: 1; }
.crumb { color: var(--muted); font-size: 13px; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 12px; }
  .brand { padding: 4px 8px; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .sidebar .spacer, .sidebar .me { display: none; }
  .main { padding: 16px; }
}

/* ───── components ───── */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { margin-left: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 550; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--err); }
.btn.danger:hover { background: var(--err-soft); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }
.dot.warn { background: var(--warn); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
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; margin: 0 -18px; padding: 0 18px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ───── forms ───── */
.form-section { padding: 18px; }
.form-section + .form-section { border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field > label { font-weight: 600; font-size: 13px; }
.field .help { font-size: 12px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font: inherit;
}
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; margin: 0; }
.field.check { flex-direction: row; align-items: center; align-self: end; min-height: 38px; }
.form-actions { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--panel-2); border-radius: 0 0 var(--radius) var(--radius); position: sticky; bottom: 0; }
.card.flush { padding: 0; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }

/* ───── project cards ───── */
.pcard { display: flex; flex-direction: column; gap: 10px; }
.pcard .title { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.counts { display: flex; gap: 6px; flex-wrap: wrap; }
.stat { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ───── modal / toast ───── */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 14, 22, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 12px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h2 { margin: 0; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 8px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.15); white-space: pre-wrap; }
.toast.err { border-left-color: var(--err); }

.secret-box { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; overflow-wrap: anywhere; white-space: pre-wrap; }
pre.log { font-family: var(--mono); font-size: 12px; background: var(--panel-2); border-radius: 8px; padding: 10px; max-height: 320px; overflow: auto; white-space: pre-wrap; margin: 6px 0 0; }
details summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }

/* ───── login ───── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); }
.login .brand { justify-content: center; font-size: 18px; padding-bottom: 20px; }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--err-soft); color: var(--err); font-size: 13px; white-space: pre-wrap; }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
