/* TokenHub. Светлая и тёмная тема через переменные. Значения контраста — для текста на фоне. */
:root {
  color-scheme: light;
  --paper: #f5f3ee;
  --surface: #fffefb;
  --surface-2: #efece4;
  --ink: #1a1a17;
  --ink-2: #4a4a43;   /* вторичный текст, контраст 8.9:1 на --paper */
  --line: #dcd8cc;
  --accent: #1f6b47;  /* ссылки, активный пункт, фокус; контраст 6.4:1 на --paper */
  --accent-ink: #ffffff;
  --danger: #a3262b;  /* контраст 6.9:1 на --paper */
  --warn: #7a5a00;    /* контраст 6.1:1 на --paper */
  --ok: #1f6b47;
  --btn-hover: #000;

  --font-serif: Georgia, "Times New Roman", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, Consolas, "Courier New", monospace;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  --r-control: 6px;
  --r-block: 10px;
  --max: 1120px;
}

/* тёмная тема: тот же смысл, другие значения */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #161613;
  --surface: #1f1f1b;
  --surface-2: #2a2a25;
  --ink: #ecebe4;
  --ink-2: #b4b2a6;   /* контраст ~8:1 на --paper */
  --line: #3a3a33;
  --accent: #7fd1a5;  /* контраст ~9:1 на --paper */
  --accent-ink: #0f1a14;
  --danger: #ff8a8e;
  --warn: #e8c46a;
  --ok: #7fd1a5;
  --btn-hover: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.6 var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { font-family: var(--font-serif); font-weight: 400; line-height: 1.15; margin: 0 0 var(--s3); letter-spacing: -0.01em; }
h1 { font-size: clamp(2.25rem, 5vw, 3.5rem); }
h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin-top: var(--s7); }
h3 { font-size: 1.25rem; }
p { margin: 0 0 var(--s3); }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
pre { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-block); padding: var(--s4); }
.muted { color: var(--ink-2); }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.small { font-size: 13px; }
.callout {
  border-left: 3px solid var(--warn); padding: var(--s3) var(--s4);
  background: var(--surface); margin: 0 0 var(--s3);
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- шапка ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  padding: var(--s3) var(--s5); border-bottom: 1px solid var(--line);
  background: var(--paper); position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.topbar nav { display: flex; gap: var(--s5); align-items: center; flex-wrap: wrap; }
.topbar nav > a, .topbar nav > button.link {
  color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; min-height: 32px;
}
.topbar nav > a:hover { text-decoration: underline; }
.topbar nav a.btn { color: var(--accent-ink); text-decoration: none; }
.topbar nav a.btn:hover { text-decoration: none; }
.brand { font-family: var(--font-serif); font-size: 1.4rem; color: var(--ink) !important; text-decoration: none !important; }
.brand b { font-weight: 400; color: var(--accent); }
.icon-btn {
  min-width: 36px; min-height: 36px; border-radius: var(--r-control); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); }

main { flex: 1; width: min(var(--max), 100% - 2 * var(--s5)); margin: 0 auto; padding: var(--s7) 0 var(--s8); }
footer {
  border-top: 1px solid var(--line); padding: var(--s4) var(--s5); color: var(--ink-2); font-size: 14px;
  display: flex; gap: var(--s4); flex-wrap: wrap; justify-content: space-between;
}

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font: inherit; font-weight: 600; font-size: 15px; line-height: 1;
  min-height: 40px; padding: 0 var(--s4); border-radius: var(--r-control);
  border: 1px solid var(--ink); background: var(--ink); color: var(--paper); cursor: pointer;
  text-decoration: none !important;
}
.btn:hover { background: var(--btn-hover); color: var(--paper); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface); color: var(--ink); }
.btn.small { min-height: 32px; padding: 0 var(--s3); font-size: 14px; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: var(--paper); }
button.link { background: none; border: 0; color: var(--ink); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.chip {
  min-height: 36px; padding: 0 var(--s3); border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; font: inherit; font-size: 14px; font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------- главная ---------- */
.hero { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: var(--s7); align-items: start; padding-bottom: var(--s6); }
.eyebrow { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); margin: 0 0 var(--s3); }
.lead { font-size: 1.125rem; color: var(--ink-2); max-width: 36em; }
.actions { display: flex; gap: var(--s3); flex-wrap: wrap; margin-top: var(--s5); }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s5); margin: var(--s7) 0 var(--s5); border-top: 1px solid var(--line); padding-top: var(--s5); }
.features p { color: var(--ink-2); margin: 0; }

/* ---------- калькулятор ---------- */
.calc-card, .calc {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-block); padding: var(--s5);
}
.calc h2 { margin-top: 0; font-size: 1.5rem; }
.calc label { margin-bottom: var(--s4); }
.calc-out {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); padding: var(--s4) 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: var(--s4) 0;
}
.calc-out strong { display: block; font-family: var(--font-serif); font-weight: 400; font-size: 1.75rem; }
.presets { display: flex; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s4); }

/* ---------- формы ---------- */
.auth { max-width: 380px; }
.auth form { display: flex; flex-direction: column; gap: var(--s4); margin: var(--s5) 0; }
label { display: flex; flex-direction: column; gap: var(--s2); font-size: 14px; color: var(--ink-2); }
input, select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-control); padding: var(--s2) var(--s3); min-height: 40px; min-width: 0;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.inline { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-bottom: var(--s4); }
.inline input { flex: 1; min-width: 220px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--s4); align-items: end; }
.grid-form .btn { justify-self: start; }
.rate-input { max-width: 120px; text-align: right; }

/* ---------- кабинет ---------- */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); flex: 1; min-width: 0; }
.sidebar {
  border-right: 1px solid var(--line); padding: var(--s5) var(--s3); display: flex; flex-direction: column; gap: var(--s1);
  background: var(--surface);
}
.sidebar > a {
  color: var(--ink-2); padding: var(--s2) var(--s3); border-radius: var(--r-control); text-decoration: none; font-size: 15px;
}
.sidebar > a:hover { color: var(--ink); background: var(--paper); }
.sidebar > a.active { color: var(--ink); background: var(--paper); box-shadow: inset 2px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; padding: var(--s4) var(--s3) 0; border-top: 1px solid var(--line); font-size: 14px; display: flex; flex-direction: column; gap: var(--s1); word-break: break-all; }
.content { padding: var(--s6) var(--s7); min-width: 0; max-width: 960px; }
.content h1 { margin-top: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); border: 1px solid var(--line); border-radius: var(--r-block); background: var(--surface); margin: var(--s5) 0; }
.stat { padding: var(--s4) var(--s5); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: var(--s1); }
.stat:last-child { border-right: 0; }
.stat strong { font-family: var(--font-serif); font-weight: 400; font-size: 2rem; line-height: 1.1; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--s5); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-block); padding: var(--s5); margin-bottom: var(--s5); }
.panel h3 { margin-bottom: var(--s3); }
.kv { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv:last-of-type { border-bottom: 0; }
.panel .more { display: inline-flex; align-items: center; min-height: 32px; margin-top: var(--s2); font-size: 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-block); background: var(--surface); margin-bottom: var(--s5); }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th, table.data td { padding: var(--s3) var(--s4); text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { color: var(--ink-2); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { font-variant-numeric: tabular-nums; text-align: right; }
table.models th, table.models td { white-space: normal; vertical-align: top; }
table.models td:first-child { min-width: 240px; }
.filters { display: flex; gap: var(--s4); flex-wrap: wrap; margin: var(--s5) 0; }
.filters label { min-width: 220px; }
.empty { padding: var(--s5); color: var(--ink-2); margin: 0; }

.pill { font-size: 13px; padding: 2px var(--s2); border-radius: var(--r-control); border: 1px solid currentColor; }
.pill.paid { color: var(--ok); }
.pill.pending { color: var(--warn); }
.pill.revoked { color: var(--danger); }

.key-reveal { margin: var(--s4) 0; padding: var(--s4); border: 1px solid var(--accent); border-radius: var(--r-block); background: var(--surface); }
.key-reveal p { margin-bottom: var(--s2); }
.secret { display: block; word-break: break-all; background: var(--surface-2); padding: var(--s3); border-radius: var(--r-control); margin-bottom: var(--s3); }

/* ---------- тосты ---------- */
#toasts { position: fixed; right: var(--s5); bottom: var(--s5); display: flex; flex-direction: column; gap: var(--s2); z-index: 50; }
.toast {
  background: var(--ink); color: var(--paper); padding: var(--s3) var(--s4); border-radius: var(--r-control);
  max-width: 340px; font-size: 15px;
}
.toast.error { background: var(--danger); color: var(--paper); }

/* ---------- адаптив ---------- */
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: var(--s5); }
  .features { grid-template-columns: 1fr; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); padding: var(--s2); }
  .sidebar > a { padding: var(--s2); }
  .sidebar-foot { display: none; }
  .content { padding: var(--s5) var(--s4); }
}
@media (max-width: 560px) {
  main { padding-top: var(--s5); }
  .topbar { padding: var(--s2) var(--s4); }
  .topbar nav { gap: var(--s3); }
  .calc-out { grid-template-columns: 1fr; }
  .stat { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
