/* styles.css — Пульт ассистента. Костяная бумага + графит, IBM Plex, тема свет/тьма.
   Эстетика dudiin.ru / karkas.digital: премиально, как визитка. */

:root {
  color-scheme: light dark;            /* явное намерение автора: без Force Dark-инверсии */
  /* ─── СВЕТЛАЯ (костяная) по умолчанию ─── */
  --paper:      #f5f3ee;
  --paper-2:    #ece9e1;
  --paper-3:    #e3dfd4;
  --ink:        #0f0f12;
  --ink-2:      #3a3a3f;
  --ink-3:      #6b6b70;
  --mute:       #8a8784;
  --line:       rgba(15,15,18,0.14);
  --line-soft:  rgba(15,15,18,0.07);
  --accent:     oklch(0.55 0.18 250);
  --accent-ink: #f5f3ee;
  --danger:     oklch(0.52 0.16 25);
  --grain-op:   0.030;
  --emboss-hi:  rgba(255,255,255,0.55);
  --card-sh:    0 1px 2px rgba(15,15,18,0.04), 0 10px 24px -16px rgba(15,15,18,0.22);
  --tabbar-h:   62px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ─── ТЁМНАЯ (графит): ручной выбор + системный фолбэк ─── */
:root[data-theme="dark"] {
  --paper:#0f0f12; --paper-2:#16161a; --paper-3:#1d1d22;
  --ink:#f3f1ec; --ink-2:#c4c2bd; --ink-3:#8e8c88; --mute:#8e8c88;
  --line:rgba(243,241,236,0.14); --line-soft:rgba(243,241,236,0.07);
  --accent:oklch(0.68 0.15 250); --accent-ink:#0f0f12; --danger:oklch(0.68 0.16 25);
  --grain-op:0.05; --emboss-hi:rgba(255,255,255,0.05);
  --card-sh:0 1px 2px rgba(0,0,0,0.3), 0 12px 28px -18px rgba(0,0,0,0.6);
}
/* Дефолт — светлая костяная ВСЕГДА (не подхватываем системную тёмную).
   Тёмная — только по кнопке-переключателю, выбор хранится в localStorage. */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }

body {
  background: var(--paper);           /* явный intent — иначе WebView инвертирует */
  color: var(--ink);
  font: 15px/1.5 'IBM Plex Sans', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  transition: background-color .35s ease, color .35s ease;
}
/* еле заметное «зерно» бумаги — тиснение поверх фона */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: var(--grain-op);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.theme-fade, .theme-fade * {
  transition: background-color .35s ease, color .35s ease, border-color .35s ease !important;
}

/* ─── каркас ─── */
#app { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }
.boot { padding: 44px; text-align: center; color: var(--ink-3);
  font-family: 'IBM Plex Mono', monospace; font-size: 13px; }

.appbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 14px) 16px 12px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  transition: background-color .35s ease, border-color .35s ease;
}
.appbar .brand { min-width: 0; }
.appbar .brand h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .brand .sub { font-family: 'IBM Plex Mono', monospace; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 1.2px; color: var(--mute); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* переключатель темы (как karkas) */
.theme-toggle {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink-2);
  display: grid; place-items: center; cursor: pointer; touch-action: manipulation;
  transition: border-color .2s, color .2s, background-color .35s;
}
.theme-toggle:active { transform: scale(.94); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }

.content {
  flex: 1; padding: 16px 14px calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  max-width: 720px; width: 100%; margin: 0 auto;
}

/* ─── заголовки групп/секций (mono, тиснёные капсы) ─── */
.group-head { display: flex; align-items: baseline; gap: 10px; margin: 20px 4px 10px; }
.group-head:first-child { margin-top: 4px; }
.group-head .t { font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1.6px; color: var(--ink-2); }
.group-head .rule { flex: 1; height: 1px; background: var(--line); }
.group-head .n { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--mute); }
.section-title { margin: 20px 4px 9px; font-family: 'IBM Plex Mono', monospace; font-size: 11px;
  text-transform: uppercase; letter-spacing: 1.4px; color: var(--mute); }

/* ─── карточки ─── */
.card {
  position: relative; background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 15px; margin-bottom: 11px; box-shadow: var(--card-sh);
  transition: background-color .35s ease, border-color .35s ease, transform .08s ease;
}
.card::after { /* верхний блик — тиснение */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 1px; border-radius: 14px 14px 0 0;
  background: var(--emboss-hi); pointer-events: none;
}
.card.tappable { cursor: pointer; touch-action: manipulation; }
.card.tappable:active { transform: scale(.987); }

.proj-head { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.proj-title { flex: 1; min-width: 0; }
.proj-name { font-weight: 600; font-size: 15.5px; letter-spacing: .1px; overflow-wrap: anywhere; }
.proj-tag { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; overflow-wrap: anywhere; }

.badge { font-family: 'IBM Plex Mono', monospace; font-size: 10px; padding: 3px 8px;
  border-radius: 6px; white-space: nowrap; border: 1px solid var(--line);
  color: var(--ink-3); background: var(--paper-3); text-transform: uppercase; letter-spacing: .6px; }
.badge.stage { color: var(--ink-2); }

/* готовность: тонкий графитовый бар + mono-процент */
.ready { display: flex; align-items: center; gap: 10px; margin: 12px 0 10px; min-width: 0; }
.meter { flex: 1; min-width: 0; height: 5px; border-radius: 5px; background: var(--paper-3); overflow: hidden;
  border: 1px solid var(--line-soft); }
.meter > i { display: block; height: 100%; background: var(--ink-2); border-radius: 5px; }
.ready .pct { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--ink-2);
  flex: 0 0 auto; min-width: 34px; text-align: right; }

.proj-meta { font-size: 13px; color: var(--ink-2); }
.proj-meta .row { display: flex; gap: 7px; margin-top: 5px; min-width: 0; }
.proj-meta .row > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.proj-meta .k { color: var(--mute); flex: 0 0 auto; font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px; padding-top: 1px; }
.blocker span:last-child { color: var(--danger); }
.stuck-pill { font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line)); border-radius: 6px; padding: 2px 6px; }

/* алерт «застряло» */
.alert { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px;
  background: color-mix(in srgb, var(--danger) 9%, var(--paper-2));
  border: 1px solid color-mix(in srgb, var(--danger) 34%, var(--line));
  border-radius: 14px; padding: 12px 14px; }
.alert .em { font-size: 16px; line-height: 1.2; }
.alert b { color: var(--danger); }

/* ─── задачи ─── */
.task { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line-soft); }
.task:last-child { border-bottom: 0; }
.check { flex: 0 0 22px; width: 22px; height: 22px; border-radius: 7px; border: 1.5px solid var(--ink-3);
  background: transparent; display: grid; place-items: center; padding: 0; cursor: pointer;
  touch-action: manipulation; transition: background .12s, border-color .12s; }
.check[aria-checked="true"] { background: var(--ink-2); border-color: var(--ink-2); }
.check[aria-checked="true"]::after { content: "✓"; color: var(--paper); font-size: 13px; font-weight: 700; }
.check[data-status="in_progress"] { border-color: var(--accent); }
.check[data-status="in_progress"]::after { content: "•"; color: var(--accent); font-size: 20px; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 14.5px; }
.task.done .task-title { color: var(--mute); text-decoration: line-through; }
.task-sub { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--mute); margin-top: 2px; }
.prio { font-family: 'IBM Plex Mono', monospace; font-size: 10px; padding: 2px 7px; border-radius: 6px;
  border: 1px solid var(--line); text-transform: uppercase; letter-spacing: .5px; }
.prio.urgent { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.prio.high { color: var(--ink-2); }

/* ─── здоровье ─── */
.stat-row { display: flex; gap: 10px; }
.stat { flex: 1; background: var(--paper-3); border: 1px solid var(--line-soft); border-radius: 11px;
  padding: 13px 8px; text-align: center; }
.stat .v { font-family: 'IBM Plex Mono', monospace; font-size: 20px; font-weight: 600; color: var(--ink); }
.stat .l { font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: var(--mute);
  margin-top: 3px; text-transform: uppercase; letter-spacing: .8px; }
.spark { display: flex; align-items: flex-end; gap: 5px; height: 60px; margin-top: 4px; }
.spark > i { flex: 1; background: var(--ink-3); border-radius: 3px 3px 0 0; min-height: 3px; opacity: .5; }
.spark > i.today { background: var(--accent); opacity: 1; }

/* ─── композер идей ─── */
.composer { display: flex; gap: 8px; align-items: flex-end; margin-top: 8px; }
.composer textarea { flex: 1; resize: none; min-height: 46px; max-height: 120px; padding: 12px;
  border-radius: 11px; border: 1px solid var(--line); background: var(--paper-3); color: var(--ink);
  font: inherit; transition: border-color .2s, background-color .35s; }
.composer textarea::placeholder { color: var(--mute); }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.btn { border: 1px solid transparent; border-radius: 11px; padding: 0 15px; height: 46px; font: inherit;
  font-weight: 600; font-size: 14px; background: var(--ink); color: var(--paper); cursor: pointer;
  touch-action: manipulation; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--paper-3); color: var(--ink-2); border-color: var(--line); }
.btn.mic { width: 46px; padding: 0; justify-content: center; font-size: 18px; }
.btn.mic.rec { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { filter: brightness(1.2); } }
.hint { font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; color: var(--mute); margin: 7px 2px 0;
  line-height: 1.5; }
.chip-scope { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--accent); margin: 8px 2px 0; }

/* ─── нижняя навигация ─── */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  display: flex; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  transition: background-color .35s ease, border-color .35s ease; }
.tabbar button { flex: 1; background: none; border: 0; color: var(--mute); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-family: 'IBM Plex Mono', monospace; font-size: 10px; text-transform: uppercase; letter-spacing: .8px;
  touch-action: manipulation; position: relative; }
.tabbar button .ic { font-size: 19px; line-height: 1; }
.tabbar button[aria-selected="true"] { color: var(--ink); }
.tabbar button[aria-selected="true"]::before { content: ""; position: absolute; top: 0; width: 26px;
  height: 2px; border-radius: 2px; background: var(--accent); }

/* ─── детальный лист ─── */
.sheet-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.42);
  opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet-scrim.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--paper);
  border-radius: 18px 18px 0 0; border-top: 1px solid var(--line);
  padding: 8px 18px calc(var(--safe-bottom) + 22px); max-height: 84vh; overflow-y: auto;
  transform: translateY(100%); transition: transform .24s ease; box-shadow: 0 -12px 40px -20px rgba(0,0,0,.4); }
.sheet.open { transform: translateY(0); }
.sheet .grab { width: 38px; height: 4px; border-radius: 4px; background: var(--line); margin: 8px auto 14px; }
.sheet h2 { margin: 0 0 3px; font-size: 19px; font-weight: 600; }

/* ─── тост ─── */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translate(-50%, 20px); z-index: 50; opacity: 0; transition: .22s;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 24px;
  font-size: 13px; max-width: 90%; pointer-events: none; box-shadow: 0 10px 30px -8px rgba(0,0,0,.5); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }

.empty { text-align: center; color: var(--mute); padding: 30px 10px; font-size: 13px;
  font-family: 'IBM Plex Mono', monospace; }
