:root {
  --bg: #f4f6fa; --panel: #fff; --text: #1d2433; --muted: #667085; --line: #e3e7ee; --accent: #2457d6; --accent-soft: #e8eefc;
  --side: #17213a; --side-text: #c9d2e6; --danger: #c8322b; --warn: #b86e00; --ok: #1f8a4c;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); display: flex; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- layout ---------- */
.sidebar { width: 200px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; color: #fff; padding: 18px 18px 14px; }
.sidebar nav { display: flex; flex-direction: column; padding: 0 8px; gap: 2px; }
.sidebar nav a { color: var(--side-text); padding: 9px 12px; border-radius: 6px; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.user { margin: auto 12px 14px; background: transparent; border: 1px solid rgba(255,255,255,.2); color: var(--side-text); border-radius: 6px; padding: 7px; cursor: pointer; }
main { flex: 1; min-width: 0; padding: 20px 24px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.cols-half { grid-template-columns: 1fr 1fr; }
@media (max-width: 1100px) { .cols-2, .cols-half { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.flush { padding: 0; overflow: auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer; }
.kpi:hover { border-color: var(--accent); }
a.kpi, a.bar-row { display: block; color: inherit; text-decoration: none; }
a.bar-row { display: grid; }
a.kpi:hover, a.bar-row:hover { text-decoration: none; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi.bad .value { color: var(--danger); }
.kpi.warn .value { color: var(--warn); }
.bar-row { display: grid; grid-template-columns: 170px 1fr 40px; gap: 8px; align-items: center; margin: 5px 0; font-size: 13px; }
.bar { height: 10px; background: var(--accent); border-radius: 5px; min-width: 2px; }

/* ---------- controls ---------- */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 12px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: #b8c1d1; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1c47b3; }
button.danger { color: var(--danger); }
button.sm { padding: 4px 8px; font-size: 12px; }
/* Sales Order status picked in the orders table */
select.so-status { width: auto; padding: 3px 6px; font-size: 12px; font-weight: 600; }
select.so-status.st-pending_confirmation { color: #b45309; border-color: #f59e0b; }
select.so-status.st-review { color: #c2410c; border-color: #fb923c; }
select.so-status.st-ignore { color: var(--muted, #6b7280); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; }
.toolbar input[type=search] { min-width: 260px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.form label.full { grid-column: 1 / -1; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 400; font-size: 14px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; border: 1px solid var(--line); border-radius: 6px; padding: 8px; max-height: 160px; overflow: auto; }
.checks label { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; color: var(--text); font-size: 13px; }
.form .section { grid-column: 1 / -1; margin: 6px 0 -4px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }

/* ---------- tables ---------- */
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfd; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
th.sort, table.sortable thead th { cursor: pointer; user-select: none; }
table.sortable thead th:hover { color: var(--text); }
table.sortable thead th[data-dir="asc"]::after { content: " ▲"; }
table.sortable thead th[data-dir="desc"]::after { content: " ▼"; }
th.sort:hover { color: var(--text); }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f6f8fd; }
td.num, th.num { text-align: right; white-space: nowrap; }
.late { color: var(--danger); font-weight: 600; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }

/* ---------- chips ---------- */
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eef1f6; color: #3d4659; }
.c-slate { background: #eef1f6; color: #3d4659; } .c-gray { background: #f0f0f0; color: #777; }
.c-violet { background: #f0eafd; color: #6233c4; } .c-amber { background: #fdf3df; color: #94580a; }
.c-blue { background: #e6effe; color: #1f4fbf; } .c-teal { background: #ddf5f2; color: #0d7166; }
.c-indigo { background: #e9eafd; color: #3f3db8; } .c-red { background: #fde9e8; color: #b42318; }
.c-orange { background: #fdeee2; color: #b34b0c; } .c-green { background: #e1f5e8; color: #1a7a43; }
.badge { display: inline-block; min-width: 20px; text-align: center; padding: 1px 6px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.red { background: #fde9e8; color: var(--danger); } .badge.amber { background: #fdf3df; color: var(--warn); }
.prio-high { color: var(--warn); font-weight: 600; } .prio-urgent { color: var(--danger); font-weight: 700; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 14px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 9px 12px; color: var(--muted); }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------- activity ---------- */
.timeline { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow: auto; }
.tl-item { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; font-size: 13px; }
.tl-item.k-note { border-color: var(--accent); } .tl-item.k-delay { border-color: var(--danger); }
.tl-item.k-import { border-color: #9aa5b8; } .tl-item.k-visit { border-color: #0d9488; } .tl-item.k-material { border-color: #c27c0e; }
.tl-meta { font-size: 11px; color: var(--muted); }

/* ---------- schedule board ---------- */
.sched-wrap { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 14px; align-items: start; }
.backlog { max-height: calc(100vh - 140px); overflow: auto; }
.backlog .item { border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; margin-bottom: 6px; background: #fff; cursor: grab; font-size: 12px; }
.backlog .item:hover { border-color: var(--accent); }
.board { overflow: auto; }
.board table { table-layout: fixed; min-width: 900px; }
.board th, .board td { border-right: 1px solid var(--line); padding: 4px; }
.board td.res { width: 140px; font-weight: 600; font-size: 13px; padding: 8px; background: #fafbfd; }
.board th.today { background: var(--accent-soft); color: var(--accent); }
.board td.cell { height: 82px; vertical-align: top; position: relative; }
.board td.cell.over { background: #fff6f5; }
.board td.cell.absent { background: repeating-linear-gradient(45deg, #f6f6f6, #f6f6f6 6px, #eee 6px, #eee 12px); }
.board td.cell.drop, .cm-day.drop, .dl-row.drop { outline: 2px dashed var(--accent); outline-offset: -3px; }
.board .load { position: absolute; right: 4px; bottom: 2px; font-size: 10px; color: var(--muted); }
.board .absent-label { font-size: 11px; color: var(--muted); font-style: italic; }
.vchip { border-radius: 5px; padding: 4px 6px; margin-bottom: 4px; font-size: 11px; line-height: 1.3; cursor: pointer; border-left: 3px solid currentColor; }
.vchip b { font-size: 11px; }
.vchip.st-cancelled { opacity: .45; text-decoration: line-through; }
.vchip.st-tentative { border-left-style: dashed; }
.vchip.st-completed { opacity: .7; }

/* ---------- modal & toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal-backdrop[hidden] { display: none; }
.modal { background: #fff; border-radius: 10px; width: min(720px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 16px 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.modal footer .spacer { flex: 1; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1d2433; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: var(--shadow); font-size: 13px; }
.toast.warn { background: #8a4b00; } .toast.err { background: var(--danger); }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.alert { padding: 10px 12px; border-radius: 6px; background: #fdf3df; color: #6b3f05; margin-bottom: 12px; font-size: 13px; }
.alert.info { background: var(--accent-soft); color: #1d3f94; }

.page-head select, .page-head input { width: auto; }
.page-head label.row { font-size: 13px; }

/* ---------- sidebar extras */
.brand-sub { font-size: 12px; font-weight: 400; color: var(--side-text); margin-top: 2px; }
.user { display: flex; flex-direction: column; text-align: left; gap: 2px; }
.user b { color: #fff; }
.user span { font-size: 11px; }

/* ---------- sign-in */
.auth { position: fixed; inset: 0; background: var(--side); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 16px; }
.auth[hidden] { display: none; }
.auth-card { background: #fff; border-radius: 12px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.auth-brand { font-size: 20px; font-weight: 700; }
.auth-err { color: var(--danger); font-size: 13px; min-height: 18px; }
.hint { font-weight: 400; color: var(--muted); }

/* ---------- modal wide + booking form */
.modal.wide { width: min(980px, 100%); }
.day-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 8px; background: #fafbfd; }
.day-row input, .day-row select { width: auto; }
.pchips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.pchip { padding: 3px 9px; border-radius: 999px; font-size: 12px; background: #fff; border: 1px solid var(--line); }
.pchip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pchip.eq.on { background: #6b4fc4; border-color: #6b4fc4; }
.pchip .ext { font-size: 10px; opacity: .7; }
.issues { margin-top: 12px; }
.issue { font-size: 13px; padding: 5px 9px; border-radius: 6px; margin-bottom: 4px; }
.issue.hard { background: #fde9e8; color: #8f1b13; }
.issue.soft { background: #fdf3df; color: #6b3f05; }
.issue.ok { background: #e1f5e8; color: #1a7a43; }
.cand { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; margin-bottom: 6px; }

/* ---------- queues & job page */
.queue-wrap { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 14px; align-items: start; }
.queue-nav { display: flex; flex-direction: column; padding: 6px; }
.queue-nav button { display: flex; justify-content: space-between; align-items: center; border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.queue-nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.queue-nav .badge { background: #eef1f6; }
.queue-nav .badge.red { background: #fde9e8; }
.booking { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.booking.released { opacity: .6; background: #fafafa; }
.booking table { margin-top: 8px; }
.ready-row { display: grid; grid-template-columns: 1fr 140px; gap: 4px 8px; align-items: center; padding: 5px 0; border-top: 1px solid var(--line); font-size: 13px; }
.ready-row .full { grid-column: 1 / -1; }
.ready-row select { padding: 4px 6px; }
.rs-pending { background: #fdf3df; } .rs-blocked { background: #fde9e8; } .rs-ready { background: #e1f5e8; }
.vchip.st-proposed, .vchip.st-draft { border-left-style: dashed; }
.vchip.st-reschedule_requested { outline: 1px dashed #b34b0c; }
.hol-label { font-size: 10px; color: #b42318; font-weight: 600; }

/* ---------- month view */
.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cm-head { padding: 6px 8px; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); }
.cm-day { min-height: 104px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 5px; cursor: pointer; overflow: hidden; }
.cm-day:hover { background: #fafbfd; }
.cm-day.other { background: #fafafa; color: var(--muted); }
.cm-day.today .cm-date span:first-child { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 6px; }
.cm-day.hol { background: #fff7f6; }
.cm-date { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; margin-bottom: 3px; }
.cm-item { font-size: 11px; border-radius: 4px; padding: 1px 4px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- day view */
.dl-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px; align-items: center; min-height: 40px; border-bottom: 1px solid var(--line); }
.dl-row.off .dl-track { background: repeating-linear-gradient(45deg, #f6f6f6, #f6f6f6 6px, #eee 6px, #eee 12px); }
.dl-head { min-height: 22px; border: 0; }
.dl-name { font-size: 13px; font-weight: 600; }
.dl-track { position: relative; height: 36px; }
.dl-hour { position: absolute; top: 0; bottom: 0; border-left: 1px solid #eef1f6; }
.dl-hlabel { position: absolute; font-size: 10px; color: var(--muted); transform: translateX(-50%); }
.dl-block { position: absolute; top: 3px; bottom: 3px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 900px) {
  .queue-wrap, .sched-wrap, .cols-2, .cols-half { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
