/* Hub Panel UI — Ocean Breeze v2 (contrast-fixed, dark-parity, mobile-first) */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap');

/* ─── Design tokens — light (WCAG AA verified) ───────────────────── */
:root {
  /* Neutral surfaces */
  --bg:          #f0f8ff;
  --surface:     #ffffff;
  --surface2:    #f3f4f6;
  --surface3:    #e5e7eb;
  --border:      #e5e7eb;
  --border-strong: #d1d5db;
  --border-mid:  #d1d5db;   /* legacy alias */

  /* Text — two accessible tiers */
  --text:  #1f2937;   /* 14.7:1 on white */
  --text2: #6b7280;   /* 4.83:1 */
  --text3: #6b7280;   /* legacy alias → kept AA-safe */

  /* Accent (action) — single brand green #22c55e across both themes (Ocean Breeze) */
  --accent:        #22c55e;
  --accent-solid:  #15803d;   /* btn bg, white text = 4.6:1 — kept dark for text contrast, do not unify */
  --accent-hover:  #166534;
  --accent-subtle: #dcfce7;
  --accent-ink:    #ffffff;
  --accent-dot:    #22c55e;

  /* Semantic */
  --success:        #15803d;  --success-subtle: #dcfce7;
  --danger:         #b91c1c;  --danger-solid:   #dc2626;  --danger-subtle:  #fef2f2;
  --warning:        #c2410c;  --warning-subtle: #fff7ed;
  --info:           #0369a1;  --info-subtle:    #e0f2fe;

  /* Brand differentiation */
  --brand-veb: #FFCE00;  --brand-veb-ink: #1f2937;  --brand-veb-subtle: #fff9db;
  --brand-lpg: #23959d;  --brand-lpg-ink: #1c7a81;  --brand-lpg-subtle: #e6f6f7;

  /* Channels */
  --ch-vk: #0077FF;  --ch-tg: #26A5E4;  --ch-mail: #F59E0B;  --ch-max: #7C3AED;

  /* Topbar */
  --topbar-bg:  #0e2a3d;
  --sb-bg:      #0e2a3d;
  --sb-border:  rgba(255,255,255,0.10);
  --sb-text:    #a9cddd;
  --sb-active:  rgba(34,197,94,0.20);
  --sb-hover:   rgba(255,255,255,0.08);

  /* Conversations / messages */
  --conv-hover:  #f3f4f6;
  --conv-active: #dcfce7;
  --unread-dot:  #22c55e;
  --unread-badge-text: #ffffff; /* white text on green badge (light theme) */
  --msg-in:      #e0f2fe;
  --msg-out:     #d1fae5;

  /* Shape + motion */
  --r-xs: 4px;
  --r-sm: 6px;
  --r:    8px;
  --r-lg: 12px;
  --shadow-xs: 0 1px 2px rgba(15,23,42,0.06);
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.06);
  --shadow-card: 0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.06);
  --shadow-pop: 0 8px 28px rgba(15,23,42,0.14);
  --t: 140ms ease;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
}

/* ─── Design tokens — dark (neutral slate, full parity) ──────────── */
[data-theme="dark"] {
  --bg:          #0f172a;
  --surface:     #1e293b;
  --surface2:    #19212e;
  --surface3:    #24324a;
  --border:      #334155;
  --border-strong: #64748b;
  --border-mid:  #64748b;

  --text:  #e2e8f0;   /* 14.5:1 */
  --text2: #94a3b8;   /* 5.71:1 on card */
  --text3: #94a3b8;

  --accent:        #22c55e;   /* unified brand green — same as light theme */
  --accent-solid:  #34d399;   /* btn bg + dark ink = AA — kept as-is for text contrast, do not unify */
  --accent-hover:  #6ee7b7;
  --accent-subtle: #064e3b;
  --accent-ink:    #0f172a;   /* dark ink on light-green button */
  --accent-dot:    #22c55e;   /* unified brand green — logo, active nav underline */

  --success:        #34d399;  --success-subtle: #064e3b;
  --danger:         #f87171;  --danger-solid:   #dc2626;  --danger-subtle:  #450a0a;
  --warning:        #fb923c;  --warning-subtle: #431407;
  --info:           #38bdf8;  --info-subtle:    #0c2a3d;

  --brand-veb: #FFCE00;  --brand-veb-ink: #1f2937;  --brand-veb-subtle: #3a2f05;
  --brand-lpg: #2dd4d4;  --brand-lpg-ink: #2dd4d4;  --brand-lpg-subtle: #0d2e30;

  --ch-vk: #3b9dff;  --ch-tg: #4db8ea;  --ch-mail: #fbbf24;  --ch-max: #a78bfa;

  --topbar-bg:  #1e293b;
  --sb-bg:      #1e293b;
  --sb-border:  #334155;
  --sb-text:    #94a3b8;
  --sb-active:  rgba(34,197,94,0.16);
  --sb-hover:   rgba(255,255,255,0.06);

  --conv-hover:  #24324a;
  --conv-active: #064e3b;
  --unread-dot:  #22c55e;
  --unread-badge-text: #0f172a; /* dark text on lighter-green badge (dark theme) — unchanged */
  --msg-in:      #0e2745;
  --msg-out:     #06341f;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-pop: 0 8px 28px rgba(0,0,0,0.55);
}

/* ─── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  height: 100%;
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
pre { white-space: pre-wrap; word-break: break-all; font-family: var(--font-mono); font-size: 12px; }
button, input, textarea, select { font-family: var(--font); }
.bx { line-height: 1; vertical-align: -0.06em; }

/* ─── Layout ─────────────────────────────────────────────────────── */
.panel-body {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ─── Top navigation bar ─────────────────────────────────────────── */
.topbar {
  min-height: 48px;
  flex-shrink: 0;
  background: var(--sb-bg);
  border-bottom: 1px solid var(--sb-border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 6px;
  z-index: 50;
  padding-top: env(safe-area-inset-top);
}

.logo {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-dot);
  letter-spacing: -0.01em;
  margin-right: 8px;
  white-space: nowrap;
}

.topbar-nav { display: flex; align-items: center; gap: 2px; flex: 1; }

.topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  min-height: 34px;
  border-radius: var(--r-sm);
  color: var(--sb-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t), color var(--t);
  white-space: nowrap;
  text-decoration: none;
}
.topbar-link .bx { font-size: 16px; }
.topbar-link:hover { background: var(--sb-hover); color: #fff; text-decoration: none; }
.topbar-link-active {
  background: var(--sb-active);
  color: var(--accent-dot);
  box-shadow: inset 0 -2px 0 var(--accent-dot);
}

.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }

.topbar-user {
  font-size: 12.5px;
  color: rgba(255,255,255,0.72);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
[data-theme="dark"] .topbar-user { color: var(--text2); }

.topbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sb-text);
  padding: 7px 9px;
  min-height: 34px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background var(--t), color var(--t);
  white-space: nowrap;
}
.topbar-btn .bx { font-size: 16px; }
.topbar-btn:hover { background: var(--sb-hover); color: #fff; }
[data-theme="dark"] .topbar-btn:hover { color: var(--text); }
.topbar-logout { border: 1px solid rgba(255,255,255,0.14); }
[data-theme="dark"] .topbar-logout { border-color: var(--border); }
.topbar-logout:hover {
  background: rgba(220,38,38,0.22);
  border-color: rgba(220,38,38,0.4);
  color: #fca5a5;
}

/* ─── Content grid ───────────────────────────────────────────────── */
.panel-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.panel-layout.cc-open { grid-template-columns: 360px 1fr 300px; }

/* ─── Conversation list ──────────────────────────────────────────── */
.conv-list-wrap {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.conv-list-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.search-form { display: flex; }

.search-input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color var(--t), box-shadow var(--t);
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.20);
}
.search-input::placeholder { color: var(--text2); opacity: 0.85; }

#conv-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Conversation items */
.conv-item {
  padding: 10px 12px 10px 13px;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background var(--t);
  position: relative;
}
.conv-item:hover { background: var(--conv-hover); }

/* Brand differentiation — 3px left stripe (neutral text label stays --text2) */
.conv-item.brand-lightpromgroup { border-left-color: var(--brand-lpg); }
.conv-item.brand-these-guys     { border-left-color: var(--brand-veb); }

/* Active — background + accent stripe; MUST win over hover & attention.
   Declared last for equal-specificity cascade correctness. */
.conv-item.conv-active,
.conv-item.conv-active:hover {
  background: var(--conv-active);
}
.conv-item.conv-active { border-left-color: var(--accent); }

.conv-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 3px;
  font-size: 11px;
  color: var(--text2);
  line-height: 1.3;
}

.conv-brand { color: var(--text2); font-weight: 500; }

.conv-contact {
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 2px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}

.conv-preview {
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: var(--text2);
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Attention — badge icon only (no full-row fill), sits by the time */
.attention-icon { color: var(--warning); font-size: 15px; line-height: 1; }

.unread-badge {
  background: var(--unread-dot);
  color: var(--unread-badge-text);
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.unread-badge.hidden { display: none; }
.lock-icon { font-size: 13px; color: var(--warning); }
.outbound-mark { color: var(--text2); }

.load-more, .conv-empty {
  padding: 14px 12px;
  text-align: center;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  transition: background var(--t);
}
.load-more:hover { background: var(--conv-hover); }
.conv-empty { cursor: default; }
.conv-empty .hint { color: var(--text2); font-size: 12px; margin-top: 4px; }

.loading { padding: 28px 12px; text-align: center; color: var(--text2); font-size: 13px; }

/* ─── Dialog view ────────────────────────────────────────────────── */
.dialog-view {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.dialog-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text2);
  gap: 8px;
  font-size: 14px;
  user-select: none;
  padding: 24px;
  text-align: center;
}
.dialog-empty .bx { font-size: 40px; opacity: 0.5; }

.dialog-header {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--surface);
  min-height: 48px;
  gap: 8px;
}

/* Mobile back button (master-detail) */
.btn-dialog-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: -6px;
  border: none;
  background: none;
  color: var(--text2);
  cursor: pointer;
  border-radius: var(--r-sm);
  font-size: 24px;
  flex-shrink: 0;
}
.btn-dialog-back:hover { background: var(--surface2); color: var(--text); }

.dialog-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 600;
  flex-wrap: wrap;
  min-width: 0;
  flex: 1;
}

.source-link { font-size: 12px; font-weight: 500; white-space: nowrap; color: var(--text2); display: inline-flex; align-items: center; gap: 3px; }
.source-link:hover { color: var(--accent); }

.dialog-body { display: flex; flex-direction: column; overflow: hidden; flex: 1; }

.messages-wrap {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ─── Messages ───────────────────────────────────────────────────── */
.msg { max-width: 78%; padding: 8px 12px; border-radius: var(--r-lg); }
.msg-inbound  { align-self: flex-start; background: var(--msg-in);  border-bottom-left-radius: var(--r-xs); }
.msg-outbound { align-self: flex-end;   background: var(--msg-out); border-bottom-right-radius: var(--r-xs); }
[data-theme="dark"] .msg { color: var(--text); }

/* День-разделитель между группами сообщений разных дней */
.day-sep {
  display: flex; align-items: center; justify-content: center;
  margin: 14px 0 6px; text-align: center;
}
.day-sep span {
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  color: var(--text2);
}

.msg-header { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; font-size: 11px; color: var(--text2); }
.msg-sender { font-weight: 600; color: var(--text2); }
.msg-time { font-variant-numeric: tabular-nums; }
.msg-link { font-size: 13px; display: inline-flex; }
.msg-subject { font-size: 11.5px; font-weight: 600; margin-bottom: 3px; color: var(--text2); }
.msg-text { font-size: 13px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; color: var(--text); }
/* Кликабельная ссылка внутри текста сообщения (контраст-паритет light/dark через --accent-solid) */
.msg-inline-link { color: var(--accent-solid); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; font-weight: 500; }
.msg-inline-link:hover { text-decoration: none; }

/* Превью-карточка ссылки (VK / Telegram / MAX) — компактная, в стиле мессенджеров.
   Использует токены дизайн-системы: --surface / --border / --accent / --r. */
.msg-linkcard {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-top: 6px;
  padding: 8px 10px;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r);
  text-decoration: none;
  color: var(--text);
  transition: border-color var(--t), box-shadow var(--t);
}
.msg-linkcard:hover { border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.msg-linkcard-img {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  border-radius: var(--r-sm);
  object-fit: cover;
  background: var(--surface2);
}
.msg-linkcard-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; justify-content: center; }
.msg-linkcard-domain {
  font-size: 10.5px; color: var(--text2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-linkcard-title {
  font-size: 12.5px; font-weight: 600; line-height: 1.3; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.msg-linkcard:hover .msg-linkcard-title { color: var(--accent-hover); }
.msg-linkcard-desc {
  font-size: 11.5px; line-height: 1.35; color: var(--text2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.msg-attachments { margin-top: 6px; font-size: 12px; display: flex; flex-direction: column; gap: 5px; }

/* Inline photo previews */
.msg-photo-link { display: inline-block; line-height: 0; }
.msg-photo {
  display: block;
  max-width: 100%;
  max-height: 220px;
  width: auto;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: var(--surface2);
}

.att-link { color: var(--accent); text-decoration: none; display: inline-flex; align-items: baseline; gap: 5px; }
.att-nolink { color: var(--text2); display: inline-flex; align-items: baseline; gap: 5px; }
.att-link .bx, .att-nolink .bx { font-size: 15px; text-decoration: none; align-self: center; }
.att-icon { flex: none; text-decoration: none; }
/* Подчёркивается при наведении только текст (имя + вес), не иконка */
.att-name { text-decoration: none; }
.att-link:hover .att-name { text-decoration: underline; }

/* Inline video previews */
.msg-video-link { display: inline-block; line-height: 0; }
.msg-video-frame {
  position: relative;
  display: inline-block;
  line-height: 0;
  border-radius: var(--r-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface2);
}
.msg-video-poster { display: block; max-width: 100%; max-height: 220px; width: auto; }
.msg-video-poster--empty {
  display: flex; align-items: center; justify-content: center;
  width: 240px; height: 135px; color: var(--text2);
}
.msg-video-poster--empty .bx { font-size: 44px; line-height: 1; }
.msg-video-play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,.05), rgba(0,0,0,.3));
  transition: background var(--t);
}
.msg-video-play .bx { font-size: 52px; line-height: 1; filter: drop-shadow(0 1px 4px rgba(0,0,0,.5)); }
.msg-video-link:hover .msg-video-play { background: linear-gradient(180deg, rgba(0,0,0,.1), rgba(0,0,0,.45)); }
.msg-video-dur {
  position: absolute; right: 6px; bottom: 6px;
  padding: 1px 6px; border-radius: 999px;
  background: rgba(0,0,0,.7); color: #fff;
  font-size: 11px; line-height: 1.5; font-variant-numeric: tabular-nums;
}
.attachment-voice .voice-player { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.voice-label { font-size: 12px; color: var(--text2); white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.msg-audio { height: 34px; max-width: 260px; }
.voice-transcript { font-size: 12px; color: var(--text2); margin-top: 3px; font-style: italic; }

.load-more-msgs { text-align: center; padding: 8px; color: var(--text2); cursor: pointer; font-size: 12px; transition: color var(--t); }
.load-more-msgs:hover { color: var(--accent); }
.no-messages, .no-more-msgs { text-align: center; padding: 16px; color: var(--text2); font-size: 12px; }

/* ─── AI Draft block ─────────────────────────────────────────────── */
.draft-block {
  margin: 0 16px 10px;
  padding: 12px;
  background: var(--warning-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  flex-shrink: 0;
}
.draft-header { display: flex; align-items: center; gap: 6px; margin-bottom: 7px; font-size: 12px; font-weight: 600; color: var(--text2); }
.draft-text { font-size: 13px; color: var(--text); margin-bottom: 8px; padding: 7px 9px; background: var(--surface); border-radius: var(--r-sm); line-height: 1.5; }
.draft-actions { display: flex; gap: 6px; }
.escalation-reason { font-size: 11px; color: var(--warning); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Reply form ─────────────────────────────────────────────────── */
.reply-form {
  position: relative;
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

.reply-textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  resize: vertical;
  min-height: 62px;
  line-height: 1.5;
  transition: border-color var(--t), box-shadow var(--t);
}
.reply-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34,197,94,0.16); }
.reply-textarea::placeholder { color: var(--text2); opacity: 0.85; }

.reply-toolbar { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; gap: 8px; min-width: 0; }
.reply-status { font-size: 12px; min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Attachment chips */
.attach-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; min-height: 0; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 6px 3px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 11.5px; color: var(--text2); max-width: 200px;
}
.attach-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.attach-chip-remove { background: none; border: none; cursor: pointer; color: var(--text2); padding: 1px 2px; border-radius: 4px; line-height: 1; font-size: 14px; flex-shrink: 0; display: inline-flex; }
.attach-chip-remove:hover { color: var(--danger); }

.reply-toolbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* Shared compact icon buttons in the reply toolbar (paperclip, emoji) */
.reply-tool-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: none; background: none;
  border-radius: var(--r-sm);
  color: var(--text2); cursor: pointer;
  transition: background var(--t), color var(--t);
  flex-shrink: 0; font-size: 20px;
}
.reply-tool-btn:hover { background: var(--surface2); color: var(--accent); }
.reply-tool-btn.is-active { background: var(--accent-subtle); color: var(--accent); }

/* Compact round send button (arrow, no text) */
.btn-send {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: none; cursor: pointer;
  border-radius: 50%;
  background: var(--accent-solid); color: var(--accent-ink);
  font-size: 24px; line-height: 1;
  flex-shrink: 0;
  transition: background var(--t), transform var(--t);
}
.btn-send:hover { background: var(--accent-hover); }
[data-theme="dark"] .btn-send:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn-send:active { transform: translateY(1px) scale(0.96); }
.btn-send:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── Emoji picker popover ───────────────────────────────────────── */
.emoji-pop {
  position: absolute;
  bottom: 100%;
  right: 12px;
  margin-bottom: 8px;
  width: 320px;
  max-width: calc(100% - 24px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: emojiPopIn 140ms ease;
}
@keyframes emojiPopIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) { .emoji-pop { animation: none; } }

.emoji-pop-search { padding: 8px 8px 4px; }
.emoji-pop-search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
}
.emoji-pop-search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34,197,94,0.16); }
.emoji-pop-search-input::placeholder { color: var(--text2); opacity: 0.85; }

.emoji-pop-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 1px;
  padding: 4px 6px;
  max-height: 224px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.emoji-pop-grid:empty::after {
  content: 'Ничего не найдено';
  grid-column: 1 / -1;
  padding: 20px 8px;
  text-align: center;
  color: var(--text2);
  font-size: 12.5px;
}
.emoji-pop-item {
  border: none; background: none; cursor: pointer;
  font-size: 22px; line-height: 1;
  aspect-ratio: 1 / 1;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t);
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.emoji-pop-item:hover { background: var(--surface2); }

.emoji-pop-tabs {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}
.emoji-pop-tab {
  flex: 1;
  border: none; background: none; cursor: pointer;
  padding: 7px 0 8px;
  font-size: 18px; line-height: 1;
  opacity: 0.55;
  border-top: 2px solid transparent;
  transition: opacity var(--t), background var(--t), border-color var(--t);
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.emoji-pop-tab:hover { opacity: 0.9; background: var(--surface3); }
.emoji-pop-tab.is-active { opacity: 1; background: var(--surface); border-top-color: var(--accent); }

.reply-success { color: var(--success); }
.reply-error   { color: var(--danger);  }
.reply-blocked { color: var(--warning); }

.reply-disabled-block { padding: 12px 16px; background: var(--surface2); border-top: 1px solid var(--border); font-size: 12px; color: var(--text2); flex-shrink: 0; }

/* ─── Customer card panel ────────────────────────────────────────── */
.customer-card-panel {
  border-left: 1px solid var(--border);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface);
  display: none;
  flex-direction: column;
  font-size: 12.5px;
}
.panel-layout.cc-open .customer-card-panel { display: flex; }

.btn-card-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text2); width: 38px; height: 38px;
  border-radius: var(--r-sm);
  transition: background var(--t), color var(--t);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 19px;
}
.btn-card-toggle:hover { background: var(--surface2); color: var(--text); }
.panel-layout.cc-open .btn-card-toggle { color: var(--accent); background: var(--accent-subtle); }

.dialog-header-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.customer-card-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text2); font-size: 13px; }

.contact-card-header { padding: 12px 16px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.contact-card-header h2 { font-size: 14px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.contact-card-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; flex: 1; }

.cc-section-title { font-size: 10px; font-weight: 700; color: var(--text2); letter-spacing: 0.07em; text-transform: uppercase; margin-bottom: 6px; }
.cc-table { display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; line-height: 1.4; }
.cc-table dt { color: var(--text2); white-space: nowrap; }
.cc-table dd { color: var(--text); word-break: break-word; }
.cc-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.cc-tag { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r-xs); padding: 2px 7px; font-size: 11px; color: var(--text2); }
.summary-text { color: var(--text2); font-style: italic; line-height: 1.5; }
.orders-list { list-style: none; }
.orders-list li { padding: 5px 0; border-bottom: 1px solid var(--border); }
.order-title { display: block; font-weight: 500; color: var(--text); }
.order-amount, .order-date, .order-status { font-size: 11px; color: var(--text2); margin-right: 4px; }

/* ─── Channel icons ──────────────────────────────────────────────── */
.ch-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  flex-shrink: 0; vertical-align: middle;
  padding: 4px;
}
.ch-icon img { width: 100%; height: 100%; display: block; }
.ch-icon-vk       { background: var(--ch-vk); }
.ch-icon-vk_captain_cmyk { background: var(--ch-vk); }
.ch-icon-telegram { background: var(--ch-tg); }
.ch-icon-mail     { background: var(--ch-mail); }
.ch-icon-max      { background: var(--ch-max); }

/* ─── Conversation filter bar ────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 4px;
  padding: 7px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  align-items: center;
  flex-wrap: nowrap; /* compact filters fit one row at typical ~360px column; narrow fallback re-enables wrap in @media ≤1000px */
}
/* display:contents dissolves the wrapper so its dropdowns become direct
   flex children of .filter-bar and wrap together with .btn-refresh */
.filter-scroll { display: contents; }
.filter-scroll .filter-dropdown { flex-shrink: 0; }

.filter-dropdown { position: relative; }

.filter-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 8px; min-height: 32px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text2);
  cursor: pointer;
  font-size: 12px; font-weight: 500; font-family: var(--font);
  transition: background var(--t), border-color var(--t), color var(--t);
  white-space: nowrap;
}
.filter-btn:hover { background: var(--surface2); border-color: var(--border-mid); color: var(--text); }
.filter-btn.filter-btn-active, .fd-open > .filter-btn {
  border-color: var(--accent); color: var(--accent); background: var(--accent-subtle);
}

.filter-caret { color: var(--text2); flex-shrink: 0; transition: transform var(--t); }
.fd-open > .filter-btn .filter-caret { transform: rotate(180deg); }

.filter-dropdown-menu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-pop);
  z-index: 200; padding: 4px;
}
.fd-open > .filter-dropdown-menu { display: block; }

.filter-opt {
  display: flex; align-items: center; gap: 7px; width: 100%;
  padding: 8px 9px; border: none; background: none; cursor: pointer;
  font-size: 12.5px; font-family: var(--font); color: var(--text);
  border-radius: var(--r-xs); text-align: left; transition: background var(--t);
}
.filter-opt:hover { background: var(--conv-hover); }
.filter-opt.filter-opt-active { color: var(--accent); font-weight: 600; }
.filter-opt-check { margin-left: auto; font-size: 12px; flex-shrink: 0; }
.filter-opt:not(.filter-opt-active) .filter-opt-check { display: none; }
.filter-opt .ch-icon { width: 18px; height: 18px; padding: 3px; flex-shrink: 0; }

/* Refresh button */
.btn-refresh { flex-shrink: 0; gap: 3px; }
.btn-refresh .bx { font-size: 14px; }
.btn-refresh.htmx-request .bx-refresh { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Live / timestamp row */
.refresh-ts-row {
  padding: 3px 12px;
  font-size: 11px; color: var(--text2);
  min-height: 20px; line-height: 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-dot); flex-shrink: 0; animation: livePulse 2s ease-in-out infinite; }
@keyframes livePulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
#last-refreshed:empty::before { content: '\00a0'; }

.refresh-status { padding: 4px 12px; font-size: 11.5px; flex-shrink: 0; border-bottom: 1px solid transparent; }
.refresh-status:not(:empty) { border-bottom-color: var(--border); }

.mailbox-addr { font-family: var(--font-mono); font-size: 11.5px; color: var(--text2); }

/* Mail: full mailbox address as plain text (no chip/pill), replaces brand label for mail rows */
.conv-mailbox {
  color: var(--text2); font-weight: 500;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dialog-mailbox { font-size: 11px; color: var(--text2); font-weight: 500; }

.btn-delete-conv {
  background: none; border: none; cursor: pointer;
  color: var(--text2); width: 38px; height: 38px;
  border-radius: var(--r-sm);
  transition: background var(--t), color var(--t);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 18px;
}
.btn-delete-conv:hover { background: var(--danger-subtle); color: var(--danger); }

/* ─── Filter reset bar ───────────────────────────────────────────── */
.filter-reset-bar { display: flex; align-items: center; gap: 5px; padding: 5px 12px; background: var(--accent-subtle); border-bottom: 1px solid var(--border); flex-wrap: wrap; flex-shrink: 0; }
.filter-chip { background: var(--accent-solid); color: var(--accent-ink); font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: var(--r-xs); text-transform: uppercase; letter-spacing: 0.04em; }
.btn-filter-reset { margin-left: auto; font-size: 11px; color: var(--accent); background: none; border: none; cursor: pointer; font-family: var(--font); padding: 2px 5px; border-radius: var(--r-xs); transition: background var(--t); font-weight: 500; }
.btn-filter-reset:hover { background: rgba(34,197,94,0.12); }

/* ─── Badges ─────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: var(--r-xs); font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; }
.badge-admin   { background: var(--accent-subtle); color: var(--accent); }
.badge-manager { background: var(--info-subtle); color: var(--info); }

.badge-channel-vk       { background: var(--info-subtle);   color: var(--info);    padding: 1px 6px; border-radius: var(--r-xs); font-size: 10.5px; font-weight: 700; }
.badge-channel-vk_captain_cmyk { background: var(--info-subtle); color: var(--info); padding: 1px 6px; border-radius: var(--r-xs); font-size: 10.5px; font-weight: 700; }
.badge-channel-telegram { background: var(--info-subtle);   color: var(--info);    padding: 1px 6px; border-radius: var(--r-xs); font-size: 10.5px; font-weight: 700; }
.badge-channel-mail     { background: var(--warning-subtle);color: var(--warning); padding: 1px 6px; border-radius: var(--r-xs); font-size: 10.5px; font-weight: 700; }
.badge-channel-max      { background: var(--accent-subtle); color: var(--accent);  padding: 1px 6px; border-radius: var(--r-xs); font-size: 10.5px; font-weight: 700; }

/* VK-source labels (только бренд «Вот Эти Ребята»): сообщество vs личный профиль captain_cmyk.
   Два цвета — чтобы источник читался с одного взгляда в списке и в шапке диалога. */
.conv-vk-src, .badge-vk-src {
  padding: 1px 6px;
  border-radius: var(--r-xs);
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}
.conv-vk-src   { font-size: 10px; }
.badge-vk-src  { font-size: 10.5px; }
.conv-vk-src-community,
.badge-vk-src-community { background: var(--info-subtle);    color: var(--info); }
.conv-vk-src-personal,
.badge-vk-src-personal  { background: var(--warning-subtle); color: var(--warning); }

.brand-tag { font-size: 11px; color: var(--text2); font-weight: 500; }

.lock-badge { font-size: 11px; padding: 2px 7px; border-radius: var(--r-xs); background: var(--warning-subtle); color: var(--warning); display: inline-flex; align-items: center; gap: 4px; }
.lock-open  { background: var(--success-subtle); color: var(--success); }
.lock-claim { background: var(--warning-subtle); color: var(--warning); }

.priority-high   { background: var(--danger-subtle);  color: var(--danger);  border-radius: var(--r-xs); padding: 2px 6px; font-size: 10.5px; font-weight: 600; }
.priority-medium { background: var(--warning-subtle); color: var(--warning); border-radius: var(--r-xs); padding: 2px 6px; font-size: 10.5px; font-weight: 600; }
.priority-low    { background: var(--surface2); color: var(--text2); border-radius: var(--r-xs); padding: 2px 6px; font-size: 10.5px; font-weight: 600; }

.status-badge { font-size: 10.5px; padding: 2px 7px; border-radius: var(--r-xs); font-weight: 600; }
.status-ok      { background: var(--success-subtle); color: var(--success); }
.status-error   { background: var(--danger-subtle);  color: var(--danger);  }
.status-running { background: var(--accent-subtle);  color: var(--accent);  }

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; min-height: 36px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px; font-weight: 600; font-family: var(--font);
  text-decoration: none; white-space: nowrap;
  transition: background var(--t), color var(--t), border-color var(--t), transform var(--t);
}
.btn .bx { font-size: 16px; }
.btn:hover  { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent-solid); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
[data-theme="dark"] .btn-primary:hover { background: var(--accent-hover); color: var(--accent-ink); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface2); border-color: var(--border-mid); }

/* Reconnect = routine action → accent, not danger */
.btn-reconnect { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn-reconnect:hover { background: var(--accent-subtle); }

.btn-danger  { background: var(--danger-solid);  color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: #fff; }

.btn-full { width: 100%; }
.btn-sm   { padding: 6px 11px; min-height: 32px; font-size: 12px; }

.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; font-family: var(--font); transition: opacity var(--t); }
.btn-link:hover { text-decoration: underline; }

.btn-icon { background: none; border: none; cursor: pointer; font-size: 18px; color: var(--sb-text); width: 34px; height: 34px; border-radius: var(--r-sm); transition: background var(--t), color var(--t); display: inline-flex; align-items: center; justify-content: center; }
.btn-icon:hover { background: var(--sb-hover); color: #fff; }
.theme-toggle { opacity: 0.8; }
.theme-toggle:hover { opacity: 1; }

/* ─── Forms ──────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text2); }

.form-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 13px; font-family: var(--font);
  transition: border-color var(--t), box-shadow var(--t);
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34,197,94,0.20); }
.form-input::placeholder { color: var(--text2); opacity: 0.85; }
.form-input-sm { width: 140px; padding: 5px 8px; font-size: 12px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }

/* ─── Tables ─────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { background: var(--surface2); padding: 9px 12px; text-align: left; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text2); border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text); }
.data-table tr:hover td { background: var(--conv-hover); }
.data-table-sm td, .data-table-sm th { padding: 7px 10px; }
.row-inactive { opacity: 0.5; }
.nowrap { white-space: nowrap; }
.ip-cell { font-size: 11px; color: var(--text2); font-variant-numeric: tabular-nums; }
.text-center { text-align: center; }
.data-table code { font-family: var(--font-mono); font-size: 12px; background: var(--surface2); padding: 1px 5px; border-radius: var(--r-xs); }
.data-table details summary { cursor: pointer; color: var(--accent); font-size: 12px; }
.data-table details pre { margin-top: 4px; background: var(--surface2); padding: 6px 8px; border-radius: var(--r-xs); font-size: 11px; }

.user-actions-cell .btn { margin: 1px 0; }

/* ─── Channels ───────────────────────────────────────────────────── */
.channels-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; padding: 16px; }
.channel-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow-card); transition: box-shadow var(--t), border-color var(--t); }
.channel-card:hover { box-shadow: var(--shadow-sm); border-color: var(--border-mid); }
.channel-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; font-weight: 600; color: var(--text); flex-wrap: wrap; }
.channel-enabled { margin-left: auto; font-size: 17px; display: inline-flex; }
.channel-enabled.enabled { color: var(--success); }
.channel-enabled.disabled { color: var(--danger); }
.channel-stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 12px; margin-bottom: 12px; }
.channel-stats dt { color: var(--text2); }
.channel-stats dd { color: var(--text); }
.channel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.check-result-wrap { margin-top: 8px; font-size: 12px; }
.check-result.ok  pre { color: var(--success); }
.check-result.error pre { color: var(--danger); }
.error-text { color: var(--danger); word-break: break-all; }

/* ─── Mail signature editor ──────────────────────────────────────── */
.mail-signature { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.mail-sig-head { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.mail-sig-head .bx { font-size: 14px; color: var(--ch-mail); }
.mail-sig-hint-inline { font-weight: 400; font-size: 11px; color: var(--text2); opacity: 0.85; }
.sig-textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
.sig-textarea:disabled { opacity: 0.6; cursor: progress; }
.sig-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 5px; flex-wrap: wrap; }
.sig-source { font-size: 11px; display: inline-flex; align-items: center; gap: 4px; }
.sig-source::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }
.sig-source-db { color: var(--success); }
.sig-source-yaml { color: var(--text2); }
.sig-counter { font-size: 11px; color: var(--text2); font-family: var(--font-mono); }
.sig-counter-warn { color: var(--warning); }
.sig-counter-over { color: var(--danger); font-weight: 600; }
.sig-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.sig-status { font-size: 12px; }
.sig-status-ok  { color: var(--success); }
.sig-status-err { color: var(--danger); }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* ─── Page layout ────────────────────────────────────────────────── */
.page-wrap { max-width: 1100px; margin: 0 auto; padding: 24px; }
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header h1 { font-size: 20px; font-weight: 600; flex: 1; letter-spacing: -0.01em; color: var(--text); }
.user-badge { font-size: 12px; color: var(--text2); }

.create-user-form { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.create-user-form h2 { font-size: 15px; font-weight: 600; margin-bottom: 14px; color: var(--text); }

/* Admin/channels loaded via HTMX into #dialog-view: allow full-width scroll */
.dialog-view > .page-wrap, .dialog-view > .channels-grid { overflow-y: auto; -webkit-overflow-scrolling: touch; height: 100%; max-width: none; box-sizing: border-box; width: 100%; }

/* ─── Login ──────────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100dvh; background: var(--bg); padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 36px 32px; width: 100%; max-width: 360px; box-shadow: var(--shadow-card); }
.login-box h1 { font-size: 20px; font-weight: 700; margin-bottom: 26px; text-align: center; letter-spacing: -0.01em; color: var(--text); }

/* ─── Alerts ─────────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--r-sm); margin-bottom: 14px; font-size: 13px; line-height: 1.4; }
.alert-error   { background: var(--danger-subtle);  color: var(--danger);  border: 1px solid rgba(220,38,38,0.20); }
.alert-success { background: var(--success-subtle); color: var(--success); border: 1px solid rgba(21,128,61,0.20); }

.reauth-hint    { color: var(--text2); font-size: 13px; line-height: 1.5; padding: 10px 12px; background: var(--info-subtle); border-radius: var(--r-sm); margin: 8px 0 16px; }
.reauth-hint a  { color: var(--info); font-weight: 600; }
.reauth-hint code { background: var(--surface3); padding: 1px 5px; border-radius: var(--r-xs); font-size: 12px; }
.reauth-error   { color: var(--danger);  padding: 10px 12px; background: var(--danger-subtle);  border-radius: var(--r-sm); margin: 8px 0; }
.reauth-success { color: var(--success); padding: 10px 12px; background: var(--success-subtle); border-radius: var(--r-sm); margin: 8px 0; }
.max-auth-raw   { color: var(--text2); font-size: 11px; line-height: 1.45; margin: 4px 0 8px; word-break: break-word; }
.reauth-not-implemented { color: var(--warning); padding: 12px 14px; background: var(--warning-subtle); border-radius: var(--r-sm); }

/* ─── Reauth ─────────────────────────────────────────────────────── */
.reauth-container { max-width: 480px; }
.reauth-container h2 { font-size: 16px; font-weight: 600; margin-bottom: 14px; color: var(--text); }
.reauth-container p { margin-bottom: 12px; color: var(--text2); }
.mailbox-reauth { margin-bottom: 24px; padding: 16px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.mailbox-reauth h3 { font-size: 13.5px; font-weight: 600; margin-bottom: 12px; color: var(--text); }

/* ─── Reduced motion ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .panel-layout { grid-template-columns: 340px 1fr; }
  .panel-layout.cc-open { grid-template-columns: 340px 1fr 260px; }
}

@media (max-width: 1000px) {
  .panel-layout { grid-template-columns: 300px 1fr; }
  .panel-layout.cc-open { grid-template-columns: 300px 1fr; }
  .customer-card-panel { display: none !important; }
  .btn-card-toggle { display: none; }
  .topbar-user { display: none; }
  /* narrow 300px column: graceful wrap fallback so nothing clips/overflows.
     Mobile (≤768px, full-width single column) still fits one row + round refresh. */
  .filter-bar { flex-wrap: wrap; }
}

/* Mobile master-detail (≤768px per brief v2 §4.1) */
@media (max-width: 768px) {
  .panel-layout, .panel-layout.cc-open { grid-template-columns: 1fr; }
  .dialog-view { display: none; }
  .panel-layout.show-dialog .conv-list-wrap { display: none; }
  .panel-layout.show-dialog .dialog-view { display: flex; }
  .btn-dialog-back { display: inline-flex; }
  .nav-label { display: none; }

  /* Filter bar wraps as one group (base rule); refresh becomes compact round icon */
  .btn-refresh { width: 44px; height: 44px; min-height: 44px; padding: 0; justify-content: center; border-radius: 50%; }
  .btn-refresh .nav-label, .btn-refresh .btn-refresh-label { display: none; }
  .btn-refresh .bx { font-size: 18px; }

  /* iOS: ≥16px avoids focus auto-zoom */
  .reply-textarea, .form-input, .search-input { font-size: 16px; }
  .reply-textarea { resize: none; }

  /* Reply toolbar: larger touch targets, popover spans the input width */
  .reply-tool-btn { width: 42px; height: 42px; }
  .btn-send { width: 42px; height: 42px; }
  .emoji-pop-search-input { font-size: 16px; }
  .emoji-pop { left: 12px; right: 12px; width: auto; max-width: none; }

  /* Touch targets */
  .filter-btn { min-height: 40px; }
  .channel-actions .btn { flex: 1; }

  /* Admin tables → cards */
  .data-table, .data-table thead, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table thead { display: none; }
  .data-table tr { margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--r-lg); padding: 10px 12px; background: var(--surface); box-shadow: var(--shadow-card); }
  .data-table td { border: none; padding: 5px 0; display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
  .data-table td::before { content: attr(data-label); font-weight: 600; color: var(--text2); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0; }
  .data-table td:empty { display: none; }
  .data-table td[data-label=""]::before, .user-actions-cell::before { content: ""; }
  .user-actions-cell { flex-direction: column; align-items: stretch; }
  .user-actions-cell > div { flex-direction: column !important; align-items: stretch !important; }
  .user-actions-cell .form-input-sm { width: 100% !important; }
  .data-table details pre { white-space: pre-wrap; }
}

@media (max-width: 480px) {
  .messages-wrap { padding: 12px; }
  .reply-form { padding: 8px 12px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .draft-block { margin: 0 12px 8px; }
  .topbar { padding: env(safe-area-inset-top) 10px 0; gap: 3px; }
  .topbar-link { padding: 7px 9px; }
  .page-wrap { padding: 16px 14px; }
  .channels-grid { padding: 12px; gap: 12px; }
  .msg { max-width: 88%; }
}

/* ─── Push notifications — bell toggle ───────────────────────────── */
.push-toggle-active { color: var(--accent-dot); }
.push-toggle-active:hover { color: var(--accent-dot); }
.push-toggle-disabled { opacity: 0.45; cursor: default; }
.push-toggle-disabled:hover { background: none; color: var(--sb-text); }

/* ─── iOS "Add to Home Screen" banner ────────────────────────────── */
.a2hs-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.4;
}
.a2hs-banner-text { flex: 1; }
.a2hs-banner-text .bx { font-size: 14px; vertical-align: -2px; }
.a2hs-banner-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  flex-shrink: 0;
  padding: 4px;
  display: inline-flex;
  align-items: center;
}
.a2hs-banner-close:hover { color: var(--text); }
