:root {
  --bg: #f5f8f6;
  --surface: #ffffff;
  --surface-2: #f8fbf9;
  --border: #e1e9e4;
  --border-strong: #d1ddd6;
  --text: #152018;
  --muted: #718078;
  --green: #127a4b;
  --green-2: #0d6840;
  --green-soft: #e8f6ee;
  --amber: #a76309;
  --amber-soft: #fff4df;
  --blue: #3a67a8;
  --blue-soft: #eaf2ff;
  --purple: #7158a5;
  --purple-soft: #f0ebff;
  --danger: #a9473f;
  --danger-soft: #fdebea;
  --neutral-soft: #eff3f1;
  --shadow: 0 18px 42px rgba(31, 53, 42, 0.06);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: #0e1712; color: white; padding: 28px 18px 20px; display: flex; flex-direction: column; border-right: 1px solid rgba(255,255,255,.06); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: linear-gradient(145deg,#1fa66d,#0f6e47); font-weight: 800; font-size: 18px; box-shadow: inset 0 1px 0 rgba(255,255,255,.22); }
.brand-name { font-size: 18px; font-weight: 800; letter-spacing: .12em; }
.brand-sub { margin-top: 3px; color: #9eb0a7; font-size: 11px; }
.nav { display: grid; gap: 6px; }
.nav-item, .sidebar-action { width: 100%; border: 0; background: transparent; color: #9eafa6; min-height: 44px; padding: 0 13px; border-radius: 12px; display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px; text-align: left; transition: 160ms ease; }
.nav-item:hover, .sidebar-action:hover { background: rgba(255,255,255,.05); color: white; }
.nav-item.active { background: rgba(47,178,115,.12); color: #b9f0d1; }
.nav-icon { font-size: 17px; }
.nav-badge { min-width: 21px; height: 21px; display: grid; place-items: center; padding: 0 6px; background: #1b7d51; color: white; border-radius: 999px; font-size: 11px; }
.crm-refresh-menu { margin: 12px 4px 0; padding: 12px; border: 1px solid rgba(255,255,255,.07); background: rgba(255,255,255,.025); border-radius: 12px; }
.crm-refresh-label { color: #60766a; font-size: 9px; font-weight: 800; letter-spacing: .13em; margin-bottom: 8px; }
.crm-refresh-now { width: 100%; min-height: 38px; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.035); color: #d6e7dd; border-radius: 10px; padding: 0 10px; display: grid; grid-template-columns: 22px 1fr; align-items: center; gap: 8px; text-align: left; font-size: 12px; font-weight: 700; transition: 160ms ease; }
.crm-refresh-now:hover { background: rgba(255,255,255,.07); color: white; }
.crm-refresh-now:disabled { opacity: .6; cursor: wait; }
.crm-auto-refresh { display: grid; gap: 6px; margin-top: 10px; color: #9eafa6; font-size: 10px; font-weight: 700; }
.crm-auto-refresh select { width: 100%; min-height: 36px; border: 1px solid rgba(255,255,255,.10); border-radius: 9px; padding: 0 9px; background: #152019; color: #d6e7dd; font: inherit; outline: none; }
.crm-auto-refresh select:focus { border-color: rgba(47,178,115,.65); box-shadow: 0 0 0 2px rgba(47,178,115,.12); }
.crm-refresh-status { margin-top: 7px; color: #71877b; font-size: 9px; line-height: 1.35; }
.sidebar-tools { margin-top: 14px; padding: 0 4px; }
.sidebar-section-label { color: #60766a; font-size: 9px; font-weight: 800; letter-spacing: .13em; padding: 0 9px 8px; }
.sidebar-action { border: 1px solid rgba(255,255,255,.07); background: rgba(255,255,255,.025); grid-template-columns: 24px 1fr; color: #cadbd2; }
.sidebar-footer { margin-top: auto; }
.profile { padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 10px; }
.avatar, .contact-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: #dcebe3; color: #2b5f47; flex: 0 0 auto; }
.profile .avatar { background: #223129; color: #d6e7dd; }
.profile-name { font-weight: 600; font-size: 13px; }
.profile-meta { color: #82968b; font-size: 11px; margin-top: 2px; }

.main { padding: 34px 38px 44px; min-width: 0; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow, .section-kicker { font-size: 10px; letter-spacing: .16em; font-weight: 800; color: var(--green); }
.title-line { display: flex; gap: 13px; align-items: center; margin-top: 6px; }
h1 { margin: 0; font-size: clamp(30px,4vw,42px); letter-spacing: -.04em; }
h2,h3,p { margin-top: 0; }
.sync-chip { display: inline-flex; align-items: center; gap: 7px; min-height: 28px; padding: 0 10px; border: 1px solid var(--border); background: white; border-radius: 999px; color: var(--muted); font-size: 10px; font-weight: 600; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.icon-button, .secondary-button, .primary-button, .telegram-button, .danger-button { border: 1px solid var(--border); background: white; min-height: 42px; border-radius: 12px; padding: 0 15px; color: var(--text); font-weight: 700; }
.icon-button { width: 42px; padding: 0; display: grid; place-items: center; }
.primary-button { background: var(--green); border-color: var(--green); color: white; box-shadow: 0 8px 18px rgba(18,122,75,.17); }
.primary-button:hover { background: var(--green-2); }
.secondary-button:hover, .icon-button:hover, .telegram-button:hover { background: #f7faf8; }
.danger-button { background: var(--danger); border-color: var(--danger); color: white; }
.compact-button { min-height: 34px; padding: 0 11px; font-size: 11px; }

.stats-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 15px; margin-bottom: 18px; }
.stat-card { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-lg); padding: 17px; box-shadow: 0 7px 20px rgba(28,54,41,.03); display: grid; grid-template-columns: 44px 1fr; gap: 12px; text-align: left; color: var(--text); transition: 150ms ease; }
.stat-card:hover { transform: translateY(-1px); border-color: #d2e2d9; box-shadow: 0 10px 24px rgba(28,54,41,.055); }
.stat-icon { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; }
.soft-green { background: var(--green-soft); color: var(--green); }
.soft-amber { background: var(--amber-soft); color: var(--amber); }
.soft-blue { background: var(--blue-soft); color: var(--blue); }
.soft-purple { background: var(--purple-soft); color: var(--purple); }
.stat-copy { display: grid; gap: 3px; }
.stat-copy strong { font-size: 25px; letter-spacing: -.03em; }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-trend { grid-column: 2; font-size: 10px; color: #829188; }
.attention { color: var(--amber); }
.active-filter { margin: -3px 0 15px; min-height: 36px; border: 1px solid #d9e8df; background: #f1f8f4; border-radius: 11px; padding: 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #35614a; font-size: 11px; }
.active-filter button { border: 0; background: transparent; color: var(--green); font-weight: 800; }

.workspace-grid { display: grid; grid-template-columns: minmax(300px,.58fr) minmax(760px,1.42fr); gap: 18px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow); }
.contacts-panel { overflow: hidden; }
.detail-panel {
  position: sticky;
  top: 20px;
  height: calc(100vh - 40px);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #c5d4cb transparent;
}
.detail-panel::-webkit-scrollbar { width: 10px; }
.detail-panel::-webkit-scrollbar-track { background: transparent; }
.detail-panel::-webkit-scrollbar-thumb { background: #c5d4cb; border: 3px solid white; border-radius: 999px; }
.detail-panel::-webkit-scrollbar-thumb:hover { background: #aebfb5; }
.panel-header { padding: 20px 20px 16px; display: flex; justify-content: space-between; align-items: center; gap: 14px; border-bottom: 1px solid var(--border); }
.panel-header.compact { padding: 18px 16px 14px; }
.panel-header h2 { margin-bottom: 4px; font-size: 18px; }
.panel-header p { margin: 0; color: var(--muted); font-size: 11px; }
.panel-header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.export-contacts-button { height: 38px; border: 1px solid #cfe0d6; border-radius: 11px; padding: 0 12px; background: #f4faf6; color: var(--green); display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 10.5px; font-weight: 800; white-space: nowrap; cursor: pointer; }
.export-contacts-button:hover { background: #eaf6ee; border-color: #bdd5c7; }
.export-contacts-button:focus-visible { outline: 2px solid #9dc7ae; outline-offset: 2px; }
.search-wrap { height: 38px; border: 1px solid var(--border); border-radius: 11px; display: flex; align-items: center; gap: 8px; padding: 0 11px; background: #fbfcfb; width: 100%; max-width: 190px; }
.search-wrap input { border: 0; outline: 0; width: 100%; background: transparent; color: var(--text); }
.contact-toolbar { padding: 10px 12px; border-bottom: 1px solid var(--border); background: #fbfcfb; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr) auto; gap: 8px; align-items: end; }
.contact-filter-select { display: grid; gap: 4px; min-width: 0; }
.contact-filter-select > span { color: var(--muted); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .055em; }
.contact-filter-select select { width: 100%; height: 34px; border: 1px solid var(--border); border-radius: 10px; background: white; color: var(--text); padding: 0 30px 0 10px; font-size: 11px; font-weight: 700; outline: 0; }
.contact-filter-select select:focus { border-color: #bfd7c9; box-shadow: 0 0 0 3px rgba(18,122,75,.07); }
.group-toggle { min-height: 34px; border: 1px solid var(--border); background: white; border-radius: 10px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: #5d6c64; font-size: 10px; font-weight: 800; cursor: pointer; }
.group-toggle:hover { background: #f5f8f6; border-color: #cfddd5; }
.group-toggle.active { background: var(--green-soft); border-color: #bfd8ca; color: var(--green); }
.group-toggle-icon { font-size: 13px; line-height: 1; }
.contact-group { display: block; }
.contact-group + .contact-group { border-top: 5px solid #f6f9f7; }
.contact-group-header { width: 100%; min-height: 34px; padding: 0 14px; border: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #f8faf9; border-bottom: 1px solid var(--border); color: #68776f; font: inherit; font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .045em; position: sticky; top: 0; z-index: 2; cursor: pointer; text-align: left; }
.contact-group-header:hover { background: #f2f6f4; }
.contact-group-header:focus-visible { outline: 2px solid #9dc7ae; outline-offset: -2px; }
.contact-group-title-wrap { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.contact-group-chevron { display: inline-block; font-size: 14px; line-height: 1; transform: rotate(0deg); transition: transform 140ms ease; }
.contact-group.collapsed .contact-group-chevron { transform: rotate(-90deg); }
.contact-group-body { display: block; }
.contact-group.collapsed .contact-group-body { display: none; }
.contact-group.collapsed .contact-group-header { border-bottom: 0; }
.contact-group-count { min-width: 22px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; background: white; border: 1px solid var(--border); color: var(--muted); font-size: 9px; }
.contact-empty-state { padding: 26px 18px; color: #718078; font-size: 12px; text-align: center; }
.contact-list { display: grid; }
.contact-row { border: 0; border-bottom: 1px solid var(--border); background: white; width: 100%; min-height: 84px; padding: 14px 17px; display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 11px; text-align: left; transition: 140ms ease; color: var(--text); }
.contact-row:last-child { border-bottom: 0; }
.contact-row:hover { background: #fafcfb; }
.contact-row.active { background: #f2f8f5; box-shadow: inset 3px 0 0 var(--green); }
.contact-main { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.contact-name { font-weight: 700; font-size: 13px; margin-bottom: 5px; }
.contact-meta { color: var(--muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-side { display: grid; justify-items: end; align-content: center; gap: 7px; min-width: 108px; }

.pill { display: inline-flex; align-items: center; justify-content: center; min-height: 25px; padding: 0 10px; border-radius: 999px; font-size: 10px; font-weight: 800; letter-spacing: .02em; white-space: nowrap; }
.success { background: var(--green-soft); color: var(--green); }
.pending { background: var(--amber-soft); color: var(--amber); }
.action-send { background: #dff5e9; color: #0f7947; }
.action-wait { background: var(--amber-soft); color: var(--amber); }
.action-review { background: #fff0e6; color: #b7651a; }
.action-stop { background: var(--danger-soft); color: var(--danger); }
.action-none { background: var(--neutral-soft); color: #6b7871; }
.status-contacted { background: var(--blue-soft); color: var(--blue); }
.status-updated { background: #edf0ff; color: #5d67a1; }
.status-new { background: #e9f5ff; color: #2f6f9e; }
.status-converted { background: #e5f4ec; color: #116b45; }
.status-max { background: var(--danger-soft); color: var(--danger); }
.approval-neutral { background: var(--neutral-soft); color: #65736b; }
.approval-sent { background: #e5f4ec; color: #116b45; }
.approval-raw { background: #fff0e6; color: #9a5d18; }

.detail-empty { min-height: 720px; display: grid; place-items: center; align-content: center; text-align: center; padding: 40px; }
.empty-icon { width: 60px; height: 60px; display: grid; place-items: center; border-radius: 18px; background: var(--green-soft); color: var(--green); font-size: 24px; margin-bottom: 16px; }
.detail-empty h3 { margin-bottom: 8px; }
.detail-empty p { color: var(--muted); max-width: 320px; line-height: 1.55; }
.detail-content { padding: 20px; display: flex; flex-direction: column; min-height: 100%; }
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 18px; }
.contact-identity { display: flex; align-items: center; gap: 12px; }
.contact-avatar.large { width: 48px; height: 48px; }
.name-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.name-row h2 { margin: 0; font-size: 19px; }
.verified { width: 17px; height: 17px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--green); color: white; font-size: 10px; }
#detailUsername { color: var(--muted); font-size: 12px; text-decoration: none; }
#detailUsername:hover { color: var(--green); }
.telegram-button { color: #28759f; }
.telegram-button.slim { min-height: 34px; padding: 0 12px; font-size: 11px; }
.inline-open { margin-left: 3px; }
.header-actions { display: flex; align-items: center; gap: 8px; position: relative; }
.ai-mode-wrap { position: relative; }
.ai-mode-button { min-height: 38px; border: 1px solid #cfe2d7; background: #f4faf7; border-radius: 11px; padding: 6px 10px; display: grid; grid-template-columns: auto auto auto; align-items: center; gap: 7px; color: var(--text); cursor: pointer; }
.ai-mode-button:hover { background: #edf7f1; border-color: #bdd8c8; }
.ai-mode-button.mode-off { background: #f7f8f7; border-color: var(--border); }
.ai-mode-label { color: var(--muted); font-size: 9px; font-weight: 700; }
.ai-mode-button strong { font-size: 11px; color: var(--green); }
.ai-mode-button.mode-off strong { color: #6c7770; }
.ai-mode-chevron { color: var(--muted); font-size: 11px; }
.ai-mode-menu { position: absolute; right: 0; top: 46px; z-index: 30; width: 300px; padding: 7px; background: white; border: 1px solid var(--border); border-radius: 13px; box-shadow: 0 16px 36px rgba(27,48,38,.16); }
.ai-mode-menu button { width: 100%; border: 0; background: transparent; border-radius: 10px; padding: 10px; text-align: left; display: grid; grid-template-columns: 10px 1fr; gap: 10px; align-items: start; color: var(--text); cursor: pointer; }
.ai-mode-menu button:hover { background: #f4f8f6; }
.ai-mode-menu button > span:last-child { display: grid; gap: 3px; }
.ai-mode-menu strong { font-size: 11px; }
.ai-mode-menu small { color: var(--muted); font-size: 9.5px; line-height: 1.4; }
.mode-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; }
.mode-dot.manual { background: var(--green); }
.mode-dot.off { background: #9ca7a1; }
.more-wrap { position: relative; }
.more-menu { position: absolute; right: 0; top: 48px; z-index: 25; min-width: 220px; padding: 7px; background: white; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 14px 32px rgba(27,48,38,.15); }
.more-menu button { width: 100%; border: 0; background: transparent; border-radius: 9px; padding: 10px 11px; text-align: left; color: var(--text); font-weight: 600; font-size: 12px; display: flex; gap: 9px; align-items: center; }
.more-menu button:hover { background: #f4f8f6; }
.menu-divider { height: 1px; background: var(--border); margin: 5px 3px; }

.workflow-strip { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 9px; margin-bottom: 14px; }
.workflow-strip.ai-off { grid-template-columns: 1fr; }
.workflow-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 13px; padding: 10px; display: grid; gap: 7px; min-width: 0; }
.workflow-label { color: var(--muted); font-size: 10px; }
.state-select { width: 100%; border: 0; outline: 0; min-height: 28px; border-radius: 999px; padding: 0 30px 0 11px; font-size: 10px; font-weight: 800; appearance: auto; background: var(--neutral-soft); color: var(--text); }
.state-select:focus { box-shadow: 0 0 0 3px rgba(18,122,75,.09); }
.state-readonly { width: 100%; min-height: 28px; border-radius: 999px; padding: 0 11px; font-size: 10px; font-weight: 800; display: flex; align-items: center; cursor: default; user-select: none; }
.readonly-state .workflow-label::after { content: "  ·  AI controlled"; color: var(--muted); font-weight: 500; }
.approval-state { align-content: start; }
.approval-line { min-height: 28px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.approval-hint { color: var(--muted); font-size: 9px; line-height: 1.35; }

.detail-main-stack { display: grid; gap: 14px; }
.info-card { border: 1px solid var(--border); border-radius: 15px; padding: 16px; background: white; }
.section-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.section-title-row h3 { margin: 4px 0 0; font-size: 14px; }
.history-count, .autosave-label { color: var(--muted); font-size: 9px; }
.conversation-box { background: #fbfcfb; border: 1px solid var(--border); border-radius: 13px; padding: 12px; min-height: 280px; overflow: visible; display: grid; align-content: start; gap: 10px; }
.message-row { display: flex; gap: 10px; }
.message-row.me { justify-content: flex-end; }
.message-bubble-wrap { max-width: 88%; display: grid; gap: 4px; }
.message-meta { font-size: 9.5px; color: var(--muted); }
.message-row.me .message-meta { text-align: right; }
.message-bubble { background: white; border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; color: #31473b; font-size: 12px; line-height: 1.55; }
.message-row.me .message-bubble { background: #edf7f1; border-color: #d7eadf; }
.ai-card { background: linear-gradient(180deg,#fbfefc,#f6fbf8); border-color: #d8e9df; }
.ai-title-row { align-items: center; }
.ai-title-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.ai-badge { padding: 6px 9px; border-radius: 9px; background: var(--green-soft); color: var(--green); font-size: 9px; font-weight: 800; letter-spacing: .06em; }
.ai-reason { margin: 0; color: #465a4e; font-size: 12px; line-height: 1.65; }
.next-followup { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 16px; align-items: center; font-size: 11px; color: var(--muted); }
.next-followup strong { color: var(--text); }
.ai-audit-grid { margin-top: 14px; padding-top: 13px; border-top: 1px solid #dce9e1; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 9px; }
.ai-audit-grid > div { min-width: 0; display: grid; gap: 5px; padding: 9px 10px; background: rgba(255,255,255,.72); border: 1px solid #dde9e2; border-radius: 11px; }
.ai-audit-grid span { color: var(--muted); font-size: 9px; }
.ai-audit-grid strong { color: var(--text); font-size: 10.5px; line-height: 1.35; word-break: break-word; }
.text-button { border: 0; background: transparent; color: var(--green); font-weight: 800; font-size: 11px; }
.draft-editor, .notes-editor { width: 100%; resize: vertical; border: 1px solid var(--border); border-radius: 13px; background: #fbfcfb; padding: 14px; color: #33473c; font: inherit; font-size: 12px; line-height: 1.65; outline: none; }
.draft-editor { min-height: 126px; }
.notes-editor { min-height: 92px; }
.draft-editor:focus, .notes-editor:focus { border-color: #9ccbb2; box-shadow: 0 0 0 3px rgba(18,122,75,.08); }
.draft-actions { margin-top: 12px; display: grid; gap: 9px; }
.single-primary { grid-template-columns: minmax(190px,280px); justify-content: end; }
.full { width: 100%; }
.action-help { margin-top: 9px; min-height: 15px; color: var(--muted); font-size: 10px; line-height: 1.45; text-align: right; }
.state-message { display: grid; grid-template-columns: 44px 1fr; gap: 13px; align-items: start; background: #fbfcfb; }
.state-message-icon { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; background: var(--neutral-soft); color: #5f6f67; font-size: 18px; }
.state-message h3 { margin: 4px 0 6px; font-size: 14px; }
.state-message p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.sent-card { background: #f7fcf9; border-color: #d5e9dd; }
.sent-grid { display: grid; grid-template-columns: 160px 1fr; gap: 14px; }
.sent-grid > div { display: grid; gap: 5px; }
.sent-text p { margin: 0; color: #33473c; font-size: 12px; line-height: 1.55; }
.meta-label { color: var(--muted); font-size: 10px; }
.contact-metrics-card { padding: 4px 2px; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; background: #fff; border: 0; border-radius: 0; }
.contact-metric-item { min-width: 0; display: grid; gap: 5px; padding: 4px 0; background: #fff; border: 0; border-radius: 0; }
.contact-metric-item strong { font-size: 12px; line-height: 1.25; color: var(--text); word-break: break-word; }
.contact-metric-item:nth-child(2) { text-align: right; justify-items: end; }
.notes-card { background: #fcfdfc; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(8,17,12,.42); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; }
.modal-card { width: min(720px,100%); max-height: calc(100vh - 40px); overflow: auto; background: white; border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 28px 70px rgba(8,22,14,.22); padding: 22px; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 14px; }
.modal-header h2 { margin: 4px 0 5px; font-size: 20px; }
.modal-header p { margin: 0; color: var(--muted); font-size: 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.confirm-modal { width: min(470px,100%); text-align: center; padding: 28px; }
.confirm-icon { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 15px; display: grid; place-items: center; background: var(--danger-soft); color: var(--danger); font-size: 22px; }
.confirm-modal h2 { margin-bottom: 9px; font-size: 19px; }
.confirm-modal p { color: var(--muted); font-size: 12px; line-height: 1.6; margin-bottom: 0; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 200; transform: translate(-50%,20px); background: #101a15; color: white; padding: 11px 14px; border-radius: 11px; opacity: 0; pointer-events: none; transition: 180ms ease; font-size: 12px; box-shadow: 0 14px 30px rgba(0,0,0,.18); }
.toast.show { opacity: 1; transform: translate(-50%,0); }

@media (max-width: 720px) {
  .ai-audit-grid { grid-template-columns: 1fr; }
  .header-actions { align-items: flex-start; }
  .ai-mode-menu { width: min(300px, calc(100vw - 48px)); }
}

@media (max-width: 1280px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .workspace-grid { grid-template-columns: 1fr; }
  .detail-panel { position: static; height: auto; min-height: auto; overflow: visible; scrollbar-gutter: auto; }
  .detail-empty { min-height: 320px; }
}
@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 14px; }
  .brand { padding-bottom: 14px; }
  .nav { display: flex; overflow-x: auto; padding-bottom: 2px; }
  .nav-item { width: auto; min-width: max-content; grid-template-columns: 20px auto auto; }
  .crm-refresh-menu, .sidebar-tools, .sidebar-footer { display: none; }
  .main { padding: 22px 16px 30px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .panel-header-actions { width: 100%; justify-content: stretch; }
  .search-wrap { max-width: none; flex: 1; }
  .workflow-strip { grid-template-columns: 1fr; }
  .sent-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .topbar .icon-button { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
  .contact-row { padding: 12px; min-height: 78px; }
  .contact-side { min-width: 95px; }
  .name-row { align-items: flex-start; }
  .inline-open { width: 100%; margin: 3px 0 0; }
  .single-primary { grid-template-columns: 1fr; }
  .contact-metrics-card { grid-template-columns: 1fr; }
}

/* Live Airtable integration */
.state-select:disabled,
.ai-mode-button:disabled,
.draft-editor[readonly],
.notes-editor[readonly] { cursor: default; opacity: .88; }
.state-select:disabled { appearance: none; padding-right: 11px; }
.ai-mode-button:disabled:hover { background: #f4faf7; border-color: #cfe2d7; }
.secondary-button:disabled,
.primary-button:disabled,
.telegram-button:disabled { cursor: not-allowed; opacity: .52; }
.history-readonly-note { margin: 10px 0 0; padding: 11px 13px; border: 1px dashed var(--border); background: #fafcfb; border-radius: 11px; display: grid; gap: 3px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.history-readonly-note strong { color: var(--text); font-size: 10px; }
.message-row.crm-latest { justify-content: stretch; }
.message-row.crm-latest .message-bubble-wrap { width: 100%; max-width: 100%; }
.message-row.crm-latest .message-bubble { background: #f7faf8; border: 1px solid var(--border); }

/* v17 — AI Mode write state */
.ai-mode-button:disabled { cursor: wait; }
.ai-mode-menu button:disabled { cursor: wait; opacity: .55; }

/* v26: compact AI Draft autosave controls */
.draft-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* v27 functional navigation views */
.activity-row { min-height: 112px; align-items: start; }
.activity-main { min-width: 0; }
.activity-reason { margin-top: 5px; color: var(--muted); font-size: 12.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.activity-meta { margin-top: 7px; color: #839088; font-size: 11.5px; font-weight: 600; }
.activity-side { align-items: flex-end; padding-top: 1px; }
@media (max-width: 760px) {
  .activity-row { min-height: 104px; }
  .activity-reason { -webkit-line-clamp: 3; }
}
/* v28 — simplified navigation and Contacts directory */
.workspace-grid.contacts-only-view { grid-template-columns: minmax(0, 1fr); }
.workspace-grid.contacts-only-view .contacts-panel { width: 100%; }
.workspace-grid.contacts-only-view .search-wrap { max-width: 320px; }
.workspace-grid.contacts-only-view .panel-header-actions { flex: 1; }
.directory-row {
  min-height: 58px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
  align-items: center;
  gap: 20px;
  background: white;
}
.directory-row:last-child { border-bottom: 0; }
.directory-row:hover { background: #fafcfb; }
.directory-name { font-size: 13px; font-weight: 700; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.directory-username { font-size: 12px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 620px) {
  .directory-row { grid-template-columns: 1fr; gap: 4px; align-content: center; min-height: 66px; }
  .workspace-grid.contacts-only-view .panel-header-actions { flex-direction: column-reverse; align-items: stretch; }
  .workspace-grid.contacts-only-view .export-contacts-button { width: 100%; }
}


/* Production authentication / security UI */
.auth-pending .app-shell { visibility: hidden; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.session-controls { display: flex; align-items: center; gap: 10px; }
.session-user { color: #6f8177; font-size: 12px; font-weight: 700; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-logout { border: 1px solid #d8e3dd; background: #fff; color: #2e4639; border-radius: 10px; padding: 8px 11px; font-size: 12px; font-weight: 750; cursor: pointer; }
.session-logout:hover { background: #f4f8f6; }
@media (max-width: 720px) { .session-user { display: none; } .session-logout { padding: 7px 9px; } }


/* v33 — compact local connector status */
.local-connector-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #d8e3dd;
  background: #fff;
  color: #465a50;
  border-radius: 10px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.local-connector-chip:hover { background: #f7faf8; }
.local-connector-chip:disabled { cursor: wait; opacity: .75; }
.local-connector-dot { width: 7px; height: 7px; border-radius: 999px; background: #9aa9a1; box-shadow: 0 0 0 3px rgba(154,169,161,.12); }
.local-connector-name { color: #33483d; }
.local-connector-state { color: #73827a; font-weight: 650; }
.local-connector-chip.is-connected .local-connector-dot { background: #2f9d69; box-shadow: 0 0 0 3px rgba(47,157,105,.12); }
.local-connector-chip.is-connected .local-connector-state { color: #2f7f5a; }
.local-connector-chip.is-offline .local-connector-dot { background: #d69a37; box-shadow: 0 0 0 3px rgba(214,154,55,.12); }
.local-connector-chip.is-offline .local-connector-state { color: #9a6a1d; }
.local-connector-chip.is-unpaired .local-connector-dot { background: #a26b5d; box-shadow: 0 0 0 3px rgba(162,107,93,.12); }
.local-connector-chip.is-unpaired .local-connector-state { color: #8d5a4d; }
@media (max-width: 860px) {
  .local-connector-name { display: none; }
}
@media (max-width: 620px) {
  .local-connector-chip { padding: 7px 9px; }
  .local-connector-state { display: none; }
}

/* v51 — dedicated Local PYRR pairing modal */
body.modal-open { overflow: hidden; }
.pairing-modal {
  position: relative;
  width: min(440px, 100%);
  padding: 30px;
  text-align: left;
  overflow: hidden;
}
.pairing-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #718178;
  font: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.pairing-close:hover { background: #f3f7f5; color: var(--text); }
.pairing-close:disabled { cursor: wait; opacity: .45; }
.pairing-icon {
  width: 52px;
  height: 52px;
  margin-bottom: 17px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--green-soft);
  border: 1px solid #d5eadf;
}
.pairing-icon span {
  width: 18px;
  height: 18px;
  border: 2px solid var(--green);
  border-radius: 6px;
  position: relative;
}
.pairing-icon span::before,
.pairing-icon span::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 2px;
  background: var(--green);
  top: 6px;
}
.pairing-icon span::before { left: -6px; }
.pairing-icon span::after { right: -6px; }
.pairing-modal .section-kicker { display: block; margin-bottom: 5px; }
.pairing-modal h2 { margin: 0 0 8px; font-size: 21px; color: var(--text); }
.pairing-modal > p:not(.pairing-security-note) { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.pairing-new-code-button {
  width: 100%;
  min-height: 42px;
  margin-top: 14px;
  padding: 10px 13px;
  border: 1px solid #cfe5d9;
  border-radius: 11px;
  background: #f3faf6;
  color: var(--green);
  font: inherit;
  font-size: 11.5px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.pairing-new-code-button:hover { background: #eaf6ef; border-color: #b9d9c7; color: #0d653d; }
.pairing-new-code-button:disabled { cursor: wait; opacity: .55; }
.pairing-field { display: grid; gap: 7px; margin-top: 22px; }
.pairing-field > span { color: #55685e; font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.pairing-code-input {
  width: 100%;
  height: 54px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #fbfcfb;
  padding: 0 16px;
  color: var(--text);
  font: inherit;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: .24em;
  text-align: center;
  outline: none;
}
.pairing-code-input::placeholder { color: #c2ccc7; }
.pairing-code-input:focus { border-color: #86c3a3; box-shadow: 0 0 0 3px rgba(18,122,75,.09); background: #fff; }
.pairing-code-input:disabled { opacity: .7; }
.pairing-error {
  margin-top: 10px;
  border: 1px solid #edd8d2;
  background: #fdf7f5;
  color: #925746;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 11px;
  line-height: 1.45;
}
.pairing-actions { margin-top: 18px; }
.pairing-actions .secondary-button,
.pairing-actions .primary-button { min-width: 112px; }
.pairing-security-note {
  margin: 18px 0 0 !important;
  padding-top: 15px;
  border-top: 1px solid var(--border);
  color: #7a8981 !important;
  font-size: 10.5px !important;
  line-height: 1.5 !important;
}
.pairing-modal.pairing-success .pairing-icon { background: #eef9f3; border-color: #cce8d8; }
.pairing-modal.pairing-success .pairing-code-input { border-color: #a9d6bd; background: #f7fcf9; }
.pairing-modal.pairing-success #confirmPairingBtn { background: #176f49; }
@media (max-width: 520px) {
  .pairing-modal { padding: 24px 20px 22px; }
  .pairing-code-input { font-size: 20px; letter-spacing: .18em; }
  .pairing-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .pairing-actions .secondary-button, .pairing-actions .primary-button { width: 100%; min-width: 0; }
}
/* v55 — Dashboard Status + AI Action filters */
@media (max-width: 520px) {
  .contact-toolbar { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  .contact-toolbar .group-toggle { grid-column: 1 / -1; width: 100%; }
}

/* PYRR v63 — channel badges */
.channel-tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  vertical-align: 1px;
}
.channel-instagram { background: rgba(255,255,255,.055); }
.channel-telegram { background: rgba(255,255,255,.035); }
.instagram-reply-card .draft-editor { margin-top: 8px; }
