/* ── Theme System ──────────────────────────────────────────────────────── */

:root {
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --sidebar-width: 52px;
  --sidebar-expanded: 220px;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --text-always-white: #ffffff;
}

/* ── Light Theme (default) ─────────────────────────────────────────────── */

:root, [data-theme="light"] {
  --bg-body:          #f2f2f7;
  --bg-card:          #ffffff;
  --bg-card-solid:    #ffffff;
  --bg-hover:         rgba(0, 0, 0, 0.04);
  --bg-input:         rgba(0, 0, 0, 0.03);
  --bg-sidebar:       #e8e8ed;
  --bg-sidebar-item:  rgba(0, 0, 0, 0.05);
  --bg-sidebar-active:#007aff;

  --border:           rgba(0, 0, 0, 0.08);
  --border-subtle:    rgba(0, 0, 0, 0.04);

  --text-primary:     #1c1c1e;
  --text-secondary:   #3c3c43;
  --text-muted:       #8e8e93;

  --blue:             #007aff;
  --green:            #34c759;
  --amber:            #ff9500;
  --red:              #ff3b30;
  --purple:           #af52de;
  --teal:             #32ade6;
  --pink:             #ff2d55;

  --blue-bg:          rgba(0, 122, 255, 0.10);
  --green-bg:         rgba(52, 199, 89, 0.10);
  --amber-bg:         rgba(255, 149, 0, 0.10);
  --red-bg:           rgba(255, 59, 48, 0.10);
  --purple-bg:        rgba(175, 82, 222, 0.10);
  --teal-bg:          rgba(50, 173, 230, 0.10);

  --shadow:           0 1px 3px rgba(0,0,0,0.08), 0 0 0 0.5px rgba(0,0,0,0.04);
  --card-shadow:      0 1px 3px rgba(0,0,0,0.08), 0 0 0 0.5px rgba(0,0,0,0.04);

  --nav-bg:           #e8e8ed;
  --nav-text:         #3c3c43;
  --nav-active-border:#007aff;
  --scrollbar-thumb:  rgba(0,0,0,0.15);
  --scrollbar-thumb-hover: rgba(0,0,0,0.25);
}

/* ── Dark Theme ────────────────────────────────────────────────────────── */

[data-theme="dark"] {
  --bg-body:          #000000;
  --bg-card:          rgba(255, 255, 255, 0.04);
  --bg-card-solid:    #1c1c1e;
  --bg-hover:         rgba(255, 255, 255, 0.07);
  --bg-input:         rgba(255, 255, 255, 0.06);
  --bg-sidebar:       #111111;
  --bg-sidebar-item:  rgba(255, 255, 255, 0.06);
  --bg-sidebar-active:#0a84ff;

  --border:           rgba(255, 255, 255, 0.08);
  --border-subtle:    rgba(255, 255, 255, 0.05);

  --text-primary:     #ffffff;
  --text-secondary:   rgba(255, 255, 255, 0.55);
  --text-muted:       rgba(255, 255, 255, 0.30);

  --blue:             #0a84ff;
  --green:            #30d158;
  --amber:            #ff9f0a;
  --red:              #ff453a;
  --purple:           #bf5af2;
  --teal:             #64d2ff;
  --pink:             #ff375f;

  --blue-bg:          rgba(10, 132, 255, 0.12);
  --green-bg:         rgba(48, 209, 88, 0.12);
  --amber-bg:         rgba(255, 159, 10, 0.12);
  --red-bg:           rgba(255, 69, 58, 0.12);
  --purple-bg:        rgba(191, 90, 242, 0.12);
  --teal-bg:          rgba(100, 210, 255, 0.12);

  --shadow:           none;
  --card-shadow:      none;

  --nav-bg:           #111111;
  --nav-text:         rgba(255, 255, 255, 0.65);
  --nav-active-border:#0a84ff;
  --scrollbar-thumb:  rgba(255,255,255,0.12);
  --scrollbar-thumb-hover: rgba(255,255,255,0.25);
}

/* ── System preference (when data-theme="system" or absent) ────────────── */

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg-body:          #000000;
    --bg-card:          rgba(255, 255, 255, 0.04);
    --bg-card-solid:    #1c1c1e;
    --bg-hover:         rgba(255, 255, 255, 0.07);
    --bg-input:         rgba(255, 255, 255, 0.06);
    --bg-sidebar:       #111111;
    --bg-sidebar-item:  rgba(255, 255, 255, 0.06);
    --bg-sidebar-active:#0a84ff;

    --border:           rgba(255, 255, 255, 0.08);
    --border-subtle:    rgba(255, 255, 255, 0.05);

    --text-primary:     #ffffff;
    --text-secondary:   rgba(255, 255, 255, 0.55);
    --text-muted:       rgba(255, 255, 255, 0.30);

    --blue:             #0a84ff;
    --green:            #30d158;
    --amber:            #ff9f0a;
    --red:              #ff453a;
    --purple:           #bf5af2;
    --teal:             #64d2ff;
    --pink:             #ff375f;

    --blue-bg:          rgba(10, 132, 255, 0.12);
    --green-bg:         rgba(48, 209, 88, 0.12);
    --amber-bg:         rgba(255, 159, 10, 0.12);
    --red-bg:           rgba(255, 69, 58, 0.12);
    --purple-bg:        rgba(191, 90, 242, 0.12);
    --teal-bg:          rgba(100, 210, 255, 0.12);

    --shadow:           none;
    --card-shadow:      none;

    --nav-bg:           #111111;
    --nav-text:         rgba(255, 255, 255, 0.65);
    --nav-active-border:#0a84ff;
    --scrollbar-thumb:  rgba(255,255,255,0.12);
    --scrollbar-thumb-hover: rgba(255,255,255,0.25);
  }
}

[x-cloak] { display: none !important; }

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--blue);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ── Scrollbar ──────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-body);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Top Nav ────────────────────────────────────────────────────────────── */

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-nav__brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.top-nav__brand span {
  color: var(--blue);
}

.top-nav__links {
  display: flex;
  gap: 4px;
}
.top-nav__links a {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.top-nav__links a:hover,
.top-nav__links a.active {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.top-nav__right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ── Period Selector ────────────────────────────────────────────────────── */

.period-selector {
  display: inline-flex;
  background: var(--bg-body);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.period-selector button {
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.period-selector button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.period-selector button.active {
  background: var(--blue);
  color: var(--text-always-white);
}

/* ── Avatar ─────────────────────────────────────────────────────────────── */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--purple-bg);
  color: var(--purple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

/* ── Theme Toggle ──────────────────────────────────────────────────────── */

.theme-toggle {
  display: flex;
  align-items: center;
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.theme-toggle__btn {
  padding: 5px 8px;
  font-size: 14px;
  line-height: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.theme-toggle__btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.theme-toggle__btn.active {
  background: var(--blue-bg);
  color: var(--blue);
}

/* ── Pagination ────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.pagination__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.pagination__btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.pagination__btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.pagination__btn.active {
  background: var(--blue);
  color: var(--text-always-white);
  border-color: var(--blue);
}
.pagination__info {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 8px;
}

/* ── KPI Cards ──────────────────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  padding: 24px;
}

@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(12px) saturate(180%);
  transition: transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--border);
}
.kpi-card--green::before  { background: var(--green); }
.kpi-card--blue::before   { background: var(--blue); }
.kpi-card--amber::before  { background: var(--amber); }
.kpi-card--red::before    { background: var(--red); }
.kpi-card--purple::before { background: var(--purple); }
.kpi-card--teal::before   { background: var(--teal); }

.kpi-card__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.kpi-card__value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  letter-spacing: -0.5px;
}

.kpi-card__trend {
  font-size: 12px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.kpi-card__trend--up { color: var(--green); }
.kpi-card__trend--down { color: var(--red); }
.kpi-card__trend--flat { color: var(--text-muted); }

/* ── Cards / Panels ─────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(12px) saturate(180%);
}

.card__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.card__body {
  padding: 20px;
}

/* ── Dual Grid ──────────────────────────────────────────────────────────── */

.dual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 24px 24px;
}

@media (max-width: 768px) {
  .dual-grid { grid-template-columns: 1fr; }
}

/* ── Funnel ─────────────────────────────────────────────────────────────── */

.funnel-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.funnel-item:last-child { margin-bottom: 0; }

.funnel-item__label {
  width: 110px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: right;
}

.funnel-item__bar-wrapper {
  flex: 1;
  background: var(--bg-body);
  border-radius: 4px;
  height: 28px;
  overflow: hidden;
  position: relative;
}

.funnel-item__bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
  display: flex;
  align-items: center;
  padding-left: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-always-white, #fff);
  min-width: 32px;
}

.funnel-item__bar--blue   { background: var(--blue); }
.funnel-item__bar--green  { background: var(--green); color: var(--bg-body); }
.funnel-item__bar--purple { background: var(--purple); }
.funnel-item__bar--amber  { background: var(--amber); color: var(--bg-body); }
.funnel-item__bar--teal   { background: var(--teal); color: var(--bg-body); }
.funnel-item__bar--red    { background: var(--red); }

.funnel-item__value {
  width: 45px;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
}

/* ── Attention Items ────────────────────────────────────────────────────── */

.attention-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-left: 3px solid var(--border);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.attention-item:last-child { border-bottom: none; }
.attention-item:hover { background: var(--bg-hover); }

.attention-item--critical { border-left-color: var(--red); }
.attention-item--warning  { border-left-color: var(--amber); }
.attention-item--info     { border-left-color: var(--blue); }

.attention-item__content {
  flex: 1;
}

.attention-item__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.attention-item__desc {
  font-size: 12px;
  color: var(--text-secondary);
}

.attention-item__count {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-right: 12px;
  min-width: 36px;
  text-align: center;
}

.attention-item__action {
  margin-left: 12px;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn--ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn--primary {
  background: var(--blue);
  color: var(--text-always-white);
}
.btn--primary:hover {
  background: var(--blue);
  opacity: 0.85;
}

.btn--sm {
  padding: 4px 10px;
  font-size: 11px;
}

/* ── CRM Layout ─────────────────────────────────────────────────────────── */

.crm-layout {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* ── CRM Sidebar ────────────────────────────────────────────────────────── */

.crm-sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
}

.crm-sidebar__nav {
  flex: 1;
}

.crm-sidebar__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.crm-sidebar__item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.crm-sidebar__item.active {
  background: var(--bg-hover);
  color: var(--blue);
  border-right: 2px solid var(--blue);
}

.crm-sidebar__icon {
  width: 18px;
  text-align: center;
  font-size: 14px;
}

/* ── Sidebar collapsible groups ─────────────────────────────────────── */

.crm-sidebar__group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: color var(--transition);
}
.crm-sidebar__group-toggle:hover {
  color: var(--text-secondary);
}

.crm-sidebar__chevron {
  font-size: 10px;
  transition: transform 0.2s ease;
  display: inline-block;
}
.crm-sidebar__chevron.open {
  transform: rotate(90deg);
}

.crm-sidebar__group-label {}

.crm-sidebar__group-items {
  overflow: hidden;
}

/* ── Sidebar focus styles (keyboard accessibility) ─────────────────── */

.crm-sidebar__item:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
  background: var(--bg-hover);
  color: var(--text-primary);
}

.crm-sidebar__group-toggle:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.crm-sidebar__divider {
  height: 1px;
  background: var(--border);
  margin: 12px 16px;
}

.crm-sidebar__footer {
  padding: 0 16px;
}

/* ── CRM Middle Panel ───────────────────────────────────────────────────── */

.crm-middle {
  width: 380px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.crm-middle__header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.crm-middle__title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}
.search-input::placeholder {
  color: var(--text-muted);
}

.filter-select {
  width: 100%;
  padding: 6px 10px;
  margin-top: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}
.filter-select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.filter-toggle input[type="checkbox"] {
  accent-color: var(--blue);
}

.crm-middle__filters {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.filter-select {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
.filter-select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}
.filter-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.crm-middle__list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* ── List Cards ─────────────────────────────────────────────────────────── */

.list-card {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.list-card:hover {
  background: var(--bg-hover);
}
.list-card.selected {
  background: var(--bg-hover);
  border-color: var(--blue);
}

.list-card__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.list-card__meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.list-card__meta span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

/* ── Badges ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}

.badge--green  { background: var(--green-bg); color: var(--green); }
.badge--blue   { background: var(--blue-bg); color: var(--blue); }
.badge--amber  { background: var(--amber-bg); color: var(--amber); }
.badge--red    { background: var(--red-bg); color: var(--red); }
.badge--purple { background: var(--purple-bg); color: var(--purple); }
.badge--teal   { background: var(--teal-bg); color: var(--teal); }
.badge--muted  { background: var(--bg-hover); color: var(--text-muted); }

/* ── CRM Detail Panel ──────────────────────────────────────────────────── */

.crm-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.crm-detail__header {
  padding: 20px 24px 0;
}

.crm-detail__name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.crm-detail__subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* ── Tabs ───────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}

.tabs__item {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tabs__item:hover {
  color: var(--text-primary);
}
.tabs__item.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── Overview Cards ─────────────────────────────────────────────────────── */

.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.overview-card {
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.overview-card__title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.overview-card__row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}
.overview-card__row .label {
  color: var(--text-secondary);
}
.overview-card__row .value {
  color: var(--text-primary);
  font-weight: 500;
}

/* ── Progress Bar ───────────────────────────────────────────────────────── */

.progress-bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar__fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}
.progress-bar__fill--green  { background: var(--green); }
.progress-bar__fill--blue   { background: var(--blue); }
.progress-bar__fill--amber  { background: var(--amber); }

/* ── Timeline ───────────────────────────────────────────────────────────── */

.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  margin-bottom: 20px;
}
.timeline-item:last-child { margin-bottom: 0; }

.timeline-item__dot {
  position: absolute;
  left: -20px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.timeline-item__dot--inbound  { background: var(--blue); }
.timeline-item__dot--outbound { background: var(--green); }
.timeline-item__dot--system   { background: var(--purple); }

.timeline-item__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.timeline-item__source {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.timeline-item__channel {
  font-size: 11px;
  color: var(--text-muted);
}

.timeline-item__time {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}

.timeline-item__content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ── Session Cards ────────────────────────────────────────────────────── */

.session-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.session-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.session-card--scheduled { border-left-color: var(--amber); }
.session-card--reply_handler { border-left-color: var(--purple); }
.session-card--general   { border-left-color: var(--blue); }

.session-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.session-card__badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.session-card__type-badge {
  background: var(--amber);
  color: var(--text-always-white);
}
.session-card--general .session-card__type-badge {
  background: var(--blue);
}
.session-card--reply_handler .session-card__type-badge {
  background: var(--purple);
}
.session-card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}
.session-card__actor {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 12px;
}
.session-card__count {
  white-space: nowrap;
}
.session-card__chevron {
  font-size: 10px;
  transition: transform 0.2s;
  display: inline-block;
}
.session-card__chevron--open {
  transform: rotate(180deg);
}

.session-card__time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Expanded messages inside a session — WhatsApp-style bubbles */
.session-card__messages {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.session-msg {
  position: relative;
  padding: 8px 12px;
  font-size: 13px;
  max-width: 80%;
  line-height: 1.5;
}
.session-msg__label {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 2px;
}

/* Bot / outbound — left-aligned, green-tinted */
.session-msg--out {
  align-self: flex-start;
  background: rgba(37, 211, 102, 0.10);
  border-radius: 2px 12px 12px 12px;
  margin-left: 8px;
}
.session-msg--out .session-msg__label { color: var(--green, #25d366); }
.session-msg--out::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 0;
  width: 0;
  height: 0;
  border-top: 6px solid rgba(37, 211, 102, 0.10);
  border-left: 6px solid transparent;
}

/* Customer / inbound — right-aligned, neutral */
.session-msg--in {
  align-self: flex-end;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px 2px 12px 12px;
  margin-right: 8px;
}
.session-msg--in .session-msg__label { color: var(--blue); }
.session-msg--in::before {
  content: '';
  position: absolute;
  right: -6px;
  top: 0;
  width: 0;
  height: 0;
  border-top: 6px solid var(--border);
  border-right: 6px solid transparent;
}

.session-msg__content {
  word-break: break-word;
}
.session-msg__time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.badge--muted {
  background: var(--border);
  color: var(--text-muted);
}

/* ── Timeline Attachments ──────────────────────────────────────────────── */

.timeline-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.timeline-attachment-img {
  max-width: 120px;
  max-height: 120px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  object-fit: cover;
  border: 1px solid var(--border);
  transition: opacity var(--transition);
}
.timeline-attachment-img:hover {
  opacity: 0.8;
}

.timeline-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--blue);
  background: var(--blue-bg);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background var(--transition);
}
.timeline-attachment-file:hover {
  background: var(--bg-hover);
}
.timeline-attachment-file__icon {
  font-size: 14px;
}
.timeline-attachment-file__name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Lightbox ──────────────────────────────────────────────────────────── */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.80);
  cursor: pointer;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  cursor: default;
}

/* ── Notes ──────────────────────────────────────────────────────────────── */

.note-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.note-item:last-child { border-bottom: none; }

.note-item__header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.note-item__author {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}
.note-item__time {
  font-size: 11px;
  color: var(--text-muted);
}
.note-item__content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ── Note Form ──────────────────────────────────────────────────────────── */

.note-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.note-form textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  outline: none;
}
.note-form textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}

.note-form__footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

/* ── Message Compose ────────────────────────────────────────────────────── */

.compose-bar {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}

.compose-bar select {
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  outline: none;
}

.compose-bar input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}
.compose-bar input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}

/* ── Empty State ────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 14px;
  gap: 12px;
}

.empty-state__icon {
  font-size: 32px;
  opacity: 0.4;
}

.empty-state__text {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Loading ────────────────────────────────────────────────────────────── */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
}

.loading__spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Chart container ────────────────────────────────────────────────────── */

.chart-container {
  position: relative;
  height: 260px;
  width: 100%;
}

/* ── Placeholder panel ──────────────────────────────────────────────────── */

.placeholder-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  min-height: 200px;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .crm-sidebar { width: 56px; overflow: hidden; }
  .crm-sidebar__item span:not(.crm-sidebar__icon) { display: none; }
  .crm-sidebar__group-toggle { padding: 8px 12px; }
  .crm-sidebar__group-label { display: none; }
  .crm-sidebar__chevron { display: none; }
  .crm-middle { width: 280px; }
}

@media (max-width: 640px) {
  .crm-layout { flex-direction: column; height: auto; }
  .crm-sidebar { width: 100%; flex-direction: row; padding: 0; border-right: none; border-bottom: 1px solid var(--border); }
  .crm-sidebar__group-items { display: flex; }
  .crm-sidebar__group-toggle { display: none; }
  .crm-sidebar__item { padding: 12px 16px; border-right: none; }
  .crm-sidebar__item.active { border-bottom: 2px solid var(--blue); border-right: none; }
  .crm-sidebar__divider, .crm-sidebar__footer { display: none; }
  .crm-middle { width: 100%; border-right: none; max-height: 40vh; }
  .crm-detail { min-height: 50vh; }
}

/* ── Login Modal ────────────────────────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.login-card {
  background: var(--bg-card, #1e2130);
  border: 1px solid var(--border, #2a2f45);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.login-card__brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary, #e2e8f0);
  text-align: center;
}

.login-card__brand span {
  color: var(--blue);
}

.login-card__heading {
  font-size: 0.875rem;
  color: var(--text-muted, #94a3b8);
  text-align: center;
  margin-top: -0.5rem;
}

.login-card__field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.login-card__field label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.login-card__field input {
  background: var(--bg-input, #0f1117);
  border: 1px solid var(--border, #2a2f45);
  border-radius: 6px;
  padding: 0.625rem 0.75rem;
  color: var(--text-primary, #e2e8f0);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}

.login-card__field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}

.login-card__submit {
  background: var(--blue);
  color: var(--text-always-white);
  border: none;
  border-radius: 6px;
  padding: 0.675rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.login-card__submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-card__error {
  font-size: 0.8rem;
  color: var(--red, #f87171);
  text-align: center;
  min-height: 1.2em;
}

/* ── Login: "or" divider + Google sign-in ──────────────────────────────── */

.login-card__divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted, #94a3b8);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-card__divider::before,
.login-card__divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border, #2a2f45);
}

.login-card__google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  background: var(--bg-card, #1e2130);
  color: var(--text-primary, #e2e8f0);
  border: 1px solid var(--border, #2a2f45);
  border-radius: 6px;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition, 0.15s), border-color var(--transition, 0.15s);
}

.login-card__google:hover {
  background: var(--bg-hover, #252a3d);
  border-color: var(--text-muted, #94a3b8);
}

.login-card__google svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ── Avatar dropdown ─────────────────────────────────────────────────────── */

.avatar-wrapper {
  position: relative;
}

.avatar-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-card, #1e2130);
  border: 1px solid var(--border, #2a2f45);
  border-radius: 8px;
  min-width: 200px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.avatar-dropdown__name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary, #e2e8f0);
}

.avatar-dropdown__email {
  font-size: 0.75rem;
  color: var(--text-muted, #94a3b8);
}

.avatar-dropdown__role {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--blue-bg);
  color: var(--blue);
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.avatar-dropdown__divider {
  height: 1px;
  background: var(--border, #2a2f45);
  margin: 0.25rem 0;
}

.avatar-dropdown__logout {
  background: none;
  border: none;
  color: var(--text-muted, #94a3b8);
  font-size: 0.8rem;
  cursor: pointer;
  text-align: left;
  padding: 0.25rem 0;
  transition: color 0.15s;
}

.avatar-dropdown__logout:hover {
  color: var(--red, #f87171);
}

/* ── Shared Confirm Dialog ─────────────────────────────────────────────── */

.crm-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.crm-dialog {
  background: var(--bg-card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: calc(100% - 48px);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
}

.crm-dialog__message {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: 20px;
}

.crm-dialog__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.crm-dialog__cancel {
  padding: 8px 16px;
  font-size: 13px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.crm-dialog__cancel:hover {
  background: var(--bg-hover);
}

.crm-dialog__confirm {
  padding: 8px 16px;
  font-size: 13px;
  background: var(--blue);
  color: var(--text-always-white);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity var(--transition);
}
.crm-dialog__confirm:hover { opacity: 0.85; }
.crm-dialog__confirm:focus { outline: 2px solid var(--blue); outline-offset: 2px; }

.crm-dialog__confirm--danger {
  background: var(--danger, #ef4444);
}

/* ── Shared Toast Notification ─────────────────────────────────────────── */

.crm-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 9999;
  pointer-events: none;
  color: var(--text-always-white);
  background: var(--success, #10b981);
  white-space: nowrap;
}

.crm-toast--error {
  background: var(--danger, #ef4444);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary {
  background: var(--blue);
  color: var(--text-always-white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
  font-family: inherit;
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
  font-family: inherit;
}
.btn-secondary:hover { background: var(--bg-input); }

/* ── Data Table ─────────────────────────────────────────────────────────── */

.crm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.crm-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.crm-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}
.crm-table tr:last-child td { border-bottom: none; }
.crm-table tr:hover td {
  background: var(--bg-hover);
}

/* ── Page / Section Header ──────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.page-header__title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.page-header__subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Modal Overlay / Panel aliases ──────────────────────────────────────── */

.modal-overlay,
.crm-dialog-overlay {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-panel,
.crm-dialog {
  background: var(--bg-card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
}
