:root,
body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0e1d;
  --sidebar: #11172a;
  --surface: #171e35;
  --surface-2: #202a46;
  --surface-3: #2d395e;
  --line: #3b4a72;
  --line-soft: rgba(136, 155, 202, .24);
  --text: #f5f7ff;
  --muted: #adb9d5;
  --accent: #70e6c1;
  --accent-deep: #1cae8a;
  --accent-ink: #071f1a;
  --blue: #66b8ff;
  --purple: #ad92ff;
  --gold: #f5cb6d;
  --rose: #ff8eae;
  --danger: #ed6e88;
  --danger-deep: #a63f59;
  --ok: #62da9c;
  --shadow: 0 22px 52px rgba(1, 5, 18, .36);
  --shadow-soft: 0 10px 28px rgba(1, 5, 18, .22);
  --table-hover: rgba(102, 184, 255, .06);
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #edf2ff;
  --sidebar: #f9fbff;
  --surface: #ffffff;
  --surface-2: #f4f7ff;
  --surface-3: #e5ebfa;
  --line: #cad6ef;
  --line-soft: rgba(57, 83, 132, .18);
  --text: #1c2743;
  --muted: #62728e;
  --accent: #008e75;
  --accent-deep: #006b59;
  --accent-ink: #ffffff;
  --blue: #1478d4;
  --purple: #704ed1;
  --gold: #a66900;
  --rose: #cc476d;
  --danger: #c13f5b;
  --danger-deep: #9e2845;
  --ok: #128460;
  --shadow: 0 20px 48px rgba(56, 79, 123, .14);
  --shadow-soft: 0 8px 24px rgba(56, 79, 123, .10);
  --table-hover: rgba(20, 120, 212, .055);
}

@media (prefers-color-scheme: light) {
  body[data-theme="system"] {
    color-scheme: light;
    --bg: #edf2ff;
    --sidebar: #f9fbff;
    --surface: #ffffff;
    --surface-2: #f4f7ff;
    --surface-3: #e5ebfa;
    --line: #cad6ef;
    --line-soft: rgba(57, 83, 132, .18);
    --text: #1c2743;
    --muted: #62728e;
    --accent: #008e75;
    --accent-deep: #006b59;
    --accent-ink: #ffffff;
    --blue: #1478d4;
    --purple: #704ed1;
    --gold: #a66900;
    --rose: #cc476d;
    --danger: #c13f5b;
    --danger-deep: #9e2845;
    --ok: #128460;
    --shadow: 0 20px 48px rgba(56, 79, 123, .14);
    --shadow-soft: 0 8px 24px rgba(56, 79, 123, .10);
    --table-hover: rgba(20, 120, 212, .055);
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--text); font: 15px/1.5 Arial, Calibri, sans-serif; }
a { color: inherit; }
button, input, textarea, select { font: inherit; }
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 41px; padding: 9px 14px; border: 1px solid transparent; border-radius: 7px; color: var(--accent-ink); background: var(--accent); font-weight: 700; cursor: pointer; text-decoration: none; transition: transform .16s ease, background .16s ease, border-color .16s ease, box-shadow .16s ease; }
button:hover, .button:hover { background: var(--accent-deep); box-shadow: 0 9px 20px rgba(25, 175, 138, .25); transform: translateY(-1px); }
button.secondary, .button.secondary { color: var(--blue); background: var(--surface-2); border-color: var(--line); }
button.secondary:hover, .button.secondary:hover { color: var(--text); background: var(--surface-3); box-shadow: none; }
button.danger { color: #fff; background: var(--danger-deep); border-color: var(--danger); }
button.danger:hover { background: var(--danger); box-shadow: 0 9px 20px rgba(181, 52, 83, .24); }
button.ghost { width: 100%; color: var(--muted); background: transparent; border-color: var(--line); }
button.ghost:hover { color: var(--text); background: var(--surface-2); box-shadow: none; }
input, textarea, select { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 7px; color: var(--text); background: var(--surface-2); outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(102, 184, 255, .18); }
textarea { min-height: 98px; resize: vertical; }
code { color: var(--blue); font: 12px/1.45 Consolas, monospace; overflow-wrap: anywhere; }
hr { margin: 24px 0; border: 0; border-top: 1px solid var(--line-soft); }
summary { color: var(--purple); cursor: pointer; font-weight: 700; }
details form { margin-top: 10px; }

.public-shell { display: flex; flex-direction: column; width: min(1120px, calc(100% - 40px)); min-height: 100vh; margin: 0 auto; }
.public-hero { display: grid; flex: 1; align-content: center; gap: 42px; padding: 80px 0; }
.public-brand { display: flex; align-items: center; gap: 12px; color: var(--muted); font-weight: 700; letter-spacing: .04em; }
.brand-mark { display: inline-grid; width: 42px; height: 42px; place-items: center; border: 2px solid var(--purple); border-radius: 50%; color: var(--gold); background: var(--surface-2); box-shadow: 0 0 0 4px rgba(173, 146, 255, .12); font-size: 13px; letter-spacing: .05em; }
.brand-mark.large { width: 54px; height: 54px; font-size: 16px; }
.hero-copy { max-width: 780px; }
.hero-copy h1 { max-width: 760px; margin: 9px 0 18px; font-size: clamp(42px, 7vw, 80px); line-height: 1.03; letter-spacing: 0; }
.hero-copy p:not(.eyebrow) { max-width: 620px; margin: 0; color: var(--muted); font-size: 18px; }
.hero-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.hero-grid div { padding: 18px; border: 1px solid var(--line); border-top: 3px solid var(--accent); background: var(--surface); box-shadow: var(--shadow-soft); }
.hero-grid div:nth-child(2) { border-top-color: var(--blue); }
.hero-grid div:nth-child(3) { border-top-color: var(--gold); }
.hero-grid strong, .hero-grid span { display: block; }
.hero-grid span { margin-top: 5px; color: var(--muted); font-size: 13px; }
.public-footer { padding: 22px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.simple-card { width: min(500px, calc(100% - 32px)); margin: 12vh auto; padding: 30px; border: 1px solid var(--line); border-top: 3px solid var(--purple); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.simple-card h1 { margin: 5px 0 12px; font-size: 29px; }
.login-card { margin-top: 10vh; }

.admin-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 24px 16px; border-right: 1px solid var(--line); background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 7px 24px; text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { color: var(--text); font-size: 15px; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 12px; }
.side-nav { display: grid; gap: 6px; }
.side-nav a { padding: 11px 12px; border: 1px solid transparent; border-left: 3px solid transparent; border-radius: 7px; color: var(--muted); text-decoration: none; transition: background .15s ease, color .15s ease, border-color .15s ease; }
.side-nav a:hover { color: var(--text); border-color: var(--line-soft); background: var(--surface); }
.side-nav a.active { border-color: var(--purple); border-left-color: var(--gold); color: var(--text); background: var(--surface-2); box-shadow: inset 0 0 0 1px rgba(173, 146, 255, .10); }
.sidebar-bottom { margin-top: auto; padding: 16px 7px 0; border-top: 1px solid var(--line); }
.account { margin-bottom: 11px; color: var(--text); font-size: 13px; font-weight: 700; }
.account span { display: block; margin-top: 2px; color: var(--blue); font-size: 12px; font-weight: 400; }
.panel-main { width: min(1500px, 100%); padding: 30px 38px 60px; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 0 0 26px; }
.panel-header h1 { margin: 3px 0 0; font-size: 29px; letter-spacing: 0; }
.eyebrow { margin: 0; color: var(--purple); font-size: 11px; font-weight: 700; letter-spacing: .12em; }
.header-status { display: inline-flex; align-items: center; gap: 8px; margin-top: 7px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--blue); background: var(--surface); font-size: 12px; box-shadow: var(--shadow-soft); }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgba(98, 218, 156, .16); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric-grid article, .panel-card { border: 1px solid var(--line); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow-soft); }
.metric-grid article { min-height: 140px; padding: 18px; border-top: 3px solid var(--accent); }
.metric-grid article:nth-child(2) { border-top-color: var(--blue); }
.metric-grid article:nth-child(3) { border-top-color: var(--gold); }
.metric-grid article:nth-child(4) { border-top-color: var(--rose); }
.metric-grid span, .metric-grid small { display: block; color: var(--muted); }
.metric-grid strong { display: block; margin: 6px 0; color: var(--gold); font-size: 38px; line-height: 1; }
.metric-grid article:nth-child(2) strong { color: var(--blue); }
.metric-grid article:nth-child(3) strong { color: var(--accent); }
.metric-grid article:nth-child(4) strong { color: var(--rose); }
.metric-grid small { font-size: 12px; }
.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.panel-card { padding: 20px; margin-bottom: 14px; }
.panel-grid .panel-card { margin-bottom: 0; }
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 17px; }
.card-heading h2, .panel-card h2 { margin: 3px 0 0; font-size: 18px; letter-spacing: 0; }
.detail-list { margin: 0; }
.detail-list div { display: flex; justify-content: space-between; gap: 18px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; text-align: right; }
.form-stack { display: grid; gap: 13px; }
.form-stack label, .form-grid label, .two-fields label, .filter-row label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.form-stack label span { font-size: 11px; }
.form-stack.compact { max-width: 580px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-grid .wide { grid-column: 1 / -1; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.filter-row { display: grid; grid-template-columns: minmax(220px, 2fr) minmax(140px, 1fr) minmax(140px, 1fr) auto; align-items: end; gap: 10px; margin: 0 0 16px; padding: 14px; border: 1px solid var(--line); border-left: 3px solid var(--blue); border-radius: 8px; background: var(--surface-2); }
.toggle { display: flex !important; align-items: center; gap: 9px; color: var(--text) !important; }
.toggle input { width: auto; accent-color: var(--purple); }
.notice, .error, .new-key { margin: 0 0 14px; padding: 13px 15px; border-radius: 7px; }
.notice { border: 1px solid var(--blue); border-left: 4px solid var(--accent); color: var(--text); background: rgba(51, 128, 206, .14); }
.error { border: 1px solid var(--danger); border-left: 4px solid var(--rose); color: var(--text); background: rgba(181, 52, 83, .18); }
.new-key { border: 1px solid var(--gold); border-left: 4px solid var(--purple); background: rgba(245, 203, 109, .09); }
.new-key p { margin: 0 0 7px; color: var(--text); }
.new-key code { display: block; padding: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--gold); font-size: 18px; overflow-wrap: anywhere; }
.muted-text { color: var(--muted); }
.small { font-size: 12px; }
.positive { color: var(--ok); font-weight: 700; }
.text-link, .back-link a { color: var(--blue); font-size: 13px; font-weight: 700; text-decoration: none; }
.text-link:hover, .back-link a:hover { color: var(--purple); text-decoration: underline; }
.back-link { margin: -5px 0 15px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 720px; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 9px; border-bottom: 1px solid var(--line-soft); vertical-align: top; text-align: left; }
th { color: var(--purple); font-size: 11px; letter-spacing: .07em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--table-hover); }
.status { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status.ok { color: #dfffee; background: #1d6048; }
.status.danger { color: #ffe8ed; background: #7d3148; }
.status.muted { color: var(--text); background: var(--surface-3); }
body[data-theme="light"] .status.ok { color: #0d6748; background: #dcf8ea; }
body[data-theme="light"] .status.danger { color: #9c2945; background: #ffe5ec; }
body[data-theme="light"] .status.muted { color: #4e5f7b; background: #e5ebfa; }
.table-action { color: var(--blue); font-weight: 700; text-decoration: none; }
.table-action:hover { color: var(--purple); text-decoration: underline; }
.empty { color: var(--muted); text-align: center; }
.inline-form { display: inline; }
.inline-form button { min-height: 33px; padding: 6px 9px; font-size: 12px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.button-row.compact-actions { min-width: 210px; margin-top: 0; }
.steps { display: grid; gap: 9px; margin: 0 0 18px; padding-left: 20px; color: var(--muted); }
.steps li::marker { color: var(--gold); font-weight: 700; }
.hash { display: inline-block; max-width: 310px; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .panel-main { padding: 26px 24px 52px; }
  .filter-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .public-shell { width: min(100% - 24px, 1120px); }
  .hero-grid, .panel-grid, .form-grid, .two-fields, .filter-row { grid-template-columns: 1fr; }
  .admin-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 15px; }
  .brand { padding-bottom: 14px; }
  .side-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-nav a { border: 1px solid var(--line); }
  .side-nav a.active { border-left-color: var(--gold); }
  .sidebar-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding-top: 12px; }
  .sidebar-bottom form, .sidebar-bottom button { width: auto; }
  .panel-main { padding: 22px 14px 42px; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-grid article { min-height: 118px; }
  .metric-grid strong { font-size: 31px; }
  .simple-card { margin: 42px auto; }
}
