/* =========================================================================
   Wamon — WhatsApp-style light & dark themes.
   Theme is resolved in JS (system / light / dark) and set as data-theme on <html>.
   ========================================================================= */

:root {
  /* surfaces */
  --bg: #eff2f5;
  --panel: #ffffff;
  --header: #f0f2f5;
  --deep: #f0f2f5;
  --raised: #ffffff;
  --input: #f0f2f5;
  --hover: #f5f6f6;
  --active: #ebeef0;
  --border: #e9edef;
  /* text */
  --text: #111b21;
  --strong: #111b21;
  --muted: #667781;
  --faint: #8696a0;
  --icon: #54656f;
  /* accents */
  --accent: #00a884;
  --accent-strong: #008069;
  --accent-text: #008069;
  --accent-soft: #d9fdd3;
  --on-accent: #ffffff;
  --blue: #027eb5;
  --blue-soft: #e1f2fb;
  --warn: #b36b00;
  --warn-soft: #fff3d6;
  --danger: #ea0038;
  --danger-soft: #fde8ed;
  /* chat */
  --chat-bg: #efeae2;
  --chat-dots: rgba(84, 101, 111, 0.085);
  --bubble-me: #d9fdd3;
  --bubble-them: #ffffff;
  --bubble-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --stamp: #667781;
  --note: #fff7d6;
  /* effects */
  --glass: rgba(255, 255, 255, 0.86);
  --shadow-sm: 0 1px 2px rgba(11, 20, 26, 0.08);
  --shadow: 0 12px 32px rgba(11, 20, 26, 0.13), 0 2px 6px rgba(11, 20, 26, 0.06);
  --scrim: rgba(11, 20, 26, 0.32);
  --skeleton: #eceff1;
  --skeleton-hi: #f7f8f9;
  /* shape & motion */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-io: cubic-bezier(0.65, 0, 0.35, 1);
  --fast: 140ms;
  --med: 240ms;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0c1317;
  --panel: #111b21;
  --header: #202c33;
  --deep: #0b141a;
  --raised: #233138;
  --input: #202c33;
  --hover: #202c33;
  --active: #2a3942;
  --border: #222d34;
  --text: #d1d7db;
  --strong: #e9edef;
  --muted: #8696a0;
  --faint: #667781;
  --icon: #aebac1;
  --accent-text: #00a884;
  --accent-soft: #0a332c;
  --blue: #53bdeb;
  --blue-soft: rgba(83, 189, 235, 0.13);
  --warn: #f5b343;
  --warn-soft: rgba(245, 179, 67, 0.13);
  --danger: #f15c6d;
  --danger-soft: rgba(241, 92, 109, 0.14);
  --chat-bg: #0b141a;
  --chat-dots: rgba(255, 255, 255, 0.03);
  --bubble-me: #005c4b;
  --bubble-them: #202c33;
  --bubble-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.25);
  --stamp: rgba(233, 237, 239, 0.6);
  --note: rgba(245, 179, 67, 0.1);
  --glass: rgba(35, 49, 56, 0.9);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
  --scrim: rgba(0, 0, 0, 0.5);
  --skeleton: #1b262c;
  --skeleton-hi: #24323a;
  color-scheme: dark;
}

/* Colour cross-fade only while switching themes, so normal interaction stays snappy. */
:root.theme-anim *,
:root.theme-anim *::before,
:root.theme-anim *::after {
  transition: background-color 0.3s var(--ease-io), border-color 0.3s var(--ease-io), color 0.3s var(--ease-io),
    fill 0.3s var(--ease-io) !important;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.2px/1.45 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
svg { flex-shrink: 0; }
h1 { font-size: 21px; font-weight: 700; margin: 0; color: var(--strong); letter-spacing: -0.015em; }
h2 { font-size: 12px; font-weight: 600; margin: 0 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
a { color: var(--accent-text); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.good { color: var(--accent-text); }
.mid { color: var(--warn); }
.bad { color: var(--danger); }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--faint) 45%, transparent) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--faint) 45%, transparent); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- shell: rail | list | main ---------- */
.app {
  display: grid;
  grid-template-columns: 64px minmax(320px, 400px) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  max-width: 1900px;
  margin: 0 auto;
  box-shadow: var(--shadow-sm);
}
.app.wide { grid-template-columns: 64px 0 minmax(0, 1fr); }
.app.wide .list-pane { visibility: hidden; border: 0; }

.rail {
  position: relative;
  background: var(--header);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0 14px;
  gap: 6px;
  z-index: 3;
}
.rail .logo {
  width: 40px; height: 40px; border-radius: 13px; margin-bottom: 14px;
  background: linear-gradient(145deg, #25d366, #00a884 60%, #008069);
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 4px 14px rgba(0, 168, 132, 0.35);
}
.rail-indicator {
  position: absolute; left: 10px; top: 0; width: 44px; height: 44px; border-radius: 50%;
  background: var(--active); pointer-events: none; opacity: 0;
  transition: transform var(--med) var(--ease), opacity var(--fast);
}
.rail-btn {
  position: relative; z-index: 1;
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--icon);
  display: grid; place-items: center;
  transition: color var(--fast), background-color var(--fast), transform var(--fast) var(--ease);
}
.rail-btn:hover { background: color-mix(in srgb, var(--active) 60%, transparent); }
.rail-btn:active { transform: scale(0.92); }
.rail-btn.active { color: var(--strong); }
.rail-btn.active svg { stroke-width: 2.2; }
.rail-btn .badge { position: absolute; top: 3px; right: 1px; transform: scale(0.92); }
.rail-btn[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; left: 54px; top: 50%; transform: translateY(-50%);
  background: var(--strong); color: var(--panel); padding: 5px 10px; border-radius: 7px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap; z-index: 50; pointer-events: none;
  animation: tip-in var(--fast) var(--ease);
}
.rail .spacer { flex: 1; }

.list-pane {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.main-pane { background: var(--deep); display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; overflow: hidden; }
.view-enter { animation: view-in var(--med) var(--ease); }

.pane-head { padding: 16px 18px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 60px; }
.pane-head .count { font-size: 12.5px; color: var(--muted); }

/* ---------- inputs ---------- */
.search {
  margin: 0 12px 10px; height: 36px;
  display: flex; align-items: center; gap: 10px;
  background: var(--input); border-radius: var(--r-sm); padding: 0 12px; color: var(--icon);
  border: 1px solid transparent;
  transition: background-color var(--fast), border-color var(--fast), box-shadow var(--fast);
}
.search:focus-within { background: var(--panel); border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.search:focus-within svg { color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: var(--text); }
.search input::placeholder { color: var(--muted); }
kbd {
  font: 500 10.5px/1 ui-monospace, 'Cascadia Mono', monospace; color: var(--muted);
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 3px 5px; background: var(--panel);
}
.input, select.input, textarea.input {
  width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 11px; outline: none; transition: border-color var(--fast), box-shadow var(--fast);
}
.input:hover { border-color: color-mix(in srgb, var(--faint) 50%, var(--border)); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
label.field { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: 999px; padding: 8px 16px; font-weight: 600; font-size: 13.5px;
  background: var(--accent); color: var(--on-accent);
  transition: background-color var(--fast), box-shadow var(--fast), transform var(--fast) var(--ease), opacity var(--fast);
}
.btn:hover { background: var(--accent-strong); box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn.ghost { background: transparent; color: var(--accent-text); border-color: var(--border); }
.btn.ghost:hover { background: var(--hover); box-shadow: none; }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.btn.danger:hover { background: var(--danger-soft); box-shadow: none; }
.btn.sm { padding: 5px 12px; font-size: 12.5px; }
.icon-btn {
  width: 38px; height: 38px; border: 0; border-radius: 50%; background: transparent; color: var(--icon);
  display: inline-grid; place-items: center;
  transition: background-color var(--fast), color var(--fast), transform var(--fast) var(--ease);
}
.icon-btn:hover { background: var(--active); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn.on { color: var(--accent-text); background: var(--accent-soft); }

/* segmented control (theme picker) */
.segmented { display: inline-flex; background: var(--input); border-radius: 999px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 13px;
  display: inline-flex; gap: 6px; align-items: center; transition: background-color var(--fast), color var(--fast), box-shadow var(--fast);
}
.segmented button.active { background: var(--panel); color: var(--strong); box-shadow: var(--shadow-sm); }

/* ---------- chips, pills, badges ---------- */
.chips { display: flex; gap: 7px; padding: 2px 12px 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 0; background: var(--input); color: var(--muted);
  border-radius: 999px; padding: 6px 13px; font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: background-color var(--fast), color var(--fast), transform var(--fast) var(--ease);
}
.chip:hover { color: var(--text); background: var(--active); }
.chip:active { transform: scale(0.96); }
.chip.active { background: var(--accent-soft); color: var(--accent-text); }
.chip select { background: transparent; border: 0; outline: none; color: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums;
  animation: badge-in var(--med) var(--ease);
}
.badge.warn { background: var(--warn); color: #fff; }
.badge.danger { background: var(--danger); }
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; background: var(--input); color: var(--muted); white-space: nowrap; line-height: 1.35;
}
.pill.stage { background: var(--blue-soft); color: var(--blue); }
.pill.won, .pill.good { background: var(--accent-soft); color: var(--accent-text); }
.pill.lost, .pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn, .pill.mid { background: var(--warn-soft); color: var(--warn); }
button.pill { border: 0; transition: filter var(--fast), transform var(--fast) var(--ease); }
button.pill:hover { filter: brightness(0.96); }
button.pill:active { transform: scale(0.96); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--faint); flex-shrink: 0; }
.dot.on { background: #25d366; box-shadow: 0 0 0 3px color-mix(in srgb, #25d366 22%, transparent); }
.dot.wait { background: var(--warn); animation: breathe 1.6s var(--ease-io) infinite; }
.dot.off { background: var(--danger); }

/* ---------- chat list ---------- */
.list { flex: 1; overflow-y: auto; overscroll-behavior: contain; position: relative; }
.list-section {
  position: sticky; top: 0; z-index: 2; background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 10px 18px 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; color: var(--accent-text);
}
.list-section.bad { color: var(--danger); }
.chat-item {
  display: grid; grid-template-columns: 49px minmax(0, 1fr); gap: 13px; align-items: center;
  padding: 0 14px 0 13px; height: 80px; cursor: pointer; position: relative;
  transition: background-color var(--fast);
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.chat-item .body {
  min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 1px;
  border-bottom: 1px solid var(--border);
}
.chat-item:hover .body, .chat-item.active .body, .chat-item:has(+ .chat-item:hover) .body, .chat-item:has(+ .chat-item.active) .body { border-color: transparent; }
.chat-item .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-item .name { font-size: 15.5px; color: var(--strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.unread .name { font-weight: 600; }
.chat-item .time { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chat-item.unread .time { color: var(--accent-text); font-weight: 600; }
.chat-item .preview { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; display: flex; align-items: center; gap: 3px; min-width: 0; }
.chat-item .preview span { overflow: hidden; text-overflow: ellipsis; }
.chat-item.unread .preview { color: var(--text); }
.chat-item .meta { display: flex; gap: 5px; align-items: center; margin-top: 3px; flex-wrap: nowrap; overflow: hidden; }
.tag { font-size: 11px; color: var(--muted); background: var(--input); border-radius: 5px; padding: 1px 6px; white-space: nowrap; }
.chat-item.enter { animation: row-in var(--med) var(--ease) both; }

.avatar {
  width: 49px; height: 49px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  font-weight: 600; font-size: 16px; color: #fff; position: relative; user-select: none; letter-spacing: 0.02em;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
}
.avatar.sm { width: 40px; height: 40px; font-size: 14px; }
.avatar.xs { width: 30px; height: 30px; font-size: 11.5px; }
.avatar .presence { position: absolute; right: 0; bottom: 1px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--panel); }

/* ---------- conversation ---------- */
.convo-wrap { display: flex; flex: 1; min-height: 0; animation: fade var(--fast) ease-out; }
.convo { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; position: relative; }
.convo-head {
  height: 60px; flex-shrink: 0; display: flex; align-items: center; gap: 12px; padding: 0 10px 0 16px;
  background: var(--header); border-left: 1px solid var(--border); z-index: 2;
}
.convo-head .who { flex: 1; min-width: 0; cursor: pointer; }
.convo-head .who .name { font-size: 16px; color: var(--strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-head .who .sub { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; }
.messages {
  flex: 1; overflow-y: auto; padding: 14px 7% 18px; position: relative;
  background-color: var(--chat-bg);
  background-image: radial-gradient(var(--chat-dots) 1.1px, transparent 1.2px);
  background-size: 18px 18px;
  display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; scroll-behavior: auto;
}
.day-group { display: flex; flex-direction: column; gap: 2px; }
.day-sep {
  position: sticky; top: 6px; z-index: 1; align-self: center; margin: 12px 0 8px;
  background: var(--panel); box-shadow: var(--bubble-shadow);
  font-size: 12.5px; color: var(--muted); padding: 5px 12px; border-radius: 8px; text-transform: uppercase; letter-spacing: 0.02em;
}
.bubble {
  max-width: min(65%, 560px); padding: 6px 8px 7px 9px; border-radius: 8px; background: var(--bubble-them);
  white-space: pre-wrap; word-wrap: break-word; position: relative; align-self: flex-start;
  box-shadow: var(--bubble-shadow); color: var(--text); font-size: 14.2px; line-height: 1.38;
  transition: opacity var(--fast);
}
.bubble.me { align-self: flex-end; background: var(--bubble-me); }
.bubble.first { margin-top: 8px; }
/* WhatsApp-style tails on the first bubble of a run */
.bubble.first:not(.me) { border-top-left-radius: 0; }
.bubble.first.me { border-top-right-radius: 0; }
.bubble.first::before {
  content: ''; position: absolute; top: 0; width: 8px; height: 13px; background: inherit;
}
.bubble.first:not(.me)::before { left: -8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.bubble.first.me::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.bubble .stamp {
  float: right; margin: 6px -2px -5px 12px; font-size: 11px; color: var(--stamp);
  display: inline-flex; gap: 3px; align-items: center; font-variant-numeric: tabular-nums;
}
.bubble.me .stamp svg { color: var(--stamp); }
.bubble.pending { opacity: 0.7; }
.bubble.failed { box-shadow: 0 0 0 1.5px var(--danger); }
.bubble .kind { font-style: italic; color: var(--muted); }
.bubble.enter { animation: bubble-in 0.28s var(--ease) both; }
.bubble.me.enter { animation-name: bubble-in-me; }
.wait-sep { align-self: center; font-size: 11.5px; color: var(--warn); margin: 6px 0 2px; padding: 2px 10px; border-radius: 999px; background: color-mix(in srgb, var(--panel) 75%, transparent); }
.wait-sep.ok { color: var(--muted); }
.load-older { align-self: center; margin: 6px 0; background: var(--panel); }

.to-bottom {
  position: absolute; right: 22px; bottom: 82px; z-index: 4; width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: var(--panel); color: var(--icon); box-shadow: var(--shadow);
  display: grid; place-items: center; opacity: 0; transform: translateY(10px) scale(0.9); pointer-events: none;
  transition: opacity var(--med) var(--ease), transform var(--med) var(--ease);
}
.to-bottom.show { opacity: 1; transform: none; pointer-events: auto; }
.to-bottom .badge { position: absolute; top: -6px; right: -4px; }

.composer {
  flex-shrink: 0; display: flex; align-items: flex-end; gap: 8px; padding: 9px 14px;
  background: var(--header); position: relative; z-index: 2;
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 42px; background: var(--panel); border: 0;
  border-radius: 10px; padding: 10px 14px; outline: none; line-height: 1.4; box-shadow: var(--shadow-sm);
  transition: height var(--fast) var(--ease);
}
.composer textarea::placeholder { color: var(--muted); }
.composer .send {
  width: 42px; height: 42px; border-radius: 50%; padding: 0; flex-shrink: 0;
  background: transparent; color: var(--icon); border: 0;
  transition: background-color var(--med) var(--ease), color var(--med) var(--ease), transform var(--med) var(--ease);
}
.composer .send:hover { box-shadow: none; background: var(--active); }
.composer .send.ready { background: var(--accent); color: #fff; transform: rotate(0deg) scale(1); }
.composer .send.ready:hover { background: var(--accent-strong); }
.composer .send:not(.ready) svg { transform: rotate(-12deg) scale(0.92); }
.composer .send svg { transition: transform var(--med) var(--ease); }
.composer-note {
  padding: 12px 18px; font-size: 13px; color: var(--warn); background: var(--header);
  display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--border);
}
.qr-pop {
  position: absolute; left: 14px; right: 64px; bottom: calc(100% + 8px); max-height: 270px; overflow-y: auto;
  background: var(--glass); backdrop-filter: blur(18px) saturate(1.5); -webkit-backdrop-filter: blur(18px) saturate(1.5);
  border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); padding: 6px;
  transform-origin: bottom left; animation: pop-in var(--fast) var(--ease); z-index: 5;
}
.qr-item { padding: 8px 11px; border-radius: 9px; cursor: pointer; display: grid; gap: 2px; transition: background-color var(--fast); }
.qr-item.sel, .qr-item:hover { background: var(--active); }
.qr-item b { color: var(--accent-text); font-size: 13px; }
.qr-item span { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- lead panel (WhatsApp "contact info" look) ---------- */
.lead-panel {
  width: 340px; flex-shrink: 0; border-left: 1px solid var(--border); background: var(--deep);
  overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 14px;
  animation: panel-in var(--med) var(--ease);
}
.lead-panel.closing { animation: panel-out 180ms var(--ease-io) forwards; }
.lead-panel .sec { padding: 16px 20px; background: var(--panel); display: grid; gap: 11px; box-shadow: var(--shadow-sm); }
.lead-panel .sec h2 { margin: 0; color: var(--accent-text); text-transform: none; letter-spacing: 0; font-size: 13.5px; font-weight: 600; }
.lead-panel .hero { text-align: center; padding: 26px 20px 20px; }
.lead-panel .hero .avatar { margin: 0 auto 12px; width: 96px; height: 96px; font-size: 32px; }
.lead-panel .hero input {
  text-align: center; font-weight: 500; font-size: 19px; color: var(--strong);
  background: transparent; border: 1px solid transparent; border-radius: 8px;
}
.lead-panel .hero input:hover { border-color: var(--border); }
.stage-track { display: flex; flex-wrap: wrap; gap: 6px; }
.stage-track button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; color: var(--muted);
  transition: background-color var(--fast), color var(--fast), border-color var(--fast), transform var(--fast) var(--ease);
}
.stage-track button:hover { color: var(--text); border-color: var(--faint); }
.stage-track button:active { transform: scale(0.95); }
.stage-track button.active { background: var(--blue); border-color: var(--blue); color: #fff; }
:root[data-theme='dark'] .stage-track button.active:not(.won):not(.lost) { color: #0b141a; }
.stage-track button.active.won { background: var(--accent); border-color: var(--accent); }
.stage-track button.active.lost { background: var(--danger); border-color: var(--danger); }
.tags-input { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 5px; transition: border-color var(--fast); }
.tags-input:focus-within { border-color: var(--accent); }
.tags-input input { flex: 1; min-width: 80px; border: 0; background: transparent; outline: none; padding: 3px; }
.tags-input .t { background: var(--accent-soft); color: var(--accent-text); border-radius: 6px; padding: 1px 4px 1px 9px; font-size: 12.5px; display: inline-flex; align-items: center; gap: 2px; animation: pop-in var(--fast) var(--ease); }
.tags-input .t button { border: 0; background: none; color: inherit; opacity: 0.6; padding: 0 3px; }
.tags-input .t button:hover { opacity: 1; }
.fu-row, .note-row { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; animation: fade var(--med) ease-out; }
.fu-row input[type='checkbox'] { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; }
.fu-row.done { color: var(--faint); text-decoration: line-through; }
.note-row { background: var(--note); border-radius: 10px; padding: 9px 11px; }
.note-row .txt { flex: 1; white-space: pre-wrap; }
.quick-dates { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- pages (wide views) ---------- */
.page { flex: 1; overflow-y: auto; padding: 26px 30px 44px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.card { background: var(--panel); border-radius: var(--r-lg); padding: 18px 20px; min-width: 0; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.grid2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: var(--panel); border-radius: var(--r-lg); padding: 16px 18px; box-shadow: var(--shadow-sm); border: 1px solid var(--border);
  animation: rise var(--med) var(--ease) both;
}
.kpi:nth-child(2) { animation-delay: 30ms; } .kpi:nth-child(3) { animation-delay: 60ms; }
.kpi:nth-child(4) { animation-delay: 90ms; } .kpi:nth-child(5) { animation-delay: 120ms; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; color: var(--strong); letter-spacing: -0.025em; }
.kpi .value.good { color: var(--accent-text); } .kpi .value.mid { color: var(--warn); } .kpi .value.bad { color: var(--danger); }
.kpi .sub { color: var(--faint); font-size: 12px; margin-top: 2px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
tbody tr { transition: background-color var(--fast); }
tbody tr:hover { background: var(--hover); }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.funnel { display: grid; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 110px; gap: 12px; align-items: center; font-size: 13.5px; }
.funnel-bar { height: 10px; background: var(--input); border-radius: 999px; overflow: hidden; }
.funnel-bar i { display: block; height: 100%; background: var(--blue); border-radius: 999px; transform-origin: left; animation: grow 0.6s var(--ease) both; }
.funnel-bar i.won { background: var(--accent); } .funnel-bar i.lost { background: var(--danger); }
.waiting-list { list-style: none; margin: 0; padding: 0; }
.waiting-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 8px; border-radius: 8px; cursor: pointer; transition: background-color var(--fast); }
.waiting-list li:hover { background: var(--hover); }

/* ---------- pipeline ---------- */
.board { flex: 1; display: flex; gap: 14px; overflow-x: auto; padding: 0 30px 22px; min-height: 0; }
.column {
  width: 280px; flex-shrink: 0; display: flex; flex-direction: column; background: var(--header);
  border-radius: var(--r-lg); min-height: 0; border: 1.5px solid transparent;
  transition: border-color var(--fast), background-color var(--fast);
}
.column.drop { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 60%, var(--header)); }
.column-head { padding: 14px 14px 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.column-head b { color: var(--strong); font-size: 14px; font-weight: 600; }
.column-head .sum { font-size: 12.5px; color: var(--muted); }
.column-body { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: grid; gap: 8px; align-content: start; }
.deal {
  background: var(--panel); border-radius: var(--r); padding: 11px 12px; cursor: grab;
  display: grid; gap: 7px; box-shadow: var(--shadow-sm); border: 1px solid var(--border);
  transition: box-shadow var(--fast), transform var(--fast) var(--ease), opacity var(--fast);
}
.deal:hover { box-shadow: 0 4px 14px color-mix(in srgb, #0b141a 12%, transparent); transform: translateY(-1px); }
.deal:active { cursor: grabbing; }
.deal.dragging { opacity: 0.4; transform: scale(0.97) rotate(-1deg); }
.deal.enter { animation: rise var(--med) var(--ease) both; }
.deal .top { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.deal .nm { font-weight: 600; color: var(--strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal .val { font-weight: 600; color: var(--accent-text); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.deal .row { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; }

/* stage tabs: phones only (desktop sees several columns at once) */
.stage-tabs { display: none; }
.stage-tab {
  flex: none; border: 0; border-radius: 999px; padding: 6px 8px 6px 13px; background: var(--input); color: var(--muted);
  font-size: 13px; font-weight: 600; display: inline-flex; gap: 7px; align-items: center;
  transition: background-color var(--fast), color var(--fast);
}
.stage-tab .n {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--panel); color: var(--text);
  font-size: 11.5px; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums;
}
.stage-tab.active { background: var(--accent-soft); color: var(--accent-text); }
.stage-tab.active .n { background: var(--accent); color: #fff; }

/* ---------- numbers & settings ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.channel-card { animation: rise var(--med) var(--ease) both; }
.channel-card img { width: 100%; max-width: 250px; display: block; margin: 14px auto; background: #fff; padding: 12px; border-radius: 12px; box-shadow: var(--shadow-sm); animation: fade var(--med) ease-out; }
.settings { display: grid; gap: 16px; max-width: 780px; }
.settings .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.day-row { display: grid; grid-template-columns: 120px 1fr 1fr; gap: 8px; align-items: center; margin: 6px 0; }
.qr-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.report-preview { background: var(--chat-bg); border-radius: var(--r); padding: 14px; white-space: pre-wrap; font-size: 13.5px; margin: 0; animation: fade var(--med) ease-out; }

/* ---------- empty states & skeletons ---------- */
.empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 30px 24px; animation: fade var(--med) ease-out; }
.empty .inner { max-width: 340px; display: grid; gap: 8px; justify-items: center; }
.empty .ico {
  width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 8px;
  background: var(--accent-soft); color: var(--accent-text);
}
.empty .ttl { font-weight: 500; color: var(--strong); font-size: 18px; letter-spacing: -0.01em; }
.empty .txt { color: var(--muted); font-size: 13.5px; line-height: 1.55; }
.empty .btn { margin-top: 8px; }
.welcome { background: var(--header); border-left: 1px solid var(--border); border-bottom: 6px solid var(--accent); }
.welcome .ico { width: 96px; height: 96px; }

.sk {
  background: linear-gradient(90deg, var(--skeleton) 0%, var(--skeleton-hi) 45%, var(--skeleton) 90%);
  background-size: 300% 100%; animation: shimmer 1.4s linear infinite; border-radius: 6px;
}
.sk-item { display: grid; grid-template-columns: 49px 1fr; gap: 13px; padding: 15px 14px 15px 13px; align-items: center; }
.sk-item .sk.av { width: 49px; height: 49px; border-radius: 50%; }
.sk-line { height: 11px; margin: 5px 0; }

/* ---------- overlays ---------- */
.ctx {
  position: fixed; z-index: 100; min-width: 220px; max-width: 270px; padding: 6px;
  background: var(--glass); backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  transform-origin: top left; animation: pop-in 160ms var(--ease);
}
.ctx .item { display: flex; align-items: center; gap: 11px; padding: 8px 11px; border-radius: 9px; cursor: pointer; font-size: 14px; color: var(--text); transition: background-color 90ms; }
.ctx .item svg { color: var(--icon); }
.ctx .item:hover, .ctx .item.sel { background: var(--active); }
.ctx .item.danger, .ctx .item.danger svg { color: var(--danger); }
.ctx .item.current { color: var(--accent-text); font-weight: 600; }
.ctx .item.current svg { color: var(--accent-text); }
.ctx .label { font-size: 11.5px; color: var(--faint); padding: 8px 11px 3px; font-weight: 500; }
.ctx .sep { height: 1px; background: var(--border); margin: 5px 6px; }

.palette-backdrop {
  position: fixed; inset: 0; z-index: 90; background: var(--scrim);
  display: grid; justify-items: center; align-items: start; padding-top: 13vh; animation: fade var(--fast) ease-out;
}
.palette {
  width: min(620px, calc(100vw - 32px)); background: var(--glass);
  backdrop-filter: blur(22px) saturate(1.6); -webkit-backdrop-filter: blur(22px) saturate(1.6);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden;
  animation: palette-in var(--med) var(--ease);
}
.palette .q { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--border); color: var(--icon); }
.palette .q input { flex: 1; border: 0; background: transparent; outline: none; font-size: 16.5px; color: var(--strong); }
.palette .res { max-height: 52vh; overflow-y: auto; padding: 6px; }
.palette .grp { font-size: 11.5px; color: var(--faint); padding: 10px 12px 4px; font-weight: 500; }
.palette .opt { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; cursor: pointer; color: var(--text); transition: background-color 90ms; }
.palette .opt svg { color: var(--icon); }
.palette .opt.sel { background: var(--active); }
.palette .opt.sel svg { color: var(--accent-text); }
.palette .opt .meta { margin-left: auto; font-size: 12px; color: var(--faint); white-space: nowrap; }
.palette .foot { display: flex; gap: 16px; padding: 9px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--faint); }

.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 120; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; padding: 11px 16px; border-radius: 12px;
  background: #1f2c33; color: #e9edef; box-shadow: var(--shadow); font-size: 14px;
  animation: toast-in var(--med) var(--ease);
}
:root[data-theme='dark'] .toast { background: #e9edef; color: #111b21; }
.toast.leave { animation: toast-out 200ms var(--ease-io) forwards; }
.toast.err svg { color: #f15c6d; }
.toast button { border: 0; background: none; color: #25d366; font-weight: 700; padding: 0; text-transform: uppercase; font-size: 12.5px; letter-spacing: 0.03em; }
:root[data-theme='dark'] .toast button { color: #008069; }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(700px 500px at 15% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
    var(--bg);
  animation: fade var(--med) ease-out;
}
.login.leaving { animation: fade-out 240ms var(--ease-io) forwards; }
.login-card {
  width: min(380px, 100%); display: grid; gap: 12px; justify-items: stretch; text-align: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 34px 30px 30px;
  box-shadow: var(--shadow); animation: rise var(--med) var(--ease);
}
.login-card .logo {
  justify-self: center; width: 56px; height: 56px; border-radius: 17px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, #25d366, #00a884 60%, #008069); box-shadow: 0 6px 20px rgba(0, 168, 132, 0.35);
}
.login-card h1 { font-size: 24px; }
.login-card p { margin: -6px 0 6px; font-size: 13.5px; }
.login-card .input { padding: 11px 14px; font-size: 15px; }
.login-card .btn { padding: 11px; font-size: 15px; }
.login-error:empty { display: none; }
.login-card { position: relative; }
.login-lang { position: absolute; top: 14px; right: 14px; }
.login-lang button { padding: 4px 10px; font-size: 12px; }
.login-card p.small { margin: 2px 0 0; }

/* demo account: explore everything, but owner-only controls are hidden (the server refuses them too) */
.role-demo .owner-only { display: none !important; }
.demo-badge {
  font-size: 9.5px; font-weight: 800; letter-spacing: 0.08em; color: #fff; background: var(--warn);
  padding: 2px 6px; border-radius: 6px; margin: -8px 0 10px;
}
@media (max-width: 760px) { .demo-badge { display: none; } }
.shake { animation: shake 0.4s var(--ease-io); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes fade-out { to { opacity: 0; } }

/* View Transitions API (route changes) — a short, quiet cross-fade */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 160ms; animation-timing-function: var(--ease-io); }

/* ---------- motion ---------- */
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -200% 0; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes row-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes palette-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes bubble-in { from { opacity: 0; transform: translate(-6px, 6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes bubble-in-me { from { opacity: 0; transform: translate(6px, 6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes panel-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes panel-out { to { opacity: 0; transform: translateX(24px); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes badge-in { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tip-in { from { opacity: 0; transform: translate(-4px, -50%); } to { opacity: 1; transform: translate(0, -50%); } }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes breathe { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .lead-panel { position: absolute; right: 0; top: 60px; bottom: 0; z-index: 6; box-shadow: var(--shadow); }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app, .app.wide { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 60px; box-shadow: none; }
  .rail { grid-row: 2; flex-direction: row; justify-content: space-around; padding: 0 4px; border-right: 0; border-top: 1px solid var(--border); background: var(--panel); }
  .rail .logo, .rail .spacer, .rail .cmdk { display: none; }
  .rail-indicator { top: 8px; left: 0; width: 56px; height: 32px; border-radius: 999px; background: var(--accent-soft); }
  .rail-btn { width: 56px; height: 44px; border-radius: 999px; }
  .rail-btn.active { color: var(--accent-text); }
  .rail-btn[data-tip]:hover::after { display: none; }
  .list-pane, .main-pane { grid-row: 1; grid-column: 1; }
  .app:not(.wide):not(.show-main) .main-pane { display: none; }
  .app.show-main .list-pane, .app.wide .list-pane { display: none; }
  .app.show-main .main-pane { animation: slide-up var(--med) var(--ease); }
  .convo-head { border-left: 0; padding-left: 4px; }
  .messages { padding: 10px 12px 14px; }
  .bubble { max-width: 85%; }
  .lead-panel { width: 100%; top: 60px; }
  .page { padding: 18px 16px 30px; }
  .stage-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 0 16px 12px; scrollbar-width: none; }
  .stage-tabs::-webkit-scrollbar { display: none; }
  /* One column per screen, snapping into place, with the next one peeking in from the right edge. */
  .board { padding: 0 16px 16px; gap: 10px; scroll-snap-type: x mandatory; scroll-padding: 0 16px; }
  .column { width: calc(100vw - 64px); scroll-snap-align: start; }
  .settings .row2 { grid-template-columns: 1fr; }
  .day-row { grid-template-columns: 90px 1fr 1fr; }
  .qr-row { grid-template-columns: 1fr; }
  .funnel-row { grid-template-columns: 96px 1fr 76px; }
  .to-bottom { bottom: 76px; right: 14px; }
  .welcome { border: 0; }
}
@keyframes slide-up { from { opacity: 0.6; transform: translateX(18px); } to { opacity: 1; transform: none; } }
@media (min-width: 761px) { .only-mobile { display: none !important; } }
