/* ============================================================
   Summit Group Wholesale CRM — Stylesheet
   Brand: Navy #1B2A4A · Blue #2E75B6 · Bg #F0F2F5
============================================================ */

:root {
  --navy: #1B2A4A;
  --navy-2: #233459;
  --blue: #2E75B6;
  --blue-2: #2462a0;
  --green: #548235;
  --orange: #ED7D31;
  --red: #C00000;
  --purple: #7030A0;
  --teal: #2F9599;
  --bg: #F0F2F5;
  --card: #ffffff;
  --border: #e2e6ed;
  --text: #1a1f2c;
  --text-dim: #5a6477;
  --text-faint: #8b94a6;
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08);
  --shadow-lg: 0 8px 24px rgba(15,23,42,.12);
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--navy);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-mark {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .5px;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .2px;
}

.brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,.6);
  text-transform: uppercase;
  letter-spacing: .8px;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 2px;
  overflow-y: auto;
}

.sidebar-footer {
  padding: 8px 8px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-version {
  text-align: center;
  font-size: 11px;
  color: rgba(255,255,255,.4);
  margin-top: 8px;
}

.nav-item {
  display: block;
  padding: 9px 12px;
  border-radius: 6px;
  color: rgba(255,255,255,.78);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}

.nav-item:hover {
  background: rgba(255,255,255,.06);
  color: #ffffff;
}

.nav-item.active {
  background: var(--blue);
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

/* ---------- Main / topbar ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  color: var(--navy);
}

.page-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  gap: 8px;
}

.view {
  padding: 24px 28px 60px;
}

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger, .btn-outline {
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover { background: var(--blue-2); }

.btn-secondary {
  background: var(--navy);
  color: #fff;
}
.btn-secondary:hover { background: var(--navy-2); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover { background: rgba(0,0,0,.05); color: var(--text); }

.btn-outline {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--blue); color: var(--blue); }

.btn-danger {
  background: #fff;
  color: var(--red);
  border: 1px solid #f3c5c5;
}
.btn-danger:hover { background: #fff3f3; }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card-flush {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: .3px;
  text-transform: uppercase;
}

/* Colored section band header (matches existing dashboard) */
.section-title {
  padding: 11px 16px;
  border-radius: 6px 6px 0 0;
  font-weight: 600;
  color: #fff;
  font-size: 13px;
  letter-spacing: .4px;
}

.section-body {
  background: var(--card);
  border-radius: 0 0 6px 6px;
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

/* ---------- KPI grid ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  border: 2px solid transparent;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.kpi-card .label {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
}

.kpi-card .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
  margin-top: 4px;
  line-height: 1.1;
}

.kpi-card .delta {
  font-size: 11px;
  margin-top: 6px;
  color: var(--text-dim);
}

.kpi-card.accent-blue   { border-top: 3px solid var(--blue); }
.kpi-card.accent-green  { border-top: 3px solid var(--green); }
.kpi-card.accent-orange { border-top: 3px solid var(--orange); }
.kpi-card.accent-purple { border-top: 3px solid var(--purple); }
.kpi-card.accent-teal   { border-top: 3px solid var(--teal); }
.kpi-card.accent-red    { border-top: 3px solid var(--red); }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tbl thead th {
  text-align: left;
  background: #f8fafc;
  color: var(--text-dim);
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.tbl tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tbl tbody tr:hover {
  background: #f8fafc;
}

.tbl tbody tr.clickable {
  cursor: pointer;
}

.tbl .empty {
  text-align: center;
  color: var(--text-faint);
  padding: 30px;
  font-style: italic;
}

.tbl .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- Pills / badges ---------- */
.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
  background: #eef1f6;
  color: var(--text-dim);
  white-space: nowrap;
}

.pill.blue   { background: #e3eef9; color: var(--blue-2); }
.pill.green  { background: #e5f1da; color: var(--green); }
.pill.orange { background: #fce6d3; color: var(--orange); }
.pill.red    { background: #f8d7d7; color: var(--red); }
.pill.purple { background: #ece0f3; color: var(--purple); }
.pill.gray   { background: #eef1f6; color: var(--text-dim); }
.pill.teal   { background: #d8eced; color: var(--teal); }

/* ---------- Filter / toolbar row ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.toolbar input[type="search"],
.toolbar select,
.toolbar input[type="text"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  background: #fff;
  min-width: 180px;
}

.toolbar input:focus, .toolbar select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46,117,182,.15);
}

.toolbar .spacer { flex: 1; }

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.form-grid .col-2 { grid-column: span 2; }

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.form-field input,
.form-field select,
.form-field textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fff;
  font-family: inherit;
}

.form-field textarea { resize: vertical; min-height: 80px; }

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46,117,182,.15);
}

/* ---------- Modal ---------- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-root.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .55);
}

.modal-panel {
  position: relative;
  background: #fff;
  border-radius: 10px;
  width: min(720px, 92vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: pop .15s ease-out;
}

@keyframes pop {
  from { transform: scale(.97); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-dim);
  line-height: 1;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toast-in .2s ease-out;
}

.toast.hidden { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------- Pipeline kanban ---------- */
.kanban {
  display: grid;
  grid-template-columns: repeat(6, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
}

.kanban-col {
  background: #f4f6fa;
  border-radius: var(--radius);
  padding: 10px;
  min-height: 200px;
}

.kanban-col-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-dim);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kanban-col-title .count {
  background: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-dim);
}

.kanban-card {
  background: #fff;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--blue);
}

.kanban-card:hover { box-shadow: var(--shadow-md); }

.kanban-card .title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
}

.kanban-card .meta {
  font-size: 11px;
  color: var(--text-dim);
}

/* ---------- Empty state ---------- */
.empty-state {
  background: #fff;
  border-radius: var(--radius);
  padding: 60px 24px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.empty-state .icon {
  font-size: 42px;
  margin-bottom: 10px;
  opacity: .4;
}

.empty-state h3 {
  margin: 0 0 6px;
  color: var(--navy);
}

.empty-state p {
  color: var(--text-dim);
  margin: 0 0 16px;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- Stat row (compact) ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat {
  background: #fff;
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.stat .label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}

.stat .value {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  margin-top: 2px;
}

/* ---------- Detail layout ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

.detail-list dt {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-top: 8px;
}

.detail-list dd {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

/* ---------- Two column layout ---------- */
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 1100px) {
  .row-2 { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .col-2 { grid-column: span 1; }
}

/* ============================================================
   Conversations module
============================================================ */
.conv-shell {
  display: grid;
  grid-template-columns: 320px 1fr 320px;
  gap: 0;
  height: calc(100vh - 145px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

@media (max-width: 1280px) {
  .conv-shell { grid-template-columns: 280px 1fr 280px; }
}
@media (max-width: 1000px) {
  .conv-shell { grid-template-columns: 240px 1fr; }
  .conv-context { display: none; }
}

/* Left list */
.conv-list {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: #fbfcfe;
}

.conv-list-head {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.conv-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  margin-bottom: 8px;
}

.conv-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.conv-filter-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-dim);
}
.conv-filter-btn.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.conv-list-scroll {
  flex: 1;
  overflow-y: auto;
}

.conv-list-foot {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: #fff;
}
.conv-list-foot .btn-primary { width: 100%; justify-content: center; }

.conv-row {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  align-items: center;
  transition: background .12s ease;
}
.conv-row:hover { background: rgba(46,117,182,.05); }
.conv-row.active { background: rgba(46,117,182,.10); }
.conv-row.unread .conv-name { color: var(--navy); font-weight: 700; }

.conv-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.conv-row-main { min-width: 0; }
.conv-row-top {
  display: flex; justify-content: space-between; gap: 6px;
  font-size: 13px; font-weight: 600;
  color: var(--text);
}
.conv-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--text-faint); font-size: 11px; font-weight: 500; flex-shrink: 0; }
.conv-preview {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-meta { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }

.conv-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 600;
  background: #eef1f6; color: var(--text-dim);
}
.conv-tag.red    { background: #f8d7d7; color: var(--red); }
.conv-tag.blue   { background: #e3eef9; color: var(--blue-2); }
.conv-tag.green  { background: #e5f1da; color: var(--green); }
.conv-tag.orange { background: #fce6d3; color: var(--orange); }
.conv-tag.purple { background: #ece0f3; color: var(--purple); }

.conv-badge {
  background: var(--blue);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 7px;
  align-self: flex-start;
}

/* Tag toggle in tag menu */
.conv-tag-toggle {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
}
.conv-tag-toggle.on {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* Middle thread */
.conv-thread {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #fff;
}

.thread-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}
.thread-name { font-weight: 700; color: var(--navy); font-size: 15px; }
.thread-sub { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.thread-actions { display: flex; gap: 4px; }

.thread-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px;
  background: #f6f8fb;
}

.msg-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
  max-width: 70%;
}
.msg-row.in { align-self: flex-start; align-items: flex-start; }
.msg-row.out { align-self: flex-end; align-items: flex-end; margin-left: auto; }

.msg-bubble {
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble-in {
  background: #e9eaee;
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.bubble-out {
  background: linear-gradient(180deg, #2E75B6, #2462a0);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-meta {
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 3px;
  padding: 0 4px;
}
.msg-status { margin-left: 6px; color: var(--orange); text-transform: capitalize; }
.msg-status.failed { color: var(--red); }
.msg-status.pending { color: var(--text-faint); }

.msg-media a { color: inherit; text-decoration: underline; }
.bubble-in .msg-media a { color: var(--blue); }

.thread-compose {
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 10px 14px 12px;
}
.compose-templates {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.compose-templates select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  background: #fff;
}
.compose-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: flex-end;
}
.compose-row textarea {
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  min-height: 42px;
}
.compose-row textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46,117,182,.15);
}
.compose-foot {
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
}

/* Right context */
.conv-context {
  background: #fbfcfe;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
}
.ctx-section {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.ctx-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-dim);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ctx-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
}
.ctx-key { color: var(--text-dim); font-size: 12px; }

.muted { color: var(--text-dim); }
.hidden { display: none !important; }
.text-right { text-align: right; }
.text-num { font-variant-numeric: tabular-nums; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }

/* Utility */
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
