/* =============================================================
   Three CRM — Design tokens + base
   Aesthetic: refined editorial-meets-software.
   - Warm off-white paper, ink near-black
   - Single hot accent (terracotta), supportive deep blue, sage
   - Serif display (Fraunces), clean grotesk body (Inter Tight),
     mono for data (JetBrains Mono)
   ============================================================= */

:root {
  /* paper / ink */
  --paper:        #F5F1EA;     /* main bg */
  --paper-2:      #EFEAE0;     /* subtle alt rows */
  --card:         #FBFAF6;
  --ink:          #1A1A1A;
  --ink-2:        #2A2A2A;
  --ink-3:        #4A4A4A;
  --muted:        #7A7670;
  --muted-2:      #9A9690;
  --rule:         rgba(26,26,26,0.10);
  --rule-2:       rgba(26,26,26,0.06);
  --hover:        rgba(26,26,26,0.04);

  /* accents */
  --accent:       #E07A5F;     /* terracotta */
  --accent-ink:   #B85C42;
  --accent-soft:  #F4D6CC;
  --blue:         #3D5A80;
  --blue-soft:    #D6E0EE;
  --sage:         #588157;
  --sage-soft:    #D7E4D4;
  --ochre:        #D4A373;
  --plum:         #6B4E71;
  --rose:         #C9184A;

  /* status */
  --ok:           #588157;
  --warn:         #D4A373;
  --err:          #C9184A;

  /* layout */
  --sidebar-w:    240px;
  --topbar-h:     56px;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    16px;

  /* type */
  --font-display: 'Fraunces', 'Times New Roman', serif;
  --font-body:    'Inter Tight', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, Menlo, monospace;

  --shadow-sm:    0 1px 2px rgba(26,26,26,0.04), 0 1px 1px rgba(26,26,26,0.02);
  --shadow:       0 8px 24px -8px rgba(26,26,26,0.12), 0 2px 6px rgba(26,26,26,0.05);
  --shadow-lg:    0 24px 60px -20px rgba(26,26,26,0.2), 0 8px 16px rgba(26,26,26,0.06);
}

[data-theme="dark"] {
  --paper:        #14130F;
  --paper-2:      #1B1A16;
  --card:         #1E1D19;
  --ink:          #F4F1E8;
  --ink-2:        #E5E1D5;
  --ink-3:        #C9C4B5;
  --muted:        #8E897C;
  --muted-2:      #6E6A5E;
  --rule:         rgba(244,241,232,0.10);
  --rule-2:       rgba(244,241,232,0.05);
  --hover:        rgba(244,241,232,0.05);
  --accent-soft:  #4A2A1E;
  --blue-soft:    #1F2C42;
  --sage-soft:    #1F2E1E;
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'ss01', 'cv11';
  letter-spacing: -0.005em;
}

button { font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

.serif { font-family: var(--font-display); font-weight: 500; letter-spacing: -0.015em; }
.mono  { font-family: var(--font-mono); font-feature-settings: 'tnum'; }
.tnum  { font-feature-settings: 'tnum', 'cv11'; }

/* ------------ App scaffold ------------ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}
.sidebar { grid-row: 1 / 3; grid-column: 1; border-right: 1px solid var(--rule); background: var(--paper); display: flex; flex-direction: column; min-height: 0; }
.topbar  { grid-row: 1; grid-column: 2; border-bottom: 1px solid var(--rule); background: var(--paper); display: flex; align-items: center; gap: 12px; padding: 0 16px; }
.workspace { grid-row: 2; grid-column: 2; overflow: auto; background: var(--paper); }

/* ------------ Sidebar ------------ */
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--rule);
}
.brand-mark {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: var(--ink); color: var(--paper);
  border-radius: 6px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
}
.brand-name { font-family: var(--font-display); font-size: 18px; font-weight: 500; letter-spacing: -0.02em; }
.brand-name .accent { color: var(--accent); }

.workspace-switcher {
  display: flex; align-items: center; justify-content: space-between;
  margin: 10px 12px; padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 12px;
  gap: 6px;
}
.workspace-switcher > div:first-child { min-width: 0; flex: 1; }
.workspace-switcher .ws-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workspace-switcher .ws-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workspace-switcher .ws-meta { color: var(--muted); font-size: 11px; }

.nav { padding: 6px 8px; overflow-y: auto; flex: 1; min-height: 0; }
.nav-section { padding: 12px 8px 4px; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted-2); font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 6px;
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  position: relative;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--ink); color: var(--paper); }
.nav-item.active .badge { background: var(--paper); color: var(--ink); }
.nav-item .icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }
.nav-item .label { flex: 1; }
.nav-item .badge {
  font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-feature-settings: 'tnum';
}
.nav-item.active .icon { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--rule);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  color: white;
  flex-shrink: 0;
}
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.lg { width: 40px; height: 40px; font-size: 14px; }
.avatar.xl { width: 56px; height: 56px; font-size: 18px; }
.user-meta { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 12px; }
.user-role { color: var(--muted); font-size: 11px; }

/* ------------ Topbar ------------ */
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.crumbs .sep { color: var(--muted-2); }
.crumbs .here { font-weight: 600; }

.search {
  flex: 1; max-width: 480px;
  display: flex; align-items: center; gap: 8px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s ease;
}
.search:hover { background: var(--card); border-color: var(--ink-3); color: var(--ink-2); }
.search .icon { width: 14px; height: 14px; }
.search .placeholder { flex: 1; }
.search .kbd { font-family: var(--font-mono); font-size: 10px; padding: 1px 5px; border-radius: 3px; background: var(--card); border: 1px solid var(--rule); color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 6px; color: var(--ink-2);
  position: relative;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn .icon { width: 16px; height: 16px; }
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}

/* ------------ Buttons ------------ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink-2);
  font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all .12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--paper-2); border-color: var(--ink-3); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: #000; }
.btn.accent { background: var(--accent); color: white; border-color: var(--accent); }
.btn.accent:hover { background: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn .icon { width: 14px; height: 14px; }
.btn.sm { padding: 4px 8px; font-size: 11px; }
.btn.lg { padding: 9px 16px; font-size: 13px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 500;
  background: var(--paper-2); color: var(--ink-3);
  border: 1px solid var(--rule);
}
.chip.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.chip.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.chip.sage { background: var(--sage-soft); color: var(--sage); border-color: transparent; }
.chip.ochre { background: #F4E5CD; color: #8A5A2A; border-color: transparent; }
.chip.plum { background: #E6DCEA; color: var(--plum); border-color: transparent; }
.chip.gray { background: var(--paper-2); color: var(--ink-3); }

/* ------------ Cards / panels ------------ */
.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.card-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--rule-2);
}
.card-title { font-family: var(--font-display); font-size: 16px; font-weight: 500; letter-spacing: -0.015em; }
.card-sub   { color: var(--muted); font-size: 11px; margin-top: 2px; }
.card-b { padding: 14px 16px; }
.card.flat { background: transparent; border-color: var(--rule-2); }

/* ------------ Page scaffolding ------------ */
.page { padding: 24px 32px 80px; max-width: 1600px; margin: 0 auto; }
.page-h {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 20px; padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap; gap: 16px;
}
.page-eyebrow { font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.page-title { font-family: var(--font-display); font-size: 36px; font-weight: 400; letter-spacing: -0.025em; line-height: 1.05; }
.page-title em { font-style: italic; color: var(--accent); font-weight: 400; }
.page-sub { color: var(--muted); margin-top: 6px; font-size: 13px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ------------ Misc ------------ */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--rule); margin: 16px 0; }
.scroll { overflow-y: auto; }

.kbd {
  font-family: var(--font-mono); font-size: 10px;
  padding: 1px 5px; border-radius: 3px;
  background: var(--card); border: 1px solid var(--rule);
  color: var(--muted);
}

/* truncation */
.trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------ Tables ------------ */
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th {
  text-align: left; font-weight: 500; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky; top: 0; z-index: 1;
}
.table td {
  padding: 12px;
  border-bottom: 1px solid var(--rule-2);
  vertical-align: middle;
}
.table tr:hover td { background: var(--hover); }
.table .num { font-family: var(--font-mono); font-feature-settings: 'tnum'; text-align: right; }

/* ------------ Scrollbars ------------ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(26,26,26,0.15); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(26,26,26,0.3); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------ Animations ------------ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
.fade-in { animation: fadeIn .25s ease both; }
.slide-up { animation: slideUp .3s ease both; }

/* ------------ Stage hint (Three brand) ------------ */
.eyebrow-rule {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted);
}
.eyebrow-rule::before, .eyebrow-rule::after { content: ''; height: 1px; width: 24px; background: var(--rule); }

/* command palette */
.cmd-overlay {
  position: fixed; inset: 0;
  background: rgba(20,18,15,0.4);
  backdrop-filter: blur(4px);
  display: grid; place-items: flex-start center;
  padding-top: 14vh;
  z-index: 1000;
  animation: fadeIn .15s ease;
}
.cmd {
  width: min(640px, 92vw);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.cmd-input {
  width: 100%; padding: 16px 20px;
  font-size: 16px; background: transparent;
  border: 0; border-bottom: 1px solid var(--rule);
  outline: 0;
}
.cmd-list { max-height: 440px; overflow-y: auto; padding: 6px; }
.cmd-section { padding: 8px 12px 4px; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.cmd-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 6px; cursor: pointer;
}
.cmd-item:hover, .cmd-item.sel { background: var(--accent-soft); }
.cmd-item .icon { width: 14px; height: 14px; color: var(--muted); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20,18,15,0.45);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 999;
  animation: fadeIn .15s ease;
  padding: 24px;
}
.modal {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  max-width: 560px; width: 100%;
  max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: slideUp .2s ease;
}
.modal-h { padding: 18px 20px; border-bottom: 1px solid var(--rule-2); display: flex; justify-content: space-between; align-items: flex-start; flex-shrink: 0; }
.modal-b { padding: 20px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--rule-2); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; flex-shrink: 0; align-items: center; }

/* form */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 11px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.field input, .field textarea, .field select {
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: 6px; padding: 8px 10px; outline: none;
  font: inherit; color: var(--ink);
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* drawer */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(20,18,15,0.35);
  backdrop-filter: blur(2px);
  z-index: 998;
  animation: fadeIn .15s ease;
}
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh;
  width: min(640px, 92vw);
  background: var(--card);
  border-left: 1px solid var(--rule);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  z-index: 999;
  animation: drawerIn .25s cubic-bezier(.22,.61,.36,1);
}
@keyframes drawerIn { from { transform: translateX(100%); } to { transform: none; } }

/* tooltip */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  font-size: 11px; padding: 4px 8px; border-radius: 4px;
  white-space: nowrap; pointer-events: none;
  z-index: 100;
}

/* AI styling */
.ai-glow {
  background: linear-gradient(135deg, rgba(224,122,95,0.08), rgba(61,90,128,0.08));
  border: 1px solid rgba(224,122,95,0.2);
}
.ai-mark {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: white; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
}
