/* MSA CRM — design tokens
   navy #11233F (brand) · paper #F4F6F9 · line #DCE1E8
   work-order orange #E8740C (one accent, used for action + the lifecycle stamp)
   paid green #1E7F4F · alert red #B3261E · muted #5B6B80 */
:root {
  --navy:#11233F; --navy-2:#1B3458; --paper:#F4F6F9; --line:#DCE1E8;
  --on-navy:#ffffff; --on-accent:#ffffff; /* v0.17.0: readable text on primary/accent, set by JS from contrast */
  --accent:#E8740C; --green:#1E7F4F; --red:#B3261E; --muted:#5B6B80; --ink:#1C2733;
  /* v0.7 (A5): surface + heading tokens so light AND dark share one component set.
     --navy/--accent are the BRAND colors, overridden per-house at load from house_config. */
  --surface:#fff; --surface-2:#EEF1F6; --surface-3:#FAFBFD; --line-2:#EAEEF3; --hover:#F7F9FC;
  --heading:var(--navy);
}
/* Dark mode: flip the neutrals, keep the brand navy/accent. Toggled via
   <html data-theme="dark"> (remembered per device in localStorage). */
[data-theme="dark"] {
  --paper:#0F1621; --line:#2A3947; --line-2:#22303D; --ink:#E6ECF3; --muted:#93A2B5;
  --surface:#182430; --surface-2:#20303F; --surface-3:#1B2835; --hover:#22323F;
  --heading:#DCE6F2; --navy-2:#24405F;
}
* { box-sizing:border-box; margin:0; }
html, body { height:100%; }
body { font-family:'Inter',sans-serif; background:var(--paper); color:var(--ink); font-size:14px; }
button { font-family:inherit; cursor:pointer; }
a { color:inherit; }

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

/* ---------- sidebar ---------- */
.side { width:200px; background:linear-gradient(180deg, var(--navy), var(--navy-2)); color:var(--on-navy); padding:22px 14px; position:sticky;
        top:0; height:100vh; display:flex; flex-direction:column; gap:2px; flex-shrink:0; }
.wordmark { font-family:'Barlow Condensed'; font-weight:700; font-size:23px; letter-spacing:.4px;
            padding:0 10px 18px; line-height:1.05; overflow-wrap:anywhere; word-break:break-word; max-width:100%; }
.wordmark span { color:var(--accent); }
.side a { display:block; padding:10px 12px; border-radius:7px; text-decoration:none; font-size:14px;
          color:var(--on-navy); opacity:.72; font-weight:500; }
.side a:hover { background:rgba(127,127,127,.16); color:var(--on-navy); opacity:1; }
.side a.active { background:var(--accent); color:var(--on-accent); opacity:1; font-weight:600; }
.logout { margin-top:auto; background:none; border:1px solid currentColor; color:var(--on-navy); opacity:.7;
          padding:8px; border-radius:7px; font-size:13px; }
.logout:hover { opacity:1; }

/* ---------- main ---------- */
main { flex:1; padding:28px 32px; max-width:1280px; }
.loading { color:var(--muted); padding:40px; }
.page-head { display:flex; align-items:baseline; justify-content:space-between; margin-bottom:20px; flex-wrap:wrap; gap:10px; }
h1 { font-family:'Barlow Condensed'; font-weight:700; font-size:30px; letter-spacing:.4px; color:var(--heading); }
.sub { color:var(--muted); font-size:13px; margin-top:2px; }

.btn { background:var(--navy); color:var(--on-navy); border:none; border-radius:7px; padding:9px 16px;
       font-size:13.5px; font-weight:600; }
.btn:hover { background:var(--navy-2); }
.btn.accent { background:var(--accent); color:var(--on-accent); }
.btn.accent:hover { background:#CF6608; }
.btn.ghost { background:none; color:var(--heading); border:1px solid var(--line); }
.btn.ghost:hover { border-color:var(--heading); }
.btn.sm { padding:5px 10px; font-size:12.5px; }
.btn.danger { background:none; color:var(--red); border:1px solid var(--line); }

/* ---------- cards & stats ---------- */
.stat-row { display:grid; grid-template-columns:repeat(auto-fit, minmax(170px,1fr)); gap:14px; margin-bottom:24px; }
.stat { background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:16px 18px; }
.stat .label { font-size:12px; text-transform:uppercase; letter-spacing:.6px; color:var(--muted); font-weight:600; }
.stat .value { font-family:'Barlow Condensed'; font-weight:700; font-size:32px; color:var(--heading);
               font-variant-numeric:tabular-nums; margin-top:4px; }
.stat .value.money::before { content:'$'; font-size:22px; vertical-align:6%; margin-right:1px; }
.stat.alert .value { color:var(--red); }

.card { background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:18px 20px; margin-bottom:18px; }
.card h2 { font-family:'Barlow Condensed'; font-weight:600; font-size:19px; letter-spacing:.4px;
           color:var(--heading); margin-bottom:12px; }

/* ---------- tables ---------- */
table { width:100%; border-collapse:collapse; background:var(--surface); border:1px solid var(--line);
        border-radius:10px; overflow:hidden; }
th { text-align:left; font-size:11.5px; text-transform:uppercase; letter-spacing:.6px;
     color:var(--muted); padding:11px 14px; border-bottom:1px solid var(--line); background:var(--surface-3); }
td { padding:12px 14px; border-bottom:1px solid var(--line-2); vertical-align:middle; }
tr:last-child td { border-bottom:none; }
tr.rowlink { cursor:pointer; }
tr.rowlink:hover { background:var(--hover); }
td.money { font-variant-numeric:tabular-nums; font-weight:600; }
td.muted, .muted { color:var(--muted); }
.empty { padding:34px; text-align:center; color:var(--muted); background:var(--surface);
         border:1px dashed var(--line); border-radius:10px; }

/* ---------- pipeline kanban ---------- */
.kanban { display:flex; gap:12px; overflow-x:auto; padding-bottom:8px; }
.kcol { background:var(--surface-2); border-radius:10px; min-width:225px; width:225px; flex-shrink:0; padding:10px; }
.kcol h3 { font-family:'Barlow Condensed'; font-size:16px; letter-spacing:.4px; color:var(--heading);
           padding:2px 4px 10px; display:flex; justify-content:space-between; }
.kcol h3 .sum { color:var(--muted); font-family:'Inter'; font-size:12px; font-weight:500; }
.kcard { background:var(--surface); border:1px solid var(--line); border-radius:8px; padding:11px 12px;
         margin-bottom:8px; cursor:pointer; }
.kcard:hover { border-color:var(--heading); }
.kcard .t { font-weight:600; font-size:13.5px; }
.kcard .c { color:var(--muted); font-size:12.5px; margin-top:3px; }
.kcard .v { color:var(--heading); font-weight:700; font-size:13px; margin-top:6px; font-variant-numeric:tabular-nums; }
.kcard .movers { display:flex; gap:6px; margin-top:8px; }
.kcard .movers button { border:1px solid var(--line); background:var(--surface); border-radius:6px;
                        padding:2px 9px; font-size:12px; color:var(--heading); }
.kcard .movers button:hover { border-color:var(--accent); color:var(--accent); }

/* ---------- the signature: job traveler strip ---------- */
.traveler { display:flex; gap:0; margin:4px 0; }
.traveler .step { font-family:'Barlow Condensed'; font-weight:600; font-size:12px; letter-spacing:1px;
  text-transform:uppercase; padding:3px 10px 2px; border:1px solid var(--line); color:#A8B3C2;
  border-right:none; background:var(--surface); white-space:nowrap; }
.traveler .step:first-child { border-radius:5px 0 0 5px; }
.traveler .step:last-child { border-radius:0 5px 5px 0; border-right:1px solid var(--line); }
.traveler .step.done { color:var(--heading); border-color:#B9C5D6; background:#EFF3F9; }
.traveler .step.now { color:#fff; background:var(--accent); border-color:var(--accent); }
.traveler .step.paid { color:#fff; background:var(--green); border-color:var(--green); }

/* ---------- pills ---------- */
.pill { display:inline-block; padding:3px 10px; border-radius:99px; font-size:12px; font-weight:600; }
.pill.draft { background:var(--surface-2); color:var(--muted); }
.pill.sent { background:#E8EEFA; color:#2B4C9B; }
.pill.overdue { background:#FBE9E7; color:var(--red); }
.pill.paid { background:#E5F3EC; color:var(--green); }

/* ---------- forms / modal ---------- */
.modal-back { display:none; position:fixed; inset:0; background:rgba(17,35,63,.5); z-index:50;
              align-items:flex-start; justify-content:center; padding:6vh 16px; overflow-y:auto; }
.modal-back.open { display:flex; }
.modal { background:var(--surface); border-radius:12px; width:min(480px,100%); padding:24px;
         box-shadow:0 24px 70px rgba(0,0,0,.3); }
.modal h2 { font-family:'Barlow Condensed'; font-size:22px; color:var(--heading); margin-bottom:14px; }
.field { margin-bottom:12px; }
.field label { display:block; font-size:12.5px; font-weight:600; color:var(--muted); margin-bottom:5px; }
.field input, .field select, .field textarea { width:100%; padding:9px 11px; border:1px solid var(--line);
  border-radius:7px; font-size:14px; font-family:inherit; background:var(--surface); color:var(--ink); }
.field input:focus, .field select:focus, .field textarea:focus { outline:2px solid var(--accent); }
/* v0.8: readable input text in both themes + softer placeholders */
.field input::placeholder, .field textarea::placeholder, .search::placeholder, .tl-add input::placeholder { color:var(--muted); opacity:.8; }
.search, .tl-add input { color:var(--ink); background:var(--surface); }
.modal .actions { display:flex; justify-content:space-between; gap:10px; margin-top:18px; }
.modal .actions .right { display:flex; gap:10px; margin-left:auto; }

/* ---------- timeline ---------- */
.tl { list-style:none; }
.tl li { display:flex; gap:12px; padding:9px 0; border-bottom:1px solid var(--line-2); font-size:13.5px; }
.tl li:last-child { border-bottom:none; }
.tl .dot { width:8px; height:8px; border-radius:99px; background:var(--accent); margin-top:6px; flex-shrink:0; }
.tl .dot.alert { background:var(--red); } .tl .dot.milestone { background:var(--green); }
.tl .dot.email { background:var(--accent); }
.tl time { color:var(--muted); font-size:12px; white-space:nowrap; margin-left:auto; }

/* ---------- settings ---------- */
code.key { background:var(--surface-2); padding:3px 8px; border-radius:6px; font-size:12.5px; word-break:break-all; }
.hint { font-size:12.5px; color:var(--muted); margin-top:8px; line-height:1.5; }

.checkbox-done { accent-color:var(--green); width:16px; height:16px; }
.taskdone { text-decoration:line-through; color:var(--muted); }

/* ---------- v0.12: mobile top bar + slide-in drawer (hidden on desktop) ---------- */
.mobilebar { display:none; }
.drawer-back { display:none; }
.menubtn { background:none; border:none; color:#fff; font-size:22px; line-height:1; padding:10px 12px; margin-left:-8px; }
.mobilebrand { font-family:'Barlow Condensed'; font-weight:700; font-size:20px; letter-spacing:.4px; color:#fff; }
.mobilebrand::first-letter { text-transform:none; }

@media (max-width: 760px) {
  /* top bar */
  body { padding-top:52px; }
  .mobilebar { display:flex; position:fixed; top:0; left:0; right:0; height:52px; z-index:70;
    background:var(--navy); color:#fff; align-items:center; gap:8px; padding:0 12px;
    box-shadow:0 2px 8px rgba(0,0,0,.18); }
  /* drawer: the sidebar slides in from the left over a dimmed backdrop */
  .side { position:fixed; top:0; left:0; bottom:0; height:100vh; width:min(78vw, 300px); z-index:80;
    transform:translateX(-105%); transition:transform .22s ease; overflow-y:auto;
    box-shadow:8px 0 30px rgba(0,0,0,.3); padding:18px 14px; }
  body.drawer-open .side { transform:translateX(0); }
  body.drawer-open .drawer-back { display:block; position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:75; }
  .side a { padding:13px 12px; font-size:15px; }           /* finger-sized menu rows */
  .sidecollapse { display:none; }                          /* collapse is a desktop idea */
  .sideopen { display:none !important; }
  body.side-collapsed .side { display:flex; }              /* ignore desktop-collapsed state */
  body.side-collapsed main { padding-left:14px; }

  main { padding:16px 12px; max-width:100%; }
  h1 { font-size:25px; }
  .page-head { flex-direction:column; align-items:stretch; gap:8px; }
  .page-head > div:last-child { width:100%; }
  .search { width:100%; margin:0 0 6px; }

  /* touch targets + no-zoom inputs (16px stops mobile browsers zooming the form) */
  .btn { min-height:42px; padding:10px 16px; }
  .btn.sm { min-height:36px; padding:7px 12px; }
  .field input, .field select, .field textarea, .search, .tl-add input { font-size:16px; min-height:44px; }
  .field textarea { min-height:88px; }
  .field input[type=checkbox] { min-height:0; width:20px; height:20px; }
  .field input[type=color] { min-height:0; }
  .checkbox-done { width:20px; height:20px; }

  /* modals: full-width sheets. v0.12.2: z-index above the top bar (the header was
     covering pop-ups) and breathing room at the top so the title is never clipped. */
  .modal-back { padding:14px 10px; z-index:95; }
  .modal { padding:18px 16px; }
  .modal .actions { position:sticky; bottom:0; background:var(--surface); padding-top:10px; }

  /* v0.12: tables become stacked cards (labels come from data-label, set by app.js) */
  table.cardify, table.cardify tbody { display:block; background:none; border:none; }
  table.cardify tr { display:block; background:var(--surface); border:1px solid var(--line);
    border-radius:10px; margin-bottom:10px; padding:6px 14px; }
  table.cardify tr.hdr { display:none; }
  table.cardify td { display:flex; justify-content:space-between; align-items:baseline; gap:12px;
    border:none; padding:8px 0; border-bottom:1px solid var(--line-2); }
  table.cardify tr td:last-child { border-bottom:none; }
  table.cardify td::before { content:attr(data-label); font-size:11px; text-transform:uppercase;
    letter-spacing:.6px; color:var(--muted); font-weight:600; flex-shrink:0; }
  table.cardify td.nolabel::before, table.cardify td:not([data-label])::before { display:none; content:none; }
  table.cardify td:empty { display:none; }
  table.cardify td .traveler { overflow-x:auto; max-width:100%; }

  /* kanban: one column per swipe */
  .kanban { scroll-snap-type:x mandatory; -webkit-overflow-scrolling:touch; }
  .kcol { scroll-snap-align:start; min-width:82vw; width:82vw; }
  .kcard .movers button { padding:6px 14px; font-size:13px; }

  .stat-row { grid-template-columns:repeat(2, 1fr); gap:10px; }
  .stat { padding:12px 14px; }
  .stat .value { font-size:26px; }
  .tl time { margin-left:0; }
}
@media (prefers-reduced-motion: reduce) { * { transition:none !important; } }

/* search box in page headers */
.search { padding:8px 12px; border:1px solid var(--line); border-radius:7px; font-size:13.5px;
  font-family:inherit; width:200px; vertical-align:middle; margin-right:6px; }
.search:focus { outline:2px solid var(--navy); }
.page-head > div:last-child { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }

/* client health lights */
.hdot { display:inline-block; width:10px; height:10px; border-radius:99px; margin-right:6px; vertical-align:1px; }
.hdot.g { background:var(--green); } .hdot.y { background:var(--accent); } .hdot.r { background:var(--red); }

/* v0.7 (A5): theme transitions, dark toggle, appearance controls */
body, .side, .card, .stat, table, td, th, .kcard, .kcol, .modal, .empty,
.field input, .field select, .field textarea, .search {
  transition: background-color .18s ease, color .18s ease, border-color .18s ease;
}
.themetgl { background:none; border:1px solid rgba(255,255,255,.25); color:#C7D2E2;
  padding:8px; border-radius:7px; font-size:13px; margin-top:16px; margin-bottom:8px; text-align:left; }
.themetgl:hover { border-color:#fff; color:#fff; }
.swatch { width:26px; height:26px; border-radius:6px; border:2px solid var(--line);
  cursor:pointer; display:inline-block; vertical-align:middle; margin:0 6px 6px 0; padding:0; }
.swatch.sel { outline:2px solid var(--heading); outline-offset:1px; }
.field input[type=color] { width:46px; height:34px; padding:2px; cursor:pointer; vertical-align:middle; }
.field input[type=file] { width:auto; max-width:100%; }
.field input.hex { width:120px; display:inline-block; vertical-align:middle; margin-left:8px; text-transform:uppercase; }
[title] { }

/* v0.8: sidebar logo + collapse */
.brandlogo { max-width:100%; min-width:0; width:auto; max-height:calc(56px * var(--logo-scale, 1));
  object-fit:contain; object-position:center; align-self:flex-start; display:block; margin:0 0 12px;
  /* v0.17.0: horizontal position 0..100. margin-left slides the box across the track;
     the matching translateX(-align%) pulls it back by its own width so edges never overflow. */
  margin-left:calc(var(--logo-align, 50) * 1%); transform:translateX(calc(var(--logo-align, 50) * -1%)); }
.sidecollapse { align-self:flex-end; background:none; border:none; color:var(--on-navy); opacity:.7; font-size:18px;
  line-height:1; cursor:pointer; padding:0 2px 6px; }
.sidecollapse:hover { color:#fff; }
.sideopen { display:none; position:fixed; top:12px; left:12px; z-index:60; background:var(--navy);
  color:#fff; border:none; border-radius:8px; padding:9px 13px; font-size:16px; cursor:pointer;
  box-shadow:0 4px 14px rgba(0,0,0,.25); }
.sideopen:hover { background:var(--navy-2); }
body.side-collapsed .side { display:none; }
body.side-collapsed .sideopen { display:block; }
body.side-collapsed main { padding-left:64px; }

/* v0.7 (A2/A3): pipeline discipline + timeline */
.kcard .next { font-size:12px; color:var(--heading); margin:4px 0 2px; }
.kcard .next.muted { color:#9aa4b2; font-style:italic; }
.kcard .next time { color:#9aa4b2; font-size:11px; }
.kcard.rotting { border-left:3px solid var(--red); }
.tl-add { display:flex; gap:6px; margin:6px 0 8px; }
.tl-add input { flex:1; padding:7px 10px; border:1px solid var(--line); border-radius:7px; font-family:inherit; font-size:13px; }

/* ---------- v0.10: Claude's Desk ---------- */
.navbadge { display:inline-block; min-width:18px; text-align:center; background:var(--accent);
  color:var(--on-accent); border-radius:99px; font-size:11px; font-weight:700; padding:1px 6px; margin-left:6px; }
.desk-item { border-left:3px solid var(--accent); }
.desk-head { display:flex; align-items:center; gap:10px; margin-bottom:10px; flex-wrap:wrap; }
.desk-head time { margin-left:auto; font-size:12px; }
.desk-detail { color:var(--muted); font-size:13.5px; margin-bottom:12px; white-space:pre-wrap; }
.desk-actions { display:flex; gap:10px; margin-top:12px; }
.tl .dot.system { background:var(--muted); }

/* v0.10.1 — scrolling list window (Claude's Desk: Decided recently + Recent activity) */
.tl.scrollbox { max-height: 320px; overflow-y: auto; padding-right: 6px; }

/* v0.10.4 — checkboxes inside .field render as normal little boxes, not full-width bordered inputs */
.field input[type=checkbox] { width:16px; height:16px; padding:0; border:none; display:inline-block; vertical-align:-3px; margin-right:6px; accent-color:var(--accent); }
.field input[type=checkbox]:focus { outline:2px solid var(--accent); outline-offset:2px; }
/* v0.10.4 — the Claude spark */
.claude-ico { vertical-align:-1px; margin-right:6px; }

/* ---------- demo banner (only present when DEMO_MODE=1) ---------- */
/* Fixed 34px strip across the top; the .has-demo-banner class pushes the whole
   app (sidebar, mobile top bar, content) down by 34px so nothing hides under it. */
.demo-banner { position:fixed; top:0; left:0; right:0; height:34px; z-index:200;
  background:#000; color:#FF4136; display:flex; align-items:center; justify-content:center;
  font-family:Inter, system-ui, sans-serif; font-weight:700; font-size:13px; letter-spacing:.2px;
  padding:0 14px; box-shadow:0 1px 4px rgba(0,0,0,.18); }
.demo-banner span { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:100%; padding:0 46px; }
/* v0.17.1: tiny brand logo pinned to the banner's right (only added when a logo exists) */
.demo-banner .demo-logo { position:absolute; right:12px; top:50%; transform:translateY(-50%);
  height:22px; width:auto; max-width:110px; object-fit:contain; }
.demo-banner strong { font-weight:700; }
body.has-demo-banner { padding-top:34px; }
body.has-demo-banner .side { top:34px; height:calc(100vh - 34px); }
body.has-demo-banner .sideopen { top:46px; }
@media (max-width:760px) {
  body.has-demo-banner { padding-top:86px; }        /* 34 banner + 52 mobile top bar */
  body.has-demo-banner .mobilebar { top:34px; }
  body.has-demo-banner .side { top:34px; height:calc(100vh - 34px); }
}

/* ---------- v0.17.1: mobile right-edge overflow fixes ---------- */
@media (max-width: 760px) {
  /* Safety net: nothing should push the page sideways on a phone. The pipeline's
     kanban keeps its own internal horizontal scroll, so this doesn't harm it. */
  main { overflow-x:hidden; }
  /* "Needs attention" rows: let the row wrap and the action buttons drop to a new
     full-width line instead of running off the right edge. */
  .tl li { flex-wrap:wrap; }
  .tl li > span:not(.dot) { flex:1 1 auto; min-width:0; }        /* text can shrink, not overflow */
  .tl time { width:100%; margin-left:0; white-space:normal;
    display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
  .tl time .btn.sm { flex:0 0 auto; }
}
