:root {
  --brand: #6b21a8;
  --brand-dark: #581c87;
  --brand-hover: #581c87;
  --brand-text: #581c87;
  --brand-soft: #f3ebfa;
  --accent: #ff5a2c;
  --accent-soft: #ffe9e1;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --text: #1f2a37;
  --muted: #6b7a8f;
  --border: #e3e8ef;
  --border-strong: #d3dbe6;

  --success: #16a34a;
  --success-soft: #e5f6ec;
  --danger: #e5484d;
  --danger-soft: #fdeaea;
  --warn: #d97706;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.10);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, 0.22);

  --sidebar-w: 240px;
  --topbar-h: 64px;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #9aa7b8; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(43, 125, 233, 0.18);
}
label { display: block; font-weight: 600; font-size: 13px; color: #40506a; margin-bottom: 14px; }
label input, label select, label textarea { margin-top: 6px; font-weight: 400; }
textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-2 > label { margin-bottom: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; font-weight: 600; font-size: 14px;
  background: var(--surface); color: var(--text); transition: .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #e94d22; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.icon-btn {
  border: none; background: transparent; color: var(--muted);
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ---------- Auth ---------- */
.auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 15% -10%, var(--brand-soft), transparent 60%),
              radial-gradient(1000px 500px at 110% 110%, var(--accent-soft), transparent 55%),
              var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 30px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.logo-mark {
  width: 42px; height: 42px; border-radius: 11px; background: var(--brand);
  color: #fff; font-weight: 800; font-size: 24px;
  display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-sm);
}
.logo-name { font-weight: 800; font-size: 19px; letter-spacing: -0.2px; }
.logo-tag { color: var(--muted); font-size: 12.5px; }
.logo-img { width: 52px; height: 38px; object-fit: contain; display: block; flex-shrink: 0; }
.logo-img-lg { width: 200px; height: 146px; }
.auth-brand { flex-direction: column; text-align: center; gap: 10px; margin-bottom: 26px; }
.auth-brand .logo-name { font-size: 26px; }
.auth-brand .logo-tag { font-size: 14px; }
.auth-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.auth-tab {
  flex: 1; border: none; background: transparent; padding: 9px; border-radius: 7px;
  font-weight: 600; color: var(--muted);
}
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.auth-form label { margin-bottom: 14px; }
.auth-form .btn { margin-top: 6px; }
.auth-msg { min-height: 20px; margin: 14px 0 0; font-size: 13px; color: var(--danger); }
.auth-note { margin: 16px 0 0; text-align: center; color: var(--muted); font-size: 12.5px; }

/* ---------- App layout ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-brand { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 14px 12px; border-bottom: 1px solid var(--border); }
.sidebar-brand .logo-img { width: 116px; height: 85px; }
.sidebar-tag { font-size: 10.5px; color: var(--muted); text-align: center; letter-spacing: .2px; line-height: 1.35; }
.sidebar-brand .logo-mark { width: 34px; height: 34px; font-size: 19px; border-radius: 9px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 14px 12px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px;
  border: none; background: transparent; color: #45536a; font-weight: 600; font-size: 14px; text-align: left;
  position: relative; transition: .12s;
}
.nav-item svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; flex-shrink: 0; }
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-text); }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px;
  background: var(--brand); border-radius: 0 4px 4px 0;
}
.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; cursor: pointer; border-radius: 10px; padding: 6px; margin: -6px; transition: background .12s; }
.user-chip:hover { background: var(--bg); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.user-meta { overflow: hidden; }
.user-name { font-weight: 700; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px;
}
.search { position: relative; flex: 1; max-width: 520px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; }
.search input { padding-left: 38px; border-radius: 10px; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 50; overflow: hidden;
}
.search-group-title { padding: 10px 14px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.search-item { display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer; }
.search-item:hover { background: var(--surface-2); }
.search-item .si-icon { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.search-item .si-main { min-width: 0; }
.search-item .si-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item .si-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-empty { padding: 14px; color: var(--muted); }

.content { flex: 1; overflow-y: auto; padding: 24px; }
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.view-title { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.3px; }
.view-sub { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }

/* ---------- Cards / KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.kpi .kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi .kpi-value { font-size: 26px; font-weight: 800; margin-top: 4px; letter-spacing: -0.5px; }
.kpi .kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent .kpi-value { color: var(--accent); }
.kpi.brand .kpi-value { color: var(--brand-text); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-body { padding: 6px 0; }
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }

/* Funnel */
.funnel-row { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 12px; padding: 10px 18px; }
.funnel-label { font-weight: 600; font-size: 13px; }
.funnel-track { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--brand), #a855f7); }
.funnel-fill.won { background: linear-gradient(90deg, #16a34a, #4ad17f); }
.funnel-fill.lost { background: linear-gradient(90deg, #e5484d, #f08a8e); }
.funnel-count { font-size: 12.5px; color: var(--muted); font-weight: 600; min-width: 24px; text-align: right; }

/* Lists */
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 18px; cursor: pointer; }
.list-item:hover { background: var(--surface-2); }
.list-item + .list-item { border-top: 1px solid var(--border); }
.li-icon { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.li-main { min-width: 0; flex: 1; }
.li-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-right { text-align: right; flex-shrink: 0; }
.li-val { font-weight: 700; font-size: 13px; }
.li-meta { color: var(--muted); font-size: 12px; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }

/* Badges / stage tags */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.stage-lead { background: #eef2ff; color: #4338ca; }
.stage-qualified { background: #e0f2fe; color: #0369a1; }
.stage-proposal { background: #fef3c7; color: #b45309; }
.stage-negotiation { background: #ffe9e1; color: #c2410c; }
.stage-won { background: var(--success-soft); color: var(--success); }
.stage-lost { background: var(--danger-soft); color: var(--danger); }

/* ---------- Pipeline board ---------- */
.board { display: flex; gap: 14px; align-items: flex-start; overflow-x: auto; padding-bottom: 16px; height: calc(100vh - var(--topbar-h) - 190px); }
.col {
  flex: 1 1 0; min-width: 250px; max-width: 320px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column;
}
.col-head { padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.col-head .col-title { font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.col-head .col-dot { width: 9px; height: 9px; border-radius: 50%; }
.col-count { background: var(--bg); color: var(--muted); border-radius: 20px; padding: 2px 9px; font-size: 12px; font-weight: 700; }
.col-body { padding: 10px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.col.drag-over { background: var(--brand-soft); border-color: var(--brand); }

.deal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 13px; cursor: grab; box-shadow: var(--shadow-sm); transition: .12s; position: relative;
}
.deal-card .dc-assign { position: absolute; top: 6px; right: 6px; opacity: .55; font-size: 14px; }
.deal-card:hover .dc-assign { opacity: 1; }
.deal-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.deal-card.dragging { opacity: .4; }
.deal-card .dc-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.deal-card .dc-person { color: #45536a; font-size: 12.5px; margin-bottom: 10px; }
.deal-card .dc-owner { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.deal-card .dc-owner .own-avatar { width: 20px; height: 20px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-text); display: inline-flex; align-items: center; justify-content: center; font-size: 10.5px; font-weight: 800; flex-shrink: 0; }
.deal-card .dc-owner .own-team { color: var(--muted); font-weight: 500; }
.deal-card .dc-person .co { color: var(--muted); }
.deal-card .dc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.deal-card .dc-value { font-weight: 800; color: var(--brand-text); font-size: 14px; }
.dc-activity { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 20px; background: var(--bg); color: var(--muted); }
.dc-activity.overdue { background: var(--danger-soft); color: var(--danger); }
.col-add { margin: 8px 10px 10px; border: 1px dashed var(--border-strong); background: transparent; color: var(--muted); border-radius: 8px; padding: 8px; font-weight: 600; font-size: 13px; }
.col-add:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* ---------- Call / phone ---------- */
.phone-link { color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; }
.phone-link:hover { color: var(--brand); text-decoration: underline; }
.call-row { margin: 10px 0; }
.phone-dial { margin-bottom: 14px; }
.phone-dial-row { margin-top: 10px; align-items: center; }
.phone-dial-actions { display: flex; align-items: center; }
.phone-hint { margin-top: 10px; }
.phone-filters { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.act-row .act-dial { font-size: 14px; }
.cal-day-item .dial-again { font-size: 13px; }
.dial-again { cursor: pointer; }
a.li-icon { text-decoration: none; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.cell-name { font-weight: 700; }
.cell-sub { color: var(--muted); font-size: 12.5px; }
.cell-title { font-weight: 600; }

/* ---------- Companies grid ---------- */
.co-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.co-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); cursor: pointer; transition: .12s; }
.co-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.co-card .co-name { font-weight: 800; font-size: 16px; }
.co-card .co-industry { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.co-card .co-foot { display: flex; align-items: center; justify-content: space-between; }
.co-card .co-link { color: var(--brand-text); font-size: 12.5px; }

/* ---------- Activities list ---------- */
.act-row { display: flex; align-items: center; gap: 14px; padding: 13px 18px; }
.act-row + .act-row { border-top: 1px solid var(--border); }
.act-check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); background: transparent; flex-shrink: 0; padding: 0; display: flex; align-items: center; justify-content: center; }
.act-check:hover { border-color: var(--brand); }
.act-check.done { background: var(--success); border-color: var(--success); }
.act-check.done::after { content: "✓"; color: #fff; font-size: 13px; }
.act-main { flex: 1; min-width: 0; }
.act-desc { font-weight: 600; }
.act-desc.done { text-decoration: line-through; color: var(--muted); }
.act-meta { color: var(--muted); font-size: 12.5px; }
.who-sep { color: var(--muted); margin: 0 6px; }
.who { white-space: nowrap; }
.who-deal { background: var(--brand-soft); color: var(--brand-text); padding: 1px 8px; border-radius: 20px; font-weight: 600; }
.who.muted { color: var(--muted); }
.act-due { flex-shrink: 0; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.act-due.overdue { color: var(--danger); background: var(--danger-soft); padding: 3px 9px; border-radius: 20px; }
.type-chip { width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }

/* ---------- Modal / Drawer ---------- */
.modal-root { position: fixed; inset: 0; z-index: 100; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16, 24, 40, 0.5); backdrop-filter: blur(2px); }
.modal {
  position: relative; z-index: 2; background: var(--surface); width: 100%; max-width: 480px;
  margin: 6vh auto; border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden;
  animation: pop .18s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); }

.drawer {
  position: relative; z-index: 2; background: var(--surface); width: 100%; max-width: 460px;
  height: 100vh; margin-left: auto; box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  animation: slide .2s ease;
}
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; }
.drawer-kicker { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--brand-text); }
.drawer-head h2 { margin: 4px 0 0; font-size: 19px; }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }
.field-block { margin-bottom: 16px; }
.field-block .fb-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: 5px; }
.field-block .fb-value { font-weight: 600; }
.stage-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.stage-pill { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 20px; padding: 6px 12px; font-weight: 600; font-size: 12.5px; }
.stage-pill.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: #1f2a37; color: #fff; padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-weight: 600; font-size: 14px; animation: rise .2s ease; max-width: 90vw;
}
.toast.error { background: var(--danger); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Topbar actions ---------- */
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.topbar-actions .btn-ghost { white-space: nowrap; }

/* ---------- Settings / AI ---------- */
.toggle-label { display: flex !important; align-items: center; gap: 10px; cursor: pointer; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.toggle-label input { margin: 0 !important; width: auto !important; transform: scale(1.2); accent-color: var(--brand); }
.preset-row { display: flex; gap: 8px; margin-bottom: 16px; }
.preset { flex: 1; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 8px; padding: 9px; font-weight: 700; font-size: 13px; color: #45536a; }
.preset:hover { border-color: var(--brand); color: var(--brand-text); background: var(--brand-soft); }
.settings-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.test-result { font-size: 13px; font-weight: 600; }
.test-result.ok { color: var(--success); }
.test-result.err { color: var(--danger); }

/* ---------- AI floating panel ---------- */
.ai-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 90;
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--brand), #a855f7); color: #fff;
  font-size: 22px; box-shadow: var(--shadow-lg); display: flex; align-items: center; justify-content: center;
  transition: transform .15s;
}
.ai-fab:hover { transform: scale(1.06); }
.ai-panel {
  position: fixed; right: 22px; bottom: 22px; z-index: 95;
  width: 380px; max-width: calc(100vw - 32px); height: 560px; max-height: calc(100vh - 44px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden; animation: pop .18s ease;
}
.ai-panel-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.ai-panel-title { font-weight: 800; font-size: 15px; }
.ai-panel-sub { color: var(--muted); font-size: 12px; }
.ai-panel-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.ai-msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 13.5px; }
.ai-msg.user { align-self: flex-end; background: var(--brand-soft); color: var(--brand-text); border-bottom-right-radius: 4px; }
.ai-msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.ai-msg.error { align-self: flex-start; background: var(--danger-soft); color: var(--danger); }
.ai-msg .ai-code { white-space: pre-wrap; }
.ai-panel-input { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-panel-input textarea { resize: none; }
.ai-welcome { color: var(--muted); font-size: 13px; text-align: center; margin: auto; padding: 20px; }

/* Deal-drawer AI */
.dd-ai-actions { display: flex; gap: 8px; }
.dd-ai-actions .btn { flex: 1; white-space: nowrap; }
.dd-ai-out .ai-msg { border-radius: 10px; }

/* ---------- Language / theme controls ---------- */
.lang-switch { display: inline-flex; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.lang-btn { border: none; background: transparent; padding: 4px 10px; border-radius: 6px; font-weight: 700; font-size: 12px; color: var(--muted); }
.lang-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.auth-options { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-bottom: 16px; }
.theme-btn { font-size: 15px; line-height: 1; }

/* ---------- Dark theme ---------- */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1420;
  --surface: #161d2b;
  --surface-2: #1b2334;
  --text: #e8edf6;
  --muted: #93a1b7;
  --border: #263145;
  --border-strong: #354260;
  --brand-hover: #7c3aed;
  --brand-soft: #2e1b47;
  --brand-text: #c9a8f0;
  --accent: #ff7a4d;
  --accent-soft: #45230f;
  --success: #43c979;
  --success-soft: #14301f;
  --danger: #ff6b6e;
  --danger-soft: #431a1d;
  --warn: #f5a524;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.65);
}
[data-theme="dark"] label { color: #b9c6da; }
[data-theme="dark"] .nav-item { color: #b3c0d6; }
[data-theme="dark"] .deal-card .dc-person { color: #a9b6cc; }
[data-theme="dark"] .preset { color: #b3c0d6; }
[data-theme="dark"] .toast { background: #2b3652; }
[data-theme="dark"] .stage-lead { background: rgba(99, 102, 241, 0.22); color: #a5b4fc; }
[data-theme="dark"] .stage-qualified { background: rgba(14, 165, 233, 0.20); color: #7dd3fc; }
[data-theme="dark"] .stage-proposal { background: rgba(245, 158, 11, 0.20); color: #fcd34d; }
[data-theme="dark"] .stage-negotiation { background: rgba(249, 115, 22, 0.20); color: #fdba74; }
[data-theme="dark"] .modal-backdrop { background: rgba(4, 8, 16, 0.65); }
[data-theme="dark"] input::placeholder, [data-theme="dark"] textarea::placeholder { color: #6d7c95; }

/* ---------- Activity timeline (per person / company) ---------- */
.timeline { list-style: none; margin: 0; padding: 14px 18px 18px; position: relative; }
.timeline::before { content: ''; position: absolute; left: 31px; top: 18px; bottom: 22px; width: 2px; background: var(--border); }
.tl-item { display: flex; gap: 12px; padding: 8px 0; position: relative; }
.tl-item .type-chip { z-index: 1; }
.tl-body { flex: 1; min-width: 0; }
.tl-desc { font-size: 13.5px; font-weight: 600; white-space: pre-wrap; word-break: break-word; }
.tl-meta { color: var(--muted); font-size: 12px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.tl-meta .tl-actor { color: var(--brand-text); font-weight: 600; }
.tl-empty { padding: 14px 18px; color: var(--muted); font-size: 13px; }

/* ---------- Teams ---------- */
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.team-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 16px 18px; }
.team-card h3 { margin: 0 0 4px; font-size: 15.5px; font-weight: 700; }
.team-role { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 2px 8px; border-radius: 20px; background: var(--brand-soft); color: var(--brand-text); }
.team-member { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); }
.team-member .avatar { width: 28px; height: 28px; font-size: 11.5px; border-radius: 50%; background: var(--bg); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.team-member .tm-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; }
.team-member .tm-mail { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tm-remove { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.tm-remove:hover { color: var(--danger); background: var(--danger-soft); }
.team-add { display: flex; gap: 8px; margin-top: 12px; }
.team-add input { flex: 1; }

/* ---------- Email automation view ---------- */
.email-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .email-grid { grid-template-columns: 1fr; } }
.email-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); display: inline-block; flex-shrink: 0; }
.status-dot.off { background: var(--danger); }
.email-addr { font-size: 12.5px; color: var(--muted); }
.tpl-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.tpl-row:first-child { border-top: none; }
.tpl-main { flex: 1; min-width: 0; }
.tpl-name { font-size: 13.5px; font-weight: 600; }
.tpl-subj { font-size: 12px; color: var(--muted); margin-top: 1px; }
.tpl-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn-mini { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 13px; padding: 3px 6px; border-radius: 6px; }
.icon-btn-mini:hover { color: var(--brand-text); background: var(--brand-soft); }
.icon-btn-mini.danger:hover { color: var(--danger); background: var(--danger-soft); }
.asg-move { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; cursor: pointer; }
.asg-move input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ---------- Notifications (bell) ---------- */
.bell-wrap { position: relative; }
.bell-btn { position: relative; font-size: 17px; }
.bell-badge { position: absolute; top: 2px; right: 2px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; padding: 0 4px; }
.bell-panel { position: absolute; right: 0; top: calc(100% + 8px); width: 340px; max-height: 440px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg, var(--shadow)); z-index: 60; }
.bell-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.bell-head-btns { display: flex; gap: 4px; }
.bell-readall { background: none; border: none; color: var(--brand-text); font-size: 12px; cursor: pointer; }
.bell-readall:hover { text-decoration: underline; }
.bell-items { max-height: 380px; overflow-y: auto; }
.bell-item { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.bell-item:last-child { border-bottom: none; }
.bell-item:hover { background: var(--bg); }
.bell-item.unread { background: var(--brand-soft); }
.bell-item-ico { font-size: 17px; line-height: 1.2; }
.bell-item-title { font-size: 13px; font-weight: 600; }
.bell-item-body { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bell-item-time { font-size: 11px; color: var(--muted); margin-top: 3px; }
.bell-empty { padding: 22px 12px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Tags ---------- */
.tag-chip { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 20px; border: 1px solid; }
.dc-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.tag-picker-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tag-pick { font-size: 12px; font-weight: 600; padding: 3px 12px; border-radius: 20px; border: 1px solid; background: transparent; cursor: pointer; }
.tag-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.tag-row:last-child { border-bottom: none; }
.tags-new-row { display: flex; gap: 8px; margin-bottom: 12px; }
.tags-new-row input { flex: 1; }
.tags-list { margin-top: 4px; }

/* ---------- Stale deals ---------- */
.stale-badge { display: inline-block; font-size: 11px; font-weight: 700; color: #b45309; background: #fef3c7; border: 1px solid #fcd34d; padding: 2px 8px; border-radius: 20px; margin-bottom: 6px; }
[data-theme="dark"] .stale-badge { color: #fbbf24; background: #78350f33; border-color: #b4530966; }

/* ---------- Reports ---------- */
.rep-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }

/* ---------- Trash ---------- */
.trash-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.trash-row:last-child { border-bottom: none; }
.trash-main { flex: 1; min-width: 0; }
.trash-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Auto-backup ---------- */
.bk-auto { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 14px; }
.bk-auto-on { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 8px 0; cursor: pointer; }
.bk-auto-on input { width: 16px; height: 16px; accent-color: var(--brand); }
.bk-auto-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; }
.bk-auto-row label { display: flex; align-items: center; gap: 6px; }
.rule-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; background: var(--bg); border: 1px solid var(--border); }
.rule-chip.inactive { opacity: .5; }
.ph-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ph { font-family: ui-monospace, monospace; font-size: 11.5px; background: var(--brand-soft); color: var(--brand-text); padding: 2px 8px; border-radius: 6px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; margin-bottom: 6px; }
.check-row:hover { border-color: var(--brand); background: var(--brand-soft); }
.check-row input { width: auto; accent-color: var(--brand); }
.check-row .cr-name { font-size: 13.5px; font-weight: 600; flex: 1; min-width: 0; }
.check-row .cr-mail { font-size: 12px; color: var(--muted); }
.email-preview { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 14px 16px; font-size: 13px; max-height: 260px; overflow: auto; }
.email-preview .ep-subject { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.email-preview .ep-body { white-space: pre-wrap; word-break: break-word; color: var(--text); }
.email-preview .ph-miss { color: var(--danger); font-weight: 600; }
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; }
.log-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.log-status { font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 20px; }
.log-status.sent { background: var(--success-soft); color: var(--success); }
.log-status.failed { background: var(--danger-soft); color: var(--danger); }
.log-status.sending { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.ai-row { display: flex; gap: 8px; margin-bottom: 10px; }
.ai-row input { flex: 1; }

/* ---------- Settings dropdown ---------- */
.settings-wrap { position: relative; }
.settings-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); padding: 6px; min-width: 190px;
  display: flex; flex-direction: column; gap: 2px;
}
.sm-item {
  background: none; border: none; cursor: pointer; text-align: left;
  padding: 9px 12px; font-size: 13.5px; font-weight: 600; color: var(--text); border-radius: 8px;
}
.sm-item:hover { background: var(--brand-soft); color: var(--brand-text); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { width: 74px; }
  .sidebar .logo-name, .sidebar .nav-item span, .sidebar .user-meta, .sidebar .btn span { display: none; }
  .nav-item { justify-content: center; }
  .sidebar-brand { justify-content: center; }
  .sidebar-brand .logo-img { width: 58px; height: 43px; }
  .sidebar-tag { display: none; }
  .user-chip { justify-content: center; }
  .topbar { padding: 0 14px; }
  .content { padding: 14px; }
}

/* ---------- Activity view: mode switch + calendar ---------- */
.mode-switch { display: inline-flex; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; padding: 3px; gap: 2px; }
.mode-btn { border: none; background: transparent; padding: 7px 14px; font-size: 13px; font-weight: 600; color: var(--muted); border-radius: 7px; }
.mode-btn.active { background: var(--brand-soft); color: var(--brand-text); }

.pipe-toolbar { display: flex; align-items: center; gap: 12px; margin: -6px 0 14px; }
.pipe-toolbar input { width: 230px; padding: 8px 12px; font-size: 13px; }

/* Contacts tab */
.type-badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.type-badge.person { background: var(--brand-soft); color: var(--brand-text); }
.type-badge.company { background: var(--success-soft); color: var(--success); }

/* Automation rules */
.auto-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.auto-row:last-child { border-bottom: none; }
.auto-row.inactive { opacity: .55; }
.auto-main { flex: 1; min-width: 0; }
.auto-name { font-weight: 700; font-size: 13.5px; }
.auto-act { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.auto-actions { display: flex; gap: 4px; flex-shrink: 0; }
.auto-hint {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
  border-radius: 12px; padding: 12px 16px; margin: 0 0 16px;
  font-size: 13px; line-height: 1.5;
}
.auto-hint strong { color: var(--brand-text); display: block; margin-bottom: 2px; }

.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.cal-head h3 { margin: 0; font-size: 15px; }
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-wrap { padding: 12px 14px 14px; }
.cal-dow, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { margin-bottom: 6px; }
.cal-dow div { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.cal-cell { min-height: 84px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; cursor: pointer; background: var(--surface); overflow: hidden; }
.cal-cell:hover { border-color: var(--brand); }
.cal-cell.out { opacity: .45; }
.cal-cell.today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.cal-num { font-size: 11.5px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.cal-cell.today .cal-num { color: var(--brand-text); }
.cal-chips { display: flex; flex-direction: column; gap: 3px; }
.cal-chip { display: flex; align-items: center; gap: 4px; border: none; background: var(--bg); border-radius: 6px; padding: 2.5px 6px; font-size: 11px; font-weight: 600; text-align: left; color: var(--text); max-width: 100%; }
.cal-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip.done { text-decoration: line-through; opacity: .55; }
.cal-chip.overdue { color: var(--danger); }
.cal-more { border: none; background: transparent; padding: 0 6px; font-size: 11px; font-weight: 700; color: var(--brand-text); text-align: left; }
.cal-day-panel { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.cal-day-head { font-size: 12.5px; font-weight: 700; margin-bottom: 8px; }
.cal-day-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.cdi-desc { flex: 1; font-size: 13px; }
.cdi-desc.done { text-decoration: line-through; opacity: .6; }
.act-edit { flex-shrink: 0; opacity: .7; }
.act-edit:hover { opacity: 1; }
.act-row[data-edit-row] { cursor: pointer; }
.act-row[data-edit-row]:hover { background: var(--surface-2); border-radius: 8px; }
@media (max-width: 720px) {
  .cal-cell { min-height: 62px; padding: 4px; }
  .cal-chip span { display: none; }
}

/* ---------- User management ---------- */
.modal-wide { max-width: 720px; }
.users-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: none; }
.user-row.off { opacity: .55; }
.user-id { flex: 1; min-width: 0; }
.user-badges { display: inline-flex; gap: 5px; margin-left: 8px; vertical-align: 1px; flex-wrap: wrap; }
.badge-admin { background: var(--brand-soft); color: var(--brand-text); }
.badge-manager { background: var(--accent-soft, rgba(120,144,255,.18)); color: var(--accent-text, inherit); border: 1px solid var(--border); }
.badge-member { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.badge-off { background: var(--bg); color: var(--muted); border: 1px dashed var(--border-strong); }
.user-mail { font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 9px; }
.btn-sm-danger { background: transparent; border-color: var(--border-strong); color: var(--danger); }
.btn-sm-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.new-user-card { margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: 16px; }
.new-user-card .fb-label { margin-bottom: 12px; }
.new-user-card form .grid-2 { margin-bottom: 12px; }
.pw-for { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
@media (max-width: 720px) {
  .user-row { flex-wrap: wrap; }
  .user-actions { width: 100%; justify-content: flex-start; }
}

/* ---------- Dashboard overdue banner ---------- */
.dash-banner { background: #fef3c7; color: #b45309; border: 1px solid #f5d9a8; border-radius: var(--radius); margin-bottom: 14px; cursor: pointer; font-weight: 600; font-size: 13.5px; padding: 10px 14px; }

/* ---------- Calendar team legend + owner labels ---------- */
.cal-legend-row { display: flex; gap: 12px; flex-wrap: wrap; padding: 4px 14px 10px; }
.cal-legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.cal-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.act-owner, .cdi-owner { font-weight: 600; font-size: 12px; }

/* ---------- Inbox ---------- */
.inbox-row { display: flex; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: center; }
.inbox-row:hover { background: var(--surface-2); }
.inbox-row.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.inbox-row:last-child { border-bottom: none; }
.inbox-wrap { display: grid; grid-template-columns: minmax(340px, 42%) 1fr; gap: 16px; align-items: start; }
#inbox-list .inbox-panel { max-height: calc(100vh - 250px); overflow-y: auto; }
.inbox-preview { min-height: 180px; padding: 16px 18px; }
.inbox-preview-head { border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 12px; }
.inbox-preview-subj { font-size: 16px; font-weight: 700; margin: 0 0 8px; line-height: 1.35; }
.inbox-preview-body { max-height: 52vh; overflow-y: auto; }
.inbox-preview-actions { margin-top: 14px; display: flex; gap: 8px; }
.inbox-preview-empty { color: var(--muted); text-align: center; padding: 32px 16px; font-size: 13.5px; }
.inbox-html-sm { min-height: 180px; max-height: 46vh; }

/* ---- AI Pre-Call Briefing: floating (non-blocking) panel ---- */
.briefing-float { position: fixed; right: 18px; bottom: 76px; width: min(430px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 14px 44px rgba(0, 0, 0, .28); z-index: 70; display: flex; flex-direction: column; }
.briefing-float.hidden { display: none !important; }
.bf-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.bf-head strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bf-head-btns { display: flex; gap: 4px; flex-shrink: 0; }
.bf-scroll { max-height: 46vh; overflow-y: auto; padding: 12px 16px; }
.bf-notes { border-top: 1px solid var(--border); padding: 10px 12px; }
.bf-notes textarea { width: 100%; resize: vertical; min-height: 44px; }
.bf-notes-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.briefing-float.collapsed { width: auto; }
.briefing-float.collapsed .bf-scroll, .briefing-float.collapsed .bf-notes { display: none; }
@media (max-width: 900px) {
  .inbox-wrap { grid-template-columns: 1fr; }
  #inbox-list .inbox-panel { max-height: 50vh; }
}
.inbox-date { width: 90px; flex-shrink: 0; font-size: 12.5px; color: var(--muted); }
.inbox-from { width: 180px; flex-shrink: 0; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-subj { flex: 1; min-width: 0; font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-text { white-space: pre-wrap; word-break: break-word; margin: 0; font-family: inherit; font-size: 13.5px; line-height: 1.55; }
.inbox-html { width: 100%; min-height: 300px; max-height: 60vh; border: none; background: #fff; }
.att-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 10px; font-size: 12.5px; margin: 4px 6px 0 0; }
.att-chip button { border: none; background: none; cursor: pointer; color: var(--muted); }
.compose-attach { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.compose-attlist { margin-top: 4px; }

/* ---------- Team color swatches ---------- */
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }

.twofa-qr { display: flex; justify-content: center; margin: 8px 0 12px; }
.twofa-secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; letter-spacing: .5px; }

/* ---------- Search shortcut hint ---------- */
.search-kbd {
  position: absolute;
  right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 11px;
  font-family: inherit;
  color: var(--muted, #8a8f98);
  border: 1px solid var(--border, #3a3f4a);
  border-radius: 5px;
  padding: 1px 7px;
  background: var(--surface, transparent);
  pointer-events: none;
  white-space: nowrap;
}
.search input { padding-right: 64px; }
@media (max-width: 640px) { .search-kbd { display: none; } .search input { padding-right: 12px; } }

/* ---------- Customer timeline (360°) ---------- */
.tl-list { display: flex; flex-direction: column; gap: 0; max-height: 60vh; overflow-y: auto; padding-right: 4px; }
.tl-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border, rgba(128,128,128,.15));
}
.tl-item:last-child { border-bottom: none; }
.tl-item.done .tl-title { opacity: .65; }
.tl-icon {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  background: var(--bg-soft, rgba(128,128,128,.12));
}
.tl-main { flex: 1; min-width: 0; }
.tl-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-sub { font-size: 12px; opacity: .75; margin-top: 2px; }
.tl-date { flex: none; font-size: 12px; opacity: .7; white-space: nowrap; padding-top: 2px; }
@media (max-width: 480px) { .tl-date { display: none; } }

/* ---------- Backup ---------- */
.bk-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border, rgba(128,128,128,.18));
  border-radius: 10px;
  margin-bottom: 8px;
}
.bk-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bk-acts { flex: none; display: flex; gap: 6px; }

/* ---------- Contacts toolbar (search + filters) ---------- */
.cont-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.cont-toolbar input[type="search"] {
  flex: 1;
  min-width: 200px;
  max-width: 380px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.cont-toolbar select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.cont-toolbar .mode-btn { cursor: pointer; }

/* AI source switch (local bridge vs server) — always visible in the AI panel head */
.ai-source {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 9px 14px; border-bottom: 1px solid var(--border);
  font-size: 12px; background: var(--surface-2, var(--bg));
}
.ai-src { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; overflow: hidden; }
.ai-src button {
  border: 0; background: transparent; padding: 6px 11px; font: inherit; font-size: 12px;
  color: var(--text); cursor: pointer; line-height: 1; white-space: nowrap;
}
.ai-src button + button { border-left: 1px solid var(--border-strong); }
.ai-src button.on { background: var(--brand); color: #fff; }
.ai-src-status { font-weight: 600; }
.ai-src-status.ok { color: var(--success); }
.ai-src-status.warn { color: #d97706; }
.ai-reload {
  margin-left: auto; border: 1px solid var(--border-strong); background: transparent;
  border-radius: 7px; padding: 5px 9px; cursor: pointer; font: inherit; font-size: 12px; color: var(--brand-text);
}
.ai-reload:hover { background: var(--brand-soft); }
.ai-src-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.ai-src-section .fb-label { display: block; margin-bottom: 8px; }
.ai-source-settings { border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); }

/* ---------------- Pipeline stages (admin) ---------------- */

/* ---------------- Combined email settings (SMTP + IMAP) ---------------- */

/* ---------------- AI markdown output ---------------- */
.ai-md { line-height: 1.55; word-wrap: break-word; }
.ai-md ul { margin: 4px 0 10px; padding-left: 20px; }
.ai-md li { margin: 2px 0; }
.ai-md strong { font-weight: 700; }
.md-h { font-weight: 700; margin: 10px 0 4px; font-size: 13.5px; }
.md-h:first-child { margin-top: 0; }

.es-section { padding: 16px 0; border-bottom: 1px solid var(--border); }
.es-section:first-child { padding-top: 2px; }
.es-section:last-child { border-bottom: none; padding-bottom: 2px; }
.es-section-head { font-weight: 700; font-size: 13.5px; margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }

.stage-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 8px; background: var(--surface-2);
}
.stage-row.off { opacity: .6; }
.stage-dot { width: 16px; height: 16px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.18); }
.stage-label { flex: 1; min-width: 90px; padding: 8px 10px; }
.stage-color { width: 42px; height: 38px; padding: 2px; cursor: pointer; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); flex: none; }
.stage-flag { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; flex: none; cursor: pointer; }
.stage-flag input { width: 15px; height: 15px; margin: 0; padding: 0; border: none; accent-color: var(--brand); cursor: pointer; flex: none; }
.stage-hidden-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface); border: 1px dashed var(--border-strong); color: var(--muted); flex: none; }
.stage-acts { display: flex; gap: 4px; margin-left: auto; flex: none; }
.stg-add { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.stg-add input[type="text"] { flex: 1; min-width: 140px; }
@media (max-width: 620px) {
  .stage-row { flex-wrap: wrap; }
  .stage-acts { width: 100%; justify-content: flex-start; margin-left: 0; }
}
