/* Lightech CRM — one stylesheet, no build step. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e2e5ea;
  --border-strong: #cbd2dc;
  --text: #16202e;
  --text-dim: #5c6a7d;
  --text-faint: #8b97a7;
  --brand: #0a3a6b;
  --accent: #e8a317;
  --accent-soft: #fdf3dd;
  --ok: #15803d;
  --ok-soft: #e6f4ea;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --bad: #b91c1c;
  --bad-soft: #fbe9e9;
  --info: #1d4ed8;
  --info-soft: #e8effc;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 36px rgba(16, 24, 40, .16);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-w: 232px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c232d;
    --border: #2a323d;
    --border-strong: #3a4450;
    --text: #e6edf3;
    --text-dim: #9aa7b6;
    --text-faint: #6e7d8f;
    --brand: #072a4e;
    --accent: #f0b429;
    --accent-soft: #3a2f12;
    --ok: #4ade80;
    --ok-soft: #14301f;
    --warn: #fbbf24;
    --warn-soft: #362a10;
    --bad: #f87171;
    --bad-soft: #3a1a1a;
    --info: #93b4fc;
    --info-soft: #16233d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 36px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }

/* Pushes whatever follows it to the far end of any flex row. */
.spacer { flex: 1 1 auto; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-loading {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--text-faint);
}

/* ---------- layout ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--brand);
  color: #e8eef7;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
  font-weight: 700;
  letter-spacing: -.01em;
  font-size: 15px;
  color: #fff;
}
.logo .logo-mark { flex: 0 0 auto; border-radius: 7px; display: block; }

/* The company wordmark, parked in the top-right corner of every page. */
.brand-mark {
  height: 26px;
  width: auto;
  flex: 0 0 auto;
  display: block;
}
.logo small { display: block; font-weight: 500; font-size: 11px; color: #8fa3bd; letter-spacing: .04em; text-transform: uppercase; }

.nav { flex: 1; overflow-y: auto; padding: 6px 10px 16px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: #b9c6d8;
  font-weight: 500;
  margin-bottom: 2px;
}
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(232, 163, 23, .16); color: #fff; }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }
.nav .count {
  margin-left: auto;
  background: rgba(255, 255, 255, .12);
  border-radius: 20px;
  padding: 1px 7px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.nav a.active .count, .nav .count.hot { background: var(--bad); color: #fff; }
.nav-section { padding: 14px 12px 4px; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: #6d7f95; }

.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 12px; color: #94a5ba; }
.sidebar-foot .who { color: #fff; font-weight: 600; font-size: 13px; }
.sidebar-foot button {
  margin-top: 8px; width: 100%;
  background: rgba(255, 255, 255, .08); color: #d6e0ec;
  border: 0; border-radius: var(--radius-sm); padding: 7px; cursor: pointer; font: inherit;
}
.sidebar-foot button:hover { background: rgba(255, 255, 255, .16); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.topbar .sub { color: var(--text-faint); font-size: 12.5px; }
.topbar .spacer { flex: 1; }

.content { padding: 20px 22px 60px; max-width: 1500px; width: 100%; }

.mobile-nav { display: none; }
.mobile-head { display: none; }

/* ---------- cards, grids ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-head h2 { margin: 0; font-size: 13.5px; font-weight: 650; letter-spacing: .01em; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }

/* ---------- stats ---------- */

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 11.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .value { font-size: 22px; font-weight: 680; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.stat.accent { border-left: 3px solid var(--accent); }
.stat.good .value { color: var(--ok); }
.stat.bad .value { color: var(--bad); }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-faint);
  font-weight: 650;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
  position: sticky; top: 0;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .strong { font-weight: 600; }
td .dim { color: var(--text-faint); font-size: 12px; }

.empty { padding: 34px 18px; text-align: center; color: var(--text-faint); }
.empty .big { font-size: 26px; opacity: .5; display: block; margin-bottom: 6px; }

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge.grey { background: var(--surface-2); color: var(--text-dim); border-color: var(--border); }
.badge.blue { background: var(--info-soft); color: var(--info); }
.badge.amber { background: var(--accent-soft); color: var(--warn); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.red { background: var(--bad-soft); color: var(--bad); }

.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- forms ---------- */

.field { margin-bottom: 12px; }
.field > label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.field .help { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: -1px;
  border-color: var(--accent);
}
textarea { min-height: 74px; resize: vertical; }
input[type=checkbox] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; margin: 0 0 14px; }
legend { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); padding: 0 5px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.25); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #3a2a00; }
.btn.accent:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- filters ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 11px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.filters input, .filters select { width: auto; min-width: 130px; flex: 0 1 auto; }
.filters .search { flex: 1 1 200px; min-width: 160px; }
.filters .spacer { flex: 1; }
/* On desktop the wrapper is invisible and its children lay out as siblings. */
.filter-extra { display: contents; }

/* ---------- detail pages ---------- */

.crumb { font-size: 12.5px; color: var(--text-faint); margin-bottom: 3px; }
.crumb a { color: var(--text-dim); }

.detail-title { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.detail-title h1 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.detail-title .spacer { flex: 1; }

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

.nextstep {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 42%, transparent);
  border-radius: var(--radius);
  padding: 12px 15px;
  margin-bottom: 16px;
  display: flex; gap: 12px; align-items: flex-start;
}
.nextstep .ico { font-size: 17px; }
.nextstep .label { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--warn); }
.nextstep .body { font-size: 14.5px; font-weight: 560; margin-top: 1px; }
.nextstep.overdue { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 42%, transparent); }
.nextstep.overdue .label { color: var(--bad); }

/* ---------- timeline ---------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .dot {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
}
.timeline .meta { font-size: 12px; color: var(--text-faint); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.timeline .note { margin-top: 3px; white-space: pre-wrap; }
.timeline .body { min-width: 0; flex: 1; }

/* ---------- funnel ---------- */

.funnel { display: flex; flex-direction: column; gap: 6px; }
.funnel-row { display: grid; grid-template-columns: 180px 1fr 108px; align-items: center; gap: 10px; font-size: 12.5px; }
.funnel-bar { background: var(--surface-2); border-radius: 5px; height: 24px; overflow: hidden; border: 1px solid var(--border); }
.funnel-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #f6cf72); min-width: 2px; }
.funnel-fill.won { background: linear-gradient(90deg, var(--ok), #6ee7a0); }
.funnel-fill.lost { background: linear-gradient(90deg, var(--bad), #f79f9f); }
.funnel-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-dim); }

/* ---------- alerts ---------- */

.alert-item { display: flex; gap: 11px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.alert-item:last-child { border-bottom: 0; }
.alert-item .sev { width: 4px; border-radius: 3px; flex: 0 0 4px; }
.alert-item .sev.high { background: var(--bad); }
.alert-item .sev.medium { background: var(--warn); }
.alert-item .sev.low { background: var(--text-faint); }
.alert-item .t { font-weight: 600; }
.alert-item .d { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }
.alert-item > div:not(.sev):not(.spacer) { min-width: 0; }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 16, 26, .55);
  display: grid; place-items: center;
  padding: 18px; z-index: 100;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: min(660px, 100%);
  max-height: 92vh;
  display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
.modal.wide { width: min(920px, 100%); }
.modal-head { padding: 15px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 15.5px; }
.modal-head .spacer { flex: 1; }
.modal-head .x { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--text-faint); line-height: 1; padding: 0 4px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; background: var(--surface-2); }

.form-error {
  background: var(--bad-soft);
  color: var(--bad);
  border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 13px;
  font-size: 13px;
}

/* ---------- toasts ---------- */

.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--brand); color: #fff;
  padding: 10px 15px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13px;
  max-width: 340px;
  animation: toast-in .18s ease-out;
}
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); color: #04240f; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

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

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: var(--brand); }
.login-card {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 28px;
  width: min(390px, 100%);
}
.login-brand { padding: 0 0 20px; }
.login-brand img { width: 190px; max-width: 70%; height: auto; display: block; }
.login-brand .login-sub {
  margin-top: 7px;
  font-size: 12px;
  letter-spacing: .05em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-faint);
}
.login-demo { margin-top: 15px; font-size: 12px; color: var(--text-faint); border-top: 1px solid var(--border); padding-top: 12px; line-height: 1.7; }
.login-demo code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }

/* ---------- map ---------- */

#map { height: 520px; border-radius: var(--radius); z-index: 1; }
.map-fallback { padding: 16px; }

/* ---------- misc ---------- */

.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-faint); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 14px; }
.mb0 { margin-bottom: 0; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

.gps-box {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  background: var(--surface-2);
  font-size: 13px;
}
.gps-box.ok { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); border-style: solid; }
.gps-box.err { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); border-style: solid; }

.file-list { list-style: none; margin: 0; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.file-list li:last-child { border-bottom: 0; }
.file-list .ico { font-size: 17px; }
.file-list .spacer { flex: 1; }

/* ---------- responsive: phone-first for reps ---------- */

@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar { display: none; }

  .mobile-head {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--brand);
    color: #fff;
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top));
    position: sticky; top: 0; z-index: 20;
  }
  .mobile-head h1 { margin: 0; font-size: 15.5px; font-weight: 620; }
  .mobile-head .brand-mark { height: 17px; margin-right: 2px; }
  .mobile-head .logo-mark { border-radius: 5px; }
  .mobile-head .spacer { flex: 1; }
  .mobile-head .back { background: none; border: 0; color: #cfe0f5; font-size: 19px; cursor: pointer; padding: 0 4px; }
  .mobile-head .logout { background: rgba(255,255,255,.12); border: 0; color: #fff; border-radius: 6px; padding: 5px 9px; font: inherit; font-size: 12px; cursor: pointer; }

  .content { padding: 14px 13px calc(78px + env(safe-area-inset-bottom)); }

  .mobile-nav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 30;
  }
  .mobile-nav a {
    flex: 1;
    text-align: center;
    padding: 8px 2px 7px;
    font-size: 10.5px;
    color: var(--text-faint);
    font-weight: 600;
  }
  .mobile-nav a:hover { text-decoration: none; }
  .mobile-nav a.active { color: var(--accent); }
  .mobile-nav .ico { display: block; font-size: 18px; margin-bottom: 1px; }
  .mobile-nav .dot-badge {
    display: inline-block; width: 7px; height: 7px; border-radius: 50%;
    background: var(--bad); position: relative; top: -12px; left: 8px; margin-right: -7px;
  }

  /* Secondary filters hide behind the "Filters" toggle. */
  .filter-extra { display: none; width: 100%; }
  .filter-extra.open { display: flex; flex-wrap: wrap; gap: 8px; }
  .filter-extra.open select, .filter-extra.open input { flex: 1 1 140px; min-width: 0; }
  .filters { gap: 8px; }
  .filters .search { flex: 1 1 100%; }

  .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.side { grid-template-columns: 1fr; }
  .field-row, .field-row.three { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
  .kv dd { font-weight: 500; }
  .funnel-row { grid-template-columns: 116px 1fr 62px; font-size: 11.5px; }
  .detail-title h1 { font-size: 18px; }
  .stat .value { font-size: 19px; }

  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { width: 100%; max-height: 94vh; border-radius: 14px 14px 0 0; }
  .toasts { left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  /* Card-style rows instead of a squashed table. */
  table.stack, table.stack thead, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 9px;
    padding: 11px 13px;
    background: var(--surface);
  }
  table.stack td { border: 0; padding: 2px 0; }
  table.stack td.num { text-align: left; }
  table.stack td[data-label]::before {
    content: attr(data-label) " ";
    color: var(--text-faint);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    margin-right: 6px;
  }
}

@media (min-width: 861px) {
  .mobile-only { display: none !important; }
}
@media (max-width: 860px) {
  .desktop-only { display: none !important; }
}

@media print {
  .sidebar, .mobile-nav, .mobile-head, .topbar, .filters, .btn { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; }
}
