/* =============================================================
   Bolinger CRM — internal dashboard
   Palette mirrors the public site (PA harbor navy + warm sand)
   ============================================================= */

:root {
  --crm-bg:        #F5F1E8;
  --crm-surface:   #FBF7EE;
  --crm-surface-2: #FFFDF6;
  --crm-offset:    #ECE5D3;
  --crm-border:    #D7CDB4;
  --crm-divider:   #E5DCC4;

  --crm-text:        #1A2A3A;
  --crm-text-muted:  #5B6878;
  --crm-text-faint:  #97A1AE;
  --crm-text-inverse:#FBF7EE;

  --crm-primary:        #143247;
  --crm-primary-hover:  #1F4B68;
  --crm-primary-active: #0C2231;
  --crm-primary-soft:   #DCE5EC;

  --crm-accent:      #B9582F;
  --crm-accent-soft: #F2D8C7;

  --crm-success:      #2F7D4F;
  --crm-success-soft: #DDEFE3;
  --crm-warn:         #B8881A;
  --crm-warn-soft:    #F4E5B8;
  --crm-error:        #B42318;
  --crm-error-soft:   #F5D9D5;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(20, 50, 71, 0.05), 0 1px 1px rgba(20, 50, 71, 0.04);
  --shadow-md: 0 6px 18px rgba(20, 50, 71, 0.08), 0 2px 6px rgba(20, 50, 71, 0.05);
  --shadow-lg: 0 24px 48px rgba(12, 34, 49, 0.18);

  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--crm-bg);
  color: var(--crm-text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--crm-primary); }
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--crm-offset);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--crm-text);
  margin: 0;
}
h1 { font-size: 1.75rem; line-height: 1.2; }
h2 { font-size: 1.125rem; line-height: 1.3; font-weight: 600; font-family: var(--font-body); letter-spacing: -0.005em; }
.muted { color: var(--crm-text-muted); }

/* ------------------------------------------------------------- */
/* Login                                                          */
/* ------------------------------------------------------------- */
[hidden] { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
  background:
    radial-gradient(800px 500px at 20% -10%, rgba(20, 50, 71, 0.10), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, rgba(185, 88, 47, 0.10), transparent 60%),
    var(--crm-bg);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: var(--radius-lg);
  padding: 2rem 2rem 1.5rem;
  box-shadow: var(--shadow-md);
}
.login-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--crm-text);
  text-decoration: none;
  margin-bottom: 1.25rem;
  font-weight: 600;
}
.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}
.login-sub {
  color: var(--crm-text-muted);
  margin: 0 0 1.5rem;
}
.login-help {
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--crm-text-muted);
  border-top: 1px solid var(--crm-divider);
  padding-top: 1rem;
  line-height: 1.55;
}

/* ------------------------------------------------------------- */
/* App shell                                                      */
/* ------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--crm-primary);
  color: var(--crm-text-inverse);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.875rem;
  gap: 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  padding: 0.25rem 0.5rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-family: var(--font-display); font-size: 1.05rem; font-weight: 500; }
.brand-text span { font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(251, 247, 238, 0.6); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: rgba(251, 247, 238, 0.78);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { background: rgba(255,255,255,0.06); color: var(--crm-text-inverse); }
.nav-link.is-active { background: rgba(255,255,255,0.12); color: var(--crm-text-inverse); }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.10);
  padding-top: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}
.sidebar-footer .btn--ghost {
  background: rgba(255,255,255,0.06);
  color: var(--crm-text-inverse);
  border-color: rgba(255,255,255,0.18);
}
.sidebar-footer .btn--ghost:hover {
  background: rgba(255,255,255,0.14);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: rgba(251, 247, 238, 0.85);
  padding: 0 0.4rem;
}
.user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5EC07A;
  box-shadow: 0 0 0 3px rgba(94,192,122,0.18);
}

/* ------------------------------------------------------------- */
/* Main content                                                   */
/* ------------------------------------------------------------- */
.main {
  padding: 2rem 2.25rem 3rem;
  max-width: 1280px;
  width: 100%;
}
.view { display: none; }
.view.is-active { display: block; }

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.view-header h1 { font-size: 1.75rem; }
.view-sub {
  color: var(--crm-text-muted);
  margin: 0.25rem 0 0;
  font-size: 0.95rem;
}

/* ------------------------------------------------------------- */
/* KPI grid + cards                                               */
/* ------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi {
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
}
.kpi-label {
  font-size: 0.78rem;
  color: var(--crm-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 0.5rem;
}
.kpi-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--crm-text);
}
.kpi-sub {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--crm-text-faint);
}

.card {
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
}
.card--flush { padding: 0; }
.card--narrow { max-width: 520px; }
.card-section-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.875rem;
  gap: 1rem;
}
.card-sub { color: var(--crm-text-muted); font-size: 0.85rem; }
.card--flush .card-header { padding: 1rem 1.25rem 0.5rem; margin-bottom: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

/* ------------------------------------------------------------- */
/* Bar list (for "by type" / "top pages")                         */
/* ------------------------------------------------------------- */
.bar-list { display: flex; flex-direction: column; gap: 0.5rem; }
.bar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
}
.bar-row .bar-label {
  font-size: 0.92rem;
  color: var(--crm-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-row .bar-count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--crm-text-muted);
}
.bar-track {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--crm-offset);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--crm-primary), var(--crm-primary-hover));
  border-radius: 4px;
  transition: width 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ------------------------------------------------------------- */
/* Forms                                                          */
/* ------------------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.875rem;
}
.field > span {
  font-size: 0.82rem;
  color: var(--crm-text-muted);
  font-weight: 500;
}
.field small { font-size: 0.78rem; color: var(--crm-text-faint); }
.field input, .field select, .field textarea {
  font: inherit;
  color: var(--crm-text);
  background: var(--crm-surface-2);
  border: 1px solid var(--crm-border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--crm-primary);
  box-shadow: 0 0 0 3px rgba(20, 50, 71, 0.12);
}
.field--inline {
  flex-direction: column;
  gap: 0.25rem;
  margin: 0;
  min-width: 140px;
}
.field--inline > span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
.field--inline input, .field--inline select { padding: 0.4rem 0.55rem; font-size: 0.92rem; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.form-alert {
  margin: 0.5rem 0 0.875rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--crm-error-soft);
  border: 1px solid var(--crm-error);
  color: #6b1410;
}
.form-alert.is-success {
  background: var(--crm-success-soft);
  border-color: var(--crm-success);
  color: #1d4d31;
}

/* ------------------------------------------------------------- */
/* Buttons                                                        */
/* ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn--primary {
  background: var(--crm-primary);
  color: var(--crm-text-inverse);
}
.btn--primary:hover:not(:disabled) { background: var(--crm-primary-hover); }
.btn--primary:active:not(:disabled) { background: var(--crm-primary-active); }
.btn--ghost {
  background: transparent;
  color: var(--crm-text);
  border-color: var(--crm-border);
}
.btn--ghost:hover { background: var(--crm-offset); }
.btn--block { width: 100%; }
.btn--sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--crm-text-muted);
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.icon-btn:hover { background: var(--crm-offset); color: var(--crm-text); }

/* ------------------------------------------------------------- */
/* Tables                                                         */
/* ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.table th, .table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--crm-divider);
  vertical-align: top;
}
.table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--crm-text-muted);
  font-weight: 600;
  background: var(--crm-offset);
}
.table tbody tr { transition: background var(--transition); }
.table tbody tr.row-clickable { cursor: pointer; }
.table tbody tr.row-clickable:hover { background: rgba(20, 50, 71, 0.04); }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--crm-text-faint);
  font-size: 0.95rem;
}

/* status pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.pill--buyer    { background: var(--crm-primary-soft); color: #0F273A; }
.pill--seller   { background: var(--crm-accent-soft); color: #6E2A0F; }
.pill--as-is    { background: #E6DEF8; color: #3E2A6B; }
.pill--reno     { background: var(--crm-warn-soft); color: #5A4108; }
.pill--default  { background: var(--crm-offset); color: var(--crm-text); }

.pill--sent    { background: var(--crm-success-soft); color: #1c4d31; }
.pill--failed  { background: var(--crm-error-soft); color: #7a160f; }
.pill--pending { background: var(--crm-offset); color: var(--crm-text-muted); }
.pill--dry-run { background: var(--crm-primary-soft); color: #0F273A; }

/* ------------------------------------------------------------- */
/* Recent leads (overview)                                        */
/* ------------------------------------------------------------- */
.lead-list { display: flex; flex-direction: column; gap: 0.5rem; }
.lead-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 100px 1.5fr auto;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--crm-divider);
  border-radius: var(--radius-sm);
  background: var(--crm-surface-2);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.lead-row:hover { background: var(--crm-offset); border-color: var(--crm-border); }
.lead-row .lead-meta {
  display: flex;
  flex-direction: column;
}
.lead-row .lead-name { font-weight: 600; color: var(--crm-text); }
.lead-row .lead-detail { color: var(--crm-text-muted); font-size: 0.85rem; }
.lead-row .lead-time { color: var(--crm-text-faint); font-size: 0.85rem; }

/* ------------------------------------------------------------- */
/* Drawer                                                         */
/* ------------------------------------------------------------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}
.drawer[hidden] { display: none; }
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 34, 49, 0.45);
  backdrop-filter: blur(2px);
  animation: fade-in 200ms ease;
}
.drawer-panel {
  position: relative;
  width: min(520px, 100%);
  background: var(--crm-surface);
  border-left: 1px solid var(--crm-border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slide-in 280ms cubic-bezier(0.16, 1, 0.3, 1);
}
.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--crm-divider);
}
.drawer-header h2 { font-size: 1.25rem; margin: 0; }
.drawer-body {
  padding: 1.25rem 1.5rem 2rem;
  overflow-y: auto;
  flex: 1;
}
@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes fade-in {
  from { opacity: 0; } to { opacity: 1; }
}

.dl-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}
.dl-list dt {
  color: var(--crm-text-muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 0.1rem;
}
.dl-list dd {
  margin: 0;
  color: var(--crm-text);
  word-break: break-word;
}
.section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--crm-text-muted);
  margin: 1.5rem 0 0.5rem;
}

/* ------------------------------------------------------------- */
/* Daily chart (simple SVG-free bars)                             */
/* ------------------------------------------------------------- */
.daily-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
  gap: 0.5rem;
  align-items: end;
  min-height: 140px;
  padding: 0.5rem 0 0;
}
.daily-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--crm-text-muted);
}
.daily-bar .bar-stack {
  width: 100%;
  background: var(--crm-offset);
  border-radius: 4px 4px 0 0;
  height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  position: relative;
}
.daily-bar .stack-views {
  background: var(--crm-primary);
  width: 100%;
  transition: height 400ms cubic-bezier(0.16, 1, 0.3, 1);
}
.daily-bar .stack-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--crm-text);
}

/* ------------------------------------------------------------- */
/* Toast                                                          */
/* ------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--crm-text);
  color: var(--crm-text-inverse);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  box-shadow: var(--shadow-md);
  z-index: 60;
  animation: slide-in 200ms ease;
}
.toast.is-error { background: var(--crm-error); }

/* ------------------------------------------------------------- */
/* Responsive                                                     */
/* ------------------------------------------------------------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
    overflow-x: auto;
  }
  .sidebar-footer { flex-direction: row; align-items: center; border-top: 0; padding-top: 0; }
  .brand-text { display: none; }
  .nav { flex-direction: row; flex: 1; }
  .nav-link { flex: 1; justify-content: center; padding: 0.5rem; }
  .nav-link span, .nav-link svg + * { display: none; }
  .main { padding: 1.5rem 1.25rem 3rem; }
  .lead-row { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------- */
/* Links view                                                     */
/* ------------------------------------------------------------- */
.link-builder {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.9rem 1rem;
}
.link-builder__label { grid-column: span 2; }
.link-builder__out {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.25rem;
}
.link-list { display: flex; flex-direction: column; }
.link-row {
  display: grid;
  grid-template-columns: minmax(150px, 220px) 1fr auto;
  gap: 0.5rem 1rem;
  align-items: center;
  padding: 0.75rem 0;
  border-top: 1px solid var(--crm-border, rgba(20, 50, 71, 0.12));
}
.link-row:first-child { border-top: 0; }
.link-row strong { font-size: 0.95rem; }
.link-row .muted { font-size: 0.8rem; }
.link-url {
  flex: 1 1 320px;
  min-width: 0;
  font-size: 0.82rem;
  word-break: break-all;
  background: var(--crm-offset, #f3efe6);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
}
.link-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.qr-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 25, 36, 0.55);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 1rem;
}
.qr-modal[hidden] { display: none; }
.qr-modal__dialog {
  background: #fff;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.qr-box { display: grid; place-items: center; margin: 0.75rem auto 1rem; }
.qr-box img, .qr-box canvas { width: 240px; height: 240px; }
.qr-modal .link-actions { justify-content: center; }
@media (max-width: 640px) {
  .link-builder__label { grid-column: auto; }
  .link-row { grid-template-columns: 1fr; }
}
