:root {
  --red: #C8102E;
  --red-dark: #A00D24;
  --red-soft: #FBE9EC;
  --ink: #1B1D21;
  --muted: #5C6370;
  --soft: #8A919C;
  --line: #E3E5E8;
  --bg: #F6F7F8;
  --card: #FFFFFF;
  --ok: #1E7F45;
  --warn: #B4540A;

  /* status groups from the lead sheet legend */
  --g-working: #E06666;
  --g-hot: #D61FD6;
  --g-contact: #F0A86A;
  --g-unresponsive: #999999;
  --g-closed: #34A853;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px; line-height: 1.45; color: var(--ink); background: var(--bg);
}
a { color: var(--red); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 0 20px; height: 56px; position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand span { color: var(--red); }
.nav { display: flex; gap: 2px; height: 100%; overflow-x: auto; }
.nav button {
  border: 0; background: none; font: inherit; color: var(--muted); padding: 0 14px;
  height: 100%; border-bottom: 3px solid transparent; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.nav button.active { color: var(--ink); border-bottom-color: var(--red); }
.topbar .spacer { flex: 1; }
.who { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ---------- layout ---------- */
.page { max-width: 1480px; margin: 0 auto; padding: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.card + .card { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
@media (max-width: 760px) { .span2 { grid-column: auto; } }

/* ---------- forms ---------- */
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(200,16,46,.12); }
input[type=checkbox] { width: auto; }
.field { margin-bottom: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border-radius: 6px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--red); background: var(--red); color: #fff; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--soft); background: #fff; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--bg); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; padding: 11px 14px; }
.btn:disabled { opacity: .55; cursor: default; }

.alert { border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }
.alert.error { background: var(--red-soft); color: var(--red-dark); }
.alert.ok { background: #E7F5EC; color: var(--ok); }
.alert.info { background: #EEF2F7; color: #34465C; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card { padding: 28px; }
.auth-head { text-align: center; margin-bottom: 18px; }
.auth-head h1 { margin-bottom: 4px; }
.auth-foot { text-align: center; margin-top: 14px; font-size: 13px; }
.captcha-row { display: flex; gap: 10px; align-items: center; }
.captcha-row img { border: 1px solid var(--line); border-radius: 6px; height: 54px; width: 160px; background: #f2f2f2; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.landing { max-width: 920px; margin: 0 auto; padding: 60px 20px; }
.landing h1 { font-size: 30px; margin-bottom: 8px; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 28px; }
@media (max-width: 760px) { .choices { grid-template-columns: 1fr; } }
.choice { display: block; text-decoration: none; color: inherit; transition: border-color .15s; }
.choice:hover { border-color: var(--red); }
.choice h2 { margin-bottom: 6px; }
.choice p { margin: 0 0 14px; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  position: sticky; top: 0; background: #FAFAFB; text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .4px; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1;
}
table.data td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #FBFBFC; }
table.data tr.click { cursor: pointer; }
table.data td select { padding: 4px 6px; font-size: 12.5px; min-width: 112px; }
table.data td select[data-f=stage] { min-width: 150px; }
table.data td.name-cell { min-width: 170px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- chips and badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.role-admin { background: #1B1D21; color: #fff; }
.badge.role-team { background: #E3ECF7; color: #24476F; }
.badge.role-engineer { background: #EFE6F7; color: #57317A; }
.badge.role-user { background: var(--bg); color: var(--muted); }
.badge.off { background: var(--red-soft); color: var(--red-dark); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.g-working { --g: var(--g-working); }
.g-hot { --g: var(--g-hot); }
.g-contact { --g: var(--g-contact); }
.g-unresponsive { --g: var(--g-unresponsive); }
.g-closed { --g: var(--g-closed); }
.dot { background: var(--g, #ccc); }
select.status-select { border-left: 5px solid var(--g, var(--line)); }
tr.lead-row td:first-child { box-shadow: inset 4px 0 0 var(--g, transparent); }

.legend { display: flex; gap: 6px; flex-wrap: wrap; }
.legend button {
  font: inherit; font-size: 12.5px; border: 1px solid var(--line); background: #fff; border-radius: 16px;
  padding: 4px 11px; cursor: pointer; color: var(--ink);
}
.legend button.active { border-color: var(--ink); background: var(--ink); color: #fff; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 14px; }
#l-stats { grid-template-columns: 1.4fr repeat(6, 1fr); }
@media (max-width: 1100px) { #l-stats { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 560px) { #l-stats { grid-template-columns: repeat(2, 1fr); } #l-stats .money { grid-column: 1 / -1; } }
@media (max-width: 1000px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; text-align: left;
  font: inherit; cursor: pointer; color: inherit;
}
.stat:hover { border-color: var(--soft); }
.stat.active { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.stat .n { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat.static { cursor: default; }
.stat .v { font-size: 13px; font-weight: 700; color: var(--ok); margin-top: 2px; min-height: 18px; }
.stat.money { background: #E9F6EE; border-color: #B7DFC5; }
.stat.money .n { color: var(--ok); }
.stat.money .l { color: #2D6A45; }

.filters { display: grid; grid-template-columns: 2fr repeat(5, 1fr); gap: 8px; margin: 12px 0; }
@media (max-width: 1100px) { .filters { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .filters { grid-template-columns: 1fr; } }
.toggles { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.toggles label { display: flex; gap: 6px; align-items: center; margin: 0; font-size: 13px; color: var(--ink); font-weight: 500; }

.due { color: var(--red); font-weight: 700; }

/* ---------- side panel ---------- */
.panel-back { position: fixed; inset: 0; background: rgba(20,22,26,.35); z-index: 40; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: #fff; z-index: 41;
  display: flex; flex-direction: column; box-shadow: -6px 0 24px rgba(0,0,0,.12);
}
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.panel-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.panel-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; background: #FAFAFB; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--soft); font-weight: 700; margin: 18px 0 10px; }
.section-title:first-child { margin-top: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { font-size: 12px; color: var(--soft); margin-bottom: 2px; }
.timeline .body { white-space: pre-wrap; }
.timeline li.note .body { background: #FFFBEA; border: 1px solid #F3E7B3; border-radius: 6px; padding: 8px 10px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20,22,26,.4); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 620px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- toast ---------- */
#toast {
  position: fixed; top: 68px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 6px; font-size: 13px; z-index: 60; opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red-dark); }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px 0; gap: 4px 10px; }
  .topbar .brand { flex: 1; }
  .topbar .who { display: none; }
  .topbar .nav { order: 3; width: 100%; height: 44px; }
  .page { padding: 14px 12px; }
  .panel-head, .panel-body, .panel-foot { padding-left: 14px; padding-right: 14px; }
  #toast { top: 110px; }
}

/* ---------- project page ---------- */
.open-items { margin-bottom: 16px; }
.oi-list { list-style: none; margin: 10px 0 0; padding: 0; }
.oi-list li { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.oi-list li:first-child { border-top: 0; }
.oi-list li > span:nth-child(2) { flex: 1; }
.oi-tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; min-width: 78px; text-align: center; background: var(--bg); color: var(--muted); }
.oi-needed .oi-tag { background: var(--red-soft); color: var(--red-dark); }
.oi-confirm .oi-tag { background: #FFF2DE; color: var(--warn); }
.oi-improves .oi-tag { background: #EEF2F7; color: #34465C; }
.src { font-size: 11px; color: var(--soft); margin-top: 3px; }
.unclear { font-size: 12px; background: #FFF6E5; border: 1px solid #F3D9A8; border-radius: 6px; padding: 5px 8px; margin-top: 4px; color: #6B4A10; }
.savebar { position: sticky; bottom: 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; display: flex; gap: 10px; justify-content: flex-end; align-items: center; box-shadow: 0 -4px 14px rgba(0,0,0,.06); margin-top: 12px; z-index: 5; }
.savebar span { margin-right: auto; font-weight: 600; }
.rooms-table td { padding: 4px 6px; }
.rooms-table input, .rooms-table select { padding: 6px 8px; font-size: 13px; }
.rooms-table td:nth-child(1) select { min-width: 90px; }
.rooms-table td:nth-child(2) input { min-width: 160px; }
.rooms-table td:nth-child(3) input, .rooms-table td:nth-child(4) input, .rooms-table td:nth-child(5) input, .rooms-table td:nth-child(6) input, .rooms-table td:nth-child(8) input { width: 92px; }
.conf { border-radius: 8px; padding: 8px 12px; max-width: 360px; font-size: 13px; }
.conf-good { background: #E7F5EC; color: #1E5E37; }
.conf-fair { background: #FFF6E5; color: #6B4A10; }
.conf-rough { background: var(--red-soft); color: var(--red-dark); }
.badge.conf-good { background: #E7F5EC; color: #1E5E37; }
.badge.conf-fair { background: #FFF6E5; color: #6B4A10; }
.badge.conf-rough { background: var(--red-soft); color: var(--red-dark); }
ul.plain { margin: 0; padding-left: 18px; font-size: 13px; }
ul.plain li { margin-bottom: 4px; }
.dropzone { display: flex; align-items: center; justify-content: center; border: 2px dashed var(--line); border-radius: 8px; padding: 28px; color: var(--muted); cursor: pointer; font-weight: 600; margin: 0; }
.dropzone.drag, .dropzone:hover { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.file { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #fff; }
.file-thumb { display: flex; align-items: center; justify-content: center; height: 120px; background: var(--bg); border-radius: 6px; overflow: hidden; text-decoration: none; color: var(--muted); font-weight: 700; }
.file-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.file-name { font-size: 13px; font-weight: 600; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 760px) { .stats[style] { grid-template-columns: repeat(2, 1fr) !important; } }
.diff { font-weight: 700; font-size: 12.5px; }
.diff-good { color: #1E7B3A; }
.diff-fair { color: #A86B00; }
.diff-rough { color: #B3261E; }

.plans { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 12px; background: var(--bg); position: sticky; top: 60px; z-index: 5; }
.plan-view { height: 380px; overflow: auto; background: #fff; border-radius: 6px; text-align: center; resize: vertical; }
.plan-view img { max-width: 100%; height: auto; }
.plan-view iframe { width: 100%; height: 100%; border: 0; }
.plan-tab.active { background: var(--ink); color: #fff; }
.center { text-align: center; }
#p-table tfoot td { border-top: 2px solid var(--line); background: var(--bg); }
#p-table tr.muted td { opacity: .55; }
#p-table a { color: inherit; text-decoration: none; }
#p-table a:hover { text-decoration: underline; }

/* ---------- lead map ---------- */
.map-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .map-grid { grid-template-columns: 1fr; } }
.map-card { position: relative; padding: 14px; }
.map-wrap svg { width: 100%; height: auto; display: block; }
.map-wrap .st { stroke: #fff; stroke-width: .8; cursor: pointer; transition: opacity .1s; }
.map-wrap .st:hover { opacity: .8; }
.map-wrap .st.sel { stroke: var(--ink); stroke-width: 2; }
.map-wrap .borders { fill: none; stroke: #fff; stroke-width: .8; pointer-events: none; }
.map-wrap .pt { fill: var(--ink); fill-opacity: .75; stroke: #fff; stroke-width: 1; cursor: pointer; }
.map-wrap .pt.won { fill: var(--ok); fill-opacity: .9; }
.map-wrap .pt:hover { fill-opacity: 1; stroke-width: 1.5; }
.map-wrap .lbl { font-size: 10px; fill: var(--ink); pointer-events: none; text-anchor: middle; font-weight: 600; }
.map-wrap .lbl.on-dark { fill: #fff; }
.map-legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.map-legend .ramp { display: inline-flex; vertical-align: middle; margin: 0 6px; }
.map-legend .ramp i { width: 22px; height: 10px; display: inline-block; }
.map-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.map-legend .key b { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--ink); opacity: .75; }
.map-legend .key b.won { background: var(--ok); opacity: .9; }
.map-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; line-height: 1.45; padding: 7px 10px; border-radius: 6px; max-width: 260px; z-index: 5; }
.map-side { margin-top: 0 !important; padding: 16px; max-height: 640px; overflow: auto; }
.map-side h2 { font-size: 16px; margin-bottom: 4px; }
.map-side table.data td { padding: 6px 6px; }
.map-side .back { margin-bottom: 8px; }

/* new lead: files waiting to upload */
.lp-filelist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.lp-filelist span { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 3px 4px 3px 10px; font-size: 12px; }
.lp-filelist span em { font-style: normal; color: var(--ok); font-weight: 700; }
.lp-filelist button { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1; padding: 0 4px; }

/* ---------- team login secret code ---------- */
.gate-card { position: relative; overflow: hidden; text-align: center; }
.gate-card form { position: relative; z-index: 1; text-align: left; }
.gate-lock { width: 64px; height: 64px; margin: 0 auto 6px; }
.gate-lock svg { width: 100%; height: 100%; }
.gate-lock .shackle { transition: transform .35s ease; transform-origin: 44px 28px; }
.gate-say { text-align: center; color: var(--muted); margin: 0 0 14px; font-weight: 600; }
.gate-card.slashed .gate-lock .shackle { transform: translateY(-6px) rotate(25deg); }
.gate-card.slashed .gate-say { color: var(--ok); }
.gate-claws { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.gate-claws .gc { fill: none; stroke-width: 9; stroke-linecap: round; stroke-dasharray: 260; stroke-dashoffset: 260; filter: drop-shadow(3px 5px 3px rgba(0,0,0,.35)); }
.gate-claws .gc1, .gate-claws .gc3 { stroke: #2F4F4F; }
.gate-claws .gc2 { stroke: #C8102E; }
.gate-card.slashed .gc { animation: gate-slash .32s cubic-bezier(.2,.8,.2,1) forwards; }
.gate-card.slashed .gc2 { animation-delay: .09s; }
.gate-card.slashed .gc3 { animation-delay: .18s; }
@keyframes gate-slash { to { stroke-dashoffset: 0; } }
.gate-card.shake { animation: gate-shake .4s; }
@keyframes gate-shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@media (prefers-reduced-motion: reduce) { .gate-card.slashed .gc, .gate-card.shake { animation: none; } }

/* ClawSoft logo in the top bar of every logged-in page */
.tb-logo { display: flex; align-items: center; flex: none; }
.tb-logo img { height: 38px; width: auto; display: block; }
.topbar .brand:empty { display: none; }
@media (max-width: 760px) { .tb-logo img { height: 30px; } }

/* Number columns: headings line up with the numbers under them */
table.data th.right, table.data td.right { text-align: right; }
table.data th.center, table.data td.center { text-align: center; }
.topbar .rip-btn { font-weight: 800; font-style: italic; white-space: nowrap; }
