:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #17191d;
  --muted: #727783;
  --line: #e6e8ec;
  --accent: #141414;
  --lime: #c8ff28;
  --blue: #335cff;
  --danger: #e53535;
  --shadow: 0 12px 34px rgba(25, 30, 42, .08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; max-width: 760px; margin: 0 auto; padding-bottom: calc(84px + var(--safe-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 11px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: rgba(244, 245, 247, .94); backdrop-filter: blur(18px); border-bottom: 1px solid rgba(0,0,0,.04);
}
.brandmark {
  width: 44px; height: 44px; border-radius: 14px; display: block; object-fit: cover;
  background: #222; box-shadow: 0 5px 16px rgba(0,0,0,.18);
}
.brandcopy { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.brandcopy strong { font-size: 17px; }
.brandcopy span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-button { border: 0; background: var(--card); width: 42px; height: 42px; border-radius: 14px; font-size: 24px; box-shadow: 0 5px 16px rgba(0,0,0,.06); }

.view { padding: 16px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.section-head h1 { margin: 0; font-size: 27px; letter-spacing: -.8px; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.counter { min-width: 38px; padding: 7px 10px; border-radius: 13px; background: var(--accent); color: white; text-align: center; font-weight: 800; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); padding: 14px; border-radius: 18px; border: 1px solid var(--line); }
.stat b { display: block; font-size: 24px; letter-spacing: -.6px; }
.stat span { color: var(--muted); font-size: 12px; }

.search { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 13px 15px; outline: none; margin-bottom: 12px; }
.search:focus { border-color: #a8aeb9; box-shadow: 0 0 0 3px rgba(51,92,255,.08); }
.filters { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 9px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 8px 12px; white-space: nowrap; }
.chip.active { background: var(--accent); border-color: var(--accent); color: white; }
.lead-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: visible; }
.lead-filters .chip { min-width: 0; padding: 8px 5px; font-size: 11px; text-align: center; white-space: normal; line-height: 1.15; }

.card-list { display: grid; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 15px; box-shadow: 0 3px 12px rgba(22,25,32,.025); }
.dialog-card { cursor: pointer; display: grid; grid-template-columns: 44px 1fr auto; gap: 11px; align-items: start; outline: none; }
.dialog-card:focus-visible { border-color: #8b93a2; box-shadow: 0 0 0 3px rgba(51,92,255,.1); }
.avatar { width: 44px; height: 44px; border-radius: 15px; display: grid; place-items: center; background: #eef0f3; font-size: 18px; font-weight: 800; }
.card-main { min-width: 0; }
.card-title { font-weight: 800; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card-subtitle { color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card-preview { margin-top: 9px; color: #454a54; font-size: 14px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; margin-top: 10px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 5px 8px; border-radius: 999px; background: #ecf7ec; color: #247333; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge.paused { background: #fff1d7; color: #8c5a00; }
.badge.question { background: #ffe8e8; color: #a52222; }

.detail-head { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.back { border: 0; background: var(--card); border-radius: 13px; width: 40px; height: 40px; font-size: 22px; }
.detail-copy { min-width: 0; flex: 1; }
.detail-copy h1 { font-size: 19px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-copy p { color: var(--muted); font-size: 12px; margin: 2px 0 0; }
.messages { display: grid; gap: 8px; margin: 14px 0; }
.message { max-width: 88%; border-radius: 18px 18px 18px 5px; padding: 10px 12px; background: white; border: 1px solid var(--line); line-height: 1.4; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.ai, .message.owner { justify-self: end; background: #e7eeff; border-color: #d8e2ff; border-radius: 18px 18px 5px 18px; }
.message small { display: block; color: var(--muted); font-size: 10px; margin-top: 5px; }
.composer { position: sticky; bottom: calc(72px + var(--safe-bottom)); background: var(--bg); padding: 8px 0; }
.composer textarea { width: 100%; min-height: 78px; resize: vertical; border: 1px solid var(--line); border-radius: 17px; padding: 12px; outline: none; }
.voice-input { position: relative; width: 100%; }
.voice-input textarea, .voice-input input { padding-right: 50px; }
.voice-button { position: absolute; right: 8px; bottom: 8px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: #eceff4; color: #17191d; display: grid; place-items: center; cursor: pointer; z-index: 2; }
.voice-button:disabled { opacity: .65; cursor: wait; }
.voice-button.recording { background: #ffdddd; color: #a80000; animation: voice-pulse 1.2s ease-in-out infinite; }
.voice-status { position: absolute; right: 51px; bottom: 16px; color: var(--muted); font-size: 11px; pointer-events: none; }
@keyframes voice-pulse { 50% { opacity: .6; } }
.action-row { display: flex; gap: 8px; margin-top: 8px; }
.button { border: 0; border-radius: 14px; padding: 12px 14px; font-weight: 750; background: var(--accent); color: white; flex: 1; }
.button.secondary { background: white; color: var(--ink); border: 1px solid var(--line); }
.button.danger { background: var(--danger); }
.button:disabled { opacity: .45; }

.lead-card h3, .knowledge-card h3 { margin: 0 0 8px; font-size: 17px; }
.lead-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.lead-title-row h3 { min-width: 0; flex: 1; }
.lead-status-badge { flex: 0 0 auto; }
.lead-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.lead-field { min-width: 0; }
.lead-field span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .4px; }
.lead-field b { font-size: 13px; overflow-wrap: anywhere; }
.lead-field.wide { grid-column: 1 / -1; }
.lead-dialog-button { width: 100%; margin-top: 12px; border: 1px solid var(--line); background: white; color: var(--ink); border-radius: 12px; padding: 10px; font-weight: 700; }
.lead-status-block { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.lead-status-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: 12px; }
.test-label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .3px; }
.lead-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.lead-status-button { min-width: 0; border: 1px solid var(--line); background: #f7f8f9; color: #383d46; border-radius: 12px; padding: 9px 6px; font-size: 12px; font-weight: 700; }
.lead-status-button.active { background: var(--accent); border-color: var(--accent); color: white; opacity: 1; }
.lead-status-button:disabled:not(.active) { opacity: .45; }

.support-box { background: #181818; color: white; border-radius: 22px; padding: 16px; margin-bottom: 14px; }
.support-box h2 { margin: 0 0 5px; font-size: 19px; }
.support-box p { margin: 0 0 12px; color: #bfc2c8; font-size: 13px; }
.support-box textarea { width: 100%; border: 0; border-radius: 14px; padding: 11px; min-height: 76px; resize: vertical; }
.support-box .voice-button { background: #3a3d44; color: white; }
.support-box .voice-button.recording { background: #7c2525; }
.support-box .voice-status { color: #c9cbd0; }
.support-answer { margin-top: 10px; padding: 11px; background: #2a2a2a; border-radius: 13px; white-space: pre-wrap; font-size: 13px; }
.support-history { display: grid; gap: 7px; margin: 0 0 12px; max-height: 220px; overflow-y: auto; }
.support-message { padding: 9px 10px; border-radius: 12px; background: #2a2a2a; color: #d9dce1; font-size: 12px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.support-message.user { margin-left: 22px; background: #343942; color: white; }
.guide-card { margin-bottom: 12px; }
.guide-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.guide-head h2, .correction-box h2, .improvement-box h2 { margin: 0 0 4px; font-size: 19px; }
.guide-head p, .correction-box > p, .improvement-box > p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.guide-toggle { flex: 0 0 auto; padding: 10px 12px; }
.guide-body { margin-top: 13px; padding-top: 4px; border-top: 1px solid var(--line); }
.guide-body[hidden] { display: none; }
.guide-section { padding: 10px 0; border-bottom: 1px solid var(--line); }
.guide-section:last-child { border-bottom: 0; padding-bottom: 2px; }
.guide-section h3 { margin: 0 0 4px; font-size: 14px; }
.guide-section p { margin: 0; color: #4b505a; font-size: 13px; line-height: 1.45; }
.correction-box { background: #eef3ff; border: 1px solid #dce5ff; border-radius: 22px; padding: 16px; margin-bottom: 12px; }
.improvement-box { background: #f5f1ff; border: 1px solid #e5dcff; border-radius: 22px; padding: 16px; margin-bottom: 12px; }
.form-field { display: block; margin-top: 12px; }
.form-field > span { display: block; margin-bottom: 5px; font-size: 12px; font-weight: 750; }
.form-field textarea, .form-field input, .form-field select { width: 100%; border: 1px solid #d8dfef; background: white; border-radius: 13px; padding: 11px; outline: none; }
.form-field textarea { min-height: 72px; resize: vertical; }
.form-field.compact input { min-height: 44px; }
.correction-box > .button, .improvement-box > .button { width: 100%; margin-top: 12px; }
.linked-dialog { margin-top: 10px; padding: 8px 10px; border-radius: 11px; background: #e9e0ff; color: #55369a; font-size: 12px; overflow-wrap: anywhere; }
.recent-title { margin: 18px 0 8px; font-size: 14px; }
.improvement-list { display: grid; gap: 8px; }
.improvement-item { background: white; border: 1px solid #e5dcff; border-radius: 14px; padding: 11px; }
.improvement-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.improvement-item p { margin: 7px 0 0; font-size: 12px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.improvement-item .analysis { color: #535968; }
.knowledge-card p { margin: 5px 0; font-size: 13px; line-height: 1.4; white-space: pre-wrap; }
.knowledge-card .answer { color: #343942; }

.safety-note { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; padding: 12px 13px; border: 1px solid #f0d997; border-radius: 16px; background: #fff9e8; }
.safety-note strong { font-size: 13px; }
.safety-note span { color: #6f633e; font-size: 12px; line-height: 1.4; }
.broadcast-composer { background: #eef3ff; border: 1px solid #dce5ff; border-radius: 22px; padding: 16px; margin-bottom: 14px; }
.broadcast-composer h2, .broadcast-message-card h2, .broadcast-audience-card h2 { margin: 0 0 5px; font-size: 19px; }
.broadcast-composer > p, .broadcast-audience-card > p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.broadcast-composer > .button { width: 100%; margin-top: 12px; }
.char-counter { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; text-align: right; }
.broadcast-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.broadcast-card-head h3 { margin: 0; font-size: 16px; }
.broadcast-card-text { margin: 10px 0; color: #414650; font-size: 13px; line-height: 1.4; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.broadcast-card .button { margin-top: 10px; width: 100%; }
.broadcast-message { margin: 10px 0; padding: 12px; border-radius: 14px; background: #f7f8fa; font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.broadcast-message-card small { color: var(--muted); }
.broadcast-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 10px 0; }
.broadcast-stat { min-width: 0; padding: 9px 5px; border-radius: 13px; background: white; border: 1px solid var(--line); text-align: center; }
.broadcast-stat b { display: block; font-size: 17px; }
.broadcast-stat span { display: block; color: var(--muted); font-size: 9px; overflow-wrap: anywhere; }
.broadcast-recipients { display: grid; gap: 7px; margin-top: 12px; }
.broadcast-recipient { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px; border-radius: 13px; background: #f7f8fa; }
.broadcast-recipient > div { min-width: 0; }
.broadcast-recipient strong, .broadcast-recipient span { display: block; }
.broadcast-recipient > div span { margin-top: 2px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.broadcast-exclusions { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.broadcast-exclusions strong { color: var(--ink); }
.broadcast-actions { flex-wrap: wrap; }
.broadcast-actions .button { min-width: 145px; }
.campaign-previewed { background: #eef2ff; color: #4256a6; }
.campaign-approved { background: #e8f7ec; color: #247333; }
.campaign-queued, .campaign-running { background: #fff1d7; color: #8c5a00; }
.campaign-paused, .campaign-failed { background: #ffe8e8; color: #a52222; }
.campaign-completed { background: #e8f7ec; color: #247333; }
.campaign-cancelled { background: #eceef2; color: #5c626d; }

.status-hero { background: var(--accent); color: white; padding: 20px; border-radius: 24px; box-shadow: var(--shadow); }
.status-hero .pulse { width: 12px; height: 12px; border-radius: 50%; background: #58df70; display: inline-block; margin-right: 7px; box-shadow: 0 0 0 6px rgba(88,223,112,.13); }
.status-hero.stopped .pulse { background: #ff5757; box-shadow: 0 0 0 6px rgba(255,87,87,.13); }
.status-hero h2 { margin: 13px 0 4px; font-size: 23px; }
.status-hero p { margin: 0; color: #babdc4; font-size: 13px; }
.control-card { margin-top: 12px; }
.control-card h3 { margin: 0 0 6px; }
.control-card p { color: var(--muted); font-size: 13px; line-height: 1.45; }
.danger-zone { border-color: #f1c3c3; background: #fffafa; }

.empty, .error-card, .loading-card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 28px 18px; text-align: center; color: var(--muted); }
.empty strong, .error-card strong, .loading-card strong { display: block; color: var(--ink); margin: 8px 0 4px; }
.spinner { width: 28px; height: 28px; border: 3px solid #e1e3e7; border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 10px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.bottom-nav {
  position: fixed; z-index: 30; left: 50%; bottom: 0; transform: translateX(-50%); width: min(760px, 100%);
  display: grid; grid-template-columns: repeat(5, 1fr); padding: 7px 4px calc(7px + var(--safe-bottom));
  background: rgba(255,255,255,.96); backdrop-filter: blur(20px); border-top: 1px solid var(--line);
}
.nav-item { border: 0; background: transparent; color: #8a8f99; padding: 4px 2px; }
.nav-item span { display: block; font-size: 20px; filter: grayscale(1); opacity: .66; }
.nav-item b { display: block; font-size: 9px; margin-top: 2px; }
.nav-item.active { color: var(--ink); }
.nav-item.active span { filter: none; opacity: 1; transform: translateY(-1px); }
.toast { position: fixed; z-index: 80; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translate(-50%, 12px); background: #191919; color: white; border-radius: 13px; padding: 10px 14px; max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: .2s; font-size: 13px; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 640px) {
  .view { padding: 22px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .card-list { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .detail-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
}
