:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  color-scheme: light dark;
  background: #f4f6f5;
  color: #202522;
  --bg: #f4f6f5;
  --surface: #fff;
  --line: #dce3df;
  --muted: #68716c;
  --accent: #176b57;
  --accent-soft: #e8f2ef;
  --danger: #a8322b;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: not-allowed; }
a { color: var(--accent); }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  min-height: 60px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 8px max(18px, calc((100vw - 1080px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; }
.brand-mark { width: 40px; height: 40px; border-radius: 7px; display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 800; }
.nav-actions, .button-row, .user-actions { display: flex; align-items: center; gap: 8px; }
.page { width: min(1080px, calc(100% - 28px)); margin: 24px auto 60px; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-panel { width: min(440px, 100%); padding: 24px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); display: grid; gap: 16px; }
.auth-panel h1 { font-size: 21px; margin: 0; }
.auth-panel p { margin: 0; color: var(--muted); line-height: 1.65; }
.origin { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.segments { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.segments button { border: 0; background: transparent; padding: 10px; color: var(--muted); }
.segments button.active { color: var(--accent); border-bottom: 2px solid var(--accent); font-weight: 700; }

.form { display: grid; gap: 13px; }
.compact-form { width: min(680px, 100%); margin: 12px 0 24px; }
.field { display: grid; gap: 6px; font-size: 13px; color: #4f5953; }
.field input, .field textarea, .field select { width: 100%; border: 1px solid #cbd4cf; border-radius: 6px; background: var(--surface); color: inherit; padding: 9px 10px; min-height: 41px; }
.field textarea { min-height: 90px; resize: vertical; }
.toggle-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.toggle-row input { width: 17px; height: 17px; accent-color: var(--accent); }
.choice-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
.choice-group legend { padding: 0 5px; color: var(--muted); font-size: 13px; }

.primary, .secondary, .danger, .icon-button { border-radius: 6px; min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 7px 13px; }
.primary { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.secondary { border: 1px solid #cbd4cf; background: var(--surface); color: inherit; text-decoration: none; }
.danger { border: 1px solid #d8aaa7; background: var(--surface); color: var(--danger); }
.icon-button { width: 36px; padding: 0; border: 1px solid transparent; background: transparent; color: var(--muted); }
.danger-icon { color: var(--danger); }
.text-button { border: 0; background: transparent; color: var(--accent); padding: 4px; justify-self: center; }
.hint, .muted { color: var(--muted); font-size: 13px; line-height: 1.6; }
.notice, .error { padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); font-size: 13px; margin-bottom: 12px; }
.error { border-color: var(--danger); background: #fff0ef; color: #872923; }

.dashboard-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: #e3e9e6; }
.identity-copy { display: grid; min-width: 0; }
.identity-copy strong { font-size: 18px; }
.identity-copy span { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow: auto; margin-bottom: 18px; }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 10px 12px; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom: 2px solid var(--accent); font-weight: 700; }

.section { padding: 4px 0 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section h2 { font-size: 17px; margin: 0; }
.subheading { margin-top: 28px !important; }
.info-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin: 4px 0 28px; }
.list { border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); align-items: center; }
.row-main { min-width: 0; display: grid; gap: 4px; }
.row-main strong, .row-main span { overflow-wrap: anywhere; }
.row-main span { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.badge { display: inline-flex; width: max-content; padding: 2px 7px; border-radius: 4px; background: #eef1ef; color: #52615a; font-size: 11px; }
.badge.active { background: var(--accent-soft); color: #125b49; }
.badge.revoked { background: #fff0ef; color: var(--danger); }
.empty { min-height: 160px; display: grid; place-items: center; color: var(--muted); }
.compact-empty { min-height: 80px; }

.dialog-backdrop { position: fixed; inset: 0; background: rgba(16, 22, 19, .55); display: grid; place-items: center; padding: 18px; z-index: 20; }
.dialog { width: min(600px, 100%); max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 22px; }
.dialog h2 { font-size: 18px; margin: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: #151b18; color: #eef4f0; border-radius: 6px; padding: 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
.token-code { max-height: 280px; overflow: auto; }
.details-line { font-size: 13px; color: var(--muted); margin: 5px 0; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat { border-left: 3px solid var(--accent); padding: 8px 12px; background: var(--surface); }
.stat strong { display: block; font-size: 24px; }
.stat span { font-size: 12px; color: var(--muted); }
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.origin-cell, .mono-cell { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; max-width: 260px; }
.table-actions { white-space: nowrap; }
.inline-select { min-height: 34px; border: 1px solid #cbd4cf; border-radius: 6px; background: var(--surface); color: inherit; padding: 4px 28px 4px 8px; }
.socials { display: flex; flex-wrap: wrap; gap: 8px; }
.maintenance-panel { display: grid; gap: 18px; }
.maintenance-summary { display: flex; align-items: baseline; gap: 9px; border-left: 3px solid var(--accent); padding: 10px 14px; }
.maintenance-summary strong { font-size: 28px; }
.maintenance-summary span { color: var(--muted); }

@media (prefers-color-scheme: dark) {
  :root { --bg: #111513; --surface: #171b19; --line: #343c37; --muted: #a4afa8; --accent: #58b99f; --accent-soft: #1c332c; --danger: #ef817a; }
  .field { color: #cbd4cf; }
  .field input, .field textarea, .field select, .inline-select { border-color: #465049; }
  .secondary { border-color: #465049; }
  .notice { color: #cae3db; }
  .error { background: #351b1a; color: #f0aaa5; }
  .badge { background: #252c28; color: #b7c1bb; }
  .badge.active { background: #1c332c; color: #70cbb2; }
  .badge.revoked { background: #351b1a; color: #f0aaa5; }
  .avatar { background: #2b332f; }
}

@media (max-width: 700px) {
  .topbar { align-items: flex-start; }
  .page { margin-top: 16px; }
  .dashboard-head { align-items: flex-start; }
  .user-actions span { display: none; }
  .stats { grid-template-columns: 1fr 1fr; }
  .row { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
  .button-row { flex-wrap: wrap; }
  .button-row > * { flex: 1; }
  .choice-group { grid-template-columns: 1fr; }
  .desktop-only { display: none; }
  table { min-width: 720px; }
}
