* { margin: 0; padding: 0; box-sizing: border-box; }

:root, [data-theme="light"] {
  --bg: #faf9f5;
  --bg-side: #f0efe9;
  --bg-card: #ffffff;
  --bg-soft: #f4f3ee;
  --border: #e3e1d9;
  --text: #2d2a24;
  --muted: #8a857a;
  --accent: #d97757;
  --on-accent: #ffffff;
  --error: #c4442f;
  --ok: #4d9e4d;
  --warn: #c99a26;
  --shadow: 0 1px 4px rgba(60, 50, 30, .08);
}
[data-theme="dark"] {
  --bg: #262624;
  --bg-side: #1f1e1c;
  --bg-card: #30302e;
  --bg-soft: #34332f;
  --border: #43423d;
  --text: #eceae4;
  --muted: #9c978c;
  --accent: #d97757;
  --on-accent: #ffffff;
  --error: #e0705d;
  --ok: #7fc97f;
  --warn: #e2c25a;
  --shadow: 0 1px 4px rgba(0, 0, 0, .35);
}

body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; height: 100vh; transition: background .2s, color .2s; }
.hidden { display: none !important; }
.error { color: var(--error); font-size: 13px; min-height: 18px; margin-top: 8px; }
h5 { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; margin: 16px 4px 6px; }

button { border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; font-size: 14px; background: var(--bg-soft); color: var(--text); }
button:hover { filter: brightness(.97); }
button.primary { background: var(--accent); color: var(--on-accent); }
button.primary:hover { filter: brightness(1.07); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.small { font-size: 12px; padding: 5px 10px; }

input, textarea, select {
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; font-size: 14px; outline: none; font-family: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.badge { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 20px; padding: 2px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- login ---------- */
#login-view { display: flex; align-items: center; justify-content: center; height: 100vh; }
#login-form { width: 320px; display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.login-logo { display: block; }
#login-form input, #login-form button { width: 100%; }
#login-form h1 { font-size: 20px; margin-bottom: 8px; }
.logo img { vertical-align: -4px; }
.hero-logo { align-self: center; }
#login-form input { text-align: center; }

/* ---------- layout ---------- */
#main-view { display: flex; height: 100vh; }
aside {
  width: 290px; min-width: 290px; background: var(--bg-side); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px; overflow-y: auto;
}
.side-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.logo { color: var(--accent); font-weight: 700; font-size: 16px; }
#whoami { color: var(--muted); font-size: 13px; }

#folder-list { display: flex; flex-direction: column; gap: 2px; }
.folder-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.folder-item:hover { background: var(--bg-soft); }
.folder-item.active { background: var(--bg-card); box-shadow: var(--shadow); font-weight: 600; }
.folder-item .cnt { color: var(--muted); font-size: 12px; }

#session-list { display: flex; flex-direction: column; gap: 4px; min-height: 60px; }
.session-item { padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.session-item:hover { background: var(--bg-soft); }
.session-item.active { background: var(--bg-card); box-shadow: var(--shadow); }
.session-item .s-title { font-size: 13.5px; font-weight: 550; display: flex; align-items: center; gap: 5px; }
.session-item .s-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.session-item .s-meta { color: var(--muted); font-size: 11.5px; display: flex; gap: 7px; }
.pin-mark { font-size: 11px; }
.s-actions { display: none; gap: 2px; margin-left: auto; }
.session-item:hover .s-actions { display: inline-flex; }
.s-act { background: none; border: 0; padding: 0 3px; font-size: 12px; opacity: .55; cursor: pointer; }
.s-act:hover { opacity: 1; }
.session-item.pinned .pin-mark { opacity: .9; }
.s-dead { color: var(--error); }

.side-foot { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.foot-btn { text-align: left; font-size: 13px; }
.foot-row { display: flex; justify-content: space-between; align-items: center; }
.side-foot a { color: var(--muted); font-size: 13px; text-decoration: none; }
#theme-seg { display: flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
#theme-seg button { border-radius: 0; padding: 4px 10px; font-size: 12px; background: transparent; color: var(--muted); }
#theme-seg button.active { background: var(--accent); color: var(--on-accent); }

/* ---------- main ---------- */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 20px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
#top-title { font-weight: 700; }
#top-tabs { display: flex; gap: 2px; background: var(--bg-soft); border-radius: 10px; padding: 3px; }
.ttab { background: transparent; color: var(--muted); padding: 5px 14px; font-size: 13px; border-radius: 8px; }
.ttab.active { background: var(--bg-card); color: var(--text); box-shadow: var(--shadow); }
#chat-status.alive { color: var(--ok); }
#chat-status.dead { color: var(--error); }
#kill-session { margin-left: auto; }

/* ---------- герой ---------- */
#hero { margin: auto; width: min(680px, 90%); text-align: center; display: flex; flex-direction: column; gap: 14px; }
.hero-logo { font-size: 44px; color: var(--accent); }
#hero h2 { font-size: 24px; font-weight: 650; }
.hero-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.hero-box textarea { border: 0; resize: none; background: transparent; padding: 6px 8px; }
.hero-box textarea:focus { border: 0; }
.controls { display: flex; gap: 8px; align-items: center; }
.controls select {
  border: 1px solid var(--border); background: var(--bg-soft); border-radius: 9px;
  padding: 5px 8px; font-size: 12.5px; color: var(--text); max-width: 170px;
}
.send-btn { margin-left: auto; width: 44px; padding: 7px 0; font-size: 16px; border-radius: 12px; }
.hint { color: var(--muted); font-size: 12px; }

/* ---------- чат (раскладка под десктоп) ---------- */
#chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#messages { flex: 1; overflow-y: auto; padding: 20px 0; display: flex; flex-direction: column; gap: 4px; }
.row { width: min(1000px, 94%); margin: 0 auto; display: flex; flex: 0 0 auto; }
.row.user { justify-content: flex-end; }        /* свои сообщения — вправо */
.row.assistant, .row.tool, .row.error { justify-content: flex-start; }
.msg { padding: 10px 15px; border-radius: 16px; word-break: break-word; max-width: 100%; }
.msg.user {
  background: var(--accent); color: var(--on-accent);
  border-bottom-right-radius: 5px; max-width: 74%; white-space: pre-wrap; margin: 3px 0;
}
.msg.assistant { background: var(--bg-card); box-shadow: var(--shadow); width: 100%; padding: 12px 16px; }
.msg.tool { background: none; color: var(--muted); font: 12px/1.5 ui-monospace, SFMono-Regular, monospace; padding: 1px 15px; white-space: pre-wrap; }
.msg.error { background: none; color: var(--error); font-size: 12.5px; padding: 2px 15px; white-space: pre-wrap; }
.msg.thinking { background: none; color: var(--muted); padding: 4px 15px; display: flex; align-items: center; gap: 8px; }
.think-star { color: var(--accent); font-size: 16px; line-height: 1; animation: think-pulse 1.6s ease-in-out infinite; }
@keyframes think-pulse {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: .55; }
  50%      { transform: scale(1.3) rotate(180deg); opacity: 1; }
}
#think-text { animation: think-fade 1.6s ease-in-out infinite; }
@keyframes think-fade { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }
#composer { padding: 12px 0 16px; width: min(1000px, 94%); margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
#composer textarea { max-height: 180px; }

/* markdown внутри ответа ассистента */
.msg.assistant .md-p { margin: 0; min-height: 1.1em; }
.msg.assistant .md-gap { height: 8px; }
.msg.assistant .md-h { font-weight: 700; margin: 10px 0 4px; }
.msg.assistant .md-h:first-child { margin-top: 0; }
.md-h1 { font-size: 1.3em; } .md-h2 { font-size: 1.17em; } .md-h3 { font-size: 1.06em; }
.msg.assistant ul, .msg.assistant ol { margin: 3px 0 6px; padding-left: 22px; }
.msg.assistant li { margin: 2px 0; }
.md-code { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font: .87em ui-monospace, SFMono-Regular, monospace; }
.md-pre { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; overflow-x: auto; margin: 7px 0; }
.md-pre code { font: 12.5px/1.55 ui-monospace, SFMono-Regular, monospace; background: none; border: 0; padding: 0; }
.md-link { color: var(--accent); text-decoration: none; }
.md-link:hover { text-decoration: underline; }
.file-link { color: var(--accent); cursor: pointer; text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; }
.file-link:hover { text-decoration-style: solid; }

/* ---------- файлы ---------- */
#files-view { flex: 1; overflow-y: auto; padding: 18px 24px; }
#crumbs { margin-bottom: 12px; font-size: 13.5px; color: var(--muted); }
#crumbs a { color: var(--accent); text-decoration: none; cursor: pointer; }
#file-list { display: flex; flex-direction: column; }
.file-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-bottom: 1px solid var(--border); font-size: 14px; cursor: pointer; border-radius: 8px;
}
.file-row:hover { background: var(--bg-soft); }
.file-row .f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .f-size, .file-row .f-date { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.file-row .f-size { width: 80px; text-align: right; }
.file-row .f-date { width: 120px; text-align: right; }
.files-empty { color: var(--muted); padding: 30px; text-align: center; }

/* ---------- цепочки ---------- */
#chains-view { flex: 1; overflow-y: auto; }
.chains-col { width: min(760px, 92%); margin: 0 auto; padding: 20px 0 40px; }
.chains-col h3 { margin: 18px 0 10px; font-size: 16px; }
.chain-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 10px;
}
.chain-card .c-title { font-weight: 700; }
.chain-card .c-desc { color: var(--muted); font-size: 13px; margin: 3px 0 8px; }
.chain-steps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.step-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 20px;
  padding: 3px 11px; font-size: 12px; color: var(--muted);
}
.step-chip .n { color: var(--accent); font-weight: 700; }
.step-chip.running { border-color: var(--warn); color: var(--text); }
.step-chip.done { border-color: var(--ok); }
.step-chip.error { border-color: var(--error); color: var(--error); }
.chain-form { display: none; flex-direction: column; gap: 8px; margin-top: 10px; }
.chain-form.open { display: flex; }
.chain-form textarea { resize: vertical; min-height: 60px; }
.run-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 12px 16px; margin-bottom: 10px; font-size: 13.5px;
}
.run-card .r-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.run-card .r-title { font-weight: 700; }
.run-card .r-status.running { color: var(--warn); }
.run-card .r-status.done { color: var(--ok); }
.run-card .r-status.error { color: var(--error); }
.run-card .r-task { color: var(--muted); font-size: 12.5px; margin: 4px 0 8px; }
.run-out {
  background: var(--bg-soft); border-radius: 10px; padding: 10px 12px;
  white-space: pre-wrap; font-size: 12.5px; margin-top: 8px; max-height: 320px; overflow-y: auto;
}

/* ---------- монитор ---------- */
#monitor-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#monitor-view header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border); font-weight: 700;
}
#mon-body { flex: 1; overflow-y: auto; padding: 18px 24px; }
#mon-body h4 { color: var(--muted); font-size: 12px; text-transform: uppercase; margin: 14px 0 8px; }
.mon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.mon-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; font-size: 13px; box-shadow: var(--shadow); }
.mon-card .m-name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.mon-card .m-tech { color: var(--muted); font: 11px/1.4 ui-monospace, SFMono-Regular, monospace; margin: 2px 0 0 16px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.fail { background: var(--error); }
.mon-card .m-detail { color: var(--muted); font-size: 12px; margin-top: 3px; }
.mon-card .m-error { color: var(--error); font: 11px/1.4 ui-monospace, monospace; margin-top: 5px; word-break: break-all; }

/* ---------- настройки: пользователи ---------- */
#settings-view { flex: 1; overflow-y: auto; }
/* Воронка/Матрица внутри панели (2026-07-15 Claude) */
#voronka-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#voronka-view header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border); font-weight: 700;
}
#voronka-view header a.badge { text-decoration: none; }
#voronka-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: #f5f6f8; }
.settings-col { width: min(760px, 92%); margin: 0 auto; padding: 20px 0 40px; }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.settings-head h3 { font-size: 16px; }
#user-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.user-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 12px 16px;
}
.user-card .u-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.user-card .u-name { font-weight: 700; }
.role-badge { font-size: 11px; padding: 2px 9px; border-radius: 20px; border: 1px solid var(--border); }
.role-badge.admin { color: var(--accent); border-color: var(--accent); }
.role-badge.employee { color: var(--muted); }
.role-badge.twofa { color: #3a9; border-color: #3a9; }

/* 2FA */
#twofa-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.twofa-on { color: #3a9; font-size: 13.5px; }
.twofa-off { color: var(--muted); font-size: 13.5px; }
#twofa-modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
#twofa-modal.hidden { display: none; }
#tf-secret { user-select: all; background: var(--bg-soft); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.backup-codes { background: var(--bg-soft); border-radius: 8px; padding: 12px; font-size: 15px; line-height: 1.8; letter-spacing: .5px; text-align: center; user-select: all; }
.user-card .u-meta { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.user-card .u-actions { display: flex; gap: 8px; margin-top: 10px; }
.user-card .u-actions button { font-size: 12px; padding: 5px 11px; }
.u-actions .danger { color: var(--error); border: 1px solid var(--border); background: transparent; }

/* модалка пользователя */
#user-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 20px; width: min(460px, 96%);
  display: flex; flex-direction: column; gap: 6px; max-height: 90vh; overflow-y: auto;
}
.modal-box.wide { width: min(560px, 96%); }
.modal-box h3 { margin-bottom: 6px; }
.modal-box label { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.um-allbar { margin: 4px 0; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; }
.chk input { width: auto; }
.chk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 12px; margin-top: 4px; }
.chk-grid.disabled { opacity: .4; pointer-events: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- монитор: группы по проектам ---------- */
.mon-group { margin-bottom: 20px; }
.mon-group-head {
  display: flex; align-items: center; gap: 9px; margin-bottom: 9px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.mon-group-head .g-name { font-weight: 700; font-size: 15px; }
.mon-group-head .g-count {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 20px;
  padding: 1px 9px; font-size: 12px; color: var(--muted);
}
.mon-group-head .g-status { margin-left: auto; font-size: 12px; }
.g-status.ok { color: var(--ok); } .g-status.warn { color: var(--warn); } .g-status.fail { color: var(--error); }
.kind-badge {
  margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: var(--bg-soft); border-radius: 5px; padding: 1px 6px;
}

#new-chat img { vertical-align: -3px; margin-right: 4px; }

/* ---------- микрофон / голосовой ввод ---------- */
.mic-btn {
  width: 44px; padding: 7px 0; font-size: 15px; border-radius: 12px;
  background: var(--bg-soft); border: 1px solid var(--border); line-height: 1;
  margin-left: auto;   /* телеграм-свап: без ➤ микрофон занимает его место справа */
  display: inline-flex; align-items: center; justify-content: center;
}
.mic-btn svg { display: block; }
.mic-btn:hover { border-color: var(--accent); }
.mic-btn.rec {
  background: var(--error); border-color: var(--error); color: #fff;
  animation: micpulse 1.1s ease-in-out infinite;
}
@keyframes micpulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.35); } }
.mic-btn.busy { color: transparent; position: relative; pointer-events: none; }
.mic-btn.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 15px; height: 15px;
  border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%;
  animation: micspin .7s linear infinite;
}
@keyframes micspin { to { transform: rotate(360deg); } }

/* ---------- живая сессия в списке ---------- */
.session-item.live { background: color-mix(in srgb, var(--ok) 8%, transparent); }
.session-item.live.active { background: var(--bg-card); box-shadow: var(--shadow); }
.live-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok); margin-right: 6px; vertical-align: 1px;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent);
  animation: livepulse 1.8s ease-out infinite;
}
@keyframes livepulse { 70%,100% { box-shadow: 0 0 0 5px transparent; } }
.s-live { color: var(--ok); font-weight: 600; }

/* ---------- продолжение сессии / attach-терминал ---------- */
.resume-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.resume-toggle input { width: auto; }
#attach-hint {
  padding: 8px 20px; background: var(--bg-soft); border-bottom: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
#attach-hint code {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 8px; font: 12px ui-monospace, SFMono-Regular, monospace; color: var(--text); user-select: all;
}

/* ---------- выбор разговора для продолжения ---------- */
.resume-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#hero-resume-sel {
  flex: 1; min-width: 200px; max-width: 100%; border: 1px solid var(--border);
  background: var(--bg-soft); border-radius: 9px; padding: 5px 8px; font-size: 12.5px; color: var(--text);
}

/* ---------- просмотр файла справа ---------- */
#file-viewer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(58%, 1040px);
  background: var(--bg-card); border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,.14); display: flex; flex-direction: column; z-index: 40;
}
#main-view.fv-open main { margin-right: min(58%, 1040px); }
.fv-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
#fv-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#fv-download { margin-left: auto; text-decoration: none; display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 5px 10px; border-radius: 10px; color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
#fv-download:hover { color: var(--text); border-color: var(--accent); }
#fv-body { flex: 1; overflow: auto; }
.fv-pre { margin: 0; padding: 14px 16px; font: 12.5px/1.6 ui-monospace, SFMono-Regular, monospace; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); }
.fv-msg { padding: 24px; color: var(--muted); }
.fv-imgwrap { padding: 16px; }
.fv-imgwrap img { max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); }
.fv-note { padding: 10px 16px 4px; font-size: 12px; }
.fv-tablewrap { overflow-x: auto; padding: 10px 14px 18px; }
.fv-table { border-collapse: collapse; font-size: 12.5px; }
.fv-table th, .fv-table td { border: 1px solid var(--border); padding: 4px 9px; text-align: left; vertical-align: top; max-width: 460px; word-break: break-word; white-space: pre-wrap; }
.fv-table th { background: var(--bg-soft); font-weight: 600; position: sticky; top: 0; z-index: 1; }
.fv-table tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-soft) 45%, transparent); }

/* ---------- индикатор контекста ---------- */
.ctx { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.ctx-bar { width: 90px; height: 6px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 20px; overflow: hidden; }
#ctx-fill { display: block; height: 100%; width: 0; background: var(--ok); transition: width .3s; }
#ctx-fill.warm { background: var(--warn); }
#ctx-fill.hot { background: var(--error); }

/* ==================== МОБИЛЬНАЯ ВЕРСИЯ (2026-07-07) ==================== */

/* динамическая высота вьюпорта: адресная строка мобильных браузеров
   съедает часть 100vh — где поддерживается, берём dvh */
@supports (height: 100dvh) {
  body, #main-view, #login-view { height: 100dvh; }
}

/* гамбургер и подложка существуют всегда, но видимы только на мобильном */
#side-toggle { display: none; }
#side-backdrop { display: none; }

@media (max-width: 820px) {
  /* ---------- сайдбар → выезжающий drawer ---------- */
  aside {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
    width: min(300px, 84vw); min-width: 0;
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
    padding-top: max(14px, env(safe-area-inset-top));
  }
  body.side-open aside { transform: translateX(0); }
  #side-backdrop {
    position: fixed; inset: 0; z-index: 55;
    background: rgba(0,0,0,.42); opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  body.side-open #side-backdrop { display: block; opacity: 1; pointer-events: auto; }
  #side-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 10px; z-index: 45;
    width: 40px; height: 40px; padding: 0; font-size: 17px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; box-shadow: var(--shadow); color: var(--text);
  }

  /* ---------- топбар: освобождаем место под гамбургер, разрешаем перенос ---------- */
  #topbar {
    flex-wrap: wrap; gap: 8px; row-gap: 6px;
    padding: 8px 12px 8px 58px; padding-top: max(8px, env(safe-area-inset-top));
  }
  #top-title { font-size: 14px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #top-tabs { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
  .ttab { padding: 5px 11px; white-space: nowrap; }
  #attach-hint { padding-left: 58px; }
  .ctx-bar { width: 56px; }

  /* контент под плавающим гамбургером, когда топбара нет (герой/монитор/настройки) */
  #monitor-view header { padding-left: 58px; }
  #voronka-view header { padding-left: 58px; }
  .settings-col, .chains-col { width: 94%; }
  .settings-col { padding-top: 44px; }   /* настройки без топбара — не лезем под гамбургер */
  #files-view { padding: 14px 12px; }
  body.side-open { overflow: hidden; }   /* не скроллить фон под открытым drawer */

  /* ---------- чат ---------- */
  .row { width: 100%; padding: 0 10px; }
  .msg.user { max-width: 86%; }
  .msg.assistant { padding: 11px 13px; }
  #messages { padding: 12px 0; }
  #composer {
    width: 100%; padding: 8px 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  /* подсказка про Enter неактуальна на телефоне (отправка — кнопкой) */
  #composer > .hint, #hero > .hint { display: none; }

  /* ---------- герой ---------- */
  #hero { width: 94%; gap: 12px; }
  #hero h2 { font-size: 20px; }
  .controls { flex-wrap: wrap; }
  .controls select { flex: 1 1 44%; max-width: none; min-width: 0; }
  .send-btn, .mic-btn { width: 46px; height: 40px; }
  .send-btn { margin-left: auto; }

  /* ---------- вьювер файла: во весь экран ---------- */
  #file-viewer { width: 100%; border-left: 0; }
  #main-view.fv-open main { margin-right: 0; }
  .fv-head { padding-top: max(10px, env(safe-area-inset-top)); }

  /* ---------- разное ---------- */
  .file-row .f-date { display: none; }
  .mon-grid { grid-template-columns: 1fr; }
  #login-form { width: min(320px, 88vw); }
}

/* совсем узкие экраны */
@media (max-width: 400px) {
  .msg.user { max-width: 92%; }
  #top-title { display: none; }
  .file-row .f-size { width: 60px; }
}

/* тач-устройства: iOS зумит поля с шрифтом <16px; hover-действий нет */
@media (pointer: coarse) {
  input, textarea, select { font-size: 16px; }
  .controls select { font-size: 14px; }
  .s-actions { display: inline-flex; }   /* пин/переименовать видимы без hover */
  button { min-height: 36px; }
  #theme-seg button { min-height: 30px; }
  .s-act { font-size: 14px; padding: 2px 6px; opacity: .7; }
}

/* ---------- задачник (2026-07-30 Claude, задача Александра) ---------- */
#tasks-view { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
button.mini { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
#tasks-view > header {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px; border-bottom: 1px solid var(--border); font-weight: 700;
}
#tasks-tabs { display: flex; gap: 4px; }
#tasks-tabs button { padding: 5px 11px; font-size: 13px; border-radius: 8px; background: transparent; color: var(--muted); }
#tasks-tabs button.on { background: var(--bg-soft); color: var(--text); }
#tasks-view #tasks-stat { margin-left: auto; }
#tasks-filters { display: flex; gap: 8px; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
#tasks-filters select, #tasks-filters input[type=search] {
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 9px; font-size: 13px;
}
#tasks-filters label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
#tasks-body { flex: 1; overflow: auto; padding: 16px 22px; }

.t-area > h3 { font-size: 15px; margin: 16px 0 6px; }
.t-area:first-child > h3 { margin-top: 0; }
.t-count { color: var(--muted); font-weight: 400; font-size: 12px; }
.t-proj { margin: 0 0 10px 10px; }
.t-proj > h4 { color: var(--muted); font-size: 12px; text-transform: uppercase; margin: 8px 0 4px; }
.t-lvl1 { margin-left: 26px; } .t-lvl2 { margin-left: 52px; } .t-lvl3 { margin-left: 78px; }
.t-row {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 11px; margin-bottom: 4px; font-size: 14px;
}
.t-row:hover { border-color: var(--accent); }
.t-row.t-closed { opacity: .5; }
.t-prio { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.t-prio.p1 { background: var(--error); } .t-prio.p2 { background: var(--warn); } .t-prio.p3 { background: var(--ok); }
.t-id { color: var(--muted); font: 12px ui-monospace, monospace; }
.t-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-badge { font-size: 11px; color: var(--muted); background: var(--bg-soft); border-radius: 6px; padding: 2px 6px; white-space: nowrap; }
.t-badge.warn { color: var(--warn); } .t-badge.obj { color: var(--accent); }
.t-status { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--bg-soft); color: var(--muted); white-space: nowrap; }
.t-status.s-in_progress { color: var(--accent); } .t-status.s-blocked { color: var(--error); }
.t-status.s-done, .t-status.s-skipped { color: var(--ok); }

.t-board { display: grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); gap: 12px; }
.t-col { background: var(--bg-soft); border-radius: 12px; padding: 10px; min-height: 120px; }
.t-col.drop { outline: 2px dashed var(--accent); }
.t-col > h4 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.t-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px; cursor: pointer; }
.t-card:hover { border-color: var(--accent); }
.t-card .t-prio { display: inline-block; margin-right: 5px; }
.t-card-foot { color: var(--muted); font-size: 11px; margin-top: 4px; display: flex; gap: 6px; align-items: center; }

.t-graph { overflow: auto; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.t-graph path { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.t-graph marker polygon { fill: var(--muted); }
.t-graph rect { fill: var(--bg-soft); stroke: var(--border); }
.t-graph rect.s-in_progress { stroke: var(--accent); }
.t-graph rect.s-blocked { stroke: var(--error); }
.t-graph rect.s-done, .t-graph rect.s-skipped { opacity: .55; }
.t-graph text { fill: var(--text); font: 12px system-ui; }
.t-graph text.g-sub { fill: var(--muted); font-size: 10px; }
.t-graph .g-node { cursor: pointer; }

.t-matrix { margin-bottom: 26px; }
.t-matrix h3 { font-size: 15px; margin-bottom: 8px; }
.t-matrix table { border-collapse: collapse; width: 100%; background: var(--bg-card); border-radius: 12px; overflow: hidden; }
.t-matrix th, .t-matrix td { border: 1px solid var(--border); padding: 7px 10px; font-size: 13px; text-align: center; }
.t-matrix th { background: var(--bg-soft); font-size: 12px; }
.t-matrix td.m-work { text-align: left; font-weight: 600; }
.m-cell { cursor: pointer; min-width: 110px; }
.m-cell i { display: block; font-style: normal; font-size: 11px; color: var(--muted); }
.m-cell.m-done { background: color-mix(in srgb, var(--ok) 18%, transparent); }
.m-cell.m-skip { background: var(--bg-soft); color: var(--muted); }
.m-cell.m-task { background: color-mix(in srgb, var(--warn) 20%, transparent); }
.m-cell.m-none:hover { background: var(--bg-soft); }

#task-detail {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(460px, 92vw);
  background: var(--bg-card); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 16px 18px; overflow-y: auto; z-index: 30;
}
.td-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.td-when { color: var(--muted); font-size: 11px; flex: 1; }
#task-detail label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
#task-detail input, #task-detail select, #task-detail textarea {
  display: block; width: 100%; margin-top: 3px; background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; font-size: 13px; font-family: inherit;
}
.td-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.td-notes { background: var(--bg-soft); border-radius: 8px; padding: 8px 10px; font-size: 12px; margin-bottom: 12px; }
.td-notes div { color: var(--muted); margin-top: 4px; }
.td-foot { display: flex; gap: 6px; flex-wrap: wrap; }
button.danger { color: var(--error); }
@media (max-width: 820px) {
  #tasks-view > header { padding-left: 58px; flex-wrap: wrap; }
  .t-board { grid-template-columns: 1fr; }
}
.t-graph path.e-sub { stroke-dasharray: 4 3; opacity: .65; }
.m-cell .m-add { position: absolute; right: 4px; top: 2px; color: var(--muted); font-weight: 700; opacity: 0; }
.m-cell { position: relative; }
.m-cell:hover .m-add { opacity: 1; }
.m-cell .m-add:hover { color: var(--accent); }
