:root {
  --bg: #EBEFF2;
  --panel: #FFFFFF;
  --ink: #1D2B36;
  --muted: #5B6B77;
  --line: #D3DAE0;
  --field: #B9C4CC;
  --amber: #F2A900;
  --amber-ink: #3A2A00;
  --link: #1C5D8A;
  --good: #1B7F48;  --good-bg: #E2F2E9;
  --check: #9A6410; --check-bg: #FBEFD8;
  --poor: #B8372A;  --poor-bg: #F7E3E0;
  --cond: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 Barlow, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px));
}
a { color: var(--link); }
h1 { font-family: var(--cond); font-weight: 600; font-size: 2rem; line-height: 1.1; margin: 4px 0 8px; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: .95rem; font-weight: 600; margin: 16px 0 6px; }
.muted { color: var(--muted); }
.small, small { font-size: .88rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff;
  display: flex; align-items: center; gap: 18px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
}
.brand { color: #fff; text-decoration: none; font-family: var(--cond); font-weight: 600; font-size: 1.35rem; letter-spacing: .01em; white-space: nowrap; }
.brand::before { content: ""; display: inline-block; width: 11px; height: 11px; background: var(--amber); margin-right: 9px; border-radius: 2px; vertical-align: 1px; }
.brand.dark { color: var(--ink); margin-bottom: 18px; }
.topnav { display: none; gap: 2px; }
.topnav a { color: #C3CED6; text-decoration: none; padding: 6px 12px; border-radius: 6px; font-weight: 500; }
.topnav a:hover { color: #fff; }
.topnav a.on { color: #fff; box-shadow: inset 0 -3px 0 var(--amber); border-radius: 0; }
.topsearch { flex: 1; max-width: 440px; margin-left: auto; }
.topsearch input { width: 100%; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14); color: #fff; padding: 8px 12px; border-radius: 6px; font: inherit; }
.topsearch input::placeholder { color: #93A5B2; }
.toplink { color: #C3CED6; text-decoration: none; font-size: .92rem; margin-left: auto; }
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .topnav { display: flex; }
  .toplink { margin-left: 0; }
}
@media (max-width: 899px) { .topsearch { display: none; } }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--panel); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottomnav a { text-align: center; padding: 12px 0 14px; text-decoration: none; color: var(--muted); font-weight: 500; }
.bottomnav a.on { color: var(--ink); box-shadow: inset 0 3px 0 var(--amber); font-weight: 600; }
@media (min-width: 900px) { .bottomnav { display: none; } }

body { overflow-x: hidden; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 18px 16px 32px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px 16px; margin-bottom: 8px; }
.sub { margin: 0 0 6px; color: var(--muted); }
.ids { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 0 0 12px; font-size: .92rem; }
.cols { display: grid; gap: 0 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .cols { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; } }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.flash { background: var(--good-bg); border: 1px solid #BADFC9; color: #134D2D; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.err { background: var(--poor-bg); border-color: #EDC3BD; color: #7A2419; }

/* Controls */
.btn { display: inline-block; border: 1px solid var(--field); background: #fff; color: var(--ink); padding: 9px 15px; border-radius: 7px; font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; line-height: 1.3; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--amber); border-color: #D99700; color: var(--amber-ink); font-weight: 600; }
.btn.primary:hover { background: #E59F00; }
.btn.small { padding: 5px 11px; font-size: .9rem; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.wide { width: 100%; }
.danger { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.danger-btn { color: var(--poor) !important; padding-left: 0; }
input, select, textarea { font: inherit; font-size: 16px; width: 100%; padding: 9px 10px; border: 1px solid var(--field); border-radius: 7px; background: #fff; color: var(--ink); }
textarea { resize: vertical; }
label.f, span.f { display: block; font-size: .9rem; font-weight: 500; color: var(--muted); }
label.f input, label.f select, label.f textarea { margin-top: 4px; color: var(--ink); }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; }
label.check input { width: 20px; height: 20px; flex: none; }
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
.stack { display: grid; gap: 14px; }
details > summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: 14px; }
details.sub-details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }

/* Badges and ratings */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; background: #E3E8EC; color: #3C4C58; white-space: nowrap; }
.st-wait { background: var(--check-bg); color: var(--check); }
.st-good { background: var(--good-bg); color: var(--good); }
.st-dead { background: #ECEDEE; color: #7C858B; text-decoration: line-through; }
.rating { display: inline-block; padding: 2px 9px; border-radius: 4px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.rating.good { background: var(--good); color: #fff; }
.rating.check { background: #E9A93B; color: #3A2600; }
.rating.poor { background: var(--poor); color: #fff; }
.rating.none { background: #E3E8EC; color: var(--muted); font-weight: 500; }
.below { color: var(--good); font-weight: 600; }
.above { color: var(--poor); font-weight: 600; }
.due { color: var(--poor); font-weight: 600; }
.tag { display: inline-block; font-size: .75rem; font-weight: 600; background: var(--good); color: #fff; padding: 1px 7px; border-radius: 4px; vertical-align: 1px; }

/* Dashboard counts: one strip, not a card grid */
.counts { display: grid; grid-template-columns: repeat(2, 1fr); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 16px; overflow: hidden; }
.counts a { display: flex; flex-direction: column; padding: 12px 16px; text-decoration: none; color: var(--ink); border-top: 1px solid var(--line); border-left: 1px solid var(--line); margin: -1px 0 0 -1px; }
.counts a:hover { background: #F5F7F8; }
.counts b { font-family: var(--cond); font-size: 2.3rem; font-weight: 600; line-height: 1; }
.counts span { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.counts a.hot b { color: var(--poor); }
@media (min-width: 700px) { .counts { grid-template-columns: repeat(5, 1fr); } }

.attn { list-style: none; margin: 0; padding: 0; }
.attn li { border-left: 4px solid var(--line); padding: 8px 12px; margin-bottom: 6px; background: #F6F8F9; border-radius: 0 6px 6px 0; }
.attn li a { color: var(--ink); text-decoration: none; display: block; }
.attn .a-due { border-color: var(--poor); }
.attn .a-good { border-color: var(--good); }
.attn .a-wait { border-color: var(--amber); }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain > li { padding: 9px 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
ul.plain > li:first-child { border-top: 0; }
ul.sup > li { display: block; }
.sup-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.inline-add { display: grid; gap: 8px; margin-top: 12px; grid-template-columns: 1fr; }
@media (min-width: 600px) { .inline-add { grid-template-columns: 1fr 1fr auto; } }

/* Filters */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; scrollbar-width: none; }
.filters a { white-space: nowrap; padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: .92rem; }
.filters a.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.filters small { opacity: .7; margin-left: 2px; }

/* Lists */
.list { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.li { display: grid; gap: 4px 12px; padding: 12px 16px; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; grid-template-columns: 1fr 1fr; }
.li:first-child { border-top: 0; }
a.li:hover { background: #F5F7F8; }
.li-name { grid-column: 1 / -1; display: flex; flex-direction: column; }
.li-name small { color: var(--muted); }
.li [data-l]::before { content: attr(data-l) " "; color: var(--muted); font-size: .85rem; }
.li-head { display: none; }
@media (min-width: 800px) {
  .li { grid-template-columns: minmax(0, 2.4fr) repeat(5, minmax(0, 1fr)); align-items: center; }
  .li > span:not(.li-name) { text-align: right; }
  .li-name { grid-column: auto; }
  .li [data-l]::before { content: none; }
  .li-head { display: grid; font-size: .85rem; color: var(--muted); font-weight: 500; padding-top: 8px; padding-bottom: 8px; }
  .sl .li { grid-template-columns: minmax(0, 2fr) 1fr 1fr 1fr; }
  .sl .li > span:not(.li-name) { text-align: left; }
}

/* The profit ticket */
.ticket {
  background: var(--ink); color: #fff; border-radius: 12px; padding: 16px 18px 18px; margin-bottom: 16px;
  border-left: 10px solid #5B6B77;
}
.ticket[data-rating="good"] { border-left-color: #35C074; }
.ticket[data-rating="check"] { border-left-color: #F2B233; }
.ticket[data-rating="poor"] { border-left-color: #E5533F; }
.ticket-head { display: flex; justify-content: space-between; gap: 12px; color: #AFBDC7; font-size: .92rem; }
.rating-word { font-weight: 600; color: #fff; }
.ticket[data-rating="good"] .rating-word { color: #5DDB97; }
.ticket[data-rating="check"] .rating-word { color: #F7C662; }
.ticket[data-rating="poor"] .rating-word { color: #FF8A78; }
.ticket-main { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 14px; }
.ticket-main .lbl { display: block; color: #AFBDC7; font-size: .85rem; }
.ticket-main > div { min-width: 0; }
.ticket-main .val { display: block; font-family: var(--cond); font-weight: 600; font-size: clamp(1.6rem, 7vw, 3rem); line-height: 1.05; white-space: nowrap; }
.ticket-lines { margin: 0; display: grid; gap: 2px; border-top: 1px solid rgba(255,255,255,.14); padding-top: 10px; }
.ticket-lines div { display: flex; justify-content: space-between; gap: 12px; }
.ticket-lines dt { color: #AFBDC7; }
.ticket-lines dd { margin: 0; }
.ticket .below { color: #5DDB97; }
.ticket .above { color: #FF8A78; }
.ticket .muted { color: #AFBDC7; }
.proj { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; }
@media (min-width: 500px) { .proj { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); } }
.proj div { background: rgba(255,255,255,.07); border-radius: 6px; padding: 7px 10px; }
.proj span { display: block; color: #AFBDC7; font-size: .82rem; }
.proj b { font-family: var(--cond); font-size: 1.3rem; font-weight: 600; }
.whatif { display: block; color: #AFBDC7; font-size: .88rem; }
.whatif input { margin-top: 4px; background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.25); color: #fff; max-width: 200px; display: block; }

/* Tables */
.scroll { overflow-x: auto; margin: 0 -4px; }
.tbl { width: 100%; border-collapse: collapse; min-width: 560px; }
.tbl th { text-align: left; font-size: .85rem; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl .num { text-align: right; }
.tbl tr.best td { background: var(--good-bg); }

/* Timeline */
.day h3 { margin: 14px 0 4px; font-size: .88rem; color: var(--muted); font-weight: 600; }
.day:first-child h3 { margin-top: 0; }
.ev { display: grid; grid-template-columns: 46px 1fr auto; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.ev time { color: var(--muted); font-size: .9rem; padding-top: 1px; }
.ev-head { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.ev-body { margin-top: 2px; }
.ev-quote strong { color: var(--good); }
.x { border: 0; background: none; color: #9AA7B0; font-size: 1.2rem; line-height: 1; cursor: pointer; padding: 2px 6px; }
.x:hover { color: var(--poor); }

/* Quote history */
.hist-sup { margin: 16px 0 4px; }
.hist-sup:first-of-type { margin-top: 0; }
.hist { display: grid; grid-template-columns: 96px 1fr auto; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.hist.old { color: var(--muted); }
.hist-date { font-size: .9rem; color: var(--muted); }

/* Quick log form */
.quick { display: grid; gap: 12px; }
.seg { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-block; padding: 8px 14px; border: 1px solid var(--field); border-radius: 999px; cursor: pointer; font-weight: 500; background: #fff; }
.seg input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.seg input:focus-visible + span { outline: 3px solid var(--amber); outline-offset: 2px; }
.followup { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.followup .f { width: 100%; }
.chip { border: 1px solid var(--field); background: #fff; color: var(--ink); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .92rem; cursor: pointer; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.followup input[type=date] { width: auto; padding: 5px 8px; }

/* Quote entry */
.quoteform { display: grid; gap: 12px; }
.qrows { display: grid; gap: 6px; }
.qhead, .qrow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.qhead span { font-size: .85rem; color: var(--muted); font-weight: 500; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 16px; margin: 0 0 12px; }
.facts dt { font-size: .85rem; color: var(--muted); }
.facts dd { margin: 0; }
.contact-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.bigsearch { display: flex; gap: 8px; margin-bottom: 16px; }
.link { margin: 0 0 6px; word-break: break-all; }

/* Auth / install */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.authbox { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: 100%; max-width: 380px; display: grid; gap: 14px; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
