:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #f0f0f4;
  --border: #e1e1e8;
  --text: #1c1c22;
  --muted: #6b6b78;
  --accent: #5865f2;
  --accent-text: #ffffff;
  --accent-soft: #eceefe;
  --ok: #1f9d55;
  --warn: #b7791f;
  --danger: #d23c3c;
  --danger-soft: #fdecec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111215;
    --surface: #1a1b20;
    --surface-2: #23242b;
    --border: #2e2f37;
    --text: #e8e8ee;
    --muted: #9a9aa8;
    --accent: #7983f5;
    --accent-text: #0e0f14;
    --accent-soft: #262a4a;
    --ok: #4ec47f;
    --warn: #e0a84a;
    --danger: #f06a6a;
    --danger-soft: #3a2224;
    --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); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* top bar + layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.who { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.who img { width: 24px; height: 24px; border-radius: 50%; }
.layout { display: flex; min-height: calc(100vh - 52px); }
.sidebar {
  position: sticky; top: 52px; height: calc(100vh - 52px); overflow-y: auto;
  width: 200px; flex: none; padding: 16px 10px;
  border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar a {
  padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none;
}
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.view { flex: 1; min-width: 0; padding: 24px; max-width: 1100px; }
.view > header { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.nav-toggle { display: none; }

/* buttons + inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; 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(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 28px; padding: 0 10px; font-size: 13px; }
.icon-btn {
  width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input[type=text], input[type=number], input[type=search], select {
  width: 100%; min-height: 34px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 22px; background: var(--border); transition: background .15s;
  pointer-events: none;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 20px; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.feature-head { display: flex; align-items: flex-start; gap: 12px; }
.feature-head .titles { flex: 1; min-width: 0; }
.feature-head p { margin: 4px 0 0; color: var(--muted); }
.feature.off .fields { opacity: .55; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); vertical-align: middle; margin-left: 6px;
}
.badge.on { background: var(--accent-soft); color: var(--accent); }
.badge.changed { background: var(--danger-soft); color: var(--warn); }
.fields { display: grid; gap: 14px; margin-top: 16px; }
.field > label, .field > .label { display: block; font-weight: 500; margin-bottom: 6px; }
.field.inline { display: flex; align-items: center; gap: 10px; }
.field.inline > label { margin: 0; order: 2; font-weight: 400; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; align-items: center; }
.actions .msg { margin-right: auto; font-size: 13px; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px;
}
.chip img { width: 18px; height: 18px; border-radius: 50%; margin-left: -6px; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chip .x { width: 20px; height: 20px; font-size: 13px; }
.chip.unknown { border-style: dashed; }
.picker { position: relative; }
.results {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px); max-height: 260px; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
}
.results button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0;
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.results button:hover, .results button:focus { background: var(--surface-2); }
.results img { width: 22px; height: 22px; border-radius: 50%; }
.single-user { display: flex; gap: 8px; align-items: center; }
.single-user .chip { flex: none; }

.rows { display: flex; flex-direction: column; gap: 10px; }
.row-card { border: 1px solid var(--border); border-radius: 8px; padding: 14px; background: var(--surface-2); }
.row-card .row-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-weight: 600; }
.row-card .fields { margin-top: 0; }
.pattern-row { display: flex; gap: 6px; margin-bottom: 6px; }
.pattern-row input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.sortable { cursor: pointer; user-select: none; }
th.sorted { color: var(--text); }
.member { display: flex; align-items: center; gap: 8px; }
.member img { width: 22px; height: 22px; border-radius: 50%; }
.tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tabs button { border: 0; background: var(--surface); color: var(--text); padding: 6px 14px; font: inherit; cursor: pointer; }
.tabs button + button { border-left: 1px solid var(--border); }
.tabs button.active { background: var(--accent); color: var(--accent-text); }
.two-col { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }

/* logs */
.logs {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px;
  height: 60vh; overflow: auto; padding: 8px 0;
}
.logs.short { height: auto; max-height: 280px; }
.log-line { display: flex; gap: 10px; padding: 1px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-line time { color: var(--muted); flex: none; }
.log-line.warn { color: var(--warn); }
.log-line.error { color: var(--danger); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { width: 220px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  padding: 10px 16px; border-radius: 8px; background: var(--text); color: var(--bg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; text-align: center; padding: 32px 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.login-card .brand-mark { width: 44px; height: 44px; font-size: 20px; border-radius: 12px; }
.login-card p { margin: 0; }
.login-card .btn { margin-top: 10px; width: 100%; }

@media (max-width: 760px) {
  .nav-toggle { display: inline-grid; place-items: center; }
  .sidebar {
    position: fixed; top: 52px; bottom: 0; left: 0; height: auto; z-index: 9; transform: translateX(-100%);
    transition: transform .2s; box-shadow: 4px 0 20px rgba(0, 0, 0, .15);
  }
  .sidebar.open { transform: none; }
  .view { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
  .who span { display: none; }
  .toolbar input[type=search] { width: 100%; }
}
