/* ==========================================================================
   Base: tokens, fonts, reset, shared components (used by public pages + app)
   Palette "White nights": dusk blue for structure/actions,
   midsummer amber only for things that are live (online, unread, ringing).
   ========================================================================== */

@font-face { font-family: "Onest"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(../fonts/onest-latin-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Onest"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(../fonts/onest-latin-ext-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Onest"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(../fonts/onest-cyrillic-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116; }
@font-face { font-family: "Unbounded"; font-style: normal; font-display: swap; font-weight: 200 900;
  src: url(../fonts/unbounded-latin-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Unbounded"; font-style: normal; font-display: swap; font-weight: 200 900;
  src: url(../fonts/unbounded-latin-ext-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Unbounded"; font-style: normal; font-display: swap; font-weight: 200 900;
  src: url(../fonts/unbounded-cyrillic-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116; }

:root {
  color-scheme: light;
  --bg: #f4f3f8;
  --surface: #ffffff;
  --surface-2: #eceaf3;
  --surface-3: #e2dfec;
  --line: #dedbe8;
  --line-strong: #c9c5d8;
  --ink: #1a1830;
  --ink-2: #5d5a73;
  --ink-3: #8e8ba3;
  --accent: #3b3a8f;
  --accent-hover: #312f7a;
  --accent-ink: #ffffff;
  --accent-soft: #e6e5f7;
  --sun: #f5a524;
  --sun-ink: #3a2500;
  --sun-soft: #fff1d6;
  --ok: #1e9e6a;
  --danger: #c9283e;
  --danger-soft: #fbe5e8;
  --bp-optimal: #1e9e6a;
  --bp-normal: #5bb36c;
  --bp-high_normal: #c9a400;
  --bp-grade1: #e58a1f;
  --bp-grade2: #e2632b;
  --bp-grade3: #c9283e;
  --shadow-1: 0 1px 2px rgb(26 24 48 / 6%), 0 1px 1px rgb(26 24 48 / 4%);
  --shadow-2: 0 12px 32px -8px rgb(26 24 48 / 22%), 0 2px 6px rgb(26 24 48 / 8%);
  --overlay: rgb(18 17 31 / 45%);

  --font-body: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Unbounded", "Onest", system-ui, sans-serif;
  --fs-xs: 0.8125rem;
  --fs-sm: 0.9375rem;
  --fs-md: 1.0625rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 2rem;
  --fs-3xl: 2.75rem;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-pill: 999px;
  --tap: 48px;
  --gap: 16px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12111f;
  --surface: #1b1a2c;
  --surface-2: #242338;
  --surface-3: #2e2d45;
  --line: #312f48;
  --line-strong: #44425f;
  --ink: #eeedf7;
  --ink-2: #aba8c3;
  --ink-3: #7c7996;
  --accent: #a9a6ff;
  --accent-hover: #bcbaff;
  --accent-ink: #14132a;
  --accent-soft: #2a2950;
  --sun: #ffb938;
  --sun-ink: #2a1a00;
  --sun-soft: #3a2c12;
  --ok: #3cc58c;
  --danger: #ff6b7f;
  --danger-soft: #3a1d26;
  --bp-optimal: #3cc58c;
  --bp-normal: #7cc98a;
  --bp-high_normal: #e5c63a;
  --bp-grade1: #f2a24a;
  --bp-grade2: #f47e4c;
  --bp-grade3: #ff6b7f;
  --shadow-1: 0 1px 2px rgb(0 0 0 / 30%);
  --shadow-2: 0 16px 40px -8px rgb(0 0 0 / 60%), 0 2px 8px rgb(0 0 0 / 30%);
  --overlay: rgb(5 5 12 / 65%);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-feature-settings: "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
p { margin: 0 0 .75em; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--accent-soft); }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.display { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.02em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; align-items: center; gap: 12px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  --btn-bg: var(--surface-2); --btn-ink: var(--ink); --btn-line: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px;
  border: 1px solid var(--btn-line); border-radius: var(--r-sm);
  background: var(--btn-bg); color: var(--btn-ink);
  font-weight: 600; font-size: var(--fs-md); line-height: 1; text-decoration: none;
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: background .15s var(--ease), transform .1s var(--ease), box-shadow .15s;
}
.btn:hover { background: color-mix(in srgb, var(--btn-bg) 88%, var(--ink)); }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-primary { --btn-bg: var(--accent); --btn-ink: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-sun { --btn-bg: var(--sun); --btn-ink: var(--sun-ink); }
.btn-outline { --btn-bg: transparent; --btn-line: var(--line-strong); }
.btn-ghost { --btn-bg: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { --btn-bg: var(--danger-soft); --btn-ink: var(--danger); }
.btn-danger-solid { --btn-bg: var(--danger); --btn-ink: #fff; }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: var(--fs-sm); border-radius: 9px; }
.btn-lg { min-height: 56px; padding: 0 26px; font-size: var(--fs-lg); border-radius: var(--r-md); }
.btn-block { display: flex; width: 100%; }
.btn-icon { padding: 0; width: var(--tap); min-width: var(--tap); border-radius: var(--r-pill); }
.btn-icon.btn-sm { width: 38px; min-width: 38px; }
.btn.is-busy { position: relative; color: transparent; pointer-events: none; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--btn-ink); border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.hint { font-size: var(--fs-xs); color: var(--ink-3); }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 11px 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font-size: max(16px, var(--fs-md));
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%; background-size: 6px 6px; background-repeat: no-repeat; }
.input-group { display: flex; gap: 8px; }
.form-grid { display: grid; gap: 14px; }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } }

.switch { position: relative; display: inline-flex; flex: none; width: 52px; height: 32px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: var(--r-pill); background: var(--surface-3); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform .2s var(--ease); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2.5px solid var(--accent); outline-offset: 2px; }

.seg { display: flex; padding: 4px; gap: 4px; background: var(--surface-2); border-radius: 12px; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; min-height: 40px; padding: 0 14px; border: 0; border-radius: 9px; background: transparent;
  color: var(--ink-2); font-weight: 600; font-size: var(--fs-sm); cursor: pointer; white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ── Surfaces ────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px; }
.card-tight { padding: 0; overflow: hidden; }
.card-title { font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); text-transform: none; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }

.avatar {
  --size: 44px; position: relative; flex: none; width: var(--size); height: var(--size); border-radius: 50%;
  display: grid; place-items: center; overflow: visible;
  background: var(--av-bg, var(--accent-soft)); color: var(--av-ink, var(--accent));
  font-weight: 700; font-size: calc(var(--size) * .38); letter-spacing: -.01em; user-select: none;
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar.is-online::after {
  content: ""; position: absolute; right: -1px; bottom: -1px; width: max(11px, calc(var(--size) * .26)); height: max(11px, calc(var(--size) * .26));
  border-radius: 50%; background: var(--sun); border: 2.5px solid var(--surface);
}
.avatar.ring { box-shadow: 0 0 0 2.5px var(--surface), 0 0 0 5px var(--sun); }

.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--r-pill); background: var(--sun); color: var(--sun-ink);
  font-size: 12px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums;
}
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 12px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--ink-2); font-size: var(--fs-xs); font-weight: 600; }
.chip svg { width: 15px; height: 15px; }
.chip-accent { background: var(--accent-soft); color: var(--accent); }
.chip-sun { background: var(--sun-soft); color: color-mix(in srgb, var(--sun) 45%, var(--ink)); }

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-md); background: var(--accent-soft); color: var(--ink); font-size: var(--fs-sm); }
.notice svg { flex: none; width: 22px; height: 22px; color: var(--accent); margin-top: 1px; }
.notice-danger { background: var(--danger-soft); }
.notice-danger svg { color: var(--danger); }
.notice-sun { background: var(--sun-soft); }
.notice-sun svg { color: color-mix(in srgb, var(--sun) 60%, var(--ink)); }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 48px 20px; color: var(--ink-2); }
.empty svg { width: 44px; height: 44px; color: var(--ink-3); }
.empty h3 { font-size: var(--fs-lg); color: var(--ink); }
.empty p { max-width: 34ch; margin: 0; }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-strong); border-right-color: var(--accent); animation: spin .8s linear infinite; margin: 40px auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

.icon { width: 20px; height: 20px; flex: none; }
.av-32 { --size: 32px; } .av-40 { --size: 40px; } .av-48 { --size: 48px; }
.av-56 { --size: 56px; } .av-72 { --size: 72px; } .av-96 { --size: 96px; }
.empty .btn svg { width: 20px; height: 20px; color: currentColor; }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg button .icon { width: 18px; height: 18px; }
.brand-logo { display: block; height: 30px; width: auto; }
.brand-logo-dark { display: none; }
:root[data-theme="dark"] .brand-logo-light { display: none; }
:root[data-theme="dark"] .brand-logo-dark { display: block; }

/* ── Theme button and its menu (app top bar, public header) ── */
.theme-btn { flex: none; }
.theme-btn .ti { display: none; width: 22px; height: 22px; }
:root:not([data-theme-pref]) .theme-btn .ti-system,
:root[data-theme-pref="system"] .theme-btn .ti-system,
:root[data-theme-pref="light"] .theme-btn .ti-light,
:root[data-theme-pref="dark"] .theme-btn .ti-dark { display: block; }
.theme-menu { position: fixed; z-index: 60; display: flex; flex-direction: column; gap: 2px; min-width: 200px; max-width: calc(100vw - 16px); padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-2); }
.theme-menu button { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 0 12px; border: 0; border-radius: 10px; background: none; color: var(--ink); font: inherit; font-size: var(--fs-sm); font-weight: 600; text-align: left; cursor: pointer; }
.theme-menu button svg { flex: none; width: 20px; height: 20px; }
.theme-menu button:hover { background: var(--surface-2); }
.theme-menu button[aria-checked="true"] { background: var(--accent-soft); color: var(--accent); }
