:root {
  --bg: #121212;
  --panel: #171717;
  --raised: #1f1f1f;
  --hover: #242424;
  --border: #2e2e2e;
  --border-strong: #3e3e3e;
  --text: #ededed;
  --muted: #a0a0a0;
  --faint: #707070;
  --green: #3ecf8e;
  --green-bg: #006239;
  --green-hover: #00703f;
  --green-soft: rgba(62, 207, 142, 0.12);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --amber: #f5b14c;
  --amber-soft: rgba(245, 177, 76, 0.12);
  --grey-soft: rgba(255, 255, 255, 0.07);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 13px/1.5 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

/* Shell */
.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 12px;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 16px; font-weight: 500; font-size: 14px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px;
  background: none; border: 0; border-radius: 6px; color: var(--muted); text-align: left; cursor: pointer;
}
.nav button:hover { background: var(--hover); color: var(--text); }
.nav button[aria-current="page"] { background: var(--hover); color: var(--text); }
.nav svg { width: 16px; height: 16px; flex: none; }
.sidebar-end { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.account {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px;
  background: none; border: 0; border-top: 1px solid var(--border); border-radius: 0; color: var(--muted); text-align: left; cursor: pointer;
}
.account:hover, .account[aria-expanded="true"] { color: var(--text); }
.account .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.account svg { width: 14px; height: 14px; flex: none; color: var(--faint); }
.avatar { display: grid; place-items: center; width: 22px; height: 22px; flex: none; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 11px; font-weight: 500; }
.account-menu {
  position: fixed; z-index: 15; padding: 4px;
  background: var(--raised); border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); animation: fade 0.1s ease-out;
}
.account-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 28px; padding: 0 8px;
  background: none; border: 0; border-radius: 5px; color: var(--muted); text-align: left; cursor: pointer;
}
.account-menu button:hover, .account-menu button:focus-visible { background: var(--hover); color: var(--text); outline: none; }
.account-menu svg { width: 14px; height: 14px; flex: none; }
.link { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; }
.link:hover { color: var(--text); }

main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 24px;
  background: var(--bg); border-bottom: 1px solid var(--border); color: var(--muted);
}
.topbar .slash { color: var(--border-strong); }
.topbar b { color: var(--text); font-weight: 500; }
.content { padding: 28px 24px 56px; max-width: 1360px; margin: 0 auto; }
.heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.heading h1 { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; }
.heading p { color: var(--muted); margin-top: 2px; }

/* Controls */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px;
  background: var(--raised); border: 1px solid var(--border-strong); border-radius: 6px;
  white-space: nowrap; cursor: pointer; transition: background 0.1s;
}
.button:hover { background: var(--hover); }
.button:disabled { opacity: 0.5; cursor: default; }
.button.primary { background: var(--green-bg); border-color: rgba(62, 207, 142, 0.35); }
.button.primary:hover { background: var(--green-hover); }
.button.danger { background: var(--red-soft); border-color: rgba(248, 113, 113, 0.35); color: #fca5a5; }
.button.danger:hover { background: rgba(248, 113, 113, 0.2); }
.button.large { height: 36px; width: 100%; }
.input, select.input, textarea.input {
  width: 100%; height: 30px; padding: 0 10px;
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: 6px; outline: none;
}
textarea.input { height: 64px; padding: 6px 10px; resize: vertical; }
.input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.12); }
.input::placeholder { color: var(--faint); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.search { position: relative; width: 280px; max-width: 100%; }
.search svg { position: absolute; left: 9px; top: 8px; width: 14px; height: 14px; color: var(--faint); }
.search .input { padding-left: 29px; }
.tabs { display: flex; gap: 2px; padding: 2px; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; }
.tabs button { height: 24px; padding: 0 9px; background: none; border: 0; border-radius: 4px; color: var(--muted); cursor: pointer; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-pressed="true"] { background: var(--hover); color: var(--text); }
.spacer { flex: 1; }

/* Tables */
.table-wrap { border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 8px 12px; text-align: left; font-weight: 400; color: var(--muted); font-size: 12px;
  background: var(--raised); border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--hover); }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.note-cell { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-weight: 500; margin-bottom: 2px; }
.pager { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; color: var(--muted); }
.pager div { display: flex; gap: 6px; }

.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px; font-size: 11.5px; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.grey { background: var(--grey-soft); color: var(--muted); }

/* Overview */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { padding: 14px 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.stat span { color: var(--muted); }
.stat b { display: block; margin-top: 4px; font-size: 24px; font-weight: 500; letter-spacing: -0.02em; }
.stat small { display: block; margin-top: 2px; color: var(--faint); font-size: 12px; }
.section-title { font-size: 14px; font-weight: 500; margin-bottom: 10px; }

/* Side panel */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.5); animation: fade 0.12s ease-out; }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21; width: 460px; max-width: 100%;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--border);
  animation: slide 0.16s ease-out;
}
.sheet-head { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px; }
.icon-button { display: grid; place-items: center; width: 26px; height: 26px; background: none; border: 0; border-radius: 5px; color: var(--muted); cursor: pointer; }
.icon-button:hover { background: var(--hover); color: var(--text); }
.icon-button svg { width: 15px; height: 15px; }
.block { padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.block:last-child { border-bottom: 0; margin-bottom: 0; }
.block h3 { font-size: 12px; font-weight: 400; color: var(--muted); margin-bottom: 8px; }
.key-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.key-line .mono { font-size: 13px; }
dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; margin-bottom: 4px; color: var(--muted); }
.field small { display: block; margin-top: 4px; color: var(--faint); font-size: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row .input { width: auto; flex: 1; min-width: 80px; }
.device { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; }
.device small { display: block; color: var(--muted); font-size: 12px; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline div { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.timeline small { color: var(--faint); font-size: 12px; }

/* Dialogs */
.dialog {
  position: fixed; top: 50%; left: 50%; z-index: 31; width: 440px; max-width: calc(100% - 32px); max-height: calc(100% - 32px);
  transform: translate(-50%, -50%); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5); animation: fade 0.12s ease-out;
}
.dialog + .scrim, .scrim.top { z-index: 30; }
.dialog h2 { padding: 12px 16px; font-size: 14px; font-weight: 500; border-bottom: 1px solid var(--border); }
.dialog-body { padding: 16px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--raised); }
.keys-box {
  max-height: 220px; overflow-y: auto; padding: 10px; margin-bottom: 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  font-family: var(--mono); font-size: 12px; line-height: 1.8; user-select: all;
}
.form-error { margin-bottom: 10px; color: var(--red); }

/* Documentation */
.docs { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 32px; align-items: start; }
.docs-nav { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow-y: auto; }
.docs-nav h2 { margin: 16px 0 4px; padding: 0 8px; font-size: 12px; font-weight: 400; color: var(--faint); }
.docs-nav h2:first-child { margin-top: 0; }
.docs-nav button { display: block; width: 100%; padding: 4px 8px; background: none; border: 0; border-radius: 5px; color: var(--muted); text-align: left; cursor: pointer; }
.docs-nav button:hover { color: var(--text); background: var(--hover); }
.docs-nav button.current { color: var(--text); background: var(--hover); }
.docs-body { max-width: 720px; font-size: 14px; line-height: 1.6; }
.docs-body section { padding-bottom: 28px; margin-bottom: 28px; border-bottom: 1px solid var(--border); scroll-margin-top: 64px; }
.docs-body section:last-child { border-bottom: 0; }
.docs-body h3 { margin: 0 0 10px; font-size: 16px; font-weight: 500; }
.docs-body p { margin: 0 0 10px; color: #c7c7c7; }
.docs-body b { font-weight: 500; color: var(--text); }
.docs-body ol, .docs-body ul { margin: 0 0 10px; padding-left: 20px; color: #c7c7c7; }
.docs-body li { margin-bottom: 4px; }
.docs-body code { padding: 1px 5px; background: var(--raised); border: 1px solid var(--border); border-radius: 4px; font-family: var(--mono); font-size: 12px; }
.note { padding: 10px 12px; margin: 0 0 10px; background: var(--raised); border: 1px solid var(--border); border-radius: 6px; color: #c7c7c7; }
.note.warn { background: var(--amber-soft); border-color: rgba(245, 177, 76, 0.3); }
.doc-table { width: 100%; margin-bottom: 10px; border: 1px solid var(--border); border-radius: 6px; border-collapse: separate; border-spacing: 0; overflow: hidden; }
.doc-table th { width: 42%; padding: 8px 12px; background: var(--raised); color: var(--text); font-size: 13px; white-space: normal; vertical-align: top; border-bottom: 1px solid var(--border); }
.doc-table td { padding: 8px 12px; color: #c7c7c7; font-size: 13px; white-space: normal; vertical-align: top; }
.doc-table tr:last-child th { border-bottom: 0; }

/* Settings */
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; align-items: start; max-width: 860px; }
.card { padding: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.card h2 { margin-bottom: 12px; font-size: 14px; font-weight: 500; }
.card dl { grid-template-columns: 170px 1fr; margin-bottom: 14px; }
.settings-hint { font-size: 12px; }

/* Sign in */
.signin { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.signin form { width: 340px; max-width: 100%; }
.signin h1 { font-size: 22px; font-weight: 500; letter-spacing: -0.01em; }
.signin p { color: var(--muted); margin: 2px 0 22px; }
.logo { display: block; width: 24px; height: 24px; flex: none; border-radius: 6px; }

/* Toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 8px 12px; background: var(--raised); border: 1px solid var(--border-strong); border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); animation: fade 0.12s ease-out; }
.toast.error { border-color: rgba(248, 113, 113, 0.5); color: #fca5a5; }

.skeleton { height: 120px; border-radius: 8px; background: var(--panel); border: 1px solid var(--border); }

@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 8px; overflow-x: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0 8px 0 0; }
  .brand span { display: none; }
  .nav { flex-direction: row; }
  .nav button { white-space: nowrap; }
  .nav svg { display: none; }
  .sidebar-end { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .account { width: auto; padding: 4px; border: 0; }
  .account .who, .account svg { display: none; }
  .docs { grid-template-columns: minmax(0, 1fr); }
  .docs-nav { position: static; max-height: none; display: none; }
  .topbar { display: none; }
  .content { padding: 20px 16px 48px; }
  .heading { flex-wrap: wrap; }
  .search { width: 100%; }
}
