:root {
  --bg: #fff;
  --sidebar: #fbfcfd;
  --line: #dfe3ea;
  --line-soft: #edf0f4;
  --text: #292d36;
  --muted: #6f7583;
  --blue: #0588ae;
  --blue-dark: #006f91;
  --blue-soft: #e5f5f8;
  --danger: #c52f57;
  --radius: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  color: var(--text); background: var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; }
button { border: 0; background: none; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(5,136,174,.22); outline-offset: 1px;
}
input, select, textarea {
  width: 100%; color: var(--text); background: #fff;
  border: 1px solid #cfd5df; border-radius: 7px; outline: none;
}

/* Login */
.login-screen {
  height: 100%; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(145deg, #f4fbfc, #fff 48%, #eff7ff);
}
.login-card {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 15px;
  padding: 36px 30px; background: #fff; border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 18px 60px rgba(30,50,70,.12);
}
.brand { color: var(--blue); font-size: 34px; font-weight: 800; text-align: center; letter-spacing: -.8px; }
.login-sub { color: var(--muted); font-size: 13px; text-align: center; margin-top: -8px; }
.login-card input { padding: 13px; text-align: center; font-size: 21px; letter-spacing: 8px; }
.login-card button, .btn-primary {
  padding: 12px 17px; color: #fff; background: var(--blue); border-radius: 7px; font-weight: 700;
}
.login-card button:hover, .btn-primary:hover { background: var(--blue-dark); }
.err { min-height: 18px; color: var(--danger); font-size: 13px; text-align: center; }

/* Shell */
.app { height: 100%; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
  min-width: 0; display: flex; flex-direction: column; gap: 14px; padding: calc(22px + var(--safe-top)) 14px 16px;
  background: var(--sidebar); border-right: 1px solid var(--line); overflow-y: auto;
}
.workspace-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.workspace-head > div { display: flex; flex-direction: column; gap: 2px; }
.workspace-head strong { font-size: 14px; }
.eyebrow { color: var(--muted); font-size: 12px; }
.icon-btn { min-width: 34px; height: 34px; border-radius: 7px; color: var(--muted); font-weight: 700; }
.icon-btn:hover { background: #f0f2f5; color: var(--text); }
.workspace-switch {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px;
  background: #fff; border: 1px solid #cfd5df; border-radius: 7px; text-align: left; font-weight: 600;
}
.workspace-logo {
  display: grid; place-items: center; width: 29px; height: 29px; color: #fff;
  background: linear-gradient(135deg, #5ec9f0, #0789ae); border-radius: 8px; font-weight: 800;
}
.chevron { margin-left: auto; font-size: 18px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 3px; }
.sidebar-nav button, .sidebar-bottom button {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 10px 11px;
  border-radius: 7px; color: #656b78; text-align: left; font-size: 14px;
}
.sidebar-nav button > span:first-child, .sidebar-bottom button > span:first-child {
  width: 19px; text-align: center; color: #777e8d; font-size: 17px;
}
.sidebar-nav button:hover, .sidebar-bottom button:hover { background: #f0f3f5; }
.sidebar-nav button.active { color: #25323a; background: #dff2f5; font-weight: 650; }
.sidebar-nav button.active > span:first-child { color: var(--blue); }
.sidebar-bottom { margin-top: auto; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.content-shell { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* Header */
.page-header { flex: none; padding: calc(18px + var(--safe-top)) 28px 0; border-bottom: 1px solid var(--line); }
.title-row { display: flex; align-items: center; justify-content: space-between; min-height: 42px; gap: 20px; }
.title-row h1 { font-size: 25px; letter-spacing: -.5px; }
.title-chevron { color: var(--muted); font-size: 18px; }
.header-actions { display: flex; align-items: center; gap: 7px; }
.text-action { padding: 8px 9px; border-radius: 6px; color: #3e434d; font-size: 14px; white-space: nowrap; }
.text-action:hover { background: #f4f5f7; }
.tabs { display: flex; align-items: end; gap: 16px; margin-top: 11px; overflow-x: auto; }
.tabs button { flex: none; padding: 10px 8px 12px; color: #464b55; border-bottom: 3px solid transparent; font-size: 14px; }
.tabs button.active { color: #20242a; border-color: var(--blue); font-weight: 650; }
.tabs .tab-add { font-size: 20px; }

/* Workspace */
.lead-workspace { flex: 1; min-height: 0; overflow: auto; padding: 16px 28px 28px; }
.toolbar { display: flex; align-items: center; gap: 9px; min-width: 900px; margin-bottom: 25px; }
.new-lead-btn {
  display: flex; align-items: center; gap: 16px; padding: 10px 13px; color: #fff;
  background: var(--blue); border-radius: 6px; font-weight: 650; font-size: 14px;
}
.new-lead-btn:hover { background: var(--blue-dark); }
.search-control { display: flex; align-items: center; gap: 6px; width: 165px; padding: 0 8px; }
.search-control span { color: var(--muted); font-size: 22px; }
.search-control input { border: 0; padding: 8px 2px; background: transparent; }
.tool-button { padding: 9px 8px; border-radius: 6px; white-space: nowrap; font-size: 14px; }
.tool-button:hover { background: #f3f5f7; }
.tool-select { display: flex; align-items: center; gap: 4px; }
.tool-select select { width: auto; min-width: 124px; border: 0; padding: 9px 24px 9px 5px; background: #fff; font-size: 14px; }
.lead-group { min-width: 900px; }
.group-title { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; padding-left: 10px; }
.group-title h2 { color: #0086be; font-size: 21px; font-weight: 700; letter-spacing: -.2px; }
.group-toggle { color: #087cac; font-size: 20px; }
.lead-total { color: var(--muted); font-size: 12px; }

/* Table */
.board { border-left: 6px solid #0795c6; border-radius: 8px 0 0 8px; }
.table-scroll { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-left: 0; }
.lead-table { width: 100%; min-width: 900px; border-collapse: collapse; table-layout: fixed; background: #fff; }
.lead-table th, .lead-table td {
  height: 54px; padding: 7px 13px; border-right: 1px solid #d5dbe5; border-bottom: 1px solid #d5dbe5;
  font-size: 14px; vertical-align: middle;
}
.lead-table th { height: 49px; background: #fff; font-size: 15px; font-weight: 500; text-align: center; }
.lead-table tr:last-child td { border-bottom: 0; }
.lead-table tbody tr { transition: background .12s; cursor: pointer; }
.lead-table tbody tr:hover td:not(.status-cell) { background: #f8fbfc; }
.check-cell { width: 42px; text-align: center; padding: 0 !important; }
.check-cell input { width: 16px; height: 16px; accent-color: var(--blue); }
.lead-table th[data-column] { position: relative; }
.column-resizer {
  position: absolute; top: 0; right: -5px; z-index: 4; width: 10px; height: 100%;
  cursor: col-resize; touch-action: none;
}
.column-resizer::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 4px; width: 2px;
  background: #1597c2; opacity: 0; transition: opacity .12s;
}
.lead-table th:hover .column-resizer::after, .column-resizer:hover::after,
.resizing-column .column-resizer::after { opacity: 1; }
.resizing-column, .resizing-column * { cursor: col-resize !important; user-select: none !important; }
.lead-cell { display: flex; align-items: center; gap: 10px; padding-left: 40px !important; }
.lead-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lead-copy strong, .lead-copy small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.lead-copy strong { font-size: 15px; font-weight: 500; }
.lead-copy small { color: var(--muted); font-size: 11px; }
.row-detail { margin-left: auto; width: 30px; height: 30px; color: #676d79; border: 1px solid transparent; border-radius: 5px; font-size: 18px; }
.row-detail:hover { border-color: var(--line); background: #fff; }
.status-cell { padding: 0 !important; background: var(--status-color); }
.status-trigger {
  width: 100%; height: 53px; padding: 0 30px 0 12px; color: #fff; background: transparent;
  border: 0; border-radius: 0; text-align: center; text-align-last: center; font-size: 15px; font-weight: 500; cursor: pointer;
}
.status-trigger::after {
  content: ""; position: absolute; top: 0; right: 0; width: 0; height: 0;
  border-top: 13px solid rgba(255,255,255,.35); border-left: 13px solid transparent;
}
.status-trigger:hover { filter: brightness(1.04); }
.status-trigger[aria-expanded="true"] { box-shadow: inset 0 0 0 2px #008fc4; }
.status-cell { position: relative; }

.status-popover {
  --arrow-left: 50%; position: fixed; z-index: 100; width: min(440px, calc(100vw - 20px));
  padding: 26px 28px 0; background: #fff; border: 1px solid #edf0f3; border-radius: 14px;
  box-shadow: 0 11px 34px rgba(30,35,45,.24); animation: statusPop .13s ease-out;
}
@keyframes statusPop { from { opacity: 0; transform: translateY(5px) scale(.985); } }
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding-bottom: 22px; }
.status-choice, .status-placeholder {
  display: grid; place-items: center; min-height: 53px; border-radius: 3px;
}
.status-choice {
  padding: 8px 12px; color: #fff; background: var(--choice-color); font-size: 18px; font-weight: 500;
  line-height: 1.15; text-align: center; transition: filter .12s, transform .08s;
}
.status-choice:hover, .status-choice:focus-visible { filter: brightness(1.07); transform: translateY(-1px); }
.status-choice:active { transform: translateY(0); }
.status-placeholder { background: #c4c4c4; }
.status-menu-action {
  display: flex; align-items: center; justify-content: center; gap: 12px; width: calc(100% + 56px);
  min-height: 61px; margin-left: -28px; padding: 10px 20px; border-top: 1px solid #e2e5ea;
  color: #343840; background: #fff; border-radius: 0; font-size: 17px;
}
.status-menu-action:hover { background: #f7f8fa; }
.status-menu-action span { font-size: 25px; }
.status-menu-action.auto { border-radius: 0 0 14px 14px; }
.status-menu-action.auto span { color: #8c58e9; }
.status-popover-arrow {
  position: absolute; left: var(--arrow-left); top: -10px; transform: translateX(-50%);
  width: 0; height: 0; border-left: 11px solid transparent; border-right: 11px solid transparent; border-bottom: 11px solid #fff;
  filter: drop-shadow(0 -1px 0 #e5e7eb);
}
.status-popover.opens-up .status-popover-arrow {
  top: auto; bottom: -10px; border-bottom: 0; border-top: 11px solid #fff;
  filter: drop-shadow(0 1px 0 #e5e7eb);
}
.comment-cell { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #535862; }
.address-cell { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #535862; }
.lead-table a { color: #0788bf; text-decoration: none; font-weight: 550; }
.lead-table a:hover { text-decoration: underline; }
.flag { margin-right: 8px; font-size: 18px; }
.followup { color: #a16106; white-space: nowrap; }
.followup.overdue { color: var(--danger); font-weight: 650; }
.empty-state { height: 190px !important; text-align: center; color: var(--muted); cursor: default; }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { margin-bottom: 6px; color: var(--text); }

/* Sheets */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(25,31,38,.34); backdrop-filter: blur(2px); }
.sheet-panel {
  position: absolute; top: 0; right: 0; width: min(470px, 100%); height: 100%; overflow-y: auto;
  padding: 22px 22px calc(22px + var(--safe-bottom)); background: #fff; border-left: 1px solid var(--line);
  box-shadow: -16px 0 45px rgba(31,40,50,.14); animation: slideIn .2s ease-out;
}
@keyframes slideIn { from { transform: translateX(100%); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h2 { font-size: 20px; }
.sheet-body { display: flex; flex-direction: column; gap: 13px; }
.sheet-body label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
.sheet-body input, .sheet-body select, .sheet-body textarea { padding: 10px 11px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; }
.btn-ghost { padding: 9px 11px; border-radius: 7px; color: var(--muted); background: #f3f5f7; }
.btn-danger { padding: 11px 16px; color: var(--danger); border: 1px solid #f0c4cf; border-radius: 7px; font-weight: 650; }
.btn-campaign { padding: 11px; color: #08708d; background: #e2f6f8; border: 1px solid #b9e8ee; border-radius: 7px; font-weight: 700; }
.sheet-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 5px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); z-index: 70;
  transform: translateX(-50%); padding: 11px 18px; color: #fff; background: #252a32;
  border-radius: 8px; box-shadow: 0 10px 30px rgba(20,25,30,.22); font-size: 13px; font-weight: 650;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 68px minmax(0, 1fr); }
  .sidebar { padding-inline: 9px; align-items: center; }
  .workspace-head, .workspace-switch span:not(.workspace-logo), .sidebar-nav button span:last-child,
  .sidebar-bottom button span:last-child { display: none; }
  .workspace-switch { justify-content: center; padding: 8px; }
  .sidebar-nav button, .sidebar-bottom button { justify-content: center; padding: 10px; }
  .sidebar-nav button > span:first-child, .sidebar-bottom button > span:first-child { width: auto; }
  .page-header { padding-left: 18px; padding-right: 18px; }
  .lead-workspace { padding-left: 18px; padding-right: 18px; }
  .text-action span { display: none; }
}

@media (max-width: 600px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 58px; }
  .sidebar { grid-row: 2; flex-direction: row; width: 100%; padding: 6px 10px calc(6px + var(--safe-bottom)); border: 0; border-top: 1px solid var(--line); overflow: hidden; z-index: 20; }
  .workspace-switch, .sidebar-bottom, .sidebar-nav button:not(.active) { display: none; }
  .sidebar-nav { width: 100%; }
  .sidebar-nav button.active { flex-direction: column; gap: 1px; padding: 4px; background: transparent; }
  .sidebar-nav button.active span:last-child { display: block; font-size: 10px; }
  .content-shell { grid-row: 1; }
  .page-header { padding: calc(12px + var(--safe-top)) 14px 0; }
  .title-row h1 { font-size: 22px; }
  .header-actions .text-action { display: none; }
  .tabs { margin-top: 4px; }
  .tabs button:not(.active):not(.tab-add) { display: none; }
  .lead-workspace { padding: 12px 14px 18px; }
  .toolbar { margin-bottom: 18px; }
  .row2 { grid-template-columns: 1fr; }
}
