:root {
  --bg: #f4f6fb;
  --bg2: #ffffff;
  --card: #ffffff;
  --card2: #eef1f8;
  --line: #e4e8f1;
  --text: #1a2030;
  --muted: #6b7488;
  --accent: #5b6cff;
  --accent2: #8b5cf6;
  --green: #15a34a;
  --amber: #d97706;
  --red: #e11d48;
  --violet: #7c3aed;
  --shadow: 0 1px 2px rgba(20,30,60,.04), 0 6px 20px rgba(20,30,60,.06);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, 'Segoe UI', Roboto, 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; position: relative; background: var(--bg); }

/* ---------- Шапка ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { display: flex; gap: 10px; align-items: center; }
.logo {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-weight: 800; font-size: 18px;
}
.t-name { font-weight: 700; }
.t-sub { font-size: 11px; color: var(--muted); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 17px; cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

/* ---------- Основное ---------- */
main { flex: 1; overflow-y: auto; padding-bottom: 90px; }

.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px;
  display: flex;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; cursor: pointer; font-size: 10.5px;
}
.tab .tab-ico { font-size: 19px; filter: grayscale(60%); opacity: .7; }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { filter: none; opacity: 1; }

/* ---------- Общие элементы ---------- */
.pad { padding: 14px 16px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border: none; border-radius: 12px;
  padding: 11px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 12px rgba(91,108,255,.25);
}
.btn:active { transform: scale(.97); }
.btn.secondary { background: var(--card2); border: 1px solid var(--line); color: var(--text); box-shadow: none; }
.btn.small { padding: 8px 12px; font-size: 12.5px; border-radius: 10px; }
.btn.danger { background: #fff; border: 1px solid var(--red); color: var(--red); box-shadow: none; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .55; }
input[type=text], input[type=number], input[type=date], textarea, select {
  width: 100%; background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 13px; font-size: 14px; font-family: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,108,255,.12); }
textarea { resize: vertical; min-height: 74px; }
label.fld { display: block; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
label.fld input, label.fld textarea, label.fld select { margin-top: 5px; font-size: 14px; }
h2.sect { font-size: 15px; margin: 4px 0 10px; }
.muted { color: var(--muted); font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  font-size: 12px; padding: 8px 12px; border-radius: 999px; cursor: pointer;
}
.chip.on { border-color: var(--accent); background: rgba(91,108,255,.12); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 30px 20px; font-size: 13.5px; }
.badge { font-size: 10.5px; padding: 3px 8px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.g { color: var(--green); border-color: rgba(21,163,74,.35); }
.badge.a { color: var(--amber); border-color: rgba(217,119,6,.35); }
.badge.r { color: var(--red); border-color: rgba(225,29,72,.35); }
.badge.v { color: var(--violet); border-color: rgba(124,58,237,.35); }

/* ---------- Чат ---------- */
.conv-list { padding: 12px 16px; }
.conv-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 9px; cursor: pointer; box-shadow: var(--shadow);
}
.conv-item:active { background: var(--card2); }
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - 150px); }
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg2);
}
.chat-msgs { flex: 1; overflow-y: auto; padding: 14px 14px 8px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 88%; font-size: 14px; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border-radius: 16px 16px 4px 16px; padding: 10px 13px; white-space: pre-wrap; box-shadow: var(--shadow); }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 11px 13px; box-shadow: var(--shadow); }
.msg.ai h3, .msg.ai h4 { margin: 8px 0 4px; font-size: 14px; }
.msg.ai ul, .msg.ai ol { padding-left: 18px; margin: 6px 0; }
.msg.ai p { margin: 6px 0; }
.msg.ai strong { color: var(--text); }
.msg.ai code { background: var(--card2); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.msg .time { display: block; font-size: 10px; color: var(--muted); margin-top: 5px; }
.typing { display: inline-flex; gap: 4px; padding: 6px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.25} 40%{opacity:1} }
.quick-row { display: flex; gap: 7px; overflow-x: auto; padding: 9px 14px; scrollbar-width: none; }
.quick-row::-webkit-scrollbar { display: none; }
.quick-chip { flex-shrink: 0; background: var(--card); border: 1px solid var(--line); color: var(--text); font-size: 12px; padding: 8px 12px; border-radius: 999px; cursor: pointer; box-shadow: var(--shadow); }
.chat-input-bar {
  padding: 8px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--bg2); border-top: 1px solid var(--line);
}
.input-row { display: flex; gap: 6px; align-items: flex-end; }
.chat-input-bar textarea { min-height: 44px; max-height: 110px; border-radius: 13px; }
.tool-btn {
  width: 40px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 16px; cursor: pointer; flex-shrink: 0;
}
.tool-btn:active { transform: scale(.93); }
.tool-btn.rec { border-color: var(--red); color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(225,29,72,.15); } }
.attach-preview { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 7px; }
.attach-preview:not(:empty) { display: flex; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card2); border: 1px solid var(--line); border-radius: 9px;
  font-size: 11.5px; padding: 5px 9px; max-width: 200px;
}
.attach-chip button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0; }
.msg .msg-atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.msg .msg-atts img { max-width: 160px; max-height: 130px; border-radius: 9px; border: 1px solid var(--line); object-fit: cover; }
.msg .att-file {
  display: inline-flex; align-items: center; gap: 5px; text-decoration: none;
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  font-size: 11.5px; border-radius: 8px; padding: 5px 9px; max-width: 190px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg .att-audio { width: 100%; height: 36px; margin-bottom: 4px; }
.msg.note { border-color: rgba(217,119,6,.4); background: rgba(217,119,6,.06); }
.kind-badge { font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--amber); display: inline-block; margin-bottom: 3px; }
.send-btn {
  width: 46px; height: 46px; border-radius: 13px; border: none; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-size: 18px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(91,108,255,.25);
}

/* ---------- Матрица Эйзенхауэра ---------- */
.subtabs { display: flex; gap: 6px; padding: 12px 16px 4px; }
.subtabs button {
  flex: 1 1 0; min-width: 0; background: var(--card); border: 1px solid var(--line); color: var(--muted);
  font-size: 12.5px; padding: 9px 2px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.subtabs button.on { color: var(--accent); border-color: var(--accent); background: rgba(91,108,255,.10); }
.matrix {
  display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; gap: 10px;
  padding: 12px 16px;
}
.quad {
  border-radius: 16px; padding: 12px; min-height: 150px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.quad h4 { font-size: 12.5px; margin-bottom: 2px; }
.quad .qsub { font-size: 10.5px; color: var(--muted); margin-bottom: 8px; }
.quad.q1 { border-color: rgba(225,29,72,.45); } .quad.q1 h4 { color: var(--red); }
.quad.q2 { border-color: rgba(21,163,74,.45); } .quad.q2 h4 { color: var(--green); }
.quad.q3 { border-color: rgba(217,119,6,.45); } .quad.q3 h4 { color: var(--amber); }
.quad.q4 { border-color: rgba(107,116,136,.35); } .quad.q4 h4 { color: var(--muted); }
.task-pill {
  background: var(--card2); border-radius: 10px; padding: 8px 10px;
  font-size: 12px; margin-bottom: 6px; border: 1px solid var(--line);
}
.task-pill.done { opacity: .5; text-decoration: line-through; }
.task-pill .tp-meta { font-size: 10px; color: var(--muted); display: block; }
.day-task { display: flex; align-items: flex-start; gap: 9px; }
.day-check {
  width: 22px; height: 22px; border-radius: 7px; border: 1.5px solid var(--line);
  background: var(--bg2); flex-shrink: 0; cursor: pointer; margin-top: 1px;
  display: grid; place-items: center; font-size: 13px; color: transparent;
}
.day-check.done { background: var(--green); border-color: var(--green); color: #fff; }
.add-inline { display: flex; gap: 8px; padding: 0 16px 12px; }
.add-inline input { flex: 1; }

/* ---------- CRM ---------- */
.stage-col { margin-bottom: 14px; }
.stage-title { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 7px; }
.deal-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 11px 13px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow);
}
.deal-amount { font-weight: 700; color: var(--green); font-size: 14.5px; }
.client-card { display: block; }

/* ---------- Чек-ин ---------- */
.mood-chips .chip { padding: 8px 13px; }
.feedback-box {
  background: linear-gradient(160deg, rgba(91,108,255,.08), rgba(139,92,246,.06));
  border: 1px solid rgba(91,108,255,.3);
}

/* ---------- Геймификация ---------- */
.game-card { border: 1px solid rgba(91,108,255,.25); background: linear-gradient(160deg, #fff, rgba(91,108,255,.05)); }
.xp-bar { height: 8px; border-radius: 999px; background: var(--card2); overflow: hidden; margin-top: 10px; }
.xp-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent2)); }

/* ---------- История/таймлайн ---------- */
.timeline { border-left: 1.5px solid var(--line); margin-left: 6px; padding-left: 13px; }
.tl-item { position: relative; padding-bottom: 11px; font-size: 12.5px; }
.tl-item::before {
  content: ''; position: absolute; left: -18px; top: 5px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.tl-item .tl-date { color: var(--muted); font-size: 10.5px; display: block; }

/* ---------- Шторка снизу ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,28,50,.45); z-index: 40; }
.sheet {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto;
  background: var(--bg2); border-radius: 20px 20px 0 0; border: 1px solid var(--line);
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); z-index: 41; box-shadow: 0 -10px 40px rgba(20,30,60,.18);
}
.sheet-grab { width: 42px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 13px; }
.hidden { display: none !important; }

/* ---------- Тост ---------- */
.toast {
  position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%);
  background: #1f2738; color: #fff; border: 1px solid rgba(255,255,255,.12);
  padding: 10px 16px; border-radius: 12px; font-size: 13px; z-index: 60; max-width: 86%;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
}
.toast.err { border-color: var(--red); }

/* Markdown в советах */
.advice-md h3, .advice-md h4 { margin: 9px 0 4px; }
.advice-md ul, .advice-md ol { padding-left: 18px; margin: 6px 0; }
.advice-md p { margin: 6px 0; }
.advice-md strong { color: var(--text); }

/* Рейтинг ответов и баннер открытых циклов */
.rate-row { display: inline-flex; gap: 5px; margin-left: 7px; vertical-align: middle; }
.rate-btn {
  background: none; border: none; font-size: 12px; cursor: pointer;
  opacity: .45; padding: 2px 3px; border-radius: 6px;
}
.rate-btn:active { transform: scale(.9); }
.rate-row:hover .rate-btn { opacity: 1; }
