:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-soft: #fbfbfd;
  --surface-raised: rgba(255, 255, 255, 0.92);
  --text: #1d1d1f;
  --text-soft: #3a3a3c;
  --muted: #6e6e73;
  --muted-2: #a1a1a6;
  --line: rgba(60, 60, 67, 0.14);
  --line-strong: rgba(60, 60, 67, 0.24);
  --blue: #007aff;
  --blue-soft: #eaf3ff;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --purple: #5856d6;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 12px 34px rgba(0,0,0,.06);
  --shadow-soft: 0 1px 2px rgba(0,0,0,.03), 0 6px 18px rgba(0,0,0,.05);
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --max: 1880px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 16% -10%, rgba(0,122,255,.08), transparent 30%),
    radial-gradient(circle at 92% 10%, rgba(52,199,89,.08), transparent 28%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select, a { font: inherit; }
button { cursor: pointer; }
a { color: var(--blue); text-decoration: none; }
a:hover, button:hover { filter: brightness(.98); }
.hidden, .visually-hidden { display: none !important; }
.desktop-only { display: inline-flex; }
.full-width { width: 100%; justify-content: center; }
.full-span { grid-column: 1 / -1; }
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255,255,255,.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.login-card h1 { margin: 0 0 12px; font-size: 34px; line-height: 1.05; }
.app-mark, .brand-icon {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--blue);
}
.app-mark { margin-bottom: 18px; }
.mini-help { color: var(--muted); font-size: 13px; line-height: 1.45; margin: 16px 0 0; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: auto minmax(280px, 520px) auto 1fr;
  align-items: center;
  gap: 18px;
  min-height: 76px;
  padding: 12px 30px;
  border-bottom: 1px solid rgba(60,60,67,.10);
  background: rgba(251,251,253,.84);
  backdrop-filter: blur(24px) saturate(160%);
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.top-search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(0,0,0,.03);
  color: var(--muted);
}
.top-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.top-search kbd {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 7px;
  background: #f6f6f8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.topnav {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}
.nav-pill {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  background: transparent;
  color: var(--text-soft);
  font-weight: 600;
}
.nav-pill.active {
  background: var(--blue-soft);
  color: var(--blue);
}
.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.user-menu, .icon-text-button, .ghost-button, .primary-button, .secondary-add-button, .row-button, .quick-action, .reset-filters {
  border: 1px solid var(--line);
  border-radius: 14px;
  min-height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.user-menu:hover, .icon-text-button:hover, .ghost-button:hover, .row-button:hover, .quick-action:hover, .reset-filters:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-soft);
}
.primary-button {
  border-color: transparent;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 8px 18px rgba(0,122,255,.24);
}
.secondary-add-button { color: var(--blue); background: var(--blue-soft); border-color: transparent; }
.icon-text-button { min-height: 38px; padding-inline: 12px; color: var(--text-soft); }
.user-menu { max-width: 240px; color: var(--muted); font-weight: 600; }
.user-menu span:first-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  display: inline-grid;
  place-items: center;
}

/* Main layout */
.app-shell {
  width: min(var(--max), 100%);
  margin: 0 auto;
  padding: 28px 30px 48px;
}
.focus-section h1 {
  margin: 0 0 16px;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: -.03em;
}
.dashboard {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 18px;
  margin-bottom: 26px;
}
.metric {
  position: relative;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface-raised);
  box-shadow: var(--shadow-soft);
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 16px;
  padding: 20px;
  text-align: left;
  overflow: hidden;
}
.metric::after {
  content: "";
  position: absolute;
  right: -26px;
  top: -30px;
  width: 94px;
  height: 94px;
  border-radius: 999px;
  background: var(--metric-color, var(--blue));
  opacity: .10;
}
.metric-icon {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  color: var(--metric-color, var(--blue));
  background: color-mix(in srgb, var(--metric-color, var(--blue)) 12%, white);
  font-weight: 900;
}
.metric-label { grid-column: 2; color: var(--muted); font-size: 14px; font-weight: 700; align-self: end; }
.metric strong { grid-column: 2; font-size: 34px; line-height: .9; letter-spacing: -.04em; align-self: start; }
.metric-red { --metric-color: var(--red); }
.metric-blue { --metric-color: var(--blue); }
.metric-green { --metric-color: var(--green); }
.metric-purple { --metric-color: var(--purple); }
.metric-orange { --metric-color: var(--orange); }

.viewbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255,255,255,.82);
  box-shadow: var(--shadow-soft);
}
.view-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.view-tab {
  border: 0;
  border-radius: 14px;
  min-height: 44px;
  padding: 0 20px;
  background: transparent;
  color: var(--text-soft);
  font-weight: 700;
}
.view-tab.active {
  background: var(--blue-soft);
  color: var(--blue);
  box-shadow: inset 0 0 0 1px rgba(0,122,255,.06);
}
.reset-filters {
  border: 0;
  background: transparent;
  color: var(--blue);
  white-space: nowrap;
}
.active-filter-row {
  margin: 12px 0 20px;
  color: var(--muted);
  font-size: 13px;
}
.hidden-filters { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; overflow: hidden; }

.workspace {
  display: grid;
  grid-template-columns: minmax(640px, 1.65fr) minmax(440px, .95fr);
  gap: 22px;
  align-items: start;
}
.lead-worklist-panel, .detail-panel, .notification-panel, .modal-frame, .modal-body, .danger-zone, .admin-user-row {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: rgba(255,255,255,.88);
  box-shadow: var(--shadow-soft);
}
.lead-worklist-panel {
  padding: 22px;
}
.section-header, .panel-title-row, .compact-row, .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.section-header { margin-bottom: 16px; }
.section-header h2, .panel-title-row h2, .modal-header h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -.03em;
}
.section-header p { margin: 5px 0 0; }

/* Lead list */
.lead-list { display: grid; gap: 10px; }
.lead-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(300px, 1.7fr) minmax(170px, .8fr) minmax(150px, .65fr) 124px;
  gap: 18px;
  align-items: center;
  min-height: 116px;
  padding: 16px 14px 16px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  transition: border-color .14s ease, box-shadow .14s ease, transform .14s ease, opacity .14s ease;
}
.lead-card:hover { border-color: rgba(0,122,255,.28); box-shadow: var(--shadow-soft); }
.lead-card.selected { border-color: rgba(0,122,255,.58); box-shadow: 0 0 0 3px rgba(0,122,255,.10), var(--shadow-soft); }
.lead-card.terminal { opacity: .76; }
.lead-card-accent {
  position: absolute;
  left: 14px;
  top: 18px;
  bottom: 18px;
  width: 5px;
  border-radius: 999px;
  background: var(--status-color, var(--blue));
}
.lead-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.lead-title-row strong { font-size: 17px; letter-spacing: -.02em; }
.mini-dot, .status-dot, .status-dot-large {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--status-color, var(--blue));
  flex: 0 0 auto;
}
.status-dot-large { width: 12px; height: 12px; }
.status-pill, .duplicate-pill, .detail-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #f2f2f7;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.status-pill .status-dot { width: 7px; height: 7px; }
.lead-phone { display: inline-flex; color: var(--text-soft); font-weight: 500; margin-bottom: 4px; }
.address-link, .link-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 700;
  text-align: left;
}
.address-link::after { content: " ↗"; font-size: 12px; }
.lead-item-summary { margin: 4px 0 0; color: var(--muted); line-height: 1.35; }
.lead-next, .lead-finance {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}
.detail-mini-label { color: var(--muted-2); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.action-pill {
  color: var(--text);
  font-weight: 800;
  font-size: 14px;
}
.action-pill.overdue { color: var(--red); }
.action-pill.today { color: var(--blue); }
.lead-finance strong { font-size: 18px; color: var(--text); }
.profit.positive { color: #149b39; font-weight: 800; }
.lead-actions { display: grid; gap: 8px; }
.row-button {
  min-height: 34px;
  border-radius: 12px;
  padding-inline: 12px;
  font-size: 13px;
  background: var(--surface-soft);
}
.primary-row-action { color: var(--blue); }
.empty-state {
  padding: 34px;
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
  background: var(--surface-soft);
  text-align: center;
}
.empty-state h3 { margin: 0 0 8px; }

/* Detail panel */
.detail-panel {
  position: sticky;
  top: 94px;
  max-height: calc(100vh - 118px);
  overflow: auto;
  padding: 22px;
}
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.detail-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.detail-title-row h2 { margin: 0; font-size: 26px; line-height: 1.1; letter-spacing: -.04em; }
.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: inline-grid;
  place-items: center;
  background: var(--surface);
  color: var(--muted);
  font-size: 20px;
}
.detail-rows { display: grid; margin-top: 4px; }
.detail-row {
  display: grid;
  grid-template-columns: 28px 130px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  border-bottom: 1px solid var(--line);
}
.detail-icon { color: var(--muted); font-weight: 800; }
.detail-label { color: var(--muted); font-weight: 700; }
.detail-value {
  color: var(--text-soft);
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
}
.detail-action {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  white-space: nowrap;
}
.detail-tag { color: var(--muted); background: var(--surface-soft); }
.status-text { display: inline-flex; align-items: center; gap: 8px; }
.detail-quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 18px 0;
}
.quick-action { min-height: 46px; color: var(--blue); background: var(--surface); }
.detail-footer {
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.compact-admin-panel {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-soft);
  box-shadow: none;
}
.compact-admin-panel h3 { margin: 0 0 10px; font-size: 15px; }
.quick-status-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.status-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 34px;
  padding: 0 12px;
  background: #fff;
  font-weight: 700;
  color: var(--text-soft);
}
.status-button.danger { color: var(--red); }
.inline-form { display: grid; gap: 10px; }
.inline-form textarea, .inline-form input, .form-grid input, .form-grid select, .form-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  min-height: 42px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.inline-form textarea:focus, .form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
  border-color: rgba(0,122,255,.55);
  box-shadow: 0 0 0 4px rgba(0,122,255,.10);
}
.timeline, .task-list { display: grid; gap: 8px; margin-top: 10px; }
.timeline-item, .task-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.timeline-item time, .task-item time { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.task-item { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.task-item.done { opacity: .62; }

/* Notifications */
.notification-panel {
  position: fixed;
  top: 86px;
  right: 28px;
  z-index: 60;
  width: min(420px, calc(100vw - 32px));
  padding: 18px;
  box-shadow: var(--shadow);
}
.notifications-list { display: grid; gap: 10px; margin-top: 14px; max-height: 62vh; overflow: auto; }
.notification-item {
  display: grid;
  gap: 4px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}
.notification-item.unread { border-color: rgba(0,122,255,.38); background: var(--blue-soft); }
.notification-item time { color: var(--muted); font-size: 12px; }

/* Dialogs / admin */
dialog.modal {
  width: min(860px, calc(100vw - 26px));
  border: 0;
  padding: 0;
  border-radius: 28px;
  background: transparent;
}
dialog::backdrop { background: rgba(0,0,0,.24); backdrop-filter: blur(8px); }
.modal-frame, .modal-body {
  border-radius: 28px 28px 0 0;
  box-shadow: none;
}
.modal-frame { border-bottom: 0; padding: 20px 22px 0; }
.modal-body {
  border-top: 0;
  border-radius: 0 0 28px 28px;
  padding: 18px 22px 22px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.compact-form { gap: 12px; }
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}
.split-actions { justify-content: space-between; }
.modal-spacer { flex: 1; }
.danger, .ghost-button.danger { color: var(--red); }
.danger-zone {
  margin-top: 18px;
  padding: 16px;
  background: #fff7f7;
  border-color: rgba(255,59,48,.18);
}
.admin-users-list { display: grid; gap: 10px; margin-top: 16px; }
.admin-user-row {
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: none;
}
.admin-user-row span { display: block; color: var(--muted); margin-top: 4px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Toast / floating */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 100;
  transform: translateX(-50%);
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(29,29,31,.92);
  color: #fff;
  box-shadow: var(--shadow);
}
.floating-add-button {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 28px;
  box-shadow: 0 12px 26px rgba(0,122,255,.32);
}
.readonly-user .admin-only { display: none !important; }

@media (max-width: 1280px) {
  .topbar { grid-template-columns: auto minmax(260px, 1fr) auto; }
  .topnav { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .detail-panel { position: static; max-height: none; }
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 12px 16px;
  }
  .brand-lockup { font-size: 16px; }
  .top-search { grid-column: 1 / -1; order: 3; }
  .top-actions .icon-text-button, .top-actions .user-menu { display: none; }
  .app-shell { padding: 20px 16px 88px; }
  .dashboard { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .metric { min-height: 88px; padding: 16px; }
  .metric strong { font-size: 28px; }
  .viewbar { align-items: stretch; flex-direction: column; }
  .view-tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .view-tab { white-space: nowrap; }
  .lead-card {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px 14px 16px 24px;
  }
  .lead-actions { grid-template-columns: repeat(3, 1fr); }
  .detail-row { grid-template-columns: 24px 1fr; gap: 8px; padding: 12px 0; }
  .detail-label { grid-column: 2; }
  .detail-value { grid-column: 2; }
  .detail-action, .detail-tag { grid-column: 2; justify-self: start; }
  .form-grid { grid-template-columns: 1fr; }
  .desktop-only { display: none !important; }
}

@media (max-width: 560px) {
  .focus-section h1 { font-size: 25px; }
  .dashboard { grid-template-columns: 1fr; }
  .metric { grid-template-columns: 42px 1fr; }
  .lead-worklist-panel, .detail-panel { padding: 16px; border-radius: 22px; }
  .detail-title-row h2 { font-size: 22px; }
  .detail-quick-actions { grid-template-columns: 1fr; }
  .lead-actions { grid-template-columns: 1fr; }
  .floating-add-button { display: inline-grid; place-items: center; }
}

/* Mobile/menu redesign extension */
.mobile-only { display: none; }
.brand-copy { display: grid; gap: 2px; }
.eyebrow-app {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 700;
}
#topSectionTitle {
  font-size: 19px;
  line-height: 1.05;
  letter-spacing: -.03em;
}
.secondary-page {
  display: grid;
  gap: 18px;
}
.secondary-page-header {
  padding: 6px 2px 2px;
}
.secondary-page-header h2 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: -.03em;
}
.secondary-page-header p { margin: 0; }
.calendar-list, .reports-grid {
  display: grid;
  gap: 14px;
}
.calendar-day-group,
.report-card {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,.88);
  box-shadow: var(--shadow-soft);
}
.calendar-day-group {
  padding: 18px;
}
.calendar-day-group h3 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: -.02em;
}
.calendar-events {
  display: grid;
  gap: 10px;
}
.calendar-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}
.calendar-time {
  min-width: 72px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.04em;
}
.calendar-meta {
  display: grid;
  gap: 4px;
}
.calendar-meta strong { font-size: 16px; }
.calendar-meta span, .calendar-price { color: var(--muted); }
.calendar-price {
  font-size: 15px;
  font-weight: 700;
  text-align: right;
}
.reports-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.report-card {
  padding: 20px;
}
.report-card .eyebrow { margin-bottom: 10px; }
.report-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 32px;
  line-height: 1;
  letter-spacing: -.04em;
}
.report-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}
.mobile-list-toolbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.soft-chip {
  border: 0;
  border-radius: 999px;
  min-height: 34px;
  padding: 0 12px;
  background: #f2f2f7;
  color: var(--text-soft);
  font-weight: 700;
}
.mobile-tabbar {
  display: none;
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 55;
  padding: 8px;
  border: 1px solid rgba(60,60,67,.10);
  border-radius: 24px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(24px) saturate(160%);
  box-shadow: 0 14px 40px rgba(0,0,0,.12);
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.mobile-tab {
  border: 0;
  border-radius: 18px;
  min-height: 56px;
  padding: 8px 6px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
}
.mobile-tab.active {
  background: var(--blue-soft);
  color: var(--blue);
}
.mobile-tab-icon {
  font-size: 18px;
  line-height: 1;
}
.app-shell.section-calendar #focusSection,
.app-shell.section-calendar #viewbarSection,
.app-shell.section-calendar #activeFilterRow,
.app-shell.section-calendar #workspaceSection,
.app-shell.section-reports #focusSection,
.app-shell.section-reports #viewbarSection,
.app-shell.section-reports #activeFilterRow,
.app-shell.section-reports #workspaceSection {
  display: none;
}
.app-shell.section-dashboard #calendarSection,
.app-shell.section-dashboard #reportsSection,
.app-shell.section-customers #calendarSection,
.app-shell.section-customers #reportsSection,
.app-shell.section-calendar #reportsSection,
.app-shell.section-reports #calendarSection {
  display: none !important;
}
.app-shell.section-customers #focusSection,
.app-shell.section-customers #viewbarSection {
  display: none;
}
.app-shell.section-customers #activeFilterRow,
.app-shell.section-customers #workspaceSection {
  display: block;
}
.app-shell.section-customers #workspaceSection {
  display: grid;
}

@media (max-width: 920px) {
  .mobile-only { display: flex; }
  .topbar {
    min-height: auto;
    align-items: start;
  }
  .brand-lockup {
    align-items: start;
  }
  #topSectionTitle { font-size: 22px; }
  .top-search kbd { display: none; }
  .top-actions {
    justify-content: flex-end;
    gap: 6px;
  }
  .top-actions .primary-button {
    min-height: 38px;
    padding-inline: 13px;
  }
  .top-actions .icon-text-button,
  .top-actions .user-menu { display: none; }
  .viewbar {
    padding: 8px;
    border-radius: 18px;
  }
  .secondary-page-header h2 { font-size: 24px; }
  .mobile-list-toolbar { display: flex; }
  .mobile-tabbar { display: grid; }
  .floating-add-button {
    right: 16px;
    bottom: calc(86px + env(safe-area-inset-bottom));
  }
  .notification-panel {
    top: auto;
    right: 12px;
    left: 12px;
    bottom: calc(84px + env(safe-area-inset-bottom));
    width: auto;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding-left: 14px;
    padding-right: 14px;
    padding-bottom: 112px;
  }
  .reports-grid {
    grid-template-columns: 1fr;
  }
  .calendar-item {
    grid-template-columns: 1fr;
  }
  .calendar-price {
    text-align: left;
  }
  .section-header h2 { font-size: 20px; }
  .lead-worklist-panel, .detail-panel, .calendar-day-group, .report-card {
    border-radius: 20px;
  }
}


/* v8: mobile-native interaction layer */
.profile-panel {
  position: fixed;
  top: 86px;
  right: 28px;
  z-index: 65;
  width: min(360px, calc(100vw - 28px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(24px) saturate(160%);
  box-shadow: var(--shadow);
}
.profile-card {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px;
}
.profile-card strong,
.profile-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-avatar {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 900;
}
.profile-actions {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.profile-action {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  text-decoration: none;
}
.profile-action.danger { color: var(--red); }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0,0,0,.20);
  backdrop-filter: blur(4px);
}
.mobile-quick-sheet {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 75;
  padding: 10px 14px 16px;
  border: 1px solid rgba(60,60,67,.14);
  border-radius: 28px;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(26px) saturate(160%);
  box-shadow: 0 -18px 55px rgba(0,0,0,.18);
}
.sheet-handle {
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: rgba(60,60,67,.22);
  margin: 0 auto 12px;
}
.sheet-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 0 2px 12px;
}
.sheet-title-row h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -.03em;
}
.mobile-sheet-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.mobile-sheet-status {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0;
  -webkit-overflow-scrolling: touch;
}
.mobile-sheet-status .status-button {
  white-space: nowrap;
  flex: 0 0 auto;
}
body.sheet-open {
  overflow: hidden;
}

.lead-card .mobile-more-button {
  display: none;
}

@media (max-width: 920px) {
  body {
    background:
      radial-gradient(circle at 18% -8%, rgba(0,122,255,.08), transparent 26%),
      var(--bg);
  }
  .topbar {
    position: sticky;
    grid-template-columns: 1fr auto;
  }
  .brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }
  .top-actions {
    align-items: start;
  }
  .top-actions .primary-button {
    display: none;
  }
  .top-actions .user-menu {
    display: inline-flex !important;
    width: 48px;
    height: 48px;
    min-height: 48px;
    padding: 0;
    border-radius: 999px;
    background: #f2f2f7;
    color: var(--text);
  }
  .top-actions .user-menu #currentUserBadge,
  .top-actions .user-menu span[aria-hidden="true"] {
    display: none;
  }
  .top-actions .user-menu::before {
    content: attr(data-initials);
    font-weight: 900;
  }
  .profile-panel {
    top: 82px;
    right: 12px;
    left: 12px;
    width: auto;
  }
  .dashboard {
    display: flex;
    overflow-x: auto;
    gap: 12px;
    margin-left: -14px;
    margin-right: -14px;
    padding: 0 14px 4px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .metric {
    min-width: 116px;
    min-height: 128px;
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 7px;
    padding: 16px 12px;
    scroll-snap-align: start;
  }
  .metric-icon,
  .metric-label,
  .metric strong {
    grid-column: auto;
  }
  .metric-icon {
    width: 42px;
    height: 42px;
    border-radius: 15px;
  }
  .metric strong {
    font-size: 30px;
  }
  .metric-label {
    align-self: auto;
    font-size: 13px;
  }
  .viewbar {
    position: sticky;
    top: 112px;
    z-index: 20;
    flex-direction: row;
    align-items: center;
    margin-left: -2px;
    margin-right: -2px;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(18px) saturate(160%);
  }
  .reset-filters {
    width: 44px;
    min-width: 44px;
    overflow: hidden;
    color: transparent;
    position: relative;
  }
  .reset-filters::after {
    content: "≡";
    color: var(--blue);
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 22px;
    transform: rotate(90deg);
  }
  .active-filter-row {
    display: none;
  }
  .lead-worklist-panel {
    border: 0;
    box-shadow: none;
    background: transparent;
    padding: 0;
  }
  .section-header {
    margin-bottom: 14px;
  }
  .section-header p {
    display: none;
  }
  .lead-list {
    gap: 14px;
  }
  .lead-card {
    border-radius: 22px;
    min-height: 0;
    padding: 18px 14px 16px 24px;
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-areas:
      "identity next"
      "finance next"
      "actions actions";
    align-items: start;
    gap: 12px 14px;
    box-shadow: var(--shadow-soft);
  }
  .lead-card.selected {
    box-shadow: 0 0 0 3px rgba(0,122,255,.10), var(--shadow-soft);
  }
  .lead-identity { grid-area: identity; min-width: 0; }
  .lead-next {
    grid-area: next;
    min-width: 128px;
    justify-items: end;
    text-align: right;
  }
  .lead-next .detail-mini-label,
  .lead-next small {
    display: none;
  }
  .lead-finance {
    grid-area: finance;
    gap: 3px;
  }
  .lead-finance span:first-of-type {
    display: none;
  }
  .lead-actions {
    grid-area: actions;
    grid-template-columns: 1fr 1fr 52px;
    gap: 8px;
  }
  .lead-actions .row-button {
    min-height: 46px;
    border-radius: 15px;
    background: #fff;
  }
  .lead-actions .row-button[data-edit-lead] {
    display: none;
  }
  .lead-card .mobile-more-button {
    display: inline-flex;
  }
  .lead-title-row strong {
    font-size: 18px;
  }
  .lead-phone {
    margin-top: 4px;
  }
  .lead-item-summary {
    font-size: 14px;
  }
  .status-pill {
    min-height: 26px;
    background: color-mix(in srgb, var(--status-color, var(--blue)) 12%, white);
    color: color-mix(in srgb, var(--status-color, var(--blue)) 55%, #1d1d1f);
  }
  .detail-panel {
    position: fixed;
    z-index: 76;
    top: auto;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    max-height: min(82vh, 760px);
    border-radius: 28px;
    background: rgba(255,255,255,.97);
    backdrop-filter: blur(26px) saturate(160%);
    box-shadow: 0 -18px 55px rgba(0,0,0,.18);
    transform: translateY(0);
  }
  .detail-panel.hidden {
    display: none !important;
  }
  body.detail-open {
    overflow: hidden;
  }
  body.detail-open #mobileSheetBackdrop {
    display: block !important;
  }
}

@media (max-width: 560px) {
  .lead-next {
    min-width: 112px;
  }
  .lead-finance strong,
  .lead-next strong {
    font-size: 17px;
  }
  .lead-actions {
    grid-template-columns: 1fr 1fr 48px;
  }
  .mobile-sheet-actions {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .mobile-sheet-actions .quick-action {
    min-height: 44px;
    padding-inline: 8px;
  }
}

/* v9-v11: PWA + offline sync status */
.offline-banner {
  position: sticky;
  top: 76px;
  z-index: 39;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 38px;
  padding: 8px 18px;
  border-bottom: 1px solid rgba(255,149,0,.22);
  background: rgba(255,249,235,.94);
  color: #8a4f00;
  backdrop-filter: blur(18px) saturate(160%);
  font-size: 13px;
}
.offline-banner strong { font-weight: 900; }
.sync-status {
  position: relative;
  color: var(--text-soft);
}
.sync-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
  display: inline-block;
  margin-right: 2px;
}
.sync-status.offline::before { background: var(--orange); }
.sync-status.pending::before { background: var(--blue); }
.sync-status.error::before { background: var(--red); }
.install-ready {
  display: inline-flex !important;
}
body.offline .lead-card,
body.offline .detail-panel,
body.offline .metric,
body.offline .panel {
  border-color: rgba(255,149,0,.22);
}
.queue-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #fff4e5;
  color: #8a4f00;
  font-size: 12px;
  font-weight: 900;
}
@media (max-width: 920px) {
  .offline-banner {
    top: 116px;
    justify-content: flex-start;
    font-size: 12px;
    line-height: 1.25;
  }
  .top-actions .sync-status,
  .top-actions #installPwaButton {
    display: none !important;
  }
}

/* v12: keep the application tab bar at the bottom on every viewport. */
.app-shell {
  padding-bottom: 126px;
}
.mobile-tabbar {
  display: grid;
  max-width: 720px;
  margin: 0 auto;
  left: 50%;
  right: auto;
  width: min(720px, calc(100vw - 24px));
  transform: translateX(-50%);
}
.calendar-item {
  border-left: 5px solid var(--status-color, var(--blue));
}
.calendar-item.done {
  opacity: .68;
}
.calendar-price {
  display: grid;
  gap: 4px;
}
.report-wide {
  grid-column: 1 / -1;
}
.report-breakdown {
  display: grid;
  gap: 9px;
}
.report-breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 38px;
  border-bottom: 1px solid var(--line);
}
.report-breakdown-row:last-child {
  border-bottom: 0;
}
.report-breakdown-row span {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text-soft);
  font-weight: 700;
}
.report-breakdown-row i {
  width: 9px;
  height: 9px;
  border-radius: 999px;
}
.report-breakdown-row strong {
  margin: 0;
  font-size: 16px;
}
@media (max-width: 920px) {
  .mobile-tabbar {
    max-width: none;
  }
}

/* v13: the main app navigation lives in the bottom tab bar on every viewport.
   The duplicated desktop top navigation is intentionally hidden. */
@media (min-width: 921px) {
  .topbar {
    grid-template-columns: auto minmax(320px, 680px) 1fr;
  }

  .topnav {
    display: none !important;
  }

  .top-actions {
    justify-self: end;
  }
}

/* v13.1: desktop topbar layout cleanup.
   The topbar keeps only brand + search + essential actions.
   Secondary admin actions live in the profile panel. */
@media (min-width: 921px) {
  .topbar {
    grid-template-columns: minmax(180px, 260px) minmax(320px, 560px) minmax(260px, auto);
    gap: 18px;
    overflow: hidden;
  }

  .brand-lockup {
    min-width: 0;
    overflow: hidden;
  }

  .brand-copy {
    min-width: 0;
  }

  .brand-copy strong,
  .eyebrow-app {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .top-search {
    width: 100%;
    max-width: 560px;
    min-width: 0;
    justify-self: center;
  }

  .top-search input {
    min-width: 0;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .top-search kbd {
    flex: 0 0 auto;
  }

  .top-actions {
    justify-self: end;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
  }

  .top-actions .icon-text-button,
  .top-actions .primary-button,
  .top-actions .user-menu {
    flex: 0 0 auto;
    min-height: 42px;
    border-radius: 16px;
    font-size: 15px;
    padding: 10px 14px;
    white-space: nowrap;
  }

  .top-actions .notification-toggle {
    max-width: 150px;
  }

  .top-actions .sync-status {
    max-width: 118px;
  }

  /* These are still available from the profile/admin panels.
     Keeping them in the topbar made the desktop header unusable. */
  .top-actions > a[href="/api/leads/export.csv"],
  .top-actions > #openAdminButton,
  .top-actions > #refreshButton,
  .top-actions > #installPwaButton {
    display: none !important;
  }

  .top-actions .user-menu {
    width: 46px;
    height: 46px;
    padding: 0;
    display: grid;
    place-items: center;
    background: #f2f2f7;
  }

  .top-actions .user-menu #currentUserBadge,
  .top-actions .user-menu span[aria-hidden="true"] {
    display: none;
  }

  .top-actions .user-menu::before {
    content: attr(data-initials);
    font-weight: 900;
  }

  .top-actions .primary-button {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (min-width: 921px) and (max-width: 1280px) {
  .topbar {
    grid-template-columns: minmax(150px, 220px) minmax(260px, 460px) auto;
    gap: 14px;
  }

  .top-search {
    max-width: 460px;
  }

  .top-search kbd {
    display: none;
  }

  .top-actions .notification-toggle {
    max-width: 128px;
  }

  .top-actions .primary-button {
    max-width: 112px;
  }
}
