/* SparkleCRM design system: Bootstrap 5.3 base, re-skinned through tokens. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e6e8ec;
  --border-strong: #d4d7dd;
  --ink: #111827;
  --ink-2: #4b5563;
  --muted: #8a8f98;
  --brand: #2a78d6;
  --brand-hover: #256abf;
  --brand-ink: #1c5cab;
  --brand-soft: #e9f2fc;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .08);
  --sidebar-w: 248px;

  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--ink);
  --bs-border-color: var(--border);
  --bs-secondary-color: var(--ink-2);
  --bs-primary: var(--brand);
  --bs-primary-rgb: 42, 120, 214;
  --bs-link-color: var(--brand-ink);
  --bs-link-color-rgb: 28, 92, 171;
  --bs-link-hover-color: var(--brand);
  --bs-border-radius: var(--radius-sm);
  --bs-focus-ring-color: rgba(42, 120, 214, .25);
}

body { font-size: .925rem; -webkit-font-smoothing: antialiased; }
h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6 { font-weight: 650; letter-spacing: -.01em; color: var(--ink); }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.text-muted, .text-secondary { color: var(--muted) !important; }
.small-caps { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; color: var(--muted); }
.tabular { font-variant-numeric: tabular-nums; }
.pre-line { white-space: pre-line; }

/* Buttons and forms */
.btn { --bs-btn-font-weight: 550; --bs-btn-border-radius: var(--radius-sm); --bs-btn-padding-x: .9rem; }
.btn-sm { --bs-btn-padding-x: .65rem; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-hover); --bs-btn-hover-border-color: var(--brand-hover); --bs-btn-active-bg: var(--brand-ink); --bs-btn-active-border-color: var(--brand-ink); }
.btn-light { --bs-btn-bg: var(--surface); --bs-btn-border-color: var(--border-strong); --bs-btn-hover-bg: var(--surface-2); --bs-btn-hover-border-color: var(--border-strong); --bs-btn-color: var(--ink); }
.btn-soft { background: var(--brand-soft); color: var(--brand-ink); border: 1px solid transparent; }
.btn-soft:hover { background: #d9e8fa; color: var(--brand-ink); }
.form-control, .form-select { border-color: var(--border-strong); border-radius: var(--radius-sm); }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(42, 120, 214, .15); }
.form-label { font-weight: 550; font-size: .85rem; color: var(--ink-2); }
.form-text { color: var(--muted); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

/* Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); }
@media (min-width: 768px) {
  .sidebar { position: sticky; top: 0; height: 100vh; flex-shrink: 0; display: flex; flex-direction: column; }
}
.sidebar .offcanvas-body { display: flex; flex-direction: column; padding: 1rem .75rem; height: 100%; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; color: var(--ink); padding: .25rem .6rem 1rem; }
.brand:hover { text-decoration: none; color: var(--ink); }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #2a78d6, #6250d6); display: grid; place-items: center; color: #fff; font-size: .9rem; }
.nav-section { margin: 1rem .6rem .35rem; }
.side-link { display: flex; align-items: center; gap: .65rem; padding: .5rem .65rem; border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 550; }
.side-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.side-link.active { background: var(--brand-soft); color: var(--brand-ink); }
.side-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.side-link .badge { margin-left: auto; }
.user-card { margin-top: auto; border-top: 1px solid var(--border); padding: .9rem .4rem 0; display: flex; align-items: center; gap: .6rem; }
.user-card .who { min-width: 0; flex: 1; line-height: 1.2; }
.user-card .who div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.content { padding: 1.5rem 1rem 3rem; max-width: 1400px; width: 100%; }
@media (min-width: 768px) { .content { padding: 2rem 2rem 3rem; } }
.impersonation-banner { background: #fff4e5; color: #8a4b00; border-bottom: 1px solid #f6d8a8; padding: .55rem 1rem; font-size: .875rem; display: flex; align-items: center; justify-content: center; gap: .75rem; flex-wrap: wrap; }

/* Page header */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; margin: 0; }
.page-header .subtitle { color: var(--muted); margin-top: .2rem; }
.back-link { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }

/* Cards */
.card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--surface); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); padding: .9rem 1.15rem; font-weight: 650; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.card-header .hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
.card-body { padding: 1.15rem; }
.card-flush .table { margin: 0; }

/* KPI tiles */
.stat { padding: 1rem 1.15rem; height: 100%; }
.stat .label { font-size: .8rem; color: var(--muted); font-weight: 550; }
.stat .value { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin-top: .25rem; color: var(--ink); }
.stat .sub { font-size: .8rem; color: var(--ink-2); margin-top: .15rem; }
.stat-warn .value { color: #b45309; }

/* Tables */
.table { --bs-table-bg: transparent; --bs-table-hover-bg: var(--surface-2); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .75rem 1rem; border-color: var(--border); vertical-align: middle; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.row-link { color: var(--ink); font-weight: 600; }
.unread .row-link::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); margin-left: .45rem; vertical-align: middle; }
.overdue { color: #b42318; font-weight: 600; }

/* Avatar */
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 650; font-size: .78rem; flex-shrink: 0; background: #eef0f3; color: var(--ink-2); }
.avatar-lg { width: 48px; height: 48px; font-size: 1rem; }
.avatar-0 { background: #e9f2fc; color: #1c5cab; }
.avatar-1 { background: #fdeee6; color: #b4461c; }
.avatar-2 { background: #e3f6ef; color: #12795a; }
.avatar-3 { background: #efedfb; color: #4a3aa7; }
.avatar-4 { background: #fdf3df; color: #8a5a00; }

/* Status pills */
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; line-height: 1.4; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill-primary { background: #e9f2fc; color: #1c5cab; }
.pill-info { background: #e3f6f3; color: #0f766e; }
.pill-violet { background: #efedfb; color: #4a3aa7; }
.pill-warning { background: #fdf3df; color: #8a5a00; }
.pill-success { background: #e4f5e4; color: #1d6b1d; }
.pill-danger { background: #fdecec; color: #b42318; }
.pill-secondary { background: #f0f1f3; color: #4b5563; }
.pill-dark { background: #e5e7eb; color: #111827; }
.tag { display: inline-block; padding: .1rem .45rem; border-radius: 6px; font-size: .7rem; font-weight: 600; background: #f0f1f3; color: var(--ink-2); }
.tag-warn { background: #fdf3df; color: #8a5a00; }
.tag-dark { background: #1f2937; color: #fff; }

/* Filters */
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
.filter-bar .form-control, .filter-bar .form-select { width: auto; min-width: 9.5rem; }
.filter-bar .search { flex: 1 1 16rem; }

/* Empty state */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .icon { width: 44px; height: 44px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-ink); display: inline-grid; place-items: center; margin-bottom: .75rem; }
.empty h2 { font-size: 1rem; color: var(--ink); margin-bottom: .25rem; }

/* Definition lists */
.dl { display: grid; grid-template-columns: minmax(7rem, 36%) 1fr; gap: .55rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-weight: 500; }
.dl dd { margin: 0; word-break: break-word; }

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.4rem; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 1.1rem; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 0; top: .35rem; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); }
.timeline li.t-note::after { border-color: var(--brand); }
.timeline li.t-status::after { border-color: #1baf7a; }
.timeline .meta { font-size: .78rem; color: var(--muted); }
.note-body { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem .7rem; margin-top: .25rem; }

/* Lead header */
.lead-hero { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.lead-hero h1 { font-size: 1.4rem; margin: 0; }
.quick-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.reason-field[hidden] { display: none; }

/* Charts */
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--ink-2); flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; background: var(--c); }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; margin-bottom: .7rem; font-size: .85rem; }
.bar-row > .pill { justify-self: start; }
.bar-row .track { grid-column: 1 / -1; height: 8px; background: #f0f1f3; border-radius: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; width: 0; border-radius: 4px; background: var(--c, var(--brand)); }
.c-won { --c: #2a78d6; } .c-lost { --c: #eb6834; } .c-open { --c: #c3c2b7; } .c-invalid { --c: #898781; }

/* Guest (sign-in) */
.guest-shell { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
@media (min-width: 992px) { .guest-shell { grid-template-columns: 1.05fr 1fr; } }
.guest-art { display: none; background: radial-gradient(1200px 600px at 10% 10%, #3b82f6 0%, transparent 60%), linear-gradient(140deg, #1c5cab, #4a3aa7); color: #fff; padding: 3rem; flex-direction: column; justify-content: space-between; }
@media (min-width: 992px) { .guest-art { display: flex; } }
.guest-art h2 { color: #fff; font-size: 2rem; max-width: 22rem; line-height: 1.2; }
.guest-art p { color: rgba(255, 255, 255, .8); max-width: 26rem; }
.guest-art .brand, .guest-art .brand:hover { color: #fff; padding: 0; }
.guest-art .brand-mark { background: rgba(255, 255, 255, .18); }
.guest-form { display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; }
.guest-card { width: 100%; max-width: 400px; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .8rem; margin: 1.25rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Misc */
.raw-json { max-height: 24rem; overflow: auto; font-size: .78rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem; }
.log-tail { max-height: 30rem; overflow: auto; font-size: .75rem; background: #0f172a; color: #e2e8f0; padding: 1rem; border-radius: var(--radius-sm); }
.code-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem; font-size: .8rem; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .4rem; }
.ok { background: #0ca30c; } .bad { background: #d03b3b; }
.table-editor td { padding: .5rem .6rem !important; }
.table-editor .form-control, .table-editor .form-select { font-size: .85rem; padding-top: .3rem; padding-bottom: .3rem; min-width: 8.5rem; }
.table-editor .w-order { min-width: 4.5rem; }
.table-editor code { white-space: nowrap; }
.w-order { width: 5rem; }

/* Lead list on phones: rows become cards */
@media (max-width: 767.98px) {
  .table-leads thead { display: none; }
  .table-leads tr { display: block; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
  .table-leads td { display: block; border: 0 !important; padding: .1rem 0 !important; }
  .table-leads td[data-label]::before { content: attr(data-label) " · "; color: var(--muted); font-size: .8rem; }
  .table-leads td.hide-sm { display: none; }
}
