:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242838;
  --surface3: #2d3247;
  --border: #2e3350;
  --text: #e8eaf0;
  --text-muted: #8892a4;
  --text-dim: #5a6478;
  --accent: #4f7cff;
  --accent-hover: #6b94ff;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --orange: #f97316;
  --purple: #a855f7;
  --sidebar-width: 220px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

/* Layout */
#app { display: flex; height: 100vh; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

#sidebar-logo h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

#sidebar-logo p {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

#sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 16px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  padding: 0 8px;
  margin-bottom: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
  user-select: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(79,124,255,0.15); color: var(--accent); }

.nav-icon { font-size: 16px; width: 20px; text-align: center; }

#sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

/* Main content */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
}

#topbar h2 {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}

#content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.stat-value.green { color: var(--green); }
.stat-value.accent { color: var(--accent); }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface3); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-yellow { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-red { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-blue { background: rgba(79,124,255,0.15); color: var(--accent); }
.badge-purple { background: rgba(168,85,247,0.15); color: var(--purple); }
.badge-gray { background: var(--surface2); color: var(--text-muted); }

/* Stage badges */
.stage-prospect { background: rgba(245,158,11,0.15); color: var(--yellow); }
.stage-demo_scheduled { background: rgba(79,124,255,0.15); color: var(--accent); }
.stage-proposal_sent { background: rgba(168,85,247,0.15); color: var(--purple); }
.stage-closed_won { background: rgba(249,115,22,0.15); color: var(--orange); }
.stage-active_client { background: rgba(34,197,94,0.15); color: var(--green); }
.stage-dead { background: var(--surface2); color: var(--text-dim); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
}
tr:hover td { background: var(--surface2); }
tr:last-child td { border-bottom: none; }
.clickable { cursor: pointer; }

/* Company list */
.company-row { cursor: pointer; }
.company-name { font-weight: 600; }
.company-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Pipeline kanban */
#pipeline-board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.pipeline-col {
  flex: 0 0 220px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.pipeline-col-header {
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pipeline-col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; }

.deal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.deal-card:hover { border-color: var(--accent); }
.deal-card-company { font-size: 12px; font-weight: 600; }
.deal-card-product { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.deal-card-fee { font-size: 13px; font-weight: 700; color: var(--green); margin-top: 6px; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.form-control {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  transition: border-color 0.15s;
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
}
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-lg { max-width: 900px; }

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

.modal-title { font-size: 15px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.close-btn:hover { background: var(--surface2); color: var(--text); }

/* Search */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
}
.search-input:focus { outline: none; border-color: var(--accent); }

/* Voice recorder */
#voice-panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.voice-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

#mic-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--surface3);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#mic-btn.recording {
  background: var(--red);
  animation: pulse 1s ease infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.voice-status { font-size: 13px; color: var(--text-muted); }

#voice-transcript {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
  margin-bottom: 10px;
}
#voice-transcript:focus { outline: none; border-color: var(--accent); }

/* Activity feed */
.activity-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; margin-top: 5px; }
.activity-content { flex: 1; }
.activity-company { font-weight: 600; font-size: 13px; }
.activity-text { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.activity-time { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* Follow-up list */
.followup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.followup-item:last-child { border-bottom: none; }
.followup-date { font-size: 12px; font-weight: 600; min-width: 80px; }
.followup-date.overdue { color: var(--red); }
.followup-date.today { color: var(--yellow); }
.followup-date.soon { color: var(--accent); }

/* Detail view */
.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.detail-title { font-size: 22px; font-weight: 700; }
.detail-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

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

.info-item { margin-bottom: 10px; }
.info-label { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-dim); }
.info-value { font-size: 13px; color: var(--text); margin-top: 2px; }

/* Referral tracker */
.referral-summary {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}

.referral-summary .fee-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.fee-gross { font-size: 13px; color: var(--text-muted); text-decoration: line-through; }
.fee-effective { font-size: 20px; font-weight: 700; color: var(--green); }
.fee-discount { font-size: 12px; color: var(--orange); }

.floor-indicator {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  padding: 4px 8px;
  background: rgba(245,158,11,0.1);
  border-radius: 4px;
  display: inline-block;
}

/* Auth screen */
#auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 24px;
}
.auth-logo h1 { font-size: 22px; font-weight: 700; color: var(--accent); }
.auth-logo p { color: var(--text-muted); font-size: 13px; }

.auth-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 8px;
}

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

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-btn {
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* Notes */
.note-item {
  background: var(--surface2);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.note-meta { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; display: flex; gap: 8px; }
.note-source { text-transform: uppercase; font-weight: 600; }
.note-text { font-size: 13px; white-space: pre-wrap; word-break: break-word; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 32px; margin-bottom: 8px; }
.empty-state p { font-size: 13px; }

/* Responsive */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: left 0.2s;
  }
  #sidebar.open { left: 0; }
  .grid-2, .form-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  #content { padding: 12px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* Toast */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
  max-width: 300px;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Misc */
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.fw-bold { font-weight: 700; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
