/* JV Hub - дизайн-система. Тема через data-theme на <html>: dark (по умолчанию) / light.
   Размер шрифта: data-font s|m|l. Все цвета - только через переменные. */
:root {
  --font: -apple-system, "Segoe UI", Roboto, "Inter", system-ui, sans-serif;
  --radius: 14px;
  --radius-s: 9px;
  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
html[data-font="s"] { font-size: 14px; }
html, html[data-font="m"] { font-size: 15.5px; }
html[data-font="l"] { font-size: 17.5px; }

html, html[data-theme="dark"] {
  --bg: #0e1116; --bg2: #161b23; --bg3: #1e2530;
  --text: #e8ecf2; --text2: #9aa5b4; --line: #262e3a;
  --accent: #4f8cff; --accent-soft: #1c2c47;
  --ok: #34c77b; --warn: #f2b93b; --bad: #f0564f;
  --ok-soft: #12301f; --warn-soft: #33290e; --bad-soft: #331113;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #f2f4f8; --bg2: #ffffff; --bg3: #e9edf3;
  --text: #171d26; --text2: #5a6577; --line: #dde3ec;
  --accent: #2f6fe4; --accent-soft: #e1ebff;
  --ok: #1d9e5e; --warn: #b57f0a; --bad: #d43a33;
  --ok-soft: #ddf3e7; --warn-soft: #f8eecf; --bad-soft: #fbe0de;
  --shadow: 0 6px 24px rgba(30,40,60,.12);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  min-height: 100dvh; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---------- каркас ---------- */
#splash {
  position: fixed; inset: 0; z-index: 99; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: var(--bg);
  transition: opacity .35s; gap: 2px;
}
#splash.hide { opacity: 0; pointer-events: none; }
.splash-logo {
  font-size: 44px; font-weight: 800; letter-spacing: 2px;
  background: linear-gradient(135deg, var(--accent), #7fb0ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.splash-sub { color: var(--text2); letter-spacing: 6px; text-transform: uppercase; font-size: 13px; }

#topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center;
  gap: 10px; padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 1.25rem; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

#view { padding: 14px 14px calc(84px + var(--safe-b)); max-width: 760px; margin: 0 auto; }

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--bg2) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; border: 0; background: none; color: var(--text2);
  border-radius: var(--radius-s); font-size: .68rem; cursor: pointer; min-height: var(--tap);
}
.tab svg { width: 23px; height: 23px; }
.tab.active { color: var(--accent); }
.tab .dot { position: absolute; margin-left: 26px; width: 8px; height: 8px;
  border-radius: 4px; background: var(--bad); }

/* ---------- компоненты ---------- */
.card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text2); margin-bottom: 10px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text2); }
.small { font-size: .82rem; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: var(--tap); padding: 9px 18px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--bg3); color: var(--text);
  font-weight: 600; cursor: pointer; transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.btn.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.btn.ghost { background: none; }
.btn.sm { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.icon { padding: 8px; min-width: var(--tap); }
.btn.block { width: 100%; }

.input, textarea.input, select.input {
  width: 100%; min-height: var(--tap); padding: 10px 13px;
  background: var(--bg3); border: 1px solid var(--line); border-radius: var(--radius-s);
  outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 96px; resize: vertical; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .82rem; color: var(--text2); margin-bottom: 5px; }

.chip {
  display: inline-flex; align-items: center; padding: 5px 12px; border-radius: 999px;
  background: var(--bg3); border: 1px solid var(--line); font-size: .82rem;
  cursor: pointer; user-select: none;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; white-space: nowrap; flex-shrink: 0;
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.neutral { background: var(--bg3); color: var(--text2); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.list-item {
  display: flex; align-items: center; gap: 11px; padding: 12px 4px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.list-item:last-child { border-bottom: 0; }

.spinner { width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 26px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--text2); padding: 34px 10px; }
.empty .icon { font-size: 34px; margin-bottom: 8px; }

#toasts { position: fixed; left: 0; right: 0; bottom: calc(76px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60;
  pointer-events: none; }
.toast {
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  box-shadow: var(--shadow); border-radius: var(--radius-s);
  padding: 10px 16px; max-width: 90vw; font-size: .9rem;
  animation: toast-in .25s;
}
.toast.err { border-color: var(--bad); }
.toast.ok { border-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* боковое меню (drawer) */
.drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 44;
  opacity: 0; transition: opacity .22s; }
.drawer-back.show { opacity: 1; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 45;
  width: min(304px, 84vw); background: var(--bg2);
  border-right: 1px solid var(--line); box-shadow: var(--shadow);
  padding: calc(14px + var(--safe-t)) 12px calc(14px + var(--safe-b));
  overflow-y: auto; display: flex; flex-direction: column;
  transform: translateX(-102%); transition: transform .22s ease-out;
}
.drawer.show { transform: translateX(0); }
.drawer-head { display: flex; align-items: baseline; gap: 7px; padding: 2px 10px 12px;
  border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.drawer-logo { font-size: 1.5rem; font-weight: 800; letter-spacing: 1px;
  background: linear-gradient(135deg, var(--accent), #7fb0ff);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.drawer-sub { color: var(--text2); letter-spacing: 3px; text-transform: uppercase;
  font-size: .72rem; }
.drawer-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text2); font-weight: 600; padding: 12px 10px 5px; }
.drawer-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  min-height: var(--tap); padding: 9px 10px; border: 0; background: none;
  color: var(--text); border-radius: var(--radius-s); font-size: .95rem;
  font-weight: 500; cursor: pointer;
}
.drawer-item svg { width: 21px; height: 21px; flex-shrink: 0; color: var(--text2); }
.drawer-item.active { background: var(--accent-soft); color: var(--accent); }
.drawer-item.active svg { color: var(--accent); }
.drawer-item:active { background: var(--bg3); }
.drawer-foot { margin-top: auto; padding: 12px 10px 0; color: var(--text2);
  font-size: .74rem; border-top: 1px solid var(--line); }
#menu-btn { width: 38px; height: 38px; padding: 7px; min-width: 0; }
#menu-btn svg { width: 100%; height: 100%; }

/* шторка снизу */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
  animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--bg2); border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 10px 16px calc(18px + var(--safe-b)); max-height: 88dvh; overflow-y: auto;
  animation: sheet-in .25s;
}
@keyframes sheet-in { from { transform: translateY(40px); opacity: .5; } }
.sheet .grip { width: 42px; height: 4px; border-radius: 2px; background: var(--line);
  margin: 2px auto 12px; }
.sheet h2 { font-size: 1.05rem; margin-bottom: 12px; }

/* markdown-просмотр */
.md { line-height: 1.55; word-wrap: break-word; }
.md h1, .md h2, .md h3 { margin: 14px 0 8px; }
.md p, .md ul, .md ol { margin-bottom: 9px; }
.md ul, .md ol { padding-left: 20px; }
.md code { background: var(--bg3); border-radius: 4px; padding: 1px 5px; font-size: .87em; }
.md pre { background: var(--bg3); padding: 10px; border-radius: var(--radius-s);
  overflow-x: auto; margin-bottom: 9px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md td, .md th { border: 1px solid var(--line); padding: 5px 9px; font-size: .88em; }
.md blockquote { border-left: 3px solid var(--accent); padding-left: 10px; color: var(--text2); }

/* чат ассистента */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; line-height: 1.45;
  white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--accent); color: #fff;
  border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: var(--bg2); border: 1px solid var(--line);
  border-bottom-left-radius: 5px; }
.msg.pending { color: var(--text2); font-style: italic; }
.chat-input { position: fixed; left: 0; right: 0; bottom: calc(64px + var(--safe-b));
  padding: 8px 12px; display: flex; gap: 8px; background: var(--bg);
  border-top: 1px solid var(--line); z-index: 15; }
.chat-input textarea { flex: 1; min-height: var(--tap); max-height: 130px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--bg3); border-radius: var(--radius-s); padding: 10px 12px; }
.stat .v { font-size: 1.25rem; font-weight: 700; }
.stat .l { font-size: .74rem; color: var(--text2); }

.seg { display: flex; background: var(--bg3); border-radius: var(--radius-s); padding: 3px; }
.seg button { flex: 1; border: 0; background: none; color: var(--text2); padding: 8px 4px;
  border-radius: 7px; font-weight: 600; font-size: .85rem; cursor: pointer; }
.seg button.active { background: var(--bg2); color: var(--text); box-shadow: var(--shadow); }

img.bp { max-width: 100%; border-radius: var(--radius-s); border: 1px solid var(--line); }
