/* SurelyPlaced Lead Desk — design system
   Light palette on :root, dark overrides only. Never define a colour
   solely inside a media query, or the toggle cannot win both ways. */

:root {
  --brand:        #2B57D4;
  --brand-ink:    #1D3E9E;
  --accent:       #35C4B0;

  --bg:           #F6F7FB;
  --surface:      #FFFFFF;
  --surface-2:    #F0F2F8;
  --line:         #E2E6F0;
  --line-strong:  #CBD2E4;

  --text:         #141A2B;
  --text-soft:    #59617A;
  --text-faint:   #8A93AC;

  --ok:           #17A673;
  --warn:         #D98A0B;
  --danger:       #DC3B4B;
  --info:         #2B57D4;

  --ring:         rgba(43, 87, 212, .35);
  --shadow-sm:    0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-md:    0 4px 12px rgba(16,24,40,.08), 0 2px 4px rgba(16,24,40,.04);
  --shadow-lg:    0 24px 48px -12px rgba(16,24,40,.25);

  --r-sm: 6px;  --r-md: 10px;  --r-lg: 14px;  --r-xl: 20px;
  --gutter: 16px;
  --topbar-h: 58px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --brand:        #6E8CFF;
  --brand-ink:    #90A6FF;
  --accent:       #3FD9C2;

  --bg:           #0B0E17;
  --surface:      #141927;
  --surface-2:    #1B2133;
  --line:         #252C42;
  --line-strong:  #36405C;

  --text:         #EAEDF7;
  --text-soft:    #A3ADC7;
  --text-faint:   #717C99;

  --ok:           #35D399;
  --warn:         #F0B541;
  --danger:       #FF6B7A;
  --info:         #6E8CFF;

  --ring:         rgba(110, 140, 255, .40);
  --shadow-sm:    0 1px 2px rgba(0,0,0,.4);
  --shadow-md:    0 4px 14px rgba(0,0,0,.45);
  --shadow-lg:    0 24px 56px -12px rgba(0,0,0,.65);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
img, svg, canvas { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ---------------- primitives ---------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r-md);
  border: 1px solid transparent; background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  transition: background .14s, border-color .14s, transform .06s, opacity .14s;
}
.btn:hover   { background: var(--line); }
.btn:active  { transform: translateY(1px); }
.btn:disabled{ opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-ink); }
.btn--ghost   { background: transparent; border-color: var(--line-strong); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger  { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--sm      { padding: 7px 12px; font-size: 13px; }
.btn--block   { width: 100%; }

.input, .select, .textarea {
  width: 100%; padding: 9px 11px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color .14s, box-shadow .14s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring);
}
.select { cursor: pointer; appearance: none; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 13px top 55%, right 8px top 55%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.select--sm { padding: 7px 28px 7px 10px; font-size: 13px; width: auto; }
.input--bare { border: none; background: transparent; padding: 7px 4px; }
.input--bare:focus { box-shadow: none; }
.textarea { resize: vertical; min-height: 72px; }

.field { display: block; margin-bottom: 14px; }
.field__label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); color: var(--text-soft); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .01em; white-space: nowrap;
  background: var(--surface-2); color: var(--text-soft);
}
.chip--call      { background: color-mix(in srgb, var(--info) 14%, transparent);   color: var(--info); }
.chip--fup       { background: color-mix(in srgb, var(--warn) 18%, transparent);   color: var(--warn); }
.chip--fupdone   { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.chip--enrolled  { background: color-mix(in srgb, var(--ok) 16%, transparent);     color: var(--ok); }
.chip--closed    { background: var(--surface-2); color: var(--text-faint); }
.chip--role      { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); text-transform: capitalize; }
.chip--warn      { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

.alert { padding: 10px 13px; border-radius: var(--r-md); font-size: 13px; margin: 0 0 14px; }
.alert--error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.alert--ok    { background: color-mix(in srgb, var(--ok) 12%, transparent);     color: var(--ok); }
.alert--warn  { background: color-mix(in srgb, var(--warn) 14%, transparent);   color: var(--warn); }

/* ---------------- login ---------------- */

.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: var(--gutter);
  background: radial-gradient(1200px 700px at 72% 18%, #16204a 0%, #0a0d18 58%, #06080f 100%);
}
.login__globe { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.login__veil {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(900px 520px at 50% 50%, transparent 0%, rgba(4,6,12,.55) 72%);
}
.login__card {
  position: relative; width: min(100%, 388px);
  padding: 32px 30px 26px; border-radius: var(--r-xl);
  background: rgba(16, 20, 34, .72);
  border: 1px solid rgba(255,255,255,.10);
  backdrop-filter: blur(22px) saturate(1.3);
  -webkit-backdrop-filter: blur(22px) saturate(1.3);
  box-shadow: var(--shadow-lg);
  color: #EAEDF7;
}
.login__card .field__label { color: #9BA6C4; }
.login__card .input {
  background: rgba(255,255,255,.055);
  border-color: rgba(255,255,255,.14);
  color: #fff;
}
.login__card .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(63,217,194,.22); }
.login__foot { margin: 18px 0 0; text-align: center; font-size: 12px; color: #7F8AA8; }

.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 26px; }
.brand__mark { width: 40px; height: 40px; flex: none; }
.brand__name { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.brand__sub  { margin: 1px 0 0; font-size: 12.5px; color: var(--accent); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

/* ---------------- app shell ---------------- */

.app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  height: var(--topbar-h); padding-inline: var(--gutter);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar__left  { display: flex; align-items: center; gap: 9px; flex: none; }
.topbar__mark  { width: 26px; height: 26px; }
.topbar__title { font-weight: 800; letter-spacing: -.02em; font-size: 15.5px; }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.tabs { display: flex; gap: 4px; margin-left: 10px; }
.tab {
  padding: 7px 15px; border: none; border-radius: 999px; cursor: pointer;
  background: transparent; color: var(--text-soft); font-weight: 650; font-size: 13.5px;
  transition: background .14s, color .14s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.is-active { background: var(--brand); color: #fff; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff; font-weight: 800; font-size: 12.5px; letter-spacing: .02em;
}

.usermenu { position: relative; }
.pop {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 212px; z-index: 40;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 6px;
}
.pop__head { padding: 9px 11px 11px; border-bottom: 1px solid var(--line); margin-bottom: 5px;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.pop__item {
  display: block; width: 100%; text-align: left; padding: 9px 11px;
  background: none; border: none; border-radius: var(--r-sm); cursor: pointer; font-size: 13.5px;
}
.pop__item:hover { background: var(--surface-2); }
.pop__item--danger { color: var(--danger); }

.view { flex: 1; padding: var(--gutter); padding-block-end: 96px; }

/* ---------------- toolbar ---------------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar__search {
  display: flex; align-items: center; gap: 7px; flex: 1 1 260px; min-width: 0;
  padding: 2px 11px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-md); color: var(--text-faint);
}
.toolbar__search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.toolbar__filters { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar__actions { display: flex; gap: 8px; margin-left: auto; }

.bulkbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px;
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
  border-radius: var(--r-md); font-size: 13px; font-weight: 600;
}

/* ---------------- table ---------------- */

.tablewrap { overflow: auto; max-height: calc(100vh - 212px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
table.leads { width: 100%; border-collapse: collapse; min-width: 980px; }
.leads th {
  position: sticky; top: 0; z-index: 5;
  text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-faint); background: var(--surface-2);
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.leads th[data-sort] { cursor: pointer; user-select: none; }
.leads th[data-sort]:hover { color: var(--text); }
.leads td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.leads tbody tr { cursor: pointer; transition: background .1s; }
.leads tbody tr:hover { background: var(--surface-2); }
.leads tbody tr:last-child td { border-bottom: none; }
.leads .num { font-variant-numeric: tabular-nums; color: var(--text-faint); font-size: 12.5px; }
.leads .name { font-weight: 650; }
.leads .phone { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.cell-sub { display: block; font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 2px; flex-wrap: wrap; }
.pager__info { font-size: 12.5px; color: var(--text-faint); }
.pager__btns { display: flex; gap: 6px; }

.empty { padding: 56px 20px; text-align: center; color: var(--text-faint); }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }

/* mobile card list replaces the table */
.cards { display: none; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 13px 14px; cursor: pointer;
}
.card:active { background: var(--surface-2); }
.card__top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card__name { font-weight: 700; }
.card__meta { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--text-soft); }

/* ---------------- dashboard ---------------- */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 15px 16px; }
.kpi__label { font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.kpi__value { font-size: 25px; font-weight: 800; letter-spacing: -.02em; margin-top: 5px; font-variant-numeric: tabular-nums; }
.kpi__sub   { font-size: 12px; color: var(--text-soft); margin-top: 2px; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; }
.panel h3 { margin: 0 0 13px; font-size: 13.5px; font-weight: 700; }
.panel--wide { grid-column: 1 / -1; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar__row { display: grid; grid-template-columns: minmax(84px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 12.5px; }
.bar__label { color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar__track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar__fill  { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--accent)); }
.bar__val   { font-variant-numeric: tabular-nums; color: var(--text-faint); min-width: 2.5ch; text-align: right; }

table.simple { width: 100%; border-collapse: collapse; font-size: 13px; }
.simple th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); padding: 7px 8px; border-bottom: 1px solid var(--line); }
.simple td { padding: 9px 8px; border-bottom: 1px solid var(--line); }
.simple tr:last-child td { border-bottom: none; }
.simple .n { text-align: right; font-variant-numeric: tabular-nums; }

.spark { display: flex; align-items: flex-end; gap: 4px; height: 62px; }
/* Capped so a handful of days renders as bars, not slabs. */
.spark__bar { flex: 1 1 auto; min-width: 4px; max-width: 26px;
  background: linear-gradient(180deg, var(--brand), var(--accent));
  border-radius: 3px 3px 0 0; opacity: .9; }

/* ---------------- drawer + modal ---------------- */

.drawer, .modal { position: fixed; inset: 0; z-index: 60; }
.drawer__scrim, .modal__scrim { position: absolute; inset: 0; background: rgba(6,9,18,.55); backdrop-filter: blur(2px); }
.drawer__panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(100%, 470px);
  background: var(--bg); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg); overflow-y: auto; padding: 20px;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(22px); opacity: .5; } to { transform: none; opacity: 1; } }
.modal__box {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(calc(100% - 28px), 620px); max-height: 86vh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg); padding: 22px;
}
.sheet__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.sheet__title { margin: 0; font-size: 17px; font-weight: 750; letter-spacing: -.01em; }
.sheet__sub { margin: 3px 0 0; font-size: 12.5px; color: var(--text-faint); }

.kv { display: grid; grid-template-columns: 112px 1fr; gap: 7px 12px; font-size: 13px; margin: 14px 0; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; word-break: break-word; }

.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 15px; margin-bottom: 13px; }
.section h4 { margin: 0 0 12px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 90;
  padding: 11px 18px; border-radius: var(--r-md);
  background: var(--text); color: var(--bg); font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lg); max-width: calc(100% - 32px);
}
.toast--error { background: var(--danger); color: #fff; }

.tabbar { display: none; }

.spinner {
  width: 17px; height: 17px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .62s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- responsive ---------------- */

@media (max-width: 1080px) {
  .toolbar__actions { margin-left: 0; }
}

@media (max-width: 860px) {
  .topbar .tabs { display: none; }
  .topbar__title { display: none; }
  .tablewrap { display: none; }
  .cards { display: flex; }
  .tabbar {
    display: grid; grid-template-columns: repeat(3, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar__btn {
    padding: 13px 4px; border: none; background: none; cursor: pointer;
    color: var(--text-faint); font-weight: 650; font-size: 12.5px; min-height: 48px;
  }
  .tabbar__btn.is-active { color: var(--brand); box-shadow: inset 0 2px 0 var(--brand); }
  .drawer__panel { width: 100%; border-left: none; }
  .row2 { grid-template-columns: 1fr; }
}

/* Foldable closed (≈320px) and small phones */
@media (max-width: 420px) {
  :root { --gutter: 12px; }
  .toolbar__filters { width: 100%; }
  .toolbar__filters .select { flex: 1 1 auto; min-width: 0; }
  .toolbar__actions { width: 100%; }
  .toolbar__actions .btn { flex: 1; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 9px; }
  .kpi__value { font-size: 21px; }
  .kv { grid-template-columns: 94px 1fr; }
  .login__card { padding: 26px 20px 22px; }
  .login__globe { opacity: .55; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
