/* Штаб — стиль Hankodo (判子道): тушь, бумага васи и одна киноварь.
   Тема: html[data-theme="dark"|"light"], ставит /static/theme.js до отрисовки. */

/* Шрифты Hankodo лежат в /static/fonts. Если файлов нет — работают запасные. */
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("/static/fonts/manrope-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("/static/fonts/manrope-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+20BD, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Playfair Display"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/fonts/playfair-cyrillic-700.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Playfair Display"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/fonts/playfair-latin-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+20BD, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ── Тёмная тема (по умолчанию): чёрная тушь ── */
:root {
  --bg: #0A0908; --bg-2: #100F0E; --surface: #141311; --surface-2: #1C1A18;
  --text: #F3EFE6; --muted: #A39D92; --muted-2: #8C867C;
  --line: rgba(243,239,230,.12); --line-2: rgba(243,239,230,.22);
  --accent: #D2372C;        /* киноварь: кнопки и крупный акцент (белый текст 4.86:1) */
  --accent-hover: #B82D24;
  --accent-ink: #E0574B;    /* красный мелкий текст на тёмном (5.2:1) */
  --on-accent: #FFFFFF;
  --ok: #6FCF97;
  --glow: rgba(210,55,44,.28);
  --wm: rgba(243,239,230,.045);
  --petal: #F2B8C6; --petal-2: #E58FA6; --branch: #3A2E28; --flower-core: #B83A55;
  --grain-op: .05;
  --shadow: 0 18px 40px -30px rgba(0,0,0,.9);
  --display: "Playfair Display", "Noto Serif", Georgia, "Times New Roman", serif;
  --body: "Manrope", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --kanji: "Noto Serif JP", "Noto Serif CJK JP", "Hiragino Mincho ProN", "Yu Mincho", "MS Mincho", serif;
  --ease: cubic-bezier(.22,1,.36,1);
  --r-btn: 4px; --r-m: 8px; --r-l: 12px;
  color-scheme: dark;
}
/* ── Светлая тема: бумага васи ── */
:root[data-theme="light"] {
  --bg: #F3EFE6; --bg-2: #E9E3D6; --surface: #FBF8F2; --surface-2: #EDE7DA;
  --text: #0E0D0C; --muted: #5E584F; --muted-2: #6E685E;
  --line: rgba(14,13,12,.14); --line-2: rgba(14,13,12,.28);
  --accent: #B82D24; --accent-hover: #9E261F; --accent-ink: #B82D24;
  --ok: #2F8A57;
  --glow: rgba(184,45,36,.22);
  --wm: rgba(14,13,12,.05);
  --petal: #EFA3B5; --petal-2: #D9728D; --branch: #4A3A30; --flower-core: #A3304B;
  --grain-op: .09;
  --shadow: 0 1px 0 rgba(14,13,12,.04), 0 18px 40px -30px rgba(14,13,12,.35);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 var(--body);
  transition: background-color .35s var(--ease), color .35s var(--ease);
}
/* зерно туши / фактура васи */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: var(--grain-op);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5  0 0 0 0 .45  0 0 0 0 .4  0 0 0 1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
body > * { position: relative; z-index: 1; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }
h1 { font-size: clamp(1.9rem, 5vw, 2.6rem); line-height: 1.08; margin: 0 0 18px; }
h2 { font-size: 1.3rem; line-height: 1.2; margin: 0 0 14px; }
h3 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.ic { width: 22px; height: 22px; flex: none; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 3px; border-radius: 4px; }

/* надзаголовок с мазком киновари */
.eyebrow {
  position: relative; display: inline-block; margin: 0 0 14px; padding-bottom: 12px;
  font-size: .75rem; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; color: var(--muted);
}
.eyebrow::after {
  content: ""; position: absolute; left: -2px; bottom: 0; width: 46px; height: 7px;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 9'><path d='M1 6.4C9 4.6 27 3 59 1.6 50 3.6 33 5.6 21 7 12 8 5 8.6 2 8.4Z' fill='%23D2372C'/></svg>") no-repeat 0 0/100% 100%;
}

/* ── Шапка ── */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 7px; }
.brand b { font-family: var(--display); font-weight: 700; font-size: 1.05rem; letter-spacing: .18em; }
.brand .kj { font: 700 .8rem/1 var(--kanji); color: var(--accent-ink); letter-spacing: .05em; white-space: nowrap; }
@media (max-width: 400px) { .brand .kj { display: none; } }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions form { margin: 0; }

/* ── Кнопки ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: var(--r-btn); border: 1px solid var(--line-2); background: transparent; color: var(--text);
  font: inherit; font-weight: 700; font-size: .95rem; cursor: pointer;
  transition: background .18s, border-color .18s, transform .18s var(--ease), box-shadow .4s var(--ease);
}
.btn:hover { border-color: var(--muted); background: color-mix(in srgb, var(--text) 6%, transparent); }
.btn:active { transform: scale(.97); }
.btn-primary, .btn-save { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn-primary:hover, .btn-save:hover { background: var(--accent-hover); border-color: transparent; box-shadow: 0 10px 30px -12px var(--glow); }
.btn-primary { width: 100%; }
.btn-office .ic { color: var(--accent-ink); }
.btn-icon {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r-btn);
  border: 1px solid var(--line-2); background: transparent; color: var(--muted); cursor: pointer;
  transition: color .18s, border-color .18s;
}
.btn-icon:hover { color: var(--text); border-color: var(--muted); }
.btn-icon[aria-pressed="true"] { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 55%, var(--line-2)); }
/* переключатель темы: в тёмной показываем солнце, в светлой — луну */
.theme-btn .i-moon { display: none; }
:root[data-theme="light"] .theme-btn .i-sun { display: none; }
:root[data-theme="light"] .theme-btn .i-moon { display: block; }

/* ── Раскладка ── */
.layout { display: flex; max-width: 1200px; margin: 0 auto; }
.main { flex: 1; min-width: 0; padding: 22px 16px calc(100px + env(safe-area-inset-bottom)); }
.main > section + section { margin-top: 34px; }
.side { display: none; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-2) 90%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 5px; font-size: .7rem; font-weight: 600; color: var(--muted); }
.tabs a.on { color: var(--accent-ink); }
.tabs a.on::before { content: ""; position: absolute; top: -7px; width: 22px; height: 3px; border-radius: 2px; background: var(--accent); transform: rotate(-4deg); }
@media (min-width: 900px) {
  .tabs { display: none; }
  .side {
    display: flex; flex-direction: column; gap: 2px; width: 230px; flex: none; padding: 22px 12px;
    position: sticky; top: 65px; height: calc(100vh - 65px);
  }
  .side a { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-m); color: var(--muted); font-weight: 600; transition: background .18s, color .18s; }
  .side a:hover { background: var(--surface); color: var(--text); }
  .side a.on { background: var(--surface); color: var(--text); }
  .side a.on::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--accent); }
  .side a.on .ic { color: var(--accent-ink); }
  .main { padding: 30px 30px 50px; }
}
.dim { opacity: .5; }

/* ── Карточки ── */
.row-head { display: flex; align-items: baseline; justify-content: space-between; }
.link { color: var(--accent-ink); font-weight: 700; font-size: .95rem; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.card {
  display: block; padding: 18px; border-radius: var(--r-l); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: border-color .3s var(--ease), transform .3s var(--ease), background-color .35s var(--ease);
}
a.card:hover { border-color: var(--line-2); transform: translateY(-3px); }
.proj-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pct { font-variant-numeric: tabular-nums; font-size: .85rem; font-weight: 700; color: var(--accent-ink); }
.bar { height: 4px; margin: 14px 0 12px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .9s var(--ease); }
.bar.big { height: 6px; }
.now { margin: 8px 0 0; font-size: .93rem; color: var(--muted); }
.now b { color: var(--text); font-weight: 700; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 6px 0 0; font-size: .93rem; }
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 12px; padding: 16px; min-height: 96px;
  border-radius: var(--r-l); background: var(--surface); border: 1px solid var(--line); font-weight: 700;
  transition: border-color .3s var(--ease), transform .3s var(--ease);
}
.tile .ic { color: var(--accent-ink); }
.tile:hover { border-color: var(--line-2); transform: translateY(-2px); }
.tile small { position: absolute; top: 12px; right: 12px; font-size: .68rem; font-weight: 600; letter-spacing: .06em; color: var(--muted); }
.empty { text-align: center; padding: 34px 16px; }
.empty p { margin: 0 0 16px; color: var(--muted); }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); margin-bottom: 12px; min-height: 44px; font-weight: 600; }

/* ── Паспорт ── */
.md { margin-top: 20px; padding: 4px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); overflow-wrap: anywhere; }
.md h2 { margin-top: 22px; }
.md ul { padding-left: 20px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--accent-ink); }
.md a { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md td, .md th { border: 1px solid var(--line); padding: 6px 10px; }

/* ── Вход ── */
.login { position: relative; min-height: 100vh; display: grid; place-items: center; padding: 16px; overflow: hidden; }
.login-card {
  position: relative; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; padding: 30px 24px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: var(--shadow);
}
.login-card img { border-radius: 10px; }
.login-card h1 { margin: 4px 0 6px; letter-spacing: .14em; }
.login-card label { font-weight: 700; font-size: .85rem; color: var(--muted); }
input[type=password], input[type=text], input[type=number], input[type=date], select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line-2); border-radius: var(--r-m);
  transition: border-color .18s, box-shadow .18s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.login-card input { min-height: 48px; padding: 0 14px; }
.err { margin: 0; color: var(--accent-ink); font-weight: 700; }

/* водяной знак-иероглиф */
.wm {
  position: absolute; pointer-events: none; user-select: none; z-index: 0;
  writing-mode: vertical-rl; font: 700 clamp(110px, 22vw, 220px)/1 var(--kanji); color: var(--wm);
}
.login .wm { right: 4vw; top: 50%; transform: translateY(-50%); }

/* ── Заметки ── */
.note-form { margin-top: 4px; }
.note-row { display: flex; gap: 12px; align-items: flex-start; }
.note-row textarea { flex: 1; min-width: 0; resize: vertical; padding: 10px 12px; }
.mic {
  display: grid; place-items: center; width: 56px; height: 56px; flex: none; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--on-accent); cursor: pointer; box-shadow: 0 10px 30px -12px var(--glow);
}
.mic[hidden] { display: none; }
.mic .ic { width: 26px; height: 26px; }
.mic.on { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); } 50% { box-shadow: 0 0 0 12px transparent; } }
.note-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.mic-status { font-size: .9rem; }
.flash { padding: 10px 14px; border-radius: var(--r-m); border-left: 3px solid var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); margin: 0 0 12px; }
.note { margin-bottom: 10px; }
.note p { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-meta { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.badge { margin-left: auto; padding: 2px 9px; border-radius: 3px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }

/* ── Главная: приветствие с веткой сакуры ── */
.hello { position: relative; padding-top: 6px; }
.hello > *:not(.sk-branch):not(.wm) { position: relative; z-index: 1; }
.hello .wm { right: -6px; top: -10px; font-size: clamp(90px, 16vw, 170px); }
.hello-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
#sakuraBtn { background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.hello h1 .accent { color: var(--accent); font-style: italic; }
.sk-branch { position: absolute; z-index: 0; top: -22px; right: -16px; width: min(72vw, 330px); height: auto; pointer-events: none; opacity: .95; }
.sk-branch .b { fill: none; stroke: var(--branch); stroke-linecap: round; }
.sk-branch .pt { fill: var(--petal); }
.sk-branch .pt2 { fill: var(--petal-2); }
.sk-branch .core { fill: var(--flower-core); }
.sk-branch .bud { fill: var(--petal-2); }
@media (min-width: 900px) { .sk-branch { right: -30px; top: -34px; } }
#sakura { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }
#sakura[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .mic.on { outline: 3px solid var(--accent); outline-offset: 3px; }
}

/* ── Финансы ── */
.pos { color: var(--ok); }
.neg { color: var(--accent-ink); }
.warn { color: #D9A441; font-weight: 700; }
:root[data-theme="light"] .warn { color: #9A6A12; }
.flash-bad { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.linkbtn { background: none; border: 0; padding: 8px 0; color: var(--accent-ink); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.seg-tabs { display: inline-flex; gap: 4px; padding: 4px; margin: 0 0 16px; border: 1px solid var(--line-2); border-radius: calc(var(--r-btn) + 4px); background: var(--bg-2); }
.seg-tabs a { padding: 8px 16px; border-radius: var(--r-btn); font-weight: 700; font-size: .92rem; color: var(--muted); }
.seg-tabs a.on { background: var(--accent); color: var(--on-accent); }

.fin-form { display: flex; flex-direction: column; gap: 14px; }
.fin-form h2 { margin: 0; }
.fin-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r-btn); overflow: hidden; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 10px 18px; font-weight: 700; color: var(--muted); transition: background .18s, color .18s; }
.seg input:checked + span { background: var(--accent); color: var(--on-accent); }
.seg input[value=in]:checked + span { background: color-mix(in srgb, var(--ok) 85%, #000); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent-ink); outline-offset: -2px; }
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld[hidden] { display: none; }
.fld > span { font-size: .8rem; font-weight: 700; color: var(--muted); }
.fld input, .fld select { min-height: 46px; padding: 0 12px; width: 100%; }
.fld-amount input { min-height: 58px; font: 700 1.8rem/1 var(--display); font-variant-numeric: tabular-nums; }
.fin-grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.fld-wide { grid-column: 1 / -1; }
@media (max-width: 520px) { .fin-grid { grid-template-columns: 1fr; } }
.chk { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 44px; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); }
.del-form { margin-top: 6px; text-align: right; }

.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.month-nav h2 { margin: 0; }
.flip .ic { transform: scaleX(-1); }
.stats { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 14px; border-radius: var(--r-l); background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.stat span { font-size: .75rem; font-weight: 700; letter-spacing: .04em; color: var(--muted); }
.stat b { font: 700 clamp(1.05rem, 4.2vw, 1.6rem)/1.15 var(--display); overflow-wrap: anywhere; }
.stat small { font-size: .78rem; color: var(--muted); }
.stat-main { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 9%, var(--surface)), var(--surface) 70%); }
@media (max-width: 420px) { .stats { grid-template-columns: 1fr 1fr; } .stat-main { grid-column: 1 / -1; order: -1; } }

.split2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.card-h { font-size: 1rem; margin: 0 0 12px; }
.card-h.mt { margin-top: 22px; }
.brk { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 7px 0; }
.brk span { font-weight: 600; font-size: .93rem; }
.brk b { font-size: .93rem; }
.brk .bar { grid-column: 1 / -1; margin: 4px 0 0; }
.bar-ok i { background: var(--ok); }
.prj { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.prj:last-child { border-bottom: 0; }
.prj span { font-weight: 700; }
.prj small { grid-row: 2; display: flex; gap: 10px; font-size: .8rem; color: var(--muted); }
.prj small em { font-style: normal; }
.prj b { grid-row: 1 / 3; grid-column: 2; align-self: center; }

.ops { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.op { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.op-main { display: flex; flex-direction: column; min-width: 0; }
.op-main span { font-size: .85rem; }
.op-c { font-size: .88rem; color: var(--muted); overflow-wrap: anywhere; margin: 2px 0 0; }
.op-sum { font-size: 1rem; white-space: nowrap; }
.op form { margin: 0; }
.op-del { width: 36px; height: 36px; border-radius: var(--r-btn); border: 1px solid transparent; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.op-del:hover { color: var(--accent-ink); border-color: var(--line-2); }

.subs { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.sub { display: flex; flex-direction: column; gap: 6px; }
.sub-due { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.sub-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.sub-head b { font: 700 1.15rem/1.2 var(--display); white-space: nowrap; }
.sub-head b small { font: 600 .78rem var(--body); color: var(--muted); }
.sub-meta, .sub-when { margin: 0; font-size: .88rem; }
.sub-actions { display: flex; gap: 8px; margin-top: 6px; }
.sub-actions form { margin: 0; }
.sub-actions .btn { min-height: 40px; padding: 0 14px; }

/* ── Напоминания и календарь ── */
.small { font-size: .85rem; }
.rem { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; margin-bottom: 8px; }
.rem-late { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.rem-main { display: flex; flex-direction: column; min-width: 0; }
.rem-main b { overflow-wrap: anywhere; }
.rem-main span { font-size: .86rem; }
.rem-main em { font-style: normal; }
.rem-act { display: flex; gap: 6px; flex: none; }
.rem-act form { margin: 0; }
.rem .btn-icon { width: 40px; height: 40px; font-size: 1.1rem; }
.t { display: inline-block; min-width: 3.1em; color: var(--accent-ink); font-weight: 700; }
.done-list { margin-top: 10px; }
.done-list summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; }
.done-list p { margin: 4px 0; font-size: .9rem; }
.tg-card p { margin: 0 0 12px; }
.tg-card code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.tg-form { display: flex; gap: 10px; flex-wrap: wrap; }
.tg-form input { flex: 1 1 220px; min-height: 46px; padding: 0 12px; }

.cal { padding: 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-wd { text-align: center; font-size: .7rem; font-weight: 700; letter-spacing: .06em; color: var(--muted); padding: 4px 0; }
.cal-d { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; aspect-ratio: 1; min-height: 40px; border-radius: var(--r-m); border: 1px solid transparent; transition: background .18s, border-color .18s; }
.cal-d b { font-weight: 700; font-size: .95rem; font-variant-numeric: tabular-nums; }
.cal-d.wknd b { color: var(--muted); }
a.cal-d:hover { background: var(--surface-2); }
.cal-d.today b { color: var(--accent-ink); }
.cal-d.today::after { content: ""; position: absolute; top: 5px; right: 6px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-d.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.dots { display: flex; gap: 3px; height: 5px; }
.dots i, .cal-legend i { display: inline-block; width: 5px; height: 5px; border-radius: 50%; }
.dot-event { background: var(--accent); }
.dot-rem { background: var(--text); opacity: .7; }
.dot-sub { background: #D9A441; }
.cal-legend { margin: 10px 0 0; font-size: .78rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cal-legend i { margin-left: 8px; }
.cal-legend i:first-child { margin-left: 0; }
.agenda-sub .t, .agenda-sub b { color: inherit; }
.agenda-event { border-left: 3px solid var(--accent); }
.agenda-sub { border-left: 3px solid #D9A441; }
.today { padding: 6px 16px; }
.today-i { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); border-left: 0; }
.today-i:last-child { border-bottom: 0; }
.today-i.agenda-sub .t { color: #D9A441; }

/* ── Плавное появление страниц ── */
@keyframes pageIn { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
.main > section:not(.dash) { animation: pageIn .6s var(--ease) both; }
.main > section:nth-of-type(2) { animation-delay: .06s; }
.main > section:nth-of-type(3) { animation-delay: .12s; }
.main > section:nth-of-type(4) { animation-delay: .18s; }
.main > section:nth-of-type(n+5) { animation-delay: .24s; }

/* ── Дашборд ── */
@keyframes rv { from { opacity: 0; transform: translateY(18px) scale(.98); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }
.dash-js .rv { animation: rv .8s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms + 60ms); }
.dash-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 700px) {
  .dash-grid { grid-template-columns: 1fr 1fr; }
  .dash-grid .chart, .dash-grid .recent { grid-column: 1 / -1; }
}
@media (min-width: 1100px) {
  .dash-grid { grid-template-columns: 1.05fr 1fr 1.25fr; }
  .dash-grid .chart { grid-column: auto; }
  .dash-grid .recent { grid-column: 2 / -1; }
  .dash-grid .limit { align-self: start; }
}

.bal { position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 8px; }
.bal-wm { position: absolute; right: -10px; bottom: -34px; font: 700 150px/1 var(--kanji); color: var(--wm); pointer-events: none; user-select: none; }
.bal > *:not(.bal-wm) { position: relative; }
.bal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .85rem; font-weight: 700; color: var(--muted); }
.chip { padding: 3px 9px; border: 1px solid var(--line-2); border-radius: 999px; font-size: .72rem; letter-spacing: .04em; color: var(--muted); }
.bal-num { font: 700 clamp(2rem, 8.5vw, 2.7rem)/1.05 var(--display); letter-spacing: -.02em; margin-top: 4px; overflow-wrap: anywhere; }
.delta { align-self: flex-start; font-size: .78rem; font-weight: 700; padding: 3px 8px; border-radius: 3px; }
.delta em { font-style: normal; font-weight: 500; color: var(--muted); }
.delta.up { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.delta.down { color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.delta.flat { color: var(--muted); background: var(--surface-2); }
.bal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.wallets { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.wallets-h { font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.wallets-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; margin-top: 8px; }
.wallet { display: flex; flex-direction: column; gap: 2px; padding: 10px; border-radius: var(--r-m); background: var(--bg-2); border: 1px solid var(--line); min-width: 0; }
.wallet span { font-size: .75rem; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallet b { font-size: .85rem; white-space: nowrap; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 14px; min-height: 118px; border-radius: var(--r-l); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); transition: transform .35s var(--ease), box-shadow .35s var(--ease), border-color .3s; min-width: 0; }
.kpi:hover { transform: translateY(-3px); border-color: var(--line-2); }
.kpi-h { display: flex; align-items: center; justify-content: space-between; font-size: .75rem; font-weight: 700; color: var(--muted); }
.kpi-h .ic { width: 18px; height: 18px; }
.kpi b { font: 700 clamp(1.15rem, 5vw, 1.5rem)/1.1 var(--display); margin-top: auto; overflow-wrap: anywhere; }
.kpi small { font-size: .74rem; color: var(--muted); }
.kpi small i { font-style: normal; font-weight: 700; color: var(--ok); }
.kpi small i.bad { color: var(--accent-ink); }
.kpi-hot { background: linear-gradient(150deg, #E2483B, var(--accent) 45%, #9E261F); border-color: transparent; color: #fff; box-shadow: 0 18px 40px -22px var(--glow); }
.kpi-hot::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; background: radial-gradient(120% 90% at 100% 0%, rgba(255,255,255,.22), transparent 55%); }
.kpi-hot .kpi-h, .kpi-hot small, .kpi-hot small i { color: rgba(255,255,255,.88); }
.kpi-hot:hover { border-color: transparent; box-shadow: 0 24px 50px -20px var(--glow); }

.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.chart-head h3 { font-size: 1.05rem; }
.chart-head .muted { font-size: .8rem; }
.legend { display: flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--muted); white-space: nowrap; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-left: 6px; }
.lg-in, .b-in { background: var(--accent); }
.lg-out, .b-out { background: var(--text); }
.bars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; height: 170px; align-items: end; padding-top: 6px; border-bottom: 1px solid var(--line); background: repeating-linear-gradient(to top, transparent 0 41px, var(--line) 41px 42px); }
.bcol { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bcol span { font-size: .72rem; font-weight: 600; color: var(--muted); padding-bottom: 6px; }
.bcol.cur span { color: var(--accent-ink); }
.bpair { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.bpair i { display: block; width: min(16px, 40%); height: 0; border-radius: 4px 4px 1px 1px; transition: height 1s var(--ease); }
.b-out { opacity: .82; }
.bcol:not(.cur) .b-in { opacity: .55; }
.bcol:not(.cur) .b-out { opacity: .32; }

.lim-edit { position: relative; }
.lim-edit summary { list-style: none; cursor: pointer; font-size: .9rem; }
.lim-edit summary::-webkit-details-marker { display: none; }
.lim-edit form { position: absolute; right: 0; top: 30px; z-index: 5; width: 260px; padding: 10px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-m); box-shadow: var(--shadow); }
.lim-bar { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; }
.lim-bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #E2483B); transition: width 1.2s var(--ease) .4s; }
.lim-bar.over i { background: repeating-linear-gradient(-45deg, var(--accent) 0 8px, var(--accent-hover) 8px 16px); }
.lim-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.lim-foot b { color: var(--text); }

.rc { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rc:last-child { border-bottom: 0; }
.rc-ic { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; font-weight: 800; }
.rc-ic.out { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-ink); }
.rc-ic.in { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.rc-main { display: flex; flex-direction: column; min-width: 0; }
.rc-main span { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc > b { white-space: nowrap; font-size: .95rem; }
.tg-proxy { margin-top: 14px; }
.tg-proxy summary { cursor: pointer; min-height: 36px; display: flex; align-items: center; }
.tg-proxy .tg-form { margin-top: 8px; }
.tg-proxy p { margin: 6px 0 0; }

/* ───────── Hankodo Quest (шаг 5) ───────── */
.q-sync { display: flex; align-items: center; gap: 8px; margin: -4px 0 16px; font-size: .85rem; color: var(--muted); }
.q-sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.q-sync.q-stale i { background: var(--accent); }
.q-funnel { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); }
.q-step { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--r-l); background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.q-step .q-lv { font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.q-step b { font: 700 1.6rem/1.15 var(--display); }
.q-step small { font-size: .78rem; color: var(--muted); }
.q-step .bar { margin: 8px 0 0; }
.q-hot { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.q-tip { margin: 0 0 12px; padding: 10px 12px; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: var(--r-m); font-size: .92rem; }
.q-op { grid-template-columns: 1fr auto; }
.q-op .op-main b { overflow-wrap: anywhere; }
a.op-main:hover b { color: var(--accent-ink); }
.q-due { background: var(--accent); color: var(--on-accent); }
.q-dot { display: inline-block; width: 8px; height: 8px; margin-left: 4px; border-radius: 50%; background: var(--line-2); vertical-align: middle; }
.q-dot.on { background: var(--ok); }
.q-search { display: flex; gap: 10px; flex-wrap: wrap; padding: 12px; margin-bottom: 12px; }
.q-search input { flex: 1 1 220px; min-height: 46px; padding: 0 12px; }
.q-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.q-filters .chip { padding: 8px 12px; font-size: .85rem; font-weight: 700; min-height: 36px; display: inline-flex; align-items: center; gap: 6px; }
.q-filters .chip b { color: var(--text); }
.q-filters .chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.q-filters .chip.on b { color: inherit; }
.q-pages { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.q-dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.q-dl dt { font-size: .8rem; font-weight: 700; color: var(--muted); padding-top: 2px; }
.q-dl dd { margin: 0; overflow-wrap: anywhere; }
.q-dl a { color: var(--accent-ink); }
.q-list { margin: 0; padding-left: 20px; }
.q-list li { margin: 4px 0; }
.q-list li::marker { color: var(--accent-ink); }
.q-msg { padding: 12px 14px; margin: 0 0 10px; border-radius: var(--r-m); background: var(--surface-2); border: 1px solid var(--line); }
.q-msg.q-in { border-left: 3px solid var(--accent); }
.q-msg p { margin: 0 0 6px; }
.q-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .93rem; }
.q-key { display: block; padding: 10px 12px; border-radius: var(--r-m); background: var(--surface-2); user-select: all; overflow-wrap: anywhere; font-size: .9rem; }

/* Quest: кнопки команд (шаг 5б) */
.q-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 4px; }
.q-btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.q-btns .btn { min-height: 44px; }
.q-msg .q-btns { margin-top: 10px; }
.fld textarea { width: 100%; min-height: 46px; padding: 10px 12px; resize: vertical; }
.badge.bad { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-ink); }
.q-do .row-head { align-items: center; gap: 12px; flex-wrap: wrap; }

/* Поручения (этап 3, шаг 3.5) */
.note-btns { display: flex; gap: 8px; flex: none; }
.ord { padding: 16px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 10px; }
.ord-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ord-head b { font-size: 1.05rem; overflow-wrap: anywhere; }
.ord-meta { font-size: .85rem; }
.ord-src { font-size: .85rem; border-left: 2px solid var(--line-2); padding-left: 10px; white-space: pre-line; overflow-wrap: anywhere; }
.ord-q { margin: 0; padding: 8px 12px; border-radius: var(--r-m); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.ord-form .fin-grid { margin: 0; }
.ord-hi { color: var(--accent-ink); }
.ord-done { padding: 10px 14px; margin-bottom: 6px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.ord-done .muted { font-size: .85rem; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .88rem; }
.note form { margin: 0; }
.inbox-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; }

/* Черновики отделов (этап 3, шаг 3.4.3) */
.draft-text { margin: 12px 0; max-height: 26rem; overflow: auto; }
.draft .fld textarea { width: 100%; }
.ord-done > summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; cursor: pointer; list-style: none; }
.ord-done > summary::-webkit-details-marker { display: none; }
details.ord-done { display: block; }
