:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1b1f27; --muted: #6b7280; --line: #e3e5ea;
  --brand: #14213d; --accent: #2563eb;
  --due: #b45309; --due-bg: #fef3c7; --over: #b91c1c; --over-bg: #fee2e2; --ok: #047857; --ok-bg: #d1fae5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1217; --card: #181c23; --ink: #e8eaee; --muted: #9aa1ad; --line: #2a303a;
    --brand: #0b1222; --accent: #60a5fa;
    --due: #fbbf24; --due-bg: #3a2c0a; --over: #f87171; --over-bg: #3b1416; --ok: #34d399; --ok-bg: #0d2e24;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 24px 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
button, .btn, input, select, textarea { font: inherit; color: inherit; }
button, .btn { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 12px; text-decoration: none; display: inline-block; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.link { border: 0; background: none; color: inherit; text-decoration: underline; padding: 4px; }
input, select, textarea { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 10px; width: 100%; }

.bar { background: var(--brand); color: #fff; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; }
.bar button.link { color: #fff; }

.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.controls input[type=date] { width: auto; }
.controls select { width: auto; flex: 1; min-width: 180px; }

.alert { background: var(--over-bg); color: var(--over); padding: 10px 12px; border-radius: 8px; margin: 12px 0; }
.alert.info { background: var(--ok-bg); color: var(--ok); }
.alert a { color: inherit; font-weight: 600; }
.empty { color: var(--muted); padding: 24px 0; }
.muted { color: var(--muted); }

.summary { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 10px; margin-top: 16px; }
.summary > div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.summary b { display: block; font-size: 24px; }
.summary span { color: var(--muted); font-size: 13px; }
.summary .due b { color: var(--due); }
.summary .quotes b { color: var(--due); }
.refresh { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 4px; }
.refresh small { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.job { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.job.due { border-left-color: var(--due); }
.job.overdue { border-left-color: var(--over); }
.job-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ro { font-weight: 700; }
.rego { margin-left: auto; font-family: ui-monospace, Menlo, monospace; background: var(--bg); padding: 2px 6px; border-radius: 4px; }
.cust { font-weight: 500; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.tag.sent { background: var(--ok-bg); color: var(--ok); }
.tag.status { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
dd.late { color: var(--over); font-weight: 600; }
dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
dt { font-size: 12px; color: var(--muted); }
dd { margin: 0; }
.due-text { color: var(--due); font-weight: 600; }
.overdue-text { color: var(--over); font-weight: 600; }
button.extend { margin-top: 6px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 18px; }
dialog p { margin: 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { flex-direction: row; }
.chip input { position: absolute; opacity: 0; width: 0; }
.chip span { border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer; }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

.login { display: grid; place-items: center; min-height: 100vh; }
.login .card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }

@media (max-width: 600px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .refresh { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
}

.tags { display: flex; gap: 6px; flex-wrap: wrap; }
a.tag { text-decoration: none; }
.tag.quote.needs-you { background: var(--due-bg); color: var(--due); font-weight: 600; border: 1px solid var(--due); }
.tag.quote.in-progress { background: var(--bg); color: var(--muted); border: 1px dashed var(--line); }
.tag.quote.accepted { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.tag.quote.rejected { background: var(--over-bg); color: var(--over); font-weight: 600; }
.job.quote-flag { box-shadow: 0 0 0 2px var(--due); }
.quote-strip { margin-top: 12px; background: var(--due-bg); color: var(--due); border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.quote-strip a { color: inherit; font-weight: 600; }

/* Quote not opened yet: solid green until someone clicks it. */
.tag.quote.unopened, .quote-strip a.unopened { background: var(--ok); color: var(--card); border: 1px solid var(--ok); font-weight: 600; }
.quote-strip a { padding: 2px 8px; border-radius: 999px; text-decoration: none; }
dialog#quote { width: min(560px, calc(100vw - 32px)); }
.qbody { padding: 18px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 64px); overflow-y: auto; }
.qbody h3 { margin: 6px 0 0; font-size: 14px; }
.qfields { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 0; }
.qfields dd { margin: 0; }
.qparts { width: 100%; border-collapse: collapse; font-size: 14px; }
.qparts th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; }
.qparts td, .qparts th { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.qparts td:first-child { width: 40px; font-weight: 600; }
.photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.photos img { width: 96px; border-radius: 6px; cursor: zoom-in; }
.photos img.big { width: 100%; cursor: zoom-out; }
.history { list-style: none; margin: 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.history small { color: var(--muted); }
.history .note { margin-top: 3px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.small { font-size: 12px; }
.qactions { display: flex; flex-wrap: wrap; gap: 8px; }
button.danger { background: var(--over-bg); color: var(--over); border-color: var(--over); font-weight: 600; }
button:disabled { opacity: .6; cursor: wait; }
.qerror { color: var(--over); background: var(--over-bg); padding: 8px 10px; border-radius: 8px; }
/* Header nav */
.bar h1 a { color: inherit; text-decoration: none; }
.bar nav { display: flex; align-items: center; gap: 12px; }
.bar nav a.link { color: inherit; text-decoration: underline; padding: 4px; }
/* Job lines */
.lines-btn { width: 100%; margin-top: 4px; }
.lines-btn:disabled { opacity: .5; cursor: default; }
.joblines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.joblines li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 14px; align-items: start; }
.joblines .tick { color: var(--ok); font-weight: 700; }
.joblines li.done .text { color: var(--muted); }
.joblines .op { font-size: 12px; font-variant-numeric: tabular-nums; }
/* Extend recipients */
.recips { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.recips legend { font-size: 13px; padding: 0 4px; }
.recip { display: flex; align-items: center; gap: 8px; }
/* Settings */
.settings { max-width: 720px; }
.settings form { display: flex; flex-direction: column; gap: 14px; }
.settings .card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.settings h3 { margin: 0 0 4px; font-size: 16px; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.settings label.check { flex-direction: row; align-items: center; gap: 8px; }
.settings input:not([type=checkbox]), .settings select { padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.settings .help { margin: -4px 0 4px; }
.advisors { width: 100%; border-collapse: collapse; font-size: 14px; }
.advisors th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 4px; }
.advisors td { padding: 3px; }
.advisors td input { width: 100%; box-sizing: border-box; }
.advisors td:first-child { width: 80px; }
.advisors td:last-child { width: 60px; text-align: center; }
.save { position: sticky; bottom: 8px; flex-direction: row !important; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.settings label.check input { width: auto; margin: 0; flex: none; }
/* Estimate-complete email, in the quote pop-up */
.estimate-mail { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.estimate-mail summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.estimate-mail form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.estimate-mail label { display: flex; flex-direction: column; gap: 4px; }
.estimate-mail textarea { font: inherit; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: inherit; }
.estimate-mail button { align-self: flex-end; }
.updating { color: var(--accent); }
