/* CryptoWorker UI theme
   Principles: system fonts, a single accent color, thin lines, no shadows, full width, dense and readable grids.
   Tokens live in :root; dark mode follows prefers-color-scheme automatically. */

:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #ebebe8;
  --text: #1c1c1c;
  --muted: #666663;
  --border: #d9d9d4;
  --accent: #1f5eff;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --ok: #1e7a3c;
  --warn: #8a5a00;
  --radius: 3px;
  --topbar-h: 46px;
  --sidebar-w: 216px;
  --gutter: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1a1a1a;
    --surface-2: #232323;
    --text: #e6e6e3;
    --muted: #9a9a96;
    --border: #2e2e2c;
    --accent: #6f9bff;
    --accent-ink: #0b1a3a;
    --danger: #ff7b72;
    --ok: #57c274;
    --warn: #e0b34a;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 15px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .6rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8rem; }
code, .mono { font-family: var(--mono); font-size: .9em; }
small, .muted { color: var(--muted); }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0 var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; color: var(--text); letter-spacing: -0.02em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { color: var(--muted); padding: .35rem .6rem; border-radius: var(--radius); }
.nav a:hover, .nav a.active { color: var(--text); background: var(--surface-2); text-decoration: none; }
.userbox { display: flex; align-items: center; gap: .6rem; white-space: nowrap; }
.userbox img { width: 24px; height: 24px; border-radius: 50%; }

/* ---------- Page body ---------- */
.page { flex: 1; width: 100%; padding: 1.1rem var(--gutter) 2rem; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.footer {
  padding: .8rem var(--gutter);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .85rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ---------- Admin: sidebar + content ---------- */
.admin { display: grid; grid-template-columns: var(--sidebar-w) 1fr; flex: 1; min-height: 0; }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); padding: .8rem 0; }
.sidebar .group { padding: .5rem var(--gutter) .25rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sidebar a { display: block; padding: .4rem var(--gutter); color: var(--text); border-left: 2px solid transparent; }
.sidebar a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar a.active { border-left-color: var(--accent); background: var(--surface-2); font-weight: 600; }
@media (max-width: 900px) {
  .admin { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); display: flex; overflow-x: auto; padding: 0; }
  .sidebar .group { display: none; }
  .sidebar a { border-left: 0; border-bottom: 2px solid transparent; white-space: nowrap; }
  .sidebar a.active { border-bottom-color: var(--accent); }
}

/* ---------- Grid (table) ---------- */
.grid-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; font-size: .92rem; }
.grid th, .grid td { padding: .45rem .7rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.grid th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.grid tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.grid td.num, .grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.wrap { white-space: normal; }
.grid .empty { text-align: center; color: var(--muted); padding: 2rem; }

/* ---------- Cards / stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; margin-bottom: 1.2rem; }
.stat { border: 1px solid var(--border); background: var(--surface); padding: .8rem .9rem; border-radius: var(--radius); }
.stat .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.panel { border: 1px solid var(--border); background: var(--surface); padding: 1rem; border-radius: var(--radius); }
.panel + .panel { margin-top: .75rem; }

/* ---------- Forms ---------- */
.form { max-width: 720px; display: grid; gap: .8rem; }
.form.wide { max-width: none; }
.field { display: grid; gap: .25rem; }
.field label { font-size: .85rem; font-weight: 600; }
.field .hint { font-size: .8rem; color: var(--muted); }
input[type="text"], input[type="number"], input[type="url"], textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: .45rem .6rem; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; border-color: var(--accent); }
textarea { min-height: 6rem; resize: vertical; }
.checks { display: flex; gap: 1rem; flex-wrap: wrap; }
.checks label { display: inline-flex; gap: .35rem; align-items: center; font-weight: 400; }
.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; color: var(--danger); }
.field-validation-error { color: var(--danger); font-size: .8rem; }

/* ---------- Buttons / badges / alerts ---------- */
.btn {
  font: inherit; display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .8rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  cursor: pointer; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.sm { padding: .2rem .5rem; font-size: .85rem; }
.inline { display: inline; }

.badge { display: inline-block; padding: .1rem .45rem; border-radius: 999px; font-size: .75rem; border: 1px solid var(--border); background: var(--surface-2); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.badge.off { color: var(--muted); }
.badge.admin { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

.alert { padding: .6rem .8rem; border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius); background: var(--surface); margin-bottom: 1rem; }
.alert.ok { border-left-color: var(--ok); }
.alert.error { border-left-color: var(--danger); }
.alert.warn { border-left-color: var(--warn); }

/* ---------- Landing page ---------- */
.hero { padding: 2.5rem 0 1.5rem; max-width: 62rem; }
.hero h1 { font-size: 2rem; margin-bottom: .5rem; }
.hero p { font-size: 1.05rem; color: var(--muted); max-width: 48rem; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; margin-top: 1rem; }

/* ---------- Realtime status ---------- */
.rt { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--muted); }
.rt::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.rt[data-state="connected"]::before { background: var(--ok); }
.rt[data-state="reconnecting"]::before { background: var(--warn); }
.rt[data-state="disconnected"]::before { background: var(--danger); }

/* ---------- Helpers ---------- */
.pager { display: flex; gap: .5rem; align-items: center; margin-top: .8rem; font-size: .9rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.avatar { width: 32px; height: 32px; border-radius: 50%; vertical-align: middle; }
.avatar.lg { width: 72px; height: 72px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.2rem; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- Mini App additions (Telegram theme mapping happens in telegram.js) ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { font: inherit; background: none; border: 0; border-bottom: 2px solid transparent; padding: .5rem .75rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.view[hidden] { display: none; }
.signal { display: grid; grid-template-columns: auto 1fr auto; gap: .6rem; align-items: center; padding: .55rem .7rem; border-bottom: 1px solid var(--border); font-size: .92rem; }
.signal .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .8rem; }
.lang { font: inherit; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: .25rem .4rem; }
.center { text-align: center; padding: 2rem 1rem; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem; }
.plan .price { font-size: 1.5rem; font-weight: 600; margin: .3rem 0; }
.faq details { border-bottom: 1px solid var(--border); padding: .5rem 0; }
.faq summary { cursor: pointer; font-weight: 600; }
