/* Crimson Lots CRM — mobile-first */
:root {
  --crimson: #990000;
  --crimson-ink: #7a0000;
  --bg: #faf7f5;
  --surface: #ffffff;
  --surface2: #f1ecea;
  --ink: #1c1917;
  --ink2: #57534e;
  --ink3: #8a827c;
  --line: #e5ddd9;
  --good: #1a7f37;
  --good-bg: #e6f4ea;
  --warn: #9a6700;
  --warn-bg: #fff3d6;
  --serious: #cf222e;
  --serious-bg: #ffe5e7;
  --accent-bg: #f7e8e8;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(28, 25, 23, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --crimson: #9b0e13;
    --crimson-ink: #ef5f64;
    --bg: #171412;
    --surface: #211d1a;
    --surface2: #2c2622;
    --ink: #ede8e4;
    --ink2: #b5aca5;
    --ink3: #7d746d;
    --line: #38312c;
    --good: #4bc26b;
    --good-bg: #12301b;
    --warn: #e3b341;
    --warn-bg: #362a10;
    --serious: #f87179;
    --serious-bg: #3d181b;
    --accent-bg: #3a1618;
    --shadow: none;
  }
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
body.shell { padding-left: calc(68px + env(safe-area-inset-left, 0px)); }
#app { max-width: 760px; margin: 0 auto; padding: 14px 14px 30px; }

h1 { font-size: 22px; margin: 6px 0 2px; }
h2 { font-size: 16px; margin: 18px 0 8px; color: var(--ink2); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.sub { color: var(--ink2); font-size: 14px; margin-bottom: 12px; }
a { color: var(--crimson-ink); text-decoration: none; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.topbar .back { font-size: 15px; color: var(--crimson-ink); padding: 6px 0; display: inline-block; }

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card.tappable { cursor: pointer; }
.card.tappable:active { background: var(--surface2); }
.card .title { font-weight: 600; font-size: 16px; }
.card .meta { color: var(--ink2); font-size: 13.5px; margin-top: 2px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.tile .num { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.tile .lbl { font-size: 12.5px; color: var(--ink2); margin-top: 1px; }
.tile.wide { grid-column: 1 / -1; }
.tile .num small { font-size: 15px; font-weight: 600; color: var(--ink2); }

/* chips + status */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface2); color: var(--ink2);
  white-space: nowrap;
}
.chip.crimson { background: var(--accent-bg); color: var(--crimson-ink); }
.chip.good    { background: var(--good-bg); color: var(--good); }
.chip.warn    { background: var(--warn-bg); color: var(--warn); }
.chip.serious { background: var(--serious-bg); color: var(--serious); }

/* filter row */
.filters { display: flex; gap: 8px; margin: 10px 0 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.filters button {
  flex: 0 0 auto;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink2);
  font-size: 14px; font-weight: 600; padding: 7px 14px; border-radius: 999px; cursor: pointer;
}
.filters button.on { background: var(--crimson); border-color: var(--crimson); color: #fff; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 11px; cursor: pointer;
  font-size: 15px; font-weight: 600; padding: 11px 16px;
  background: var(--crimson); color: #fff;
}
.btn:active { opacity: 0.85; }
.btn.ghost { background: var(--surface2); color: var(--ink); }
.btn.small { font-size: 13px; padding: 7px 12px; border-radius: 9px; }
.btn.danger { background: var(--serious-bg); color: var(--serious); }
.btn.block { width: 100%; margin-top: 8px; }
.addfab {
  position: fixed; right: 16px; bottom: calc(22px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--crimson); color: #fff; border: 0;
  font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  z-index: 40;
}

/* lists inside cards */
.miniline { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.miniline:first-of-type { border-top: 0; }
.miniline .l { color: var(--ink2); }
.miniline .r { font-weight: 600; text-align: right; }

/* checklist */
.check { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14.5px; }
.check:first-child { border-top: 0; }
.check input { width: 19px; height: 19px; margin-top: 1px; accent-color: var(--crimson); }
.check.done label { color: var(--ink3); text-decoration: line-through; }

/* forms */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px;
}
.field textarea { min-height: 84px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--ink3); margin-top: 3px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checkbox-field { display: flex; align-items: center; gap: 9px; padding: 4px 0 10px; }
.checkbox-field input { width: 19px; height: 19px; accent-color: var(--crimson); }
.checkbox-field label { font-size: 14.5px; font-weight: 600; }

/* modal (bottom sheet) */
#modal-root:empty { display: none; }
.sheet-wrap {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 760px;
  max-height: 90dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet h3 { font-size: 18px; margin-bottom: 12px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet .actions .btn { flex: 1; }
@media (min-width: 700px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 18px; max-height: 84vh; }
}

/* nav rail (left, vertical) */
#tabbar[hidden] { display: none; }
#tabbar {
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
  width: 68px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: calc(12px + env(safe-area-inset-top, 0px)) 0 14px env(safe-area-inset-left, 0px);
}
#tabbar .brand { width: 38px; height: 38px; border-radius: 10px; margin-bottom: 12px; }
#tabbar a {
  flex: 0 0 auto; width: 58px; padding: 9px 0 8px;
  text-align: center; border-radius: 13px;
  font-size: 9.5px; font-weight: 600; color: var(--ink3);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
#tabbar a.on { color: var(--crimson-ink); background: var(--accent-bg); }

/* login */
.login {
  min-height: 80dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; text-align: center;
}
.login .mark {
  width: 76px; height: 76px; border-radius: 20px; background: var(--crimson);
  color: #fff; font: bold 34px Georgia, serif;
  display: flex; align-items: center; justify-content: center;
}
.login input {
  font-size: 22px; text-align: center; letter-spacing: 0.35em;
  width: 220px; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.login .err { color: var(--serious); font-size: 14px; font-weight: 600; min-height: 20px; }

/* toast */
body.shell #toast { left: calc(50% + 34px); }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(26px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  z-index: 70; max-width: 90vw; text-align: center;
}

/* more menu grid */
.moregrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.moregrid .card { margin: 0; text-align: center; padding: 20px 10px; }
.moregrid .card .ico { font-size: 26px; display: block; margin-bottom: 6px; }

/* tables (money) */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; color: var(--ink2); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tblwrap { overflow-x: auto; }

.empty { text-align: center; color: var(--ink3); padding: 26px 10px; font-size: 14.5px; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; font-weight: 500; }
.filelink { display: inline-flex; align-items: center; gap: 6px; background: var(--surface2); border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; margin: 3px 4px 3px 0; }

/* sectioned lead cards */
.leadcard { padding: 0; overflow: hidden; }
.lc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px 10px; }
.lc-name { font-weight: 600; font-size: 16px; }
.lc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; padding: 10px 14px 11px; border-top: 1px solid var(--line); }
.lc-fact { min-width: 0; }
.lc-fact.wide { grid-column: 1 / -1; }
.lc-fact .k { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink3); margin-bottom: 1px; }
.lc-fact .v { font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
.lc-maps { padding: 0 14px 10px; }
.lc-maps .maplinks { margin-top: 0; }
.lc-steps { padding: 8px 14px 9px; border-top: 1px solid var(--line); }
.lc-steps > .k { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink3); margin-bottom: 2px; }
.lc-steps .check { font-size: 13.5px; padding: 5px 0; border-top: 0; }
.lc-steps .check input { width: 17px; height: 17px; }
.lc-notes-toggle { display: block; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); color: var(--crimson-ink); font-family: inherit; font-size: 13px; font-weight: 600; padding: 9px 14px; cursor: pointer; }
.lc-notes { padding: 2px 14px 11px; font-size: 13.5px; line-height: 1.5; color: var(--ink2); white-space: pre-wrap; }
.lc-actions { display: flex; gap: 8px; align-items: center; padding: 10px 14px 12px; border-top: 1px solid var(--line); background: var(--surface2); }
.lc-actions select { flex: 1; min-width: 0; font-family: inherit; font-size: 13.5px; padding: 8px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }

/* brand + dashboard polish */
.brandbar { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.brandbar .brandmark { width: 46px; height: 46px; border-radius: 12px; }
.brandbar h1 { margin: 0; }
.brandbar .sub { margin: 0; }
.card.hero {
  background: linear-gradient(135deg, #9b0e13 0%, #6d0206 60%, #560003 100%);
  border: 0; color: #fff;
}
.card.hero .title { color: #fff; font-size: 17px; }
.card.hero .meta { color: rgba(255, 255, 255, 0.82); }
.card.hero .chip { background: rgba(255, 255, 255, 0.16); color: #fff; }
.card.hero .btn.herobtn {
  background: rgba(255, 255, 255, 0.14); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.28);
  margin-top: 12px; font-size: 13px; padding: 8px 14px; border-radius: 10px;
}
.tile { position: relative; }
.tile .tic { position: absolute; top: 10px; right: 10px; color: var(--crimson-ink); opacity: 0.35; }
.progress { height: 6px; background: var(--surface2); border-radius: 99px; margin: 2px 0 10px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--crimson); border-radius: 99px; transition: width 0.3s; }
.maplinks { display: flex; gap: 6px; margin-top: 5px; }
.maplinks .filelink { display: inline-flex; align-items: center; gap: 5px; }

/* Manual theme override (More → Theme). Attribute selector outranks the media query. */
:root[data-theme="dark"] {
  --crimson: #9b0e13;
  --crimson-ink: #ef5f64;
  --bg: #171412;
  --surface: #211d1a;
  --surface2: #2c2622;
  --ink: #ede8e4;
  --ink2: #b5aca5;
  --ink3: #7d746d;
  --line: #38312c;
  --good: #4bc26b;
  --good-bg: #12301b;
  --warn: #e3b341;
  --warn-bg: #362a10;
  --serious: #f87179;
  --serious-bg: #3d181b;
  --accent-bg: #3a1618;
  --shadow: none;
}
:root[data-theme="light"] {
  --crimson: #990000;
  --crimson-ink: #7a0000;
  --bg: #faf7f5;
  --surface: #ffffff;
  --surface2: #f1ecea;
  --ink: #1c1917;
  --ink2: #57534e;
  --ink3: #8a827c;
  --line: #e5ddd9;
  --good: #1a7f37;
  --good-bg: #e6f4ea;
  --warn: #9a6700;
  --warn-bg: #fff3d6;
  --serious: #cf222e;
  --serious-bg: #ffe5e7;
  --accent-bg: #f7e8e8;
  --shadow: 0 1px 3px rgba(28, 25, 23, 0.08);
}
