:root {
  color-scheme: light;
  --bg: #fff;
  --sidebar: #f7f7f7;
  --subtle: #fafafa;
  --hover: #eee;
  --selected: #e9e9e9;
  --border: #e4e4e4;
  --text: #202020;
  --muted: #666;
  --primary: #171717;
  --primary-hover: #363636;
  --primary-text: #fff;
  --focus: #737373;
  --positive: #226644;
  --positive-bg: #edf6f0;
  --warning: #795a13;
  --warning-bg: #fbf6e9;
  --danger: #a73030;
  --danger-bg: #fdf0f0;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #212121;
  --sidebar: #171717;
  --subtle: #262626;
  --hover: #303030;
  --selected: #343434;
  --border: #3d3d3d;
  --text: #eee;
  --muted: #b0b0b0;
  --primary: #eee;
  --primary-hover: #d4d4d4;
  --primary-text: #171717;
  --focus: #b4b4b4;
  --positive: #8dd7a9;
  --positive-bg: #203329;
  --warning: #e0be74;
  --warning-bg: #39321f;
  --danger: #efa0a0;
  --danger-bg: #3a2626;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; font-weight: 650; letter-spacing: -.025em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p, small, .hint { color: var(--muted); }
small, .hint { display: block; font-size: 12px; }
a { color: var(--text); font-weight: 550; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select { font: inherit; }

button, .button {
  min-height: 36px;
  padding: 7px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
}

button:hover, .button:hover { background: var(--hover); }
.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.text { min-height: 0; padding: 0; border: 0; background: transparent; }
.text:hover { background: transparent; text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.skip { position: absolute; top: 8px; left: -1000px; z-index: 2; background: var(--bg); padding: 6px; }
.skip:focus { left: 8px; }

.dashboard { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100dvh; }
.dashboard > aside {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 9px; font-size: 16px; line-height: 1; white-space: nowrap; }
aside .brand { padding: 0 8px; }
.brand-mark { display: block; width: 30px; height: 30px; flex: none; }
.brand strong { font-weight: 650; }
aside nav { display: grid; gap: 3px; margin-top: 27px; }
aside nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}
aside nav a:hover { color: var(--text); background: var(--hover); }
aside nav a[aria-current="page"] { color: var(--text); background: var(--selected); }
.icon, .empty-icon { display: inline-block; width: 16px; height: 16px; position: relative; flex: none; }
.domain-icon { border: 1.5px solid; border-radius: 50%; }
.domain-icon::before { content: ""; position: absolute; inset: 0 25%; border: 1px solid; border-radius: 50%; }
.domain-icon::after { content: ""; position: absolute; top: 46%; left: 0; right: 0; border-top: 1px solid; }
.key-icon::before { content: ""; position: absolute; width: 55%; height: 55%; border: 1.5px solid; border-radius: 50%; }
.key-icon::after { content: ""; position: absolute; left: 39%; top: 58%; height: 30%; width: 66%; border-top: 1.5px solid; border-right: 1.5px solid; transform: rotate(45deg); }
.terminal-icon { width: 17px; height: 14px; border: 1.5px solid; border-radius: 3px; }
.terminal-icon::after { content: "›_"; position: absolute; inset: -2px 2px; font: bold 10px/14px monospace; }

.account {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 12px 4px 0;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.account strong { font-weight: 550; }
.account form { margin-left: auto; }
.account .text { color: var(--muted); font-size: 12px; white-space: nowrap; }
.avatar { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 50%; background: var(--selected); font-weight: 650; }
.main-shell { min-width: 0; }
.topbar {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
}
.crumb { color: var(--muted); font-size: 13px; }
.crumb span { margin: 0 7px; }
.crumb strong { color: var(--text); font-weight: 550; }

.preferences { display: flex; align-items: center; gap: 8px; flex: none; }
.language-options { display: flex; padding: 2px; border: 1px solid var(--border); border-radius: 7px; }
.language-options a { padding: 3px 7px; border-radius: 4px; font-size: 12px; color: var(--muted); text-decoration: none; }
.language-options a:hover { background: var(--hover); }
.language-options a[aria-current] { color: var(--text); background: var(--selected); }
.preferences select { width: auto; min-height: 30px; padding: 4px 6px; font-size: 12px; }

main#main { width: 100%; max-width: 1400px; margin: 0 auto; padding: 25px clamp(16px, 3vw, 38px) 58px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.heading-actions, .actions, .form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.metrics, .table-wrap, .editor, .empty, .reveal { border: 1px solid var(--border); border-radius: 9px; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 18px; }
.metrics > div { display: grid; gap: 6px; padding: 15px 18px; }
.metrics > div + div { border-left: 1px solid var(--border); }
.metrics span { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.metrics strong { font-size: 27px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1; }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; flex: none; }
.green { background: var(--positive); }
.amber { background: var(--warning); }

.table-wrap { overflow: auto; }
table { width: 100%; min-width: 560px; border-collapse: collapse; text-align: left; font-size: 13px; }
caption { padding: 13px 15px; text-align: left; font-weight: 650; }
th, td { padding: 11px 15px; vertical-align: top; }
th { border-top: 1px solid var(--border); color: var(--muted); background: var(--subtle); font-size: 12px; font-weight: 550; white-space: nowrap; }
tbody tr { border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--subtle); }
tbody tr.client-offline, tbody tr.client-offline:hover { background: var(--danger-bg); }
.client-offline td:first-child, .offline-status { color: var(--danger); }
td strong { font-weight: 600; }
.mono, code { font-family: "IBM Plex Mono", ui-monospace, monospace; overflow-wrap: anywhere; }
.result { min-width: 7em; max-width: 24em; overflow-wrap: anywhere; }
.pill { display: inline-block; border-radius: 1rem; padding: 2px 8px; background: var(--warning-bg); color: var(--warning); font-size: 12px; }
.pill.ok { background: var(--positive-bg); color: var(--positive); }
.empty { padding: clamp(30px, 6vw, 66px) 20px; text-align: center; }
.empty-icon { margin-bottom: 12px; color: var(--muted); }
.empty p, .editor > p, .login-intro p, .reveal p, .danger-zone p { margin: 5px 0 12px; }
.editor, .reveal { max-width: 748px; padding: clamp(16px, 3vw, 25px); }
.editor h2 { margin-bottom: 10px; }
label, fieldset { display: block; margin: 13px 0; font-size: 13px; font-weight: 550; }
input:not([type="checkbox"]):not([type="hidden"]), select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
}
label input:not([type="checkbox"]), label select { display: block; margin-top: 5px; }
.preferences select { width: auto; padding: 4px 6px; }
input::placeholder { color: var(--muted); }
fieldset { padding: 4px 12px 6px; border: 1px solid var(--border); border-radius: 7px; }
legend { padding: 0 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
input[type="checkbox"] { width: 16px; height: 16px; flex: none; }
.form-actions, .bottom-actions { margin-top: 19px; }
.danger-zone { margin-top: 24px; padding-top: 17px; border-top: 1px solid var(--border); }
.danger { color: var(--danger); }
.danger:hover { background: var(--danger-bg); }
.notice, .alert { margin-bottom: 14px; padding: 9px 12px; border-radius: 7px; background: var(--positive-bg); color: var(--positive); }
.alert { background: var(--danger-bg); color: var(--danger); }
.reveal { margin-bottom: 18px; }
.reveal code, pre { padding: 9px 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--subtle); }
.reveal code { display: block; user-select: all; }
pre { overflow: auto; font-size: 12px; }
pre code { overflow-wrap: normal; }
.setup h2 { margin-top: 19px; }
.setup-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 17px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--subtle);
}
.setup-tabs a {
  display: grid;
  place-items: center;
  min-height: 38px;
  padding: 5px 8px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  text-decoration: none;
}
.setup-tabs a:hover { background: var(--hover); color: var(--text); }
.setup-tabs a[aria-current="page"] { background: var(--selected); color: var(--text); }

.auth { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; padding: 16px 20px; background: var(--sidebar); }
.auth-preferences { justify-self: end; }
.login-card { place-self: center; width: min(100%, 400px); padding: 28px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.login-card .brand { margin-bottom: 21px; }
.login-card .wide { margin-top: 5px; width: 100%; }

@media (max-width: 760px) {
  .dashboard { display: block; }
  .dashboard > aside {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  aside .brand { padding: 0; }
  aside nav { grid-area: 2 / 1 / 3 / -1; display: flex; flex-wrap: wrap; gap: 3px; margin: 0; }
  aside nav a { padding: 5px 8px; gap: 6px; }
  .account { margin: 0; padding: 0; border: 0; }
  .account .avatar, .account strong { display: none; }
  .topbar { min-height: 0; padding: 8px 14px; }
  .crumb span { margin: 0 3px; }
  .setup-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .setup pre, .setup pre code { white-space: pre-wrap; overflow-wrap: anywhere; }
  .metrics > div { padding: 12px 8px; }
  .metrics strong { font-size: 23px; }
}

.audit-icon { border: 1.5px solid; border-radius: 3px; }
.audit-icon::after { content: ""; position: absolute; inset: 4px 3px; border-top: 1px solid; border-bottom: 1px solid; }
.audit-filters, .audit-pagination { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.audit-filters [aria-current] { background: var(--selected); }
.audit-refresh { margin-left: auto; }
.audit-pagination { justify-content: flex-end; margin: 14px 0 0; }
.audit-table td { overflow-wrap: anywhere; }
.audit-table td small.mono { max-width: 22ch; }
.audit-ip { min-width: 10rem; }
.audit-ip-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.audit-ip-button { gap: 5px; white-space: nowrap; }
.audit-ip-search { width: 10px; height: 10px; border: 1.5px solid currentColor; border-radius: 50%; position: relative; margin-right: 2px; }
.audit-ip-search::after { content: ""; position: absolute; width: 5px; height: 1.5px; background: currentColor; bottom: -2px; right: -4px; transform: rotate(45deg); }
.audit-ip-status { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.audit-ip-details:not([hidden]) { display: grid; grid-template-columns: minmax(4.5em, max-content) minmax(0, 1fr); gap: 4px 10px; margin: 8px 0 0; max-width: 22rem; font-size: 13px; }
.audit-ip-details dt { color: var(--muted); }
.audit-ip-details dd { margin: 0; }
.nowrap { white-space: nowrap; }
.pending-fields { padding: 0; margin: 0; border: 0; }
