/* ============================================================
   Iron Mind CRM — main.css
   Brand: brandbook.md (Frontend Brand Guardian)
   Light CRM theme — Close.io inspired, Iron Mind orange accent
   ============================================================ */

/* ----------------------------------------------------------
   1. CSS Custom Properties (Brand Tokens)
   ---------------------------------------------------------- */
:root {
  /* Colors — brandbook §CRM Color System (light theme) */
  --color-bg-primary:   #f5f6f8;   /* Page / app bg — light gray */
  --color-bg-surface:   #ffffff;   /* Sidebar, cards, panels — white */
  --color-bg-elevated:  #f0f2f5;   /* Subtle elevation, table hover */
  --color-bg-input:     #ffffff;   /* Form inputs — white */

  /* Accent — Iron Mind orange (brand identity, Amber Rule applies) */
  --color-accent:        #e87c2e;
  --color-accent-hover:  #d06820;
  --color-accent-subtle: rgba(232, 124, 46, 0.08);
  --color-accent-border: rgba(232, 124, 46, 0.3);

  /* Text */
  --color-text-primary:   #1a1d23;  /* Near-black */
  --color-text-secondary: #3d4452;  /* Secondary text */
  --color-text-muted:     #7a8499;  /* Muted / labels */

  /* Borders */
  --color-border:       rgba(0, 0, 0, 0.08);
  --color-border-hover: rgba(0, 0, 0, 0.15);

  /* Status badge colors */
  --status-new:              #3b82f6;
  --status-new-bg:           rgba(59, 130, 246, 0.12);
  --status-contacted:        #f59e0b;
  --status-contacted-bg:     rgba(245, 158, 11, 0.12);
  --status-qualified:        #22c55e;
  --status-qualified-bg:     rgba(34, 197, 94, 0.12);
  --status-proposal:         #a78bfa;
  --status-proposal-bg:      rgba(167, 139, 250, 0.12);
  --status-closed-won:       #10b981;
  --status-closed-won-bg:    rgba(16, 185, 129, 0.12);
  --status-closed-lost:      #ef4444;
  --status-closed-lost-bg:   rgba(239, 68, 68, 0.12);
  --status-not-interested:   #6b7280;
  --status-not-interested-bg:rgba(107, 114, 128, 0.12);

  /* Typography — brandbook §Typography System */
  --font-display: 'Barlow Condensed', sans-serif;
  --font-body:    'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing — brandbook §Spacing System */
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 48px;
  --space-6: 64px;
  --space-7: 96px;
  --space-8: 128px;

  /* Layout */
  --sidebar-width:    220px;
  --topbar-height:    56px;
  --radius-sm:        3px;
  --radius-md:        5px;
  --radius-lg:        8px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease-out;
}

/* ----------------------------------------------------------
   2. Reset & Base
   ---------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.hidden { display: none !important; }

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--color-text-primary);
  background: var(--color-bg-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover { color: var(--color-accent-hover); }

img, svg { display: block; }

ul, ol { list-style: none; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

button { cursor: pointer; }

/* ----------------------------------------------------------
   3. Typography helpers
   ---------------------------------------------------------- */
.text-muted    { color: var(--color-text-muted); }
.text-mono     { font-family: var(--font-mono); }
.text-sm       { font-size: 12px; }
.text-upper    { text-transform: uppercase; letter-spacing: 0.08em; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ----------------------------------------------------------
   4. App Shell — Sidebar + Topbar Layout
   ---------------------------------------------------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--color-bg-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition-slow);
}

.sidebar__brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 var(--space-2);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sidebar__logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-primary);
  line-height: 1;
}

.sidebar__logo-text span {
  color: var(--color-accent);
}

.sidebar__nav {
  flex: 1;
  padding: var(--space-2) 0;
  overflow-y: auto;
}

.nav-section {
  padding: 0 var(--space-1);
  margin-bottom: var(--space-1);
}

.nav-section__label {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-text-muted);
  padding: var(--space-1) 12px 6px;
  display: block;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 400;
  transition: color var(--transition-fast), background var(--transition-fast);
  position: relative;
  white-space: nowrap;
}

.nav-link svg {
  width: 16px; height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.nav-link:hover {
  color: var(--color-text-primary);
  background: rgba(0, 0, 0, 0.04);
}

.nav-link:hover svg { opacity: 1; }

.nav-link.active {
  color: var(--color-text-primary);
  background: var(--color-accent-subtle);
}

.nav-link.active svg { opacity: 1; }

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 2px;
  background: var(--color-accent);
  border-radius: 0 2px 2px 0;
}

.sidebar__footer {
  padding: var(--space-2);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sidebar__user-info {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
  truncate: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sidebar__user-name {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ---- Main area ---- */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ---- Topbar ---- */
.topbar {
  height: var(--topbar-height);
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-3);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
}

.topbar__page-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-primary);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__user-name {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.topbar__avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-accent);
  text-transform: uppercase;
  flex-shrink: 0;
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  padding: 6px;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
}

.sidebar-toggle:hover { color: var(--color-text-primary); background: rgba(0,0,0,0.05); }

/* ---- Page content ---- */
.page-content {
  flex: 1;
  padding: var(--space-3);
}

/* ----------------------------------------------------------
   5. Flash Messages
   ---------------------------------------------------------- */
.flash-bar {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.flash-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
}

.flash-msg--success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #166534;
}

.flash-msg--error {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #991b1b;
}

.flash-msg--warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #92400e;
}

.flash-msg--info {
  background: var(--color-accent-subtle);
  border: 1px solid var(--color-accent-border);
  color: var(--color-accent);
}

.flash-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  opacity: 0.6;
  padding: 2px 4px;
  border-radius: 2px;
  line-height: 1;
  font-size: 16px;
}
.flash-close:hover { opacity: 1; }

/* ----------------------------------------------------------
   6. Buttons — brandbook §Component Patterns > Buttons
   ---------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

/* Primary — Amber Rule: one per viewport */
.btn--primary {
  background: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
}
.btn--primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  color: #ffffff;
}

/* Ghost */
.btn--ghost {
  background: transparent;
  color: var(--color-accent);
  border-color: var(--color-accent-border);
}
.btn--ghost:hover {
  background: var(--color-accent-subtle);
  border-color: var(--color-accent);
  color: var(--color-accent-hover);
}

/* Muted */
.btn--muted {
  background: var(--color-bg-elevated);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
.btn--muted:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: var(--color-border-hover);
  color: var(--color-text-primary);
}

/* Danger */
.btn--danger {
  background: transparent;
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.3);
}
.btn--danger:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(248, 113, 113, 0.5);
}

/* Size variants */
.btn--sm {
  padding: 5px 12px;
  font-size: 11px;
}

.btn--lg {
  padding: 11px 28px;
  font-size: 13px;
}

.btn--icon {
  padding: 7px;
  border-radius: var(--radius-sm);
}

.btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ----------------------------------------------------------
   7. Form Elements — brandbook §Component Patterns > Contact Form
   ---------------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-2);
}

.form-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.form-label .required {
  color: #f87171;
  margin-left: 3px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-text-muted);
  opacity: 0.6;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(232, 124, 46, 0.2);
}

.form-input:invalid:not(:placeholder-shown),
.form-textarea:invalid:not(:placeholder-shown) {
  border-color: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15);
}

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

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237a8499' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

.form-select option {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
}

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

.form-error {
  font-size: 11px;
  color: #f87171;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.form-section-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-2);
  margin-top: var(--space-3);
}

.form-section-title:first-child { margin-top: 0; }

/* Toggle switch (for TLS booleans) */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0; height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.toggle-track::after {
  content: '';
  position: absolute;
  left: 3px; top: 50%;
  transform: translateY(-50%);
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--color-text-muted);
  transition: transform var(--transition-fast), background var(--transition-fast);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--color-accent-subtle);
  border-color: var(--color-accent-border);
}

.toggle-switch input:checked + .toggle-track::after {
  background: var(--color-accent);
  transform: translate(16px, -50%);
}

.toggle-switch input:focus-visible + .toggle-track {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.toggle-label {
  font-size: 13px;
  color: var(--color-text-secondary);
  cursor: pointer;
}

/* ----------------------------------------------------------
   8. Cards / Surface Panels
   ---------------------------------------------------------- */
.card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.card--elevated {
  background: var(--color-bg-elevated);
}

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

.card__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-primary);
}

/* ----------------------------------------------------------
   9. Tables — power-user dense layout
   ---------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-surface);
}

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

.data-table thead {
  border-bottom: 1px solid var(--color-border);
}

.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  white-space: nowrap;
  background: var(--color-bg-elevated);
}

.data-table th:first-child { border-radius: var(--radius-md) 0 0 0; }
.data-table th:last-child  { border-radius: 0 var(--radius-md) 0 0; }

.data-table td {
  padding: 10px 14px;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--transition-fast);
  cursor: pointer;
}

.data-table tbody tr:hover td {
  background: var(--color-bg-elevated);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table .col-company { font-weight: 500; color: var(--color-text-primary); }
.data-table .col-actions { white-space: nowrap; width: 1px; }
.data-table .col-link { width: 40px; text-align: center; }

/* ----------------------------------------------------------
   10. Status Badges
   ---------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge--new {
  color: var(--status-new);
  background: var(--status-new-bg);
  border-color: rgba(59, 130, 246, 0.25);
}

.badge--contacted {
  color: var(--status-contacted);
  background: var(--status-contacted-bg);
  border-color: rgba(245, 158, 11, 0.25);
}

.badge--qualified {
  color: var(--status-qualified);
  background: var(--status-qualified-bg);
  border-color: rgba(34, 197, 94, 0.25);
}

.badge--proposal {
  color: var(--status-proposal);
  background: var(--status-proposal-bg);
  border-color: rgba(167, 139, 250, 0.25);
}

.badge--closed_won {
  color: var(--status-closed-won);
  background: var(--status-closed-won-bg);
  border-color: rgba(16, 185, 129, 0.25);
}

.badge--closed_lost {
  color: var(--status-closed-lost);
  background: var(--status-closed-lost-bg);
  border-color: rgba(239, 68, 68, 0.25);
}

.badge--not_interested {
  color: var(--status-not-interested);
  background: var(--status-not-interested-bg);
  border-color: rgba(107, 114, 128, 0.25);
}

/* Role badges */
.badge--admin {
  color: var(--color-accent);
  background: var(--color-accent-subtle);
  border-color: var(--color-accent-border);
}

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

.badge--active {
  color: #4ade80;
  background: rgba(34, 197, 94, 0.1);
  border-color: rgba(34, 197, 94, 0.2);
}

.badge--inactive {
  color: #f87171;
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.2);
}

/* ----------------------------------------------------------
   11. Page Headers (inside page-content)
   ---------------------------------------------------------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  gap: var(--space-2);
}

.page-header__left { min-width: 0; }

.page-header__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-primary);
  line-height: 1.1;
}

.page-header__subtitle {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.page-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

/* ----------------------------------------------------------
   12. Toolbar (search + filter row above tables)
   ---------------------------------------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}

.toolbar__search {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 340px;
}

.toolbar__search-icon {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
  width: 14px; height: 14px;
}

.toolbar__search .form-input {
  padding-left: 32px;
}

.toolbar__right {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

/* ----------------------------------------------------------
   13. Pagination
   ---------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0;
  font-size: 12px;
  color: var(--color-text-muted);
}

.pagination__info { }

.pagination__controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination__btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.pagination__btn:hover:not(:disabled) {
  border-color: var(--color-border-hover);
  color: var(--color-text-primary);
  background: var(--color-bg-elevated);
}

.pagination__btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ----------------------------------------------------------
   14. Stat Cards (Dashboard)
   ---------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.stat-card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  transition: border-color var(--transition-fast);
}

.stat-card:hover { border-color: var(--color-border-hover); }

.stat-card__value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  color: var(--color-accent);
  line-height: 1.1;
  margin-bottom: 4px;
}

.stat-card__label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.stat-card__delta {
  font-size: 11px;
  margin-top: 6px;
}

.stat-card__delta--up   { color: #4ade80; }
.stat-card__delta--down { color: #f87171; }

/* ----------------------------------------------------------
   15. Lead Detail — Two-column layout
   ---------------------------------------------------------- */
.detail-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: var(--space-3);
  align-items: start;
}

.detail-panel {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.detail-panel__header {
  padding: 14px var(--space-2);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-bg-elevated);
}

.detail-panel__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.detail-panel__body {
  padding: var(--space-2);
}

/* Lead info fields */
.lead-field {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: var(--space-1);
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}

.lead-field:last-child { border-bottom: none; }

.lead-field__label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  padding-top: 1px;
}

.lead-field__value {
  font-size: 13px;
  color: var(--color-text-primary);
  word-break: break-word;
}

.lead-field__value a {
  color: var(--color-accent);
}

.lead-field__value a:hover {
  color: var(--color-accent-hover);
  text-decoration: underline;
}

.lead-field__empty {
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 12px;
}

/* Secondary contacts */
.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.contact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  gap: var(--space-1);
}

.contact-item__info { min-width: 0; }

.contact-item__name {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-primary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.contact-item__email {
  font-size: 11px;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ----------------------------------------------------------
   16. Email Thread
   ---------------------------------------------------------- */
.email-thread {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2);
  max-height: 480px;
  overflow-y: auto;
}

.email-msg {
  max-width: 85%;
}

.email-msg--inbound  { align-self: flex-start; }
.email-msg--outbound { align-self: flex-end; }

.email-msg__meta {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.email-msg--outbound .email-msg__meta { justify-content: flex-end; }

.email-msg__bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.55;
  color: var(--color-text-secondary);
  word-break: break-word;
}

.email-msg--inbound .email-msg__bubble {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: var(--radius-sm);
}

.email-msg--outbound .email-msg__bubble {
  background: var(--color-accent-subtle);
  border: 1px solid var(--color-accent-border);
  border-bottom-right-radius: var(--radius-sm);
  color: var(--color-text-primary);
}

.email-msg__subject {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

/* Compose panel */
.compose-panel {
  border-top: 1px solid var(--color-border);
  padding: var(--space-2);
  background: var(--color-bg-elevated);
}

.compose-panel__header {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.compose-panel.hidden { display: none; }

.email-empty {
  padding: var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13px;
}

/* ----------------------------------------------------------
   17. Activity Log / Timeline
   ---------------------------------------------------------- */
.activity-feed {
  display: flex;
  flex-direction: column;
  padding: var(--space-1) var(--space-2);
  max-height: 400px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  position: relative;
}

.activity-item::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 36px;
  bottom: -10px;
  width: 1px;
  background: var(--color-border);
}

.activity-item:last-child::before { display: none; }

.activity-icon {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
}

.activity-icon svg { width: 14px; height: 14px; }

.activity-icon--note    { color: var(--color-text-muted); }
.activity-icon--call    { color: #4ade80; }
.activity-icon--email   { color: var(--color-accent); }
.activity-icon--status  { color: #a78bfa; }
.activity-icon--meeting { color: #38bdf8; }

.activity-body { flex: 1; min-width: 0; }

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

.activity-body__time {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
  font-family: var(--font-mono);
}

/* Quick-add activity form */
.activity-add-form {
  padding: var(--space-2);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.activity-add-form__tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}

.activity-tab {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.activity-tab.active,
.activity-tab:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  border-color: var(--color-border-hover);
}

/* ----------------------------------------------------------
   18. Kanban Board
   ---------------------------------------------------------- */
.kanban-wrapper {
  overflow-x: auto;
  padding-bottom: var(--space-3);
  /* subtract topbar + page padding */
  min-height: calc(100vh - var(--topbar-height) - var(--space-3) * 2 - 60px);
}

.kanban-board {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  min-width: max-content;
  padding: 4px 2px;
}

.kanban-col {
  width: 230px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.kanban-col__header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-bg-elevated);
  position: sticky;
  top: 0;
}

.kanban-col__title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.kanban-col__count {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  background: rgba(0,0,0,0.05);
  padding: 1px 7px;
  border-radius: 10px;
}

/* Column accent lines per status */
.kanban-col[data-status="new"]            .kanban-col__header { border-top: 2px solid var(--status-new); }
.kanban-col[data-status="contacted"]      .kanban-col__header { border-top: 2px solid var(--status-contacted); }
.kanban-col[data-status="qualified"]      .kanban-col__header { border-top: 2px solid var(--status-qualified); }
.kanban-col[data-status="proposal"]       .kanban-col__header { border-top: 2px solid var(--status-proposal); }
.kanban-col[data-status="closed_won"]     .kanban-col__header { border-top: 2px solid var(--status-closed-won); }
.kanban-col[data-status="closed_lost"]    .kanban-col__header { border-top: 2px solid var(--status-closed-lost); }
.kanban-col[data-status="not_interested"] .kanban-col__header { border-top: 2px solid var(--status-not-interested); }

.kanban-col__cards {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 120px;
}

/* Drop target state */
.kanban-col__cards.drag-over {
  background: rgba(232, 124, 46, 0.04);
  outline: 1px dashed var(--color-accent-border);
  outline-offset: -4px;
  border-radius: var(--radius-sm);
}

.kanban-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: grab;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
  user-select: none;
}

.kanban-card:hover {
  border-color: var(--color-border-hover);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.kanban-card:active { cursor: grabbing; }

.kanban-card.dragging {
  opacity: 0.4;
  transform: rotate(1deg);
}

.kanban-card__company {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 3px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.kanban-card__contact {
  font-size: 11px;
  color: var(--color-text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.kanban-card__title {
  font-size: 11px;
  color: var(--color-text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.kanban-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--color-border);
}

.kanban-card__email-icon {
  color: var(--color-text-muted);
  width: 13px; height: 13px;
  opacity: 0.6;
}

.kanban-card__link {
  font-size: 10px;
  color: var(--color-text-muted);
  text-decoration: none;
}
.kanban-card__link:hover { color: var(--color-accent); }

/* ----------------------------------------------------------
   19. Tabs (detail page)
   ---------------------------------------------------------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-2);
  background: var(--color-bg-elevated);
}

.tab-btn {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--color-text-primary); }

.tab-btn.active {
  color: var(--color-text-primary);
  border-bottom-color: var(--color-accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ----------------------------------------------------------
   20. Modals
   ---------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
}

.modal-backdrop:not(.hidden) { display: flex; }

.modal {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal__header {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-primary);
}

.modal__body {
  padding: var(--space-3);
  flex: 1;
}

.modal__footer {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-1);
  flex-shrink: 0;
}

/* ----------------------------------------------------------
   21. Login Page
   ---------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-primary);
  padding: var(--space-3);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

.login-card__brand {
  text-align: center;
  margin-bottom: var(--space-4);
}

.login-card__logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-primary);
  line-height: 1;
  margin-bottom: 6px;
}

.login-card__logo span { color: var(--color-accent); }

.login-card__tagline {
  font-size: 12px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.login-card__title {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
  text-align: center;
}

/* Login page logo — brandbook §CRM Logo Placement */
.login-logo {
  height: 36px;
  width: auto;
  display: block;
  margin: 0 auto var(--space-2);
}

/* ----------------------------------------------------------
   21a. Sidebar Logo — brandbook §CRM Logo Placement
   ---------------------------------------------------------- */

/* Sidebar logo image */
.sidebar__logo-img {
  height: 28px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

/* "CRM" label beside the logo */
.sidebar__logo-crm {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--color-text-muted);
  margin-left: 6px;
  padding-left: 6px;
  border-left: 1px solid var(--color-border);
  line-height: 1;
  align-self: center;
}

/* ----------------------------------------------------------
   22. Settings Page
   ---------------------------------------------------------- */
.settings-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: var(--space-3);
  align-items: start;
}

.settings-nav {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.settings-nav__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  transition: all var(--transition-fast);
  text-decoration: none;
}

.settings-nav__item:last-child { border-bottom: none; }

.settings-nav__item:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-elevated);
}

.settings-nav__item.active {
  color: var(--color-text-primary);
  background: var(--color-accent-subtle);
}

.settings-nav__item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 2px;
  background: var(--color-accent);
}

.settings-panel {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.settings-panel__header {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
}

.settings-panel__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-primary);
}

.settings-panel__subtitle {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 3px;
}

.settings-panel__body {
  padding: var(--space-3);
}

.settings-panel__footer {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-bg-elevated);
  flex-wrap: wrap;
  gap: var(--space-1);
}

.sync-status {
  font-size: 12px;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

.sync-status__dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--color-text-muted);
  vertical-align: middle;
}

.sync-status--ok .sync-status__dot { background: #4ade80; }
.sync-status--err .sync-status__dot { background: #f87171; }

/* ----------------------------------------------------------
   23. Admin Users page
   ---------------------------------------------------------- */
.user-avatar-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-accent);
  text-transform: uppercase;
  flex-shrink: 0;
}

/* ----------------------------------------------------------
   24. Dashboard — recent activity + pipeline mini
   ---------------------------------------------------------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.pipeline-mini {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pipeline-mini-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.pipeline-mini-label {
  width: 110px;
  color: var(--color-text-muted);
  flex-shrink: 0;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.pipeline-mini-bar-wrap {
  flex: 1;
  height: 6px;
  background: rgba(0,0,0,0.07);
  border-radius: 3px;
  overflow: hidden;
}

.pipeline-mini-bar {
  height: 100%;
  border-radius: 3px;
  background: var(--color-accent);
  min-width: 2px;
}

.pipeline-mini-count {
  width: 22px;
  text-align: right;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  flex-shrink: 0;
}

/* ----------------------------------------------------------
   25. Scrollbars (webkit)
   ---------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.14);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.22); }

/* ----------------------------------------------------------
   26. Utility
   ---------------------------------------------------------- */
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.w-full { width: 100%; }

.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-2) 0;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  text-align: center;
  color: var(--color-text-muted);
}

.empty-state__icon {
  width: 40px; height: 40px;
  margin-bottom: var(--space-2);
  opacity: 0.3;
}

.empty-state__title {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.empty-state__text {
  font-size: 12px;
  max-width: 280px;
}

/* ----------------------------------------------------------
   27. Responsive
   ---------------------------------------------------------- */
@media (max-width: 1100px) {
  .detail-layout {
    grid-template-columns: 320px 1fr;
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .detail-layout {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .settings-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  .sidebar {
    transform: translateX(-220px);
    width: 220px;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  }

  .main-wrapper {
    margin-left: 0;
  }

  .sidebar-toggle { display: flex; }

  .topbar__user-name { display: none; }

  .kanban-board { min-width: 700px; }

  .page-content { padding: var(--space-2); }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar__search { max-width: 100%; }

  .toolbar__right {
    margin-left: 0;
    justify-content: flex-end;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

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