:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --surface: #171a21;
  --border: #2a3140;
  --text: #e8eaef;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --danger: #f87171;
  --high: #f97316;
  --med: #eab308;
  --low: #64748b;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #dde1ea;
    --text: #111827;
    --muted: #5b6472;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.auth-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
}

.muted {
  color: var(--muted);
  margin: 0 0 1rem;
  font-size: 0.95rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.field span {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

input,
select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.btn {
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 0.9rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0;
}

.error.hidden,
.hidden {
  display: none !important;
}

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.inline select {
  width: auto;
  min-width: 9rem;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.leads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.leads-table th,
.leads-table td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.leads-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

.leads-table tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.pri-high {
  background: rgba(249, 115, 22, 0.2);
  color: var(--high);
}

.pri-med {
  background: rgba(234, 179, 8, 0.2);
  color: var(--med);
}

.pri-low {
  background: rgba(100, 116, 139, 0.25);
  color: var(--low);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
  }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: min(88vh, 720px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.35);
}

@media (min-width: 640px) {
  .modal-panel {
    border-radius: 12px;
  }
}

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

.modal-head h2 {
  margin: 0;
  font-size: 1rem;
}

.modal-meta {
  padding: 0.35rem 1rem 0;
  font-size: 0.85rem;
}

.thread {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bubble-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.bubble-wrap.out {
  align-items: flex-end;
}

.bubble-label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.bubble {
  max-width: 95%;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble-wrap.out .bubble {
  background: rgba(91, 140, 255, 0.15);
  border-color: rgba(91, 140, 255, 0.35);
}

.small {
  font-size: 0.8rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
