:root {
  --ink: #16232a;
  --muted: #5d6b72;
  --line: #dfe5e6;
  --bg: #f4f6f5;
  --card: #ffffff;
  --brand: #0f3d3e;
  --brand-2: #1d6b6a;
  --accent: #e8b04b;
  --good: #23784f;
  --warn: #b26a00;
  --bad: #b3261e;
  --info: #1f5fa8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 35, 42, .06), 0 2px 8px rgba(16, 35, 42, .05);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--brand-2); }
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.boot { padding: 3rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--brand); color: #e6f1f0; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; gap: .6rem; align-items: center; padding: .25rem .5rem 1rem; font-weight: 700; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 400; color: #9fc7c3; font-size: .75rem; }
.nav a { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 8px; color: #d4e6e4; text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.08); }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.nav .ico { width: 1.2rem; text-align: center; opacity: .85; }
.side .who { margin-top: auto; padding: .75rem .5rem 0; border-top: 1px solid rgba(255,255,255,.12); font-size: .85rem; }
.side .who a { color: #9fc7c3; }
.main { padding: 1.5rem 2rem 4rem; max-width: 1400px; width: 100%; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.head .actions select { width: auto; }
.head .actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.topbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .side.open { display: flex; position: fixed; inset: 0 30% 0 0; z-index: 50; height: 100%; }
  .topbar { display: flex; align-items: center; justify-content: space-between; background: var(--brand); color: #fff; padding: .6rem 1rem; position: sticky; top: 0; z-index: 40; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 1.4rem; padding: .25rem .5rem; }
  .main { padding: 1rem 1rem 4rem; }
}

/* ---------- cards & grids ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid, .legend + .week { margin-top: 1rem; }
.grid > .card, .grid > form.card { margin-top: 0; }
.spacer { height: 1rem; }
.pre { white-space: pre-wrap; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
@media (max-width: 1000px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }
.stat { display: block; text-decoration: none; color: inherit; }
.stat .n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.alert .n { color: var(--bad); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: .75rem; align-items: center; }
.list li:first-child { border-top: 0; }
.list a { text-decoration: none; color: inherit; }
.list a:hover .t { text-decoration: underline; }
.list .t { font-weight: 600; }
.empty { color: var(--muted); padding: .75rem 0; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; white-space: pre-wrap; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfb; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f6faf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.neg td { background: #fdeeee; }
tfoot td { font-weight: 600; border-bottom: 0; }

/* ---------- forms ---------- */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; font-weight: 500; }
input, select, textarea { width: 100%; font: inherit; color: inherit; padding: .55rem .65rem; border: 1px solid #c9d2d4; border-radius: 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8fd0c8; outline-offset: 0; border-color: var(--brand-2); }
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox] { width: auto; margin-right: .4rem; }
.check { display: flex; align-items: center; color: var(--ink); font-size: .95rem; }
.field { margin-bottom: .85rem; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select, .toolbar input[type=date] { width: auto; }
.err { color: var(--bad); font-size: .9rem; margin-top: .5rem; min-height: 1.2em; }

button, .btn { display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-weight: 600; padding: .55rem .95rem; border-radius: 8px; border: 1px solid #c9d2d4; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
button:hover, .btn:hover { background: #f1f4f4; }
.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.primary:hover { background: var(--brand); }
.danger { color: var(--bad); border-color: #e6b8b5; }
.danger:hover { background: #fdeeee; }
.go { background: var(--good); border-color: var(--good); color: #fff; }
.go:hover { background: #1b603f; }
.sm { padding: .3rem .6rem; font-size: .85rem; }
.link { background: none; border: 0; padding: 0; color: var(--brand-2); font-weight: 500; text-decoration: underline; }
button:disabled { opacity: .55; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid #c9d2d4; border-radius: 8px; overflow: hidden; }
.seg a { padding: .45rem .8rem; text-decoration: none; color: var(--ink); font-weight: 500; border-right: 1px solid #c9d2d4; background: #fff; }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--brand-2); color: #fff; }

/* ---------- pills ---------- */
.pill { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e9eef0; color: #3c4b52; white-space: nowrap; }
.st-scheduled { background: #e5eefb; color: var(--info); }
.st-in_progress { background: #fff1d6; color: var(--warn); }
.st-completed { background: #dff3e8; color: var(--good); }
.st-invoiced { background: #e9e4f7; color: #5b3fa8; }
.st-cancelled { background: #eee; color: #777; text-decoration: line-through; }
.st-to_enter { background: #fff1d6; color: var(--warn); }
.st-entered { background: #dff3e8; color: var(--good); }
.st-void { background: #eee; color: #777; }
.role-admin { background: #fde7e5; color: var(--bad); }
.role-office { background: #e5eefb; color: var(--info); }
.role-tech { background: #dff3e8; color: var(--good); }

/* ---------- schedule ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(130px, 1fr)); gap: .5rem; overflow-x: auto; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); min-height: 260px; display: flex; flex-direction: column; }
.day.today { border-color: var(--brand-2); box-shadow: 0 0 0 1px var(--brand-2); }
.day .dh { padding: .5rem .6rem; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: baseline; }
.day .dh b { font-size: .95rem; }
.day .dh span { color: var(--muted); font-size: .8rem; }
.day .add { border: 0; background: none; color: var(--brand-2); font-size: 1.1rem; padding: 0 .2rem; }
.day .jobs { padding: .4rem; display: flex; flex-direction: column; gap: .4rem; }
.job { display: block; text-decoration: none; color: inherit; border-radius: 8px; padding: .45rem .5rem; border-left: 4px solid #999; background: #f6f8f8; font-size: .85rem; }
.job:hover { background: #eef4f3; }
.job .tm { font-weight: 700; }
.job .cu { font-weight: 600; }
.job .ti, .job .te { color: var(--muted); }
.job.s-completed, .job.s-invoiced { opacity: .7; }
.job.s-cancelled { opacity: .45; text-decoration: line-through; }
.tc-0 { border-left-color: #1d6b6a; } .tc-1 { border-left-color: #1f5fa8; } .tc-2 { border-left-color: #b26a00; }
.tc-3 { border-left-color: #7a3fa8; } .tc-4 { border-left-color: #b3261e; } .tc-5 { border-left-color: #23784f; }
.tc-6 { border-left-color: #a8327f; } .tc-7 { border-left-color: #4a5a63; } .tc-none { border-left-color: #c9d2d4; border-left-style: dashed; }
.legend { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .85rem; }
.legend span { border-left-width: 4px; border-left-style: solid; padding-left: .4rem; }
@media (max-width: 860px) {
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; }
}

/* ---------- part picker ---------- */
.picker { position: relative; }
.picker .results { position: absolute; left: 0; right: 0; top: 100%; z-index: 10; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; }
.picker .results button { display: flex; width: 100%; justify-content: space-between; border: 0; border-radius: 0; border-bottom: 1px solid var(--line); font-weight: 400; text-align: left; white-space: normal; }
.picker .results button:last-child { border-bottom: 0; }

/* ---------- modal & toast ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(16, 35, 42, .45); }
#modal-body { padding: 1.3rem 1.4rem; max-height: 88vh; overflow-y: auto; }
#modal-body h2 { font-size: 1.15rem; }
#toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(200%); visibility: hidden; background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; transition: transform .2s; z-index: 100; max-width: 90vw; }
#toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }
#toast.bad { background: var(--bad); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #0f3d3e 0%, #1d6b6a 60%, #2f8f86 100%); }
.login .card { width: min(400px, 100%); padding: 2rem; }
.login .logo { display: flex; gap: .7rem; align-items: center; margin-bottom: 1.25rem; }
.login .logo img { width: 42px; height: 42px; }

/* ---------- invoice summary ---------- */
.inv { max-width: 860px; }
.inv-top { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 2px solid var(--ink); padding-bottom: .75rem; margin-bottom: 1rem; }
.inv-top h2 { font-size: 1.3rem; margin: 0; }
.totals { margin-left: auto; width: min(360px, 100%); }
.totals td { border: 0; padding: .3rem .6rem; }
.totals tr.grand td { border-top: 2px solid var(--ink); font-size: 1.1rem; font-weight: 700; }
.sage-box { background: #fafbfb; border: 1px dashed #b9c4c6; border-radius: 8px; padding: .75rem 1rem; margin-top: 1rem; }

@media print {
  .side, .topbar, .no-print, #toast { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  body, :root { background: #fff; }
  .card { border: 0; box-shadow: none; padding: 0; }
  a { color: inherit; text-decoration: none; }
}

/* stock locations */
td.lowc { background: #fff3e0; }
td.lowc b { color: var(--warn); }
td.need { background: #e8f0fb; }
td.need b { color: var(--info); }
table.compact td, table.compact th { padding: .35rem .4rem; }
table.compact input { padding: .35rem .5rem; }
.qty-in { width: 90px; text-align: right; }
.card .head { margin-bottom: .5rem; }
.add-part { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .75rem; }
.add-part .grid.g3 { grid-template-columns: 1fr 1.4fr auto; align-items: end; }
.add-part .grid.g3 .field { margin-bottom: 0; }
@media (max-width: 640px) { .add-part .grid.g3 { grid-template-columns: 1fr 1fr auto; } }
