/* ── Design Tokens ── */
:root {
  --navy: #0d1f3c;
  --navy-light: #162d54;
  --navy-mid: #1a3560;
  --gold: #c4a24d;
  --gold-light: #d4b560;
  --white: #ffffff;
  --bg: #f0f2f7;
  --surface: #ffffff;
  --border: #dde1ea;
  --text: #1a1f2e;
  --text-muted: #6b7280;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --sidebar-w: 220px;

  /* Stage colours */
  --stage-inbox: #6366f1;
  --stage-initial: #8b5cf6;
  --stage-diligence: #f59e0b;
  --stage-term: #f97316;
  --stage-loi: #10b981;
  --stage-closing: #059669;
  --stage-passed: #ef4444;
  --stage-portfolio: #0ea5e9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1120;
    --surface: #141c2e;
    --border: #253454;
    --text: #e8ecf4;
    --text-muted: #8899bb;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); display: flex; height: 100vh; overflow: hidden; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .75rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: -1px; }
label { font-size: .8rem; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: .3rem; }
textarea { resize: vertical; min-height: 80px; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--navy-mid);
  display: flex;
  align-items: center;
  gap: .6rem;
}

.brand-badge {
  background: var(--gold);
  color: var(--navy);
  font-weight: 800;
  font-size: .75rem;
  padding: .2rem .5rem;
  border-radius: 4px;
  letter-spacing: .05em;
}

.brand-label {
  color: var(--white);
  font-weight: 600;
  font-size: .9rem;
}

.nav-links { list-style: none; padding: .75rem 0; flex: 1; }

.nav-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem 1rem;
  color: rgba(255,255,255,.65);
  font-size: .875rem;
  transition: all .15s;
}
.nav-link svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.nav-link:hover { color: var(--white); background: rgba(255,255,255,.06); }
.nav-link.active { color: var(--gold); background: rgba(196,162,77,.1); border-right: 3px solid var(--gold); }

/* ── Main ── */
.main-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ── Page Header ── */
.page-header {
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-title { font-size: 1.1rem; font-weight: 700; }
.page-header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Page Body ── */
.page-body { padding: 1.25rem 1.5rem; flex: 1; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: .875rem;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--navy-light); }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { background: var(--gold-light); }
.btn-danger { background: #fee2e2; color: #dc2626; }
.btn-danger:hover { background: #fecaca; }
.btn-ghost { border: 1px solid var(--border); color: var(--text-muted); }
.btn-ghost:hover { border-color: var(--navy); color: var(--text); }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

/* ── Stats Row ── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}
.stat-num { font-size: 2rem; font-weight: 800; color: var(--navy); line-height: 1; }
.stat-label { font-size: .75rem; color: var(--text-muted); margin-top: .3rem; }
.stat-num.danger { color: #dc2626; }
.stat-num.warning { color: #d97706; }
.stat-num.success { color: #059669; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { text-align: left; padding: .6rem .75rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); border-bottom: 2px solid var(--border); white-space: nowrap; }
td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(13,31,60,.03); }
.col-num { width: 48px; font-weight: 700; color: var(--text-muted); }

/* ── Stage Badge ── */
.stage-badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  padding: .2rem .5rem;
  border-radius: 20px;
  white-space: nowrap;
}
.stage-inbox    { background: #ede9fe; color: #4f46e5; }
.stage-initial  { background: #ede9fe; color: #7c3aed; }
.stage-diligence { background: #fef3c7; color: #92400e; }
.stage-term     { background: #ffedd5; color: #9a3412; }
.stage-loi      { background: #d1fae5; color: #065f46; }
.stage-closing  { background: #a7f3d0; color: #064e3b; }
.stage-passed   { background: #fee2e2; color: #991b1b; }
.stage-portfolio { background: #e0f2fe; color: #0c4a6e; }

/* ── Pipeline (Kanban) ── */
.kanban-board {
  display: flex;
  gap: .75rem;
  overflow-x: auto;
  padding-bottom: .5rem;
  align-items: flex-start;
  min-height: calc(100vh - 140px);
}
.kanban-col {
  min-width: 200px;
  width: 200px;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 160px);
}
.kanban-col-header {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.kanban-col-body { overflow-y: auto; padding: .5rem; flex: 1; display: flex; flex-direction: column; gap: .5rem; }

.deal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .6rem .75rem;
  cursor: pointer;
  transition: box-shadow .15s;
}
.deal-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.deal-card-num { font-size: .65rem; font-weight: 700; color: var(--text-muted); }
.deal-card-name { font-size: .8rem; font-weight: 700; margin: .15rem 0; line-height: 1.3; }
.deal-card-sector { font-size: .7rem; color: var(--text-muted); }
.deal-card-meta { display: flex; gap: .4rem; margin-top: .4rem; flex-wrap: wrap; }
.deal-card-due { font-size: .68rem; padding: .15rem .35rem; border-radius: 4px; }
.due-overdue { background: #fee2e2; color: #dc2626; }
.due-today    { background: #fef3c7; color: #92400e; }
.due-soon     { background: #f0fdf4; color: #166534; }
.deal-card-owner { font-size: .68rem; color: var(--text-muted); background: var(--bg); padding: .15rem .35rem; border-radius: 4px; }

/* ── Filters ── */
.filters-row {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.filters-row input, .filters-row select { width: auto; min-width: 150px; }

/* ── Deal Detail ── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-section { margin-bottom: 1.5rem; }
.detail-section h4 { font-size: .75rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: .08em; margin-bottom: .75rem; padding-bottom: .4rem; border-bottom: 1px solid var(--border); }
.field-group { display: flex; flex-direction: column; gap: .5rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* ── Notes ── */
.notes-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .75rem; max-height: 250px; overflow-y: auto; }
.note-item { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .6rem; }
.note-text { font-size: .875rem; margin-bottom: .25rem; }
.note-meta { font-size: .7rem; color: var(--text-muted); }

/* ── Contacts ── */
.contacts-list { display: flex; flex-direction: column; gap: .5rem; }
.contact-item { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .6rem; display: flex; justify-content: space-between; align-items: flex-start; }
.contact-name { font-weight: 600; font-size: .875rem; }
.contact-meta { font-size: .75rem; color: var(--text-muted); }

/* ── Email Log ── */
.log-item { padding: .65rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; font-size: .825rem; }
.log-header { display: flex; justify-content: space-between; margin-bottom: .25rem; }
.log-to { font-weight: 600; }
.log-time { font-size: .7rem; color: var(--text-muted); }
.log-subject { color: var(--text-muted); font-size: .78rem; }
.log-status { display: inline-block; font-size: .65rem; font-weight: 700; padding: .15rem .4rem; border-radius: 20px; }
.log-ok { background: #d1fae5; color: #065f46; }
.log-fail { background: #fee2e2; color: #991b1b; }

/* ── Template Editor ── */
.template-preview { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; font-size: .875rem; white-space: pre-wrap; word-break: break-word; min-height: 80px; }
.var-hints { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.var-hint { background: var(--navy); color: var(--gold); font-size: .7rem; padding: .2rem .45rem; border-radius: 4px; cursor: pointer; font-family: monospace; }
.var-hint:hover { background: var(--navy-light); }

/* ── Team cards ── */
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.team-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.team-card-name { font-weight: 700; font-size: .95rem; margin-bottom: .2rem; }
.team-card-role { font-size: .78rem; color: var(--gold); font-weight: 600; margin-bottom: .3rem; }
.team-card-email { font-size: .78rem; color: var(--text-muted); word-break: break-all; }

/* ── Dashboard ── */
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.stage-bar { display: flex; flex-direction: column; gap: .4rem; }
.stage-bar-row { display: flex; align-items: center; gap: .6rem; font-size: .8rem; }
.stage-bar-label { width: 130px; font-size: .78rem; color: var(--text-muted); flex-shrink: 0; }
.stage-bar-track { flex: 1; background: var(--bg); border-radius: 20px; height: 8px; }
.stage-bar-fill { background: var(--navy); border-radius: 20px; height: 8px; min-width: 4px; transition: width .3s; }
.stage-bar-count { width: 28px; text-align: right; font-weight: 700; color: var(--text); }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close { font-size: 1.4rem; color: var(--text-muted); line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: .75rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }
.modal.modal-wide { max-width: 860px; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: .5rem; z-index: 2000; }
.toast { padding: .65rem 1rem; border-radius: 8px; font-size: .875rem; font-weight: 500; box-shadow: 0 4px 16px rgba(0,0,0,.2); animation: slide-in .2s ease; max-width: 340px; }
.toast-success { background: #065f46; color: #fff; }
.toast-error { background: #991b1b; color: #fff; }
.toast-info { background: var(--navy); color: #fff; }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Loading ── */
.loading-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 1rem; color: var(--text-muted); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--navy); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { text-align: center; padding: 2rem; color: var(--text-muted); }

/* ── Misc ── */
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: .75rem; stroke: var(--border); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .825rem; }
.gap-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.valuation-tag { font-size: .78rem; font-weight: 600; color: var(--gold); }
.material-tag { font-size: .7rem; background: #e0f2fe; color: #0c4a6e; padding: .15rem .4rem; border-radius: 4px; }
.overdue-indicator { color: #dc2626; font-weight: 700; }
