:root {
  --text: #172B4D;
  --text-subtle: #44546F;
  --text-subtlest: #626F86;
  --text-inverse: #FFFFFF;
  --bg: #FFFFFF;
  --bg-sunken: #F7F8F9;
  --bg-column: #F1F2F4;
  --bg-neutral: #091E420F;
  --bg-neutral-hover: #091E4224;
  --bg-selected: #E9F2FF;
  --border: #DCDFE4;
  --border-strong: #091E4224;
  --brand: #0C66E4;
  --brand-hover: #0055CC;
  --danger: #C9372C;
  --danger-bg: #FFECEB;
  --success: #216E4E;
  --success-bg: #DCFFF1;
  --warning-bg: #FFF7D6;
  --warning: #7F5F01;
  --info-bg: #E9F2FF;
  --info: #0055CC;
  --purple-bg: #F3F0FF;
  --purple: #5E4DB2;
  --shadow-card: 0 1px 1px #091E4240, 0 0 1px #091E424F;
  --shadow-overlay: 0 8px 12px #091E4226, 0 0 1px #091E424F;
  --radius: 3px;
  --lane-width: 272px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 20px;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
[hidden] { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border: none; border-radius: var(--radius); background: var(--bg-neutral); color: var(--text-subtle);
  font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg-neutral-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: var(--text-inverse); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.subtle { background: transparent; }
.btn.subtle:hover { background: var(--bg-neutral); }
.btn.danger { background: var(--danger); color: white; }
.btn.small { height: 24px; padding: 0 8px; font-size: 12px; }
.btn.selected { background: var(--bg-selected); color: var(--brand); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  border: none; border-radius: var(--radius); background: transparent; color: var(--text-subtle); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-neutral-hover); }
.icon { display: inline-flex; width: 16px; height: 16px; flex: none; }
.icon svg { width: 100%; height: 100%; }

.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 6px 8px; border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--bg-sunken); outline: none; transition: border-color .1s, background .1s;
}
textarea.input { height: auto; min-height: 80px; resize: vertical; line-height: 20px; }
.input:hover { background: #F1F2F4; }
.input:focus { border-color: var(--brand); background: var(--bg); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 600; color: var(--text-subtle); }
.hint { font-size: 12px; color: var(--text-subtlest); }
.error-text { color: var(--danger); font-size: 13px; margin: 8px 0; }

/* ---------- auth pages ---------- */
.auth-page { min-height: 100%; display: flex; align-items: center; justify-content: center; background: var(--bg-sunken); padding: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--bg); padding: 32px 40px; border-radius: 4px; box-shadow: 0 0 10px #091E421A; }
.auth-card .logo { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.auth-card h1 { font-size: 16px; text-align: center; margin-bottom: 24px; color: var(--text-subtle); font-weight: 600; }
.auth-card .btn { width: 100%; justify-content: center; height: 40px; }

.logo-mark { width: 24px; height: 24px; border-radius: 5px; background: var(--brand); display: inline-flex; align-items: flex-start; justify-content: center; gap: 2px; padding: 5px 4px; }
.logo-mark i { display: block; width: 4px; background: white; border-radius: 1px; }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; height: 100vh; }
.topnav {
  height: 56px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.topnav .brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; color: var(--text); }
.topnav .spacer { flex: 1; }
.sync-pill { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-subtlest); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: #8590A2; }
.sync-dot.ok { background: #22A06B; }
.sync-dot.err { background: var(--danger); }
.sync-dot.busy { background: var(--brand); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.body { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 240px; flex: none; border-right: 1px solid var(--border); background: var(--bg-sunken);
  padding: 16px 8px; overflow-y: auto;
}
.sidebar .project { display: flex; align-items: center; gap: 8px; padding: 0 8px 16px; }
.sidebar .project-icon { width: 32px; height: 32px; border-radius: 4px; background: linear-gradient(135deg, #0C66E4, #6E5DC6); display: flex; align-items: center; justify-content: center; color: white; font-weight: 700; }
.sidebar .project-name { font-weight: 600; }
.sidebar .project-sub { font-size: 12px; color: var(--text-subtlest); }
.nav-section { margin-top: 12px; }
.nav-heading { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-subtlest); padding: 4px 8px; letter-spacing: .02em; }
.nav-link {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 8px; border-radius: var(--radius);
  color: var(--text-subtle); font-weight: 500; text-decoration: none !important;
}
.nav-link:hover { background: var(--bg-neutral); }
.nav-link.active { background: var(--bg-selected); color: var(--brand); }
.nav-link.active::before { content: ""; position: absolute; }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- board page ---------- */
.page { padding: 20px 24px 0; display: flex; flex-direction: column; min-height: 0; flex: 1; }
.page.scroll { overflow-y: auto; padding-bottom: 40px; }
.breadcrumbs { font-size: 14px; color: var(--text-subtlest); margin-bottom: 8px; }
.title-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.title-row h1 { font-size: 24px; line-height: 28px; flex: 1; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.search { position: relative; width: 200px; }
.search .icon { position: absolute; left: 8px; top: 10px; color: var(--text-subtlest); }
.search .input { padding-left: 30px; }
.avatar-filter { display: flex; align-items: center; }
.avatar-filter .avatar { margin-left: -4px; border: 2px solid var(--bg); cursor: pointer; transition: transform .1s; }
.avatar-filter .avatar:first-child { margin-left: 0; }
.avatar-filter .avatar:hover { transform: translateY(-2px); z-index: 1; }
.avatar-filter .avatar.on { box-shadow: 0 0 0 2px var(--brand); z-index: 2; }
.toolbar .group-by { display: flex; align-items: center; gap: 6px; color: var(--text-subtle); font-size: 13px; }
.toolbar .group-by select { height: 32px; width: auto; }
.toolbar .spacer { flex: 1; }

.avatar {
  width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: white; flex: none; user-select: none;
}
.avatar.lg { width: 32px; height: 32px; font-size: 12px; }
.avatar.none { background: #DFE1E6; color: var(--text-subtle); }

.board-scroll { flex: 1; overflow: auto; min-height: 0; padding-bottom: 16px; }
.board-grid { display: inline-flex; flex-direction: column; min-width: 100%; }
.lane-headers { display: flex; gap: 8px; position: sticky; top: 0; z-index: 3; background: var(--bg); padding-bottom: 2px; }
.lane-header {
  width: var(--lane-width); flex: none; display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 4px 0 12px;
  background: var(--bg-column); border-radius: 6px 6px 0 0; font-size: 12px; font-weight: 600; color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: .02em; position: relative;
}
.lane-header[draggable="true"] { cursor: grab; }
.lane-header .lane-color { width: 10px; height: 10px; border-radius: 2px; flex: none; box-shadow: inset 0 0 0 1px #091E4224; }
.lane-header .lane-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lane-header .lane-count { font-weight: 500; color: var(--text-subtlest); text-transform: none; }
.lane-header.over-wip { background: var(--danger-bg); }
.lane-header.over-wip .lane-count { color: var(--danger); font-weight: 700; }
.lane-header input { text-transform: none; height: 28px; font-size: 13px; }
.lane-header.drop-before::before, .lane-header.drop-after::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 3px; background: var(--brand); border-radius: 2px;
}
.lane-header.drop-before::before { left: -6px; }
.lane-header.drop-after::after { right: -6px; }
.lane-add { width: 40px; flex: none; display: flex; align-items: flex-start; }
.lane-add .icon-btn { width: 40px; height: 40px; background: var(--bg-column); border-radius: 6px; }
.lane-add-form { width: var(--lane-width); flex: none; background: var(--bg-column); border-radius: 6px; padding: 4px; }

.swimlane-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 4px 6px; font-weight: 600; font-size: 13px;
  position: sticky; left: 0; cursor: pointer; user-select: none; width: max-content;
}
.swimlane-header .chev { transition: transform .15s; color: var(--text-subtle); }
.swimlane-header.collapsed .chev { transform: rotate(-90deg); }
.swimlane-header .count { font-weight: 400; color: var(--text-subtlest); }
.lane-row { display: flex; gap: 8px; }
.lane-row + .swimlane-header { margin-top: 4px; border-top: 1px solid var(--border); }
.lane-body {
  width: var(--lane-width); flex: none; background: var(--bg-column); padding: 2px 4px 8px; min-height: 80px;
  display: flex; flex-direction: column; gap: 4px; transition: background .1s;
}
.lane-row:last-child .lane-body { border-radius: 0 0 6px 6px; min-height: calc(100vh - 290px); }
.lane-body.drag-over { background: #E4E6EA; }
.lane-spacer { width: 40px; flex: none; }

.card {
  background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow-card); padding: 10px 10px 8px;
  cursor: pointer; display: flex; flex-direction: column; gap: 6px; position: relative;
}
.card:hover { background: #F7F8F9; }
.card[draggable="true"] { cursor: grab; }
.card.dragging { opacity: .4; }
.card-title { font-size: 14px; line-height: 20px; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.card-customer { font-size: 12px; color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.card-date { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--text-subtle); background: var(--bg-neutral); padding: 0 4px; border-radius: 3px; height: 18px; }
.card-date.soon { background: var(--warning-bg); color: var(--warning); }
.card-footer { display: flex; align-items: center; gap: 6px; height: 24px; }
.card-key { font-size: 12px; font-weight: 600; color: var(--text-subtle); }
.card-amount { font-size: 12px; color: var(--text-subtle); }
.card-footer .spacer { flex: 1; }
.card-notes { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; color: var(--text-subtlest); }
.type-icon { width: 16px; height: 16px; border-radius: 3px; display: inline-flex; align-items: center; justify-content: center; color: white; flex: none; }
.type-icon svg { width: 10px; height: 10px; }
.type-icon.estimate { background: #6E5DC6; }
.type-icon.job { background: #1F845A; }
.drop-placeholder { height: 4px; background: var(--brand); border-radius: 2px; margin: 0 2px; flex: none; }
.empty-lane { font-size: 12px; color: var(--text-subtlest); text-align: center; padding: 16px 0; }

.lozenge {
  display: inline-flex; align-items: center; height: 18px; padding: 0 4px; border-radius: 3px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; background: var(--bg-neutral); color: var(--text-subtle); white-space: nowrap; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis;
}
.lozenge.green { background: var(--success-bg); color: var(--success); }
.lozenge.red { background: var(--danger-bg); color: var(--danger); }
.lozenge.yellow { background: var(--warning-bg); color: var(--warning); }
.lozenge.blue { background: var(--info-bg); color: var(--info); }
.lozenge.purple { background: var(--purple-bg); color: var(--purple); }

.banner { padding: 10px 14px; border-radius: var(--radius); background: var(--warning-bg); color: var(--text); margin-bottom: 12px; font-size: 13px; }
.banner.error { background: var(--danger-bg); }

/* ---------- menus, modals, toasts ---------- */
.menu {
  position: fixed; z-index: 50; min-width: 180px; background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow-overlay);
  padding: 6px 0; text-transform: none; letter-spacing: 0;
}
.menu button { display: block; width: 100%; text-align: left; padding: 7px 16px; border: none; background: none; cursor: pointer; font-size: 14px; font-weight: 400; color: var(--text); }
.menu button:hover { background: var(--bg-neutral); }
.menu button:disabled { color: var(--text-subtlest); cursor: default; background: none; }
.menu button.danger { color: var(--danger); }
.menu hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

.modal-backdrop { position: fixed; inset: 0; background: #091E427D; z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px 16px; overflow-y: auto; }
.modal { background: var(--bg); border-radius: 4px; box-shadow: var(--shadow-overlay); width: 100%; max-width: 480px; display: flex; flex-direction: column; }
.modal.wide { max-width: 1000px; }
.modal-header { display: flex; align-items: center; gap: 8px; padding: 20px 24px 8px; }
.modal-header h2 { font-size: 20px; line-height: 24px; flex: 1; }
.modal-body { padding: 8px 24px 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 24px 20px; }
.modal-footer .left { margin-right: auto; }

.issue-top { display: flex; align-items: center; gap: 8px; padding: 16px 16px 0 24px; font-size: 14px; color: var(--text-subtle); }
.issue-top .spacer { flex: 1; }
.issue-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 32px; padding: 12px 24px 24px; }
.issue-title { font-size: 24px; line-height: 28px; font-weight: 500; margin: 8px 0 20px; overflow-wrap: anywhere; }
.section-title { font-size: 14px; font-weight: 600; margin: 20px 0 8px; }
.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px 12px; align-items: center; font-size: 14px; }
.kv > dt { color: var(--text-subtle); font-weight: 600; font-size: 12px; }
.kv > dd { margin: 0; overflow-wrap: anywhere; }
.side-panel { border: 1px solid var(--border); border-radius: 4px; }
.side-panel .side-head { padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
.side-panel .side-body { padding: 16px; }
.side-actions { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.side-actions select { width: auto; max-width: 100%; font-weight: 600; }
.lane-select { background: var(--bg-neutral); border: none; height: 32px; border-radius: var(--radius); padding: 0 8px; font-weight: 600; cursor: pointer; }
.timestamps { font-size: 12px; color: var(--text-subtlest); margin-top: 12px; line-height: 18px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th { text-align: left; font-size: 12px; color: var(--text-subtle); font-weight: 600; border-bottom: 2px solid var(--border); padding: 6px 8px; }
table.simple td { border-bottom: 1px solid var(--border); padding: 8px; vertical-align: middle; }
table.simple td.num, table.simple th.num { text-align: right; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin: 24px 0 12px; }
.tab { border: none; background: none; padding: 6px 8px; margin-bottom: -2px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--text-subtle); font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.composer { display: flex; gap: 12px; margin-bottom: 20px; }
.composer .grow { flex: 1; }
.composer-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.note { display: flex; gap: 12px; margin-bottom: 20px; }
.note-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.note-head .who { font-weight: 600; }
.note-head .when { color: var(--text-subtlest); font-size: 13px; }
.note-body { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.sync-badge { font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.sync-badge.sent { color: var(--success); }
.sync-badge.failed { color: var(--danger); }
.sync-badge.pending { color: var(--text-subtlest); }
.activity-item { display: flex; gap: 10px; font-size: 13px; padding: 6px 0; color: var(--text-subtle); }
.activity-item .when { color: var(--text-subtlest); white-space: nowrap; }
pre.hcp-notes { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; font-family: inherit; font-size: 13px; margin: 0; max-height: 360px; overflow-y: auto; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 28px; height: 28px; border-radius: 4px; border: 2px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 1px #091E4224; }
.swatch.on { border-color: var(--brand); }
.status-checks { display: grid; grid-template-columns: 1fr; gap: 4px 12px; max-height: 220px; overflow-y: auto; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.status-checks label { display: flex; align-items: center; gap: 6px; font-size: 13px; text-transform: capitalize; }
.status-checks .taken { color: var(--text-subtlest); font-size: 11px; text-transform: none; }

#toasts { position: fixed; bottom: 24px; left: 24px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #172B4D; color: white; padding: 12px 16px; border-radius: 4px; box-shadow: var(--shadow-overlay); max-width: 420px; font-size: 14px; animation: toastIn .15s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

/* ---------- admin pages ---------- */
.admin-card { border: 1px solid var(--border); border-radius: 4px; overflow-x: auto; margin-bottom: 24px; }
.role-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 24px; }
.role-legend > div { border: 1px solid var(--border); border-radius: 4px; padding: 12px; font-size: 13px; color: var(--text-subtle); }
.role-legend b { display: block; color: var(--text); text-transform: capitalize; margin-bottom: 4px; }
.checks-inline { display: flex; gap: 12px; flex-wrap: wrap; }
.checks-inline label { display: flex; gap: 4px; align-items: center; font-size: 13px; }
.muted { color: var(--text-subtlest); }
.toggle { position: relative; width: 32px; height: 16px; flex: none; appearance: none; background: #8590A2; border-radius: 8px; cursor: pointer; transition: background .15s; margin: 0; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; background: white; border-radius: 50%; transition: transform .15s; }
.toggle:checked { background: #22A06B; }
.toggle:checked::after { transform: translateX(16px); }
.toggle:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .issue-grid { grid-template-columns: 1fr; }
  .page { padding: 16px 16px 0; }
  .modal-backdrop { padding-top: 16px; }
  .sync-pill .label { display: none; }
}
