/* ---------- reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: #0f172a; color: #e2e8f0; line-height: 1.6;
}
a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- sidebar ---------- */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 220px;
  background: #1e293b; display: flex; flex-direction: column;
  padding: 1rem 0; overflow-y: auto; z-index: 100;
}
.sidebar-brand {
  padding: 0 1.25rem 1rem; font-size: 1.15rem; font-weight: 700;
  color: #f1f5f9; letter-spacing: .02em;
}
.sidebar-section {
  padding: .6rem 1.25rem .3rem; font-size: .7rem; text-transform: uppercase;
  letter-spacing: .08em; color: #64748b; font-weight: 600;
}
.sidebar a {
  display: block; padding: .5rem 1.25rem; color: #94a3b8;
  font-size: .9rem; transition: background .15s, color .15s;
}
.sidebar a:hover { background: #334155; color: #f1f5f9; text-decoration: none; }
.sidebar a.active { background: #334155; color: #60a5fa; border-left: 3px solid #60a5fa; }
.sidebar-spacer { flex: 1; }
.sidebar-user {
  padding: .75rem 1.25rem; border-top: 1px solid #334155;
  font-size: .8rem; color: #94a3b8; display: flex; justify-content: space-between; align-items: center;
}
.logout-link { color: #f87171; font-size: .8rem; }

/* ---------- main ---------- */
main { padding: 1.5rem 2rem; }
main.with-sidebar { margin-left: 220px; }

/* ---------- auth ---------- */
.auth-container {
  display: flex; align-items: center; justify-content: center; min-height: 80vh;
}
.auth-card {
  background: #1e293b; border-radius: 12px; padding: 2.5rem; width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,.3);
}
.auth-card h1 { font-size: 1.5rem; margin-bottom: .25rem; color: #f1f5f9; }
.auth-sub { color: #94a3b8; margin-bottom: 1.5rem; font-size: .9rem; }
.auth-card label { display: block; margin-bottom: .25rem; font-size: .85rem; color: #94a3b8; }
.auth-card input[type="text"],
.auth-card input[type="password"] {
  width: 100%; padding: .6rem .75rem; border: 1px solid #334155; border-radius: 6px;
  background: #0f172a; color: #e2e8f0; font-size: .95rem; margin-bottom: 1rem;
}
.auth-card input:focus { outline: none; border-color: #60a5fa; }

/* ---------- buttons ---------- */
.btn {
  display: inline-block; padding: .45rem 1rem; border-radius: 6px; border: none;
  font-size: .85rem; cursor: pointer; transition: background .15s; text-decoration: none;
}
.btn-primary { background: #3b82f6; color: #fff; }
.btn-primary:hover { background: #2563eb; text-decoration: none; }
.btn-secondary { background: #334155; color: #e2e8f0; }
.btn-secondary:hover { background: #475569; text-decoration: none; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-full { width: 100%; text-align: center; padding: .65rem; }

/* ---------- flash ---------- */
.flash { padding: .6rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .9rem; }
.flash-error { background: #7f1d1d; color: #fca5a5; }
.flash-success { background: #14532d; color: #86efac; }

/* ---------- page header ---------- */
.page-header { margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.5rem; color: #f1f5f9; }

/* ---------- metric cards ---------- */
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.metric-grid-3 { grid-template-columns: repeat(3, 1fr); }
.metric-card {
  background: #1e293b; border-radius: 10px; padding: 1.25rem; text-align: center;
}
.metric-value { font-size: 1.8rem; font-weight: 700; color: #f1f5f9; }
.metric-label { font-size: .8rem; color: #94a3b8; margin-top: .2rem; }

/* ---------- cards ---------- */
.card {
  background: #1e293b; border-radius: 10px; padding: 1.25rem; margin-bottom: 1rem;
}
.card h2 { font-size: 1.15rem; color: #f1f5f9; margin-bottom: .75rem; }
.card h3 { font-size: 1rem; color: #cbd5e1; margin-bottom: .75rem; }

/* ---------- charts ---------- */
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.chart-card-wide { grid-column: 1 / -1; }
.chart-card canvas { max-height: 280px; }
.chart-card-wide canvas { max-height: 200px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead th {
  text-align: left; padding: .55rem .6rem; color: #94a3b8; font-weight: 600;
  border-bottom: 1px solid #334155; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em;
}
tbody td { padding: .55rem .6rem; border-bottom: 1px solid #1e293b44; }
table.compact td, table.compact th { padding: .35rem .5rem; }
.clickable-row { cursor: pointer; transition: background .12s; }
.clickable-row:hover { background: #334155; }

/* ---------- filters ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filter-group { display: flex; flex-direction: column; }
.filter-group label { font-size: .75rem; color: #94a3b8; margin-bottom: .2rem; }
.filter-group input, .filter-group select {
  padding: .4rem .6rem; border: 1px solid #334155; border-radius: 6px;
  background: #0f172a; color: #e2e8f0; font-size: .85rem;
}
.filter-group input:focus, .filter-group select:focus { outline: none; border-color: #60a5fa; }
.filter-actions { flex-direction: row; gap: .5rem; display: flex; align-items: flex-end; }

/* ---------- pagination ---------- */
.pagination { display: flex; align-items: center; gap: .75rem; padding: .75rem 0; justify-content: center; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: .15rem .55rem; border-radius: 9999px;
  font-size: .75rem; font-weight: 600;
}
.badge-green { background: #065f4620; color: #34d399; border: 1px solid #34d39944; }
.badge-amber { background: #78350f20; color: #fbbf24; border: 1px solid #fbbf2444; }
.badge-red   { background: #7f1d1d20; color: #f87171; border: 1px solid #f8717144; }

/* ---------- detail page ---------- */
.detail-header { display: flex; flex-direction: column; gap: .75rem; }
.detail-meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .5rem; }
.meta-label { display: block; font-size: .7rem; color: #64748b; text-transform: uppercase; letter-spacing: .06em; }
.detail-actions { display: flex; gap: .5rem; }

/* ---------- two column ---------- */
.two-col { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1rem; }
.col-left, .col-right { min-width: 0; }

/* ---------- transcript ---------- */
.transcript { max-height: 600px; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; }
.chat-bubble { padding: .6rem .85rem; border-radius: 10px; max-width: 85%; }
.chat-bubble.agent { background: #1e40af22; border: 1px solid #1e40af44; align-self: flex-start; }
.chat-bubble.user  { background: #065f4622; border: 1px solid #065f4644; align-self: flex-end; }
.chat-bubble.system { background: #33415522; border: 1px solid #33415544; align-self: center; font-style: italic; }
.chat-role { font-size: .7rem; font-weight: 600; color: #64748b; text-transform: uppercase; }
.chat-bubble p { margin-top: .15rem; font-size: .9rem; }

/* ---------- analysis list ---------- */
.analysis-list { display: grid; grid-template-columns: auto 1fr; gap: .3rem .75rem; }
.analysis-list dt { font-size: .8rem; color: #64748b; padding-top: .1rem; }
.analysis-list dd { font-size: .9rem; }

/* ---------- CRM cards grid ---------- */
.crm-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }

/* ---------- form inline row ---------- */
.form-inline-row { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.form-inline-row input[type="text"],
.form-inline-row input[type="password"] {
  padding: .45rem .6rem; border: 1px solid #334155; border-radius: 6px;
  background: #0f172a; color: #e2e8f0; font-size: .88rem;
}
.form-inline-row input:focus { outline: none; border-color: #60a5fa; }
.checkbox-label { display: flex; align-items: center; gap: .3rem; font-size: .88rem; color: #94a3b8; }

/* ---------- dealsheet form ---------- */
.ds-section { margin-bottom: .5rem; }
.ds-section h2 { font-size: 1.1rem; color: #f1f5f9; margin-bottom: .75rem; }
.ds-section-body {}
.ds-section-body.hidden { display: none; }
.ds-collapsible { cursor: pointer; user-select: none; }
.ds-collapsible::before { content: '\25BC '; font-size: .7rem; color: #64748b; }
.ds-collapsible.collapsed::before { content: '\25B6 '; }
.ds-collapsible-details { margin-top: .75rem; }
.ds-collapsible-details summary {
  cursor: pointer; font-size: .9rem; color: #94a3b8; padding: .4rem 0; user-select: none;
}
.ds-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: .6rem; }
.ds-field { display: flex; flex-direction: column; flex: 1; min-width: 150px; }
.ds-field-sm { flex: 0 0 100px; min-width: 80px; }
.ds-field-wide { flex: 2; min-width: 250px; }
.ds-field label { font-size: .78rem; color: #94a3b8; margin-bottom: .2rem; }
.ds-field input, .ds-field select, .ds-field textarea {
  padding: .45rem .6rem; border: 1px solid #334155; border-radius: 6px;
  background: #0f172a; color: #e2e8f0; font-size: .88rem; font-family: inherit;
}
.ds-field input:focus, .ds-field select:focus, .ds-field textarea:focus {
  outline: none; border-color: #60a5fa;
}
.ds-field textarea { resize: vertical; }
.ds-input-readonly {
  background: #1e293b !important; color: #94a3b8 !important;
  cursor: not-allowed; border-color: #1e293b !important;
}
.ds-readonly {
  padding: .45rem .6rem; background: #1e293b; border: 1px solid #1e293b;
  border-radius: 6px; font-size: .95rem; color: #94a3b8; min-height: 2rem;
}
.ds-btn-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; padding-top: .75rem;
  border-top: 1px solid #334155;
}
.ds-actions {
  display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; margin-bottom: 2rem;
}

/* ---------- dealsheet detail ---------- */
.ds-detail-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .5rem .75rem;
}
.ds-detail-grid-wide { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.ds-detail-field { display: flex; flex-direction: column; padding: .3rem 0; }
.ds-detail-field span:last-child { font-size: .95rem; }

/* ---------- utilities ---------- */
.chart-loading { padding: 2rem; text-align: center; color: #64748b; font-size: .9rem; }
.mono { font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace; font-size: .85rem; }
.muted { color: #64748b; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .sidebar { width: 180px; }
  main.with-sidebar { margin-left: 180px; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .crm-cards { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .sidebar { position: static; width: 100%; }
  main.with-sidebar { margin-left: 0; }
}
