*, *::before, *::after { box-sizing: border-box; }

:root {
  --sidebar-w: 220px;
  --sidebar-bg: #111827;
  --sidebar-hover: #1f2937;
  --sidebar-text: #9ca3af;
  --sidebar-active: #f9fafb;
  --accent: #3b82f6;
  --border: #e5e7eb;
  --bg: #f9fafb;
  --white: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 18px 20px 16px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
  border-bottom: 1px solid #1f2937;
}

.sidebar-nav { flex: 1; padding: 6px 0; }

.nav-item {
  display: block;
  padding: 10px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.1s, color 0.1s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #d1d5db; }
.nav-item.active { color: var(--sidebar-active); background: var(--sidebar-hover); font-weight: 500; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid #1f2937;
}

.sidebar-user-name {
  font-size: 12px;
  color: var(--sidebar-text);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: none;
  border: 1px solid #374151;
  color: #9ca3af;
  padding: 5px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  width: 100%;
  text-align: left;
  font-family: var(--font);
}
.logout-btn:hover { background: #1f2937; color: #d1d5db; }

.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.content-header {
  padding: 22px 32px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}
.content-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}
.header-sub {
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 8px;
}

.content-body { padding: 24px 32px; flex: 1; }

/* ── Login ── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 40px;
  width: 360px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.login-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 28px;
}

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
}
.form-group input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  font-family: var(--font);
}
.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  font-family: var(--font);
  transition: background .1s;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #2563eb; }
.btn-secondary { background: var(--white); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-block { width: 100%; justify-content: center; margin-top: 8px; }

/* ── Alerts ── */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
}
.badge-snf              { background: #dbeafe; color: #1d4ed8; }
.badge-liquor_license   { background: #fef3c7; color: #92400e; }
.badge-tax_sale         { background: #fee2e2; color: #991b1b; }
.badge-bankruptcy       { background: #ede9fe; color: #6d28d9; }
.badge-auction          { background: #ffedd5; color: #9a3412; }
.badge-enforcement      { background: #ffe4e6; color: #9f1239; }

.sff-badge {
  display: inline-block;
  padding: 1px 7px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
}

/* ── Score pill ── */
.score-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}
.score-high { background: #dcfce7; color: #166534; }
.score-med  { background: #fef9c3; color: #854d0e; }
.score-low  { background: #f3f4f6; color: var(--muted); }

/* ── Stars ── */
.stars       { color: #f59e0b; letter-spacing: 1px; }
.stars-empty { color: #d1d5db; letter-spacing: 1px; }

/* ── Cards ── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th {
  text-align: left;
  padding: 9px 14px;
  background: #f9fafb;
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover td { background: #f9fafb; }
table.data-table a { color: var(--accent); text-decoration: none; }
table.data-table a:hover { text-decoration: underline; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.filter-bar select {
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  background: var(--white);
  height: 34px;
  font-family: var(--font);
}
.filter-check {
  flex-direction: row !important;
  align-items: center !important;
  gap: 6px !important;
  font-size: 13px !important;
  font-weight: 400 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  color: var(--text) !important;
  padding-bottom: 2px;
}

/* ── Event list (feed) ── */
.event-list { display: flex; flex-direction: column; gap: 10px; }

.event-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.event-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.event-state, .event-city { font-size: 12px; color: var(--muted); }
.event-time { font-size: 12px; color: var(--muted); margin-left: auto; }
.event-title { font-size: 15px; font-weight: 500; margin-bottom: 4px; }
.event-title a { color: var(--text); text-decoration: none; }
.event-title a:hover { color: var(--accent); }
.event-summary { font-size: 13px; color: var(--muted); }
.event-score { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ── Record detail ── */
.record-detail {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  align-items: start;
}

.detail-section { margin-bottom: 20px; }
.detail-section h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 0 0 10px;
}
.detail-row {
  display: flex;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: 12px; color: var(--muted); width: 160px; flex-shrink: 0; }
.detail-value { font-size: 13px; color: var(--text); word-break: break-word; }

/* ── Admin statuses ── */
.status-ok      { color: #166534; font-weight: 500; }
.status-error   { color: #991b1b; font-weight: 500; }
.status-running { color: #1d4ed8; font-weight: 500; }
.status-none    { color: var(--muted); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 0;
  color: var(--muted);
  font-size: 15px;
}

/* ── Error page ── */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 80px 32px;
  text-align: center;
}
.error-page h1 { font-size: 22px; margin: 0 0 8px; }
.error-page p { color: var(--muted); margin: 0; }

/* ── External link ── */
.external-link::after { content: " ↗"; font-size: 11px; }

/* ── Code ── */
code {
  font-family: "SFMono-Regular", Menlo, monospace;
  font-size: 12px;
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .record-detail { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { margin-left: 0; }
  .content-header, .content-body { padding-left: 16px; padding-right: 16px; }
}

/* ── Deal status badges ── */
.deal-status {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  text-transform: capitalize;
}
.deal-status-new          { background: #f3f4f6; color: #374151; }
.deal-status-researching  { background: #dbeafe; color: #1d4ed8; }
.deal-status-contacted    { background: #fef3c7; color: #92400e; }
.deal-status-negotiating  { background: #ffedd5; color: #9a3412; }
.deal-status-dead         { background: #fee2e2; color: #991b1b; }
.deal-status-closed       { background: #dcfce7; color: #166534; }

/* ── Status tabs ── */
.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
}
.status-tab {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--white);
  transition: background .1s, color .1s;
}
.status-tab:hover { background: var(--bg); color: var(--text); }
.status-tab.active { background: var(--text); color: #fff; border-color: var(--text); }
.tab-count {
  display: inline-block;
  background: rgba(0,0,0,.1);
  border-radius: 8px;
  padding: 0 5px;
  font-size: 11px;
  margin-left: 4px;
}
.status-tab.active .tab-count { background: rgba(255,255,255,.2); }

/* ── Deal layout ── */
.deal-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) { .deal-layout { grid-template-columns: 1fr; } }

/* ── Activity timeline ── */
.activity-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }

.activity-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.activity-type-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 1px 6px;
  border-radius: 4px;
}
.activity-type-note           { background: #f3f4f6; color: #374151; }
.activity-type-call_logged    { background: #d1fae5; color: #065f46; }
.activity-type-status_change  { background: #dbeafe; color: #1d4ed8; }
.activity-type-assignment     { background: #ede9fe; color: #6d28d9; }

/* ── Toggle button (alert on/off) ── */
.toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: background .1s;
}
.toggle-on  { background: #dcfce7; border-color: #86efac; color: #166534; }
.toggle-off { color: var(--muted); }
.toggle-btn:hover { opacity: .8; }
