:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-muted: #f7f8fb;
  --line: #e4e8ee;
  --line-strong: #d3dae3;
  --text: #122033;
  --muted: #5d6b7c;
  --faint: #8b97a6;
  --navy: #1b365d;
  --navy-hover: #152a4a;
  --brass: #c9a24a;
  --accent: #1b365d;
  --accent-soft: #eef3f9;
  --danger: #c2413b;
  --danger-soft: #fdf1f0;
  --ok: #1f7a54;
  --ok-soft: #edf8f3;
  --warn: #b45309;
  --warn-soft: #fff6eb;
  --shadow: 0 1px 2px rgba(18, 32, 51, 0.04), 0 10px 28px rgba(18, 32, 51, 0.05);
  --shadow-lg: 0 18px 50px rgba(18, 32, 51, 0.14);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", "Segoe UI Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --focus: 0 0 0 3px rgba(27, 54, 93, 0.22);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
html { -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  color-scheme: light;
}

a { color: var(--navy); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand .mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--navy);
  position: relative;
  flex: 0 0 auto;
}

.brand .mark::before {
  content: "";
  position: absolute;
  inset: 4px 5px 3px;
  border: 1.5px solid var(--brass);
  border-radius: 4px 4px 7px 7px;
  border-top-width: 2px;
}

.brand .mark::after {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--brass);
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topnav a,
.topnav .link-btn {
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 7px 10px;
  border-radius: 7px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
}

.topnav a:hover,
.topnav .link-btn:hover { color: var(--text); background: var(--surface-muted); }

.topnav a.is-active {
  color: var(--navy);
  background: var(--accent-soft);
}

.topnav form { display: inline; margin: 0; }

main {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 72px;
  flex: 1;
}

body.auth main {
  max-width: 460px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: 8vh;
  padding-bottom: 8vh;
}

.flash-stack { display: grid; gap: 10px; margin-bottom: 18px; }
body.auth .flash-stack { margin-bottom: 14px; }

.flash {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  border: 1px solid;
}

.flash.error { background: var(--danger-soft); border-color: #f0c9c6; color: #8f2d28; }
.flash.success { background: var(--ok-soft); border-color: #c8e8d8; color: #176346; }

.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card { padding: 32px 32px 28px; }

body.auth .card { margin: 0; }

.card.wide,
.card.table-card { max-width: none; }

.page { display: grid; gap: 18px; }

.page-header h1,
.card > h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
  line-height: 1.2;
}

.card > h1 { font-size: 22px; }

.lede {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 22px;
  line-height: 1.55;
}

.page-header .lede,
.panel-head .lede { margin-bottom: 0; }

.panel { padding: 22px 24px; }
.panel.narrow { max-width: 560px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.panel-head { margin-bottom: 16px; }
.panel-head h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.stack { display: grid; gap: 14px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.stat .k {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 6px;
}

.stat .v {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.nav-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.nav-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.nav-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-lg);
}

.nav-card strong {
  display: block;
  font-size: 14.5px;
  margin-bottom: 4px;
}

.nav-card span {
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 4px;
  background: #e9edf2;
  border-radius: 10px;
  width: fit-content;
  max-width: 100%;
}

.tab {
  appearance: none;
  text-decoration: none;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 7px;
}

.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--navy); box-shadow: 0 1px 2px rgba(18, 32, 51, 0.08); }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 16px 0 6px;
}

.field { margin-top: 16px; }
.field > label { margin-top: 0; }
.field.tight { margin-top: 0; }

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  min-height: 42px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
}

textarea {
  min-height: 96px;
  font-family: var(--mono);
  font-size: 13px;
  resize: vertical;
}

select { cursor: pointer; }

input::placeholder,
textarea::placeholder { color: var(--faint); }

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: var(--focus);
}

input[readonly] {
  background: var(--surface-muted);
  color: var(--muted);
}

.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.otp {
  font-family: var(--mono);
  letter-spacing: 0.28em;
  font-size: 18px;
  text-align: center;
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  font-family: inherit;
  background: none;
  color: inherit;
}

button:focus-visible,
.btn:focus-visible,
a:focus-visible,
.tab:focus-visible,
.page-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-hover); }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-muted); }
.btn-danger { background: var(--surface); border-color: #e8b4b0; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }
.form-actions { margin-top: 22px; }
.row-actions { display: flex; gap: 10px; margin-top: 22px; }
.row-actions .btn { flex: 1; }

.btn-sm {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
}

.link-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  font-family: inherit;
  min-height: 0;
}

.btn-text {
  min-height: 0;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}

.btn-text:hover { color: var(--text); }
.btn-text.danger { color: var(--danger); }
.btn-text.danger:hover { color: #9f2d28; }
.btn-text.ok { color: var(--ok); }

.copy-btn {
  min-height: 28px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface);
  flex: 0 0 auto;
}

.copy-btn:hover { color: var(--text); background: var(--surface-muted); }
.copy-btn.is-copied { color: var(--ok); border-color: #c8e8d8; background: var(--ok-soft); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.muted-link { color: var(--muted); font-size: 13.5px; text-decoration: none; }
.muted-link:hover { color: var(--navy); }
.foot-links { text-align: center; margin-top: 20px; font-size: 13.5px; color: var(--muted); }

.status {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  min-height: 1.2em;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.inline-form .grow { flex: 1; min-width: 0; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th, td {
  text-align: left;
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  overflow-wrap: break-word;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-top: 4px;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-muted); }

table.table-fixed { table-layout: fixed; }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

.cell-secondary {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

td.num { text-align: right; white-space: nowrap; }

code, .mono { font-family: var(--mono); font-size: 12.5px; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-muted);
  color: var(--muted);
}

.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--danger-soft); color: var(--danger); }
.pill.accent, .pill.brass { background: var(--accent-soft); color: var(--navy); }

.kv {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 8px 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  align-items: start;
}

.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); padding-top: 2px; }
.kv .val {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}
.kv .mono { overflow-wrap: anywhere; }

.secret-box {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  word-break: break-all;
}

.qr-frame {
  background: #fff;
  border: 1px solid var(--line);
  padding: 16px;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: center;
}

.scope-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.scope-list li {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.scope-list li:last-child { border-bottom: none; }

.notice {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #f0d9a8;
  background: var(--warn-soft);
  color: #8a4b12;
  font-size: 13.5px;
  margin: 0 0 8px;
}

.danger-zone {
  margin-top: 28px;
  padding-top: 8px;
}

.empty {
  color: var(--muted);
  font-size: 14px;
  padding: 8px 0 4px;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.page-nav { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.page-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 4px 10px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.page-btn:hover { background: var(--surface-muted); }
.page-btn.is-current {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
  pointer-events: none;
}

.page-ellipsis { color: var(--faint); padding: 0 4px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.setting-row .panel-head { margin-bottom: 0; flex: 1; min-width: 220px; }
.setting-row .lede { max-width: 520px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 36, 0.48);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  max-width: 420px;
  width: 100%;
  position: relative;
}

.modal h2 { font-size: 18px; margin: 0 0 4px; letter-spacing: -0.02em; }
.modal .lede { margin-bottom: 8px; }

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--faint);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 6px;
  min-height: 0;
}

.modal-close:hover { color: var(--text); }

.error-code {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 8px;
}

@media (max-width: 760px) {
  .stat-grid,
  .nav-cards { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 4px; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .setting-row { flex-direction: column; }
  .card, .panel { padding: 20px; }
  .topbar-inner, main { padding-left: 16px; padding-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .nav-card { transition: none; }
}
