:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --ink: #1c1b19;
  --ink-2: #57544e;
  --ink-3: #8a867e;
  --line: #e3e1dc;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2ef;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1b1b19;
    --surface-2: #242421;
    --ink: #ecebe8;
    --ink-2: #b3b0a9;
    --ink-3: #7d7a73;
    --line: #2f2e2b;
    --accent: #2dd4bf;
    --accent-ink: #062e2a;
    --accent-soft: #123532;
    --ok: #4ade80;
    --ok-soft: #12301d;
    --warn: #fbbf24;
    --warn-soft: #3a2c0c;
    --bad: #f87171;
    --bad-soft: #3b1515;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand img { width: 26px; height: 26px; }
.nav-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 8px; border: 0; background: none;
  color: var(--ink-2); cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12.5px; color: var(--ink-3); }
.side-foot b { display: block; color: var(--ink-2); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 0 0 12px; }
.sub { color: var(--ink-3); margin: 2px 0 0; }

/* components */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { color: var(--ink-3); font-size: 12.5px; }
.stat .v { font-size: 22px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.inst { display: flex; flex-direction: column; gap: 12px; cursor: pointer; transition: border-color .15s; }
.inst:hover { border-color: var(--ink-3); }
.inst-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.inst-name { font-weight: 650; font-size: 15px; word-break: break-word; }
.inst-meta { color: var(--ink-3); font-size: 13px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.muted { color: var(--ink-3); }
.empty { text-align: center; padding: 48px 20px; color: var(--ink-3); }

label.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-weight: 550; font-size: 13px; }
label.field small { font-weight: 400; color: var(--ink-3); }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], select, textarea {
  width: 100%; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-bottom: 8px; cursor: pointer; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; margin-bottom: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.secret {
  font-family: var(--mono); font-size: 12.5px; padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px dashed var(--line); word-break: break-all; user-select: all;
}
.callout { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; margin-bottom: 12px; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 10; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: min(560px, 100%); padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(820px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink-3); padding: 4px 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.qr { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px 0; }
.qr img { width: 280px; height: 280px; border-radius: 10px; background: #fff; padding: 8px; }
.code-big { font-family: var(--mono); font-size: 28px; letter-spacing: .2em; font-weight: 700; padding: 12px 18px; background: var(--surface-2); border-radius: 10px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .brand { padding: 0 0 18px; justify-content: center; font-size: 20px; }
.err { color: var(--bad); font-size: 13px; min-height: 20px; margin-bottom: 8px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast-item { background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 13.5px; box-shadow: var(--shadow); max-width: 90vw; }
.toast-item.bad { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .brand { padding: 4px 8px; width: 100%; }
  .nav-item { width: auto; }
  .side-foot { display: none; }
  main { padding: 20px 16px 48px; }
  .two { grid-template-columns: 1fr; }
}
