/* LTH CRM — polished self-hosted UI */

:root {
  --bg: #0a0e17;
  --bg-elevated: #111827;
  --surface: #151c2c;
  --surface-hover: #1a2336;
  --surface2: #1e293b;
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.22);
  --text: #f8fafc;
  --text-secondary: #cbd5e1;
  --muted: #64748b;
  --brand: #3b82f6;
  --brand-dim: rgba(59, 130, 246, 0.12);
  --brand-hover: #2563eb;
  --accent: #06b6d4;
  --danger: #ef4444;
  --success: #22c55e;
  --warn: #f59e0b;
  --sidebar-w: 15rem;
  --drawer-w: min(42rem, 100vw);
  --radius: 0.75rem;
  --radius-lg: 1rem;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* --- Auth pages --- */
.center-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(59, 130, 246, 0.15), transparent),
    var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 26rem;
  box-shadow: var(--shadow);
}

.auth-card-wide { max-width: 32rem; }

.auth-brand { text-align: center; margin-bottom: 1.75rem; }

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  border-radius: 0.875rem;
  font-weight: 700;
  font-size: 0.875rem;
  letter-spacing: 0.04em;
  color: #fff;
  margin-bottom: 1rem;
}

.logo-mark.sm { width: 2.25rem; height: 2.25rem; font-size: 0.6875rem; border-radius: 0.625rem; }

h1 { font-size: 1.375rem; font-weight: 700; margin: 0 0 0.375rem; letter-spacing: -0.02em; }
h2 { font-size: 1.125rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

.subtitle { color: var(--muted); font-size: 0.875rem; margin: 0 0 1.25rem; }
.hint { color: var(--muted); font-size: 0.8125rem; margin: 0.5rem 0; }
.hint-warn { color: var(--warn); }

.loader {
  width: 2rem; height: 2rem;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.form-stack label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.625rem 0.875rem;
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  margin-bottom: 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-dim);
}

input::placeholder { color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.625rem 1rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-sm { padding: 0.4375rem 0.875rem; font-size: 0.8125rem; width: auto; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-block { width: 100%; margin-top: 0.5rem; }
.btn-danger { color: var(--danger); border-color: rgba(239, 68, 68, 0.35); background: transparent; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.alert-error { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.25); color: #fca5a5; }
.alert-info { background: rgba(245, 158, 11, 0.08); border: 1px solid rgba(245, 158, 11, 0.25); color: #fcd34d; }
.alert-success { background: rgba(34, 197, 94, 0.1); border: 1px solid rgba(34, 197, 94, 0.25); color: #86efac; }

.mfa-input { text-align: center; font-size: 1.5rem; letter-spacing: 0.4em; font-weight: 600; }

/* --- App shell --- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.875rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.sidebar-title { font-weight: 700; font-size: 0.9375rem; }
.sidebar-sub { font-size: 0.75rem; color: var(--muted); margin-top: 0.125rem; text-transform: capitalize; }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 0.75rem; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--surface); color: var(--text-secondary); }
.nav-item.active { background: var(--brand-dim); color: var(--brand); }
.nav-muted { color: var(--muted); font-size: 0.8125rem; }
.nav-icon { opacity: 0.7; font-size: 1rem; width: 1.25rem; text-align: center; }

.app-main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  padding: 1.25rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 14, 23, 0.8);
  backdrop-filter: blur(8px);
}

.page-title { font-size: 1.25rem; font-weight: 700; margin: 0; }
.page-sub { font-size: 0.8125rem; color: var(--muted); margin: 0.25rem 0 0; }

.content { padding: 1.5rem 1.75rem 2rem; flex: 1; }

/* --- KPI row --- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.875rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.125rem;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}

.kpi:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.kpi.active { border-color: rgba(59, 130, 246, 0.5); background: var(--brand-dim); }
.kpi-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.kpi-label { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; font-weight: 500; }

/* --- Toolbar --- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.search-wrap {
  flex: 1;
  min-width: 14rem;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  font-size: 1rem;
}

.search-wrap input {
  margin: 0;
  padding-left: 2.25rem;
  background: var(--surface);
}

.toolbar-select {
  width: auto;
  min-width: 11rem;
  margin: 0;
  background: var(--surface);
}

.chip-group { display: flex; gap: 0.375rem; flex-wrap: wrap; }

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 9999px;
  padding: 0.375rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.chip:hover { color: var(--text-secondary); border-color: var(--border-strong); }
.chip.active { background: var(--brand-dim); border-color: rgba(59, 130, 246, 0.4); color: var(--brand); }

/* --- Table --- */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

.data-table th {
  text-align: left;
  padding: 0.75rem 1.25rem;
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}

.data-table td {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr.clickable { cursor: pointer; transition: background 0.12s; }
.data-table tr.clickable:hover { background: var(--surface-hover); }

.contact-cell { display: flex; align-items: center; gap: 0.75rem; }

.avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.625rem;
  background: linear-gradient(135deg, var(--brand-dim), rgba(6, 182, 212, 0.15));
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand);
  flex-shrink: 0;
}

.avatar.lg { width: 3rem; height: 3rem; font-size: 1rem; border-radius: 0.75rem; }

.contact-name { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 0.75rem; color: var(--muted); margin-top: 0.125rem; }

.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; font-size: 0.875rem; }

/* --- Badges & tags --- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 600;
  border: 1px solid;
  white-space: nowrap;
}

.badge-new { background: rgba(59,130,246,0.15); color: #93c5fd; border-color: rgba(59,130,246,0.3); }
.badge-email_sent, .badge-in_progress, .badge-contacted { background: rgba(14,165,233,0.12); color: #7dd3fc; border-color: rgba(14,165,233,0.28); }
.badge-email_received { background: rgba(6,182,212,0.12); color: #67e8f9; border-color: rgba(6,182,212,0.28); }
.badge-warm { background: rgba(245,158,11,0.12); color: #fcd34d; border-color: rgba(245,158,11,0.28); }
.badge-hot { background: rgba(249,115,22,0.12); color: #fdba74; border-color: rgba(249,115,22,0.28); }
.badge-discovery { background: rgba(168,85,247,0.12); color: #d8b4fe; border-color: rgba(168,85,247,0.28); }
.badge-invoice_sent { background: rgba(99,102,241,0.12); color: #a5b4fc; border-color: rgba(99,102,241,0.28); }
.badge-invoice_paid { background: rgba(34,197,94,0.12); color: #86efac; border-color: rgba(34,197,94,0.28); }
.badge-active { background: rgba(16,185,129,0.12); color: #6ee7b7; border-color: rgba(16,185,129,0.28); }
.badge-closed { background: rgba(34,197,94,0.12); color: #86efac; border-color: rgba(34,197,94,0.28); }
.badge-lost { background: rgba(239,68,68,0.12); color: #fca5a5; border-color: rgba(239,68,68,0.28); }
.badge-spam { background: rgba(100,116,139,0.12); color: #cbd5e1; border-color: rgba(100,116,139,0.28); }
.badge-pending { background: rgba(245,158,11,0.12); color: #fcd34d; border-color: rgba(245,158,11,0.28); }
.badge-paid { background: rgba(34,197,94,0.12); color: #86efac; border-color: rgba(34,197,94,0.28); }

.tag {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 0.3rem;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 0.35rem;
  vertical-align: middle;
}
.tag-managed_sale { background: rgba(99,102,241,0.15); color: #a5b4fc; border: 1px solid rgba(99,102,241,0.3); }
.tag-in_house { background: rgba(20,184,166,0.15); color: #5eead4; border: 1px solid rgba(20,184,166,0.3); }

/* --- Drawer --- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex;
  justify-content: flex-end;
}

.drawer {
  width: var(--drawer-w);
  height: 100%;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.4);
  animation: slideIn 0.22s ease-out;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0.8; }
  to { transform: translateX(0); opacity: 1; }
}

.drawer-head {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.drawer-title-block { display: flex; gap: 1rem; align-items: flex-start; min-width: 0; }
.drawer-head h2 { font-size: 1.125rem; margin: 0; word-break: break-word; }
.drawer-sub { font-size: 0.8125rem; color: var(--muted); margin: 0.25rem 0 0; }
.drawer-badges { margin-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.375rem; align-items: center; }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-hover); }

.drawer-tabs {
  display: flex;
  gap: 0;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0.875rem 1rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

/* --- Detail panels --- */
.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem 1.25rem;
}

@media (max-width: 520px) { .info-grid { grid-template-columns: 1fr; } }

.info-item label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.info-item div { font-size: 0.875rem; color: var(--text-secondary); }

.message-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
  white-space: pre-wrap;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.panel-section {
  margin-bottom: 1.5rem;
}

.panel-section h3 {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 0.875rem;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.875rem; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

.field-label { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.25rem; }

.reply-item, .card-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  margin-bottom: 0.625rem;
  font-size: 0.875rem;
}

.claim-banner {
  background: var(--brand-dim);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.claim-banner p { margin: 0; font-size: 0.8125rem; color: var(--text-secondary); }

/* --- Timeline --- */
.timeline { margin: 0; }
.timeline-item {
  display: grid;
  grid-template-columns: 1rem 1fr;
  gap: 0.875rem;
  padding-bottom: 1.125rem;
  position: relative;
}
.timeline-item:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 0.4375rem;
  top: 1.125rem;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--brand);
  margin-top: 0.2rem;
  box-shadow: 0 0 0 3px var(--brand-dim);
}
.timeline-msg { font-size: 0.875rem; margin-top: 0.25rem; color: var(--text-secondary); white-space: pre-wrap; }

/* --- Team / panels --- */
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.panel-card-narrow { max-width: 32rem; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.inline-form { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }

.user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: none; }
.user-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.secret-box {
  font-family: ui-monospace, monospace;
  background: var(--bg);
  padding: 0.875rem;
  border-radius: var(--radius);
  word-break: break-all;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  margin: 0.75rem 0;
}

.checkbox-row { display: flex; gap: 0.75rem; align-items: start; margin-bottom: 1rem; }
.checkbox-row input { width: auto; margin: 0.25rem 0 0; }

.earning-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.earning-amount { font-weight: 700; color: var(--text); }
