:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f0f1f4; --text: #1b1d22; --muted: #646b78;
  --line: #e1e4ea; --accent: #1f5fd1; --accent-ink: #ffffff; --ok: #12804a; --warn: #b26b00; --bad: #c0362c;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --row1: #e6e9ef; --row2: #eff1f5; --row3: #f9fafb; --row-hover: #dde7fb;
  --unofficial: #fbe1e1; --unofficial-2: #fdecec; --unofficial-ink: #c0362c;
  --recent: #dcf3e4; --recent-2: #e8f8ee; --recent-ink: #12804a;
  --month-bg: #d9e8fb; --month-ink: #163d73; --month-line: #9fc0ea;
  color-scheme: light;
}
/* dark: chosen in Settings (theme.js sets data-theme; palette and background colours are set
   there too). Without theme.js the system setting is used. */
:root[data-theme="dark"] {
  --bg: #121418; --surface: #1b1e24; --surface-2: #23272f; --text: #e8eaee; --muted: #9aa1ad;
  --line: #2f343d; --accent: #6b9dff; --accent-ink: #0d1424; --ok: #4cc58a; --warn: #f0b24a; --bad: #ff7b70;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  --row1: #15181d; --row2: #1b1e24; --row3: #22262d; --row-hover: #26324a;
  --unofficial: #3a1d20; --unofficial-2: #432226; --unofficial-ink: #d9534a;
  --recent: #173426; --recent-2: #1b3b2b; --recent-ink: #4cc58a;
  --month-bg: #1c2d47; --month-ink: #b9d3ff; --month-line: #2f4a73;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #121418; --surface: #1b1e24; --surface-2: #23272f; --text: #e8eaee; --muted: #9aa1ad;
    --line: #2f343d; --accent: #6b9dff; --accent-ink: #0d1424; --ok: #4cc58a; --warn: #f0b24a; --bad: #ff7b70;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
    --row1: #15181d; --row2: #1b1e24; --row3: #22262d; --row-hover: #26324a;
    --unofficial: #3a1d20; --unofficial-2: #432226; --unofficial-ink: #d9534a;
    --recent: #173426; --recent-2: #1b3b2b; --recent-ink: #4cc58a;
    --month-bg: #1c2d47; --month-ink: #b9d3ff; --month-line: #2f4a73;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--surface-2); color: var(--text); }
.sync { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 5px 12px;
  font-size: 12px; cursor: pointer; white-space: nowrap; }
.sync.ok { color: var(--ok); } .sync.warn { color: var(--warn); } .sync.bad { color: var(--bad); }

main { max-width: 1400px; margin: 0 auto; padding: 16px 16px 96px; }
.view { display: none; } .view.on { display: block; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; min-width: 0; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.toolbar input { width: auto; }
button.ghost, button.primary, button.danger { border-radius: 8px; padding: 9px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
button.ghost { background: var(--surface); border: 1px solid var(--line); }
button.primary { background: var(--accent); color: var(--accent-ink); border: 0; }
button.danger { background: none; color: var(--bad); border: 1px solid var(--line); }
/* "new version" bar under the header */
.upd-bar:not([hidden]) { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 6px) 10px 6px 16px;
  background: var(--accent); color: var(--accent-ink); font-size: 14px; }
.upd-bar:not([hidden]) ~ .top { padding-top: 10px; }   /* the bar above already keeps clear of the phone's status bar */
.upd-bar:not([hidden]) ~ .upd-bar { padding-top: 6px; }
.news-bar { background: #12804a !important; color: #fff !important; }
.upd-bar.news-bar .upd-go span { text-decoration: none; font-weight: 400; }
.news-bar .upd-go { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Settings → News */
.news-list { display: grid; gap: 4px; max-height: 60vh; overflow: auto; }
.news-day { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 10px 0 2px; }
.news-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left; width: 100%;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; color: var(--text); }
.news-item.fresh { background: var(--recent); }
.news-item:hover { border-color: var(--recent-ink); }
.upd-bar .upd-go { flex: 1; text-align: left; background: none; border: 0; color: inherit; font: inherit; padding: 6px 0; cursor: pointer; }
.upd-bar .upd-go span { text-decoration: underline; }
.upd-bar button.icon { width: 32px; height: 32px; background: none; border: 0; color: inherit; font-size: 16px; }
.upd-box { margin-top: 16px; padding: 12px 14px; border: 2px solid var(--accent); border-radius: 10px; }
.upd-box button { display: block; margin-top: 10px; }
/* "Get the app" links (browser at the server) */
.app-dl:not([hidden]) { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.app-dl p { flex-basis: 100%; margin: 0; }
.app-dl a.btn { flex: 1; text-align: center; text-decoration: none; color: inherit; border-radius: 8px; padding: 9px 14px;
  font-weight: 600; background: var(--surface); border: 1px solid var(--line); }
.app-dl a.btn:hover { border-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 11px; cursor: pointer; font-size: 13px; }
.chip.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip b { font-weight: 600; margin-left: 4px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; cursor: pointer; user-select: none; }
tbody tr { cursor: pointer; }
/* three shades repeating: darker, a bit lighter, lightest */
#dwList tbody tr:nth-child(3n+1), .cards .card:nth-child(3n+1) { background: var(--row1); }
#dwList tbody tr:nth-child(3n+2), .cards .card:nth-child(3n+2) { background: var(--row2); }
#dwList tbody tr:nth-child(3n+3), .cards .card:nth-child(3n+3) { background: var(--row3); }
.z0, .dl.z0 { background: var(--row1); } .z1, .dl.z1 { background: var(--row2); } .z2, .dl.z2 { background: var(--row3); }
/* not official (pre-delivered): light red */
/* officially delivered in the last 10 days: soft green */
#dwList tbody tr.recent, .cards .card.recent { background: var(--recent); }
#dwList tbody tr.recent:nth-child(even), .cards .card.recent:nth-child(even) { background: var(--recent-2); }
.new-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 4px; background: var(--recent-ink); color: #fff; vertical-align: 1px; }
#dwList tbody tr.unofficial, .cards .card.unofficial, tr.unofficial, .dl.unofficial { background: var(--unofficial); }
#dwList tbody tr.unofficial:nth-child(even), .cards .card.unofficial:nth-child(even), tr.unofficial.z1, .dl.unofficial.z1 { background: var(--unofficial-2); }
#dwList tbody tr:hover, .cards .card:hover, .dl:hover, #dlList tbody tr[data-dl]:hover { background: var(--row-hover); }
.un-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 4px; background: var(--unofficial-ink); color: #fff; vertical-align: 1px; }
.hint.un { background: var(--unofficial); color: var(--text); border: 1px solid var(--unofficial-ink); }
label.check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); font-weight: 600; cursor: pointer; }
label.check input { width: auto; margin-top: 3px; }
label.check .small { font-weight: 400; }
/* hours started in an earlier month */
.carry[hidden] { display: none; }
tr.ghost td, .dl.ghost { opacity: .85; }
tr.ghost td:first-child { border-left: 3px solid var(--warn); }
.dl.ghost { border-left: 3px solid var(--warn); }
.un-tag.progress { background: var(--warn); color: #1b1d22; }

/* export dialogs */
.export-choice { display: grid; gap: 2px; text-align: left; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer; }
.export-choice:hover { border-color: var(--accent); }
.export-choice b { font-size: 15px; }
.export-choice span { color: var(--muted); font-size: 13px; }
/* show the email exactly as it will be sent: no app table styles inside */
.email-preview table, .email-preview tbody, .email-preview tr, .email-preview th, .email-preview td, .email-preview p { all: revert; }
.email-preview { background: #fff; color: #000; border: 1px solid var(--line); border-radius: 8px; padding: 14px; max-height: 260px; overflow: auto; }
.report-preview { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.report-preview table { box-shadow: none; border-radius: 0; }
.report-preview th { position: static; cursor: default; }
.report-preview tr.total td { background: var(--surface-2); }
.extra-row { display: grid; grid-template-columns: 110px 1fr 70px 32px; gap: 6px; margin-bottom: 6px; }
dialog { width: min(720px, calc(100vw - 24px)); }

/* wide two-column dialog (email delivery) */
dialog.wide { width: min(1280px, calc(100vw - 32px)); height: calc(100vh - 40px); max-height: none; }
dialog.wide form { height: 100%; grid-template-rows: auto 1fr auto; padding: 16px 20px; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head .icon { width: 34px; }
.email-layout { display: grid; grid-template-columns: minmax(360px, 440px) 1fr; gap: 20px; min-height: 0; }
.email-left { overflow-y: auto; display: grid; gap: 10px; align-content: start; padding-right: 6px; }
.email-left .batch { max-height: 34vh; }
.email-right { display: flex; flex-direction: column; min-height: 0; gap: 8px; }
.email-right .email-preview { flex: 1; max-height: none; padding: 20px 24px; }
.preview-head { display: flex; justify-content: space-between; align-items: baseline; }
.step { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.step-n { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; }
.chip.more { border-style: dashed; color: var(--muted); }
#eOlder { display: contents; }
#eOlder[hidden] { display: none; }
details.texts { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
details.texts summary { cursor: pointer; font-weight: 600; color: var(--muted); }
details.texts[open] { display: grid; gap: 8px; }
.actions.sticky { margin: 0; padding-top: 12px; border-top: 1px solid var(--line); }
@media (max-width: 820px) {
  #view-deliveries .toolbar { flex-wrap: wrap; }
  #view-deliveries .toolbar input { flex-basis: 100%; }
  #view-deliveries .toolbar button { flex: 1; }
  dialog.wide { height: auto; max-height: calc(100vh - 24px); overflow-y: auto; }
  dialog.wide form { height: auto; grid-template-rows: none; overflow: visible; padding-bottom: 0; }
  .email-left { overflow: visible; padding-right: 0; }
  .actions.sticky { position: sticky; bottom: 0; background: var(--surface); padding-bottom: 14px; z-index: 2; }
  .email-layout { grid-template-columns: 1fr; }
  .email-left .batch { max-height: none; }
  .email-right .email-preview { max-height: 50vh; }
}
/* deliveries table */
tr.month-row td { background: var(--month-bg); color: var(--month-ink); border-top: 2px solid var(--month-line); border-bottom: 1px solid var(--month-line); padding: 10px 12px; }
tr.month-row td b { font-size: 15px; margin-right: 12px; }
tr.month-row td .muted { color: var(--month-ink); opacity: .8; }
#dlList .cards .month { background: var(--month-bg); color: var(--month-ink); border-radius: 8px; padding: 8px 12px; }
#dlList .cards .month .muted { color: var(--month-ink); opacity: .8; }
tr.month-row { cursor: default; }
/* half-line gap between months */
tr.month-gap td { height: 11px; padding: 0; border: 0; background: var(--bg); }
tr.month-gap { cursor: default; pointer-events: none; }
#dlList .cards { margin-top: 0; }

/* resizable columns */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
.table-wrap table { box-shadow: none; }
table.resizable { table-layout: fixed; }
table.resizable td { overflow-wrap: anywhere; }
th { position: sticky; }
.col-resize { position: absolute; top: 0; right: -4px; width: 9px; height: 100%; cursor: col-resize; z-index: 2; }
.col-resize::after { content: ''; position: absolute; top: 20%; bottom: 20%; left: 4px; width: 1px; background: var(--line); }
.col-resize:hover::after, body.resizing .col-resize::after { background: var(--accent); width: 2px; }
body.resizing, body.resizing * { cursor: col-resize !important; user-select: none; }
td.mono, .mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; }
td.rev { font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.s-Complete { background: #2b2d33; color: #fff; }
.s-Corrected { background: #fde3e1; color: #a5221a; }
.s-Delivered { background: #d9f3e3; color: #0b6b39; }
.s-Delivered-with-NODs { background: #e9f9ee; color: #2a8a50; border-color: #9fe0b5; }
.s-To-Deliver { background: #fff4c2; color: #7a5a00; }
.s-Need-update { background: #ffe3e3; color: #a23a3a; }
.s-VARD-Side { background: #fbe6d1; color: #8a4a12; }
.s-In-Progress { background: #e6e1ff; color: #4a36b5; }
.t-badge { font-size: 11px; padding: 1px 7px; border-radius: 4px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

.cards { display: none; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 8px; cursor: pointer; }
.card .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card .name { font-weight: 600; }
.card .row2 { display: flex; gap: 10px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.card .meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.card .dots { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 5px; font-size: 14px; }
.dtag { display: inline-flex; align-items: center; gap: 6px; }
.dtag .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px var(--line); }
.dtag .dot.unknown { background: transparent; border: 1px dashed var(--muted); box-shadow: none; }

.month { margin: 18px 0 8px; display: flex; justify-content: space-between; align-items: baseline; }
.month h3 { margin: 0; font-size: 15px; }
.dl { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 14px; margin-bottom: 6px;
  display: grid; grid-template-columns: 92px 1fr auto; gap: 4px 12px; cursor: pointer; }
.dl .date { color: var(--muted); font-size: 12px; }
.dl .what { font-weight: 600; }
.dl .reason { grid-column: 2 / 4; color: var(--muted); font-size: 13px; }
.dl .hrs { text-align: right; white-space: nowrap; }
/* hours on one line, total underneath */
.hrs-cell { display: inline-flex; flex-direction: column; line-height: 1.35; }
.dl .hrs-cell { align-items: flex-end; }
.hrs-total { white-space: nowrap; }

.fab { position: fixed; right: 20px; bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 6; background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 999px; padding: 14px 22px; font-weight: 700; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.25); cursor: pointer; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 18px 20px; display: grid; gap: 12px; }
dialog h2 { margin: 0; font-size: 18px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.actions .left { margin-right: auto; }
.hint { background: var(--surface-2); border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.hint.ok { color: var(--ok); }
.history { max-height: 200px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.history div { padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 13px; display: flex; gap: 10px; }
.history div:last-child { border-bottom: 0; }

.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; max-width: 640px; }
.panel h2 { margin-top: 0; }
.big { font-size: 26px; font-weight: 700; letter-spacing: .02em; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px;
  border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; }
.toast.act { pointer-events: auto; display: flex; align-items: center; gap: 12px; width: max-content; }
.toast-btn { background: none; border: 0; color: #8ab4ff; font-weight: 700; padding: 4px 2px; cursor: pointer; text-transform: uppercase; font-size: 13px; }

.phone-only { display: none; }      /* shown on the phone only (rules below) */
@media (max-width: 820px) {
  .top { flex-wrap: wrap; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs button { flex: 1; }
  .table-wrap { display: none; }
  .cards { display: block; }
  .pc-only { display: none; }
  .phone-only { display: inline-block; }
  .settings-btn span { display: none; }      /* phone: gear icon only, so the header stays on one line */
  .tabs button { padding: 8px 4px; }
  .cb-lib-btn { padding: 6px 10px; flex: 0 0 auto; }
  /* phone: text on the left, hours in their own column on the right */
  .dl { grid-template-columns: 1fr auto; column-gap: 14px; }
  .dl .date, .dl .what, .dl .reason { grid-column: 1; }
  .dl .hrs { grid-column: 2; grid-row: 1 / span 3; align-self: stretch; display: flex; align-items: center; justify-content: flex-end;
    min-width: 58px; padding-left: 12px; border-left: 1px solid var(--line); }
  .tot-word { display: none; }
}
body.phone .pc-only { display: none; }
body.phone .phone-only { display: inline-block; }
body:not(.role-viewer) .viewer-only { display: none !important; }

/* tags coloured from Settings */
.badge.sm { font-size: 11px; padding: 1px 8px; }
.badge.unknown { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--line); }

/* Settings button, right corner */
.settings-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap; }
.settings-btn:hover, .settings-btn.on { color: var(--text); background: var(--surface-2); }
.settings-btn.on { border-color: var(--accent); }

/* Settings page */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.settings-grid .panel { max-width: none; }
/* Settings > Appearance */
.theme-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: start; margin: 12px 0; }
.theme-lbl { color: var(--muted); font-size: 13px; padding-top: 8px; }
.theme-row .seg { margin-left: 0; justify-self: start; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px 5px 6px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 12px; }
.swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.sw-c { width: 18px; height: 18px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); flex: 0 0 auto; }
.sw-bg { position: relative; overflow: hidden; border-width: 2px; border-style: solid; }
.sw-bg i { position: absolute; right: 0; bottom: 0; width: 55%; height: 55%; border-top-left-radius: 4px; }
.swatch input[type=color] { width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; }
.swatch input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch input[type=color]::-webkit-color-swatch { border: 1px solid rgba(0,0,0,.2); border-radius: 50%; }
@media (max-width: 820px) { .theme-row { grid-template-columns: 1fr; gap: 6px; } .theme-lbl { padding-top: 0; } }
.tag-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tag-head h2 { margin: 0; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); font-weight: 600; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 40px; height: 22px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.is-off { opacity: .45; pointer-events: none; }
.tag-list { display: grid; gap: 6px; margin: 10px 0; }
.tag-row { display: grid; grid-template-columns: 38px 1fr 28px 32px 32px 32px; gap: 6px; align-items: center; }
.tag-row input[type="color"] { padding: 2px; height: 36px; cursor: pointer; }
.tag-row .cnt { text-align: center; }
button.icon { height: 36px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; cursor: pointer; padding: 0; }
button.icon:disabled { opacity: .35; cursor: default; }
button.icon.del { color: var(--bad); }
label.auto { margin-top: 14px; }
.hint.warn { background: #fff4d6; color: #7a4d00; border: 1px solid #f0d48a; }
:root[data-theme="dark"] .hint.warn { background: #3a2f14; color: #f5cf7a; border-color: #5c4a1e; }
.batch { display: grid; gap: 6px; max-height: 300px; overflow: auto; }
.brow { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  color: var(--text); font-weight: 400; font-size: 14px; cursor: pointer; }
.brow input { width: auto; margin-top: 3px; }
.brow.b-ok .small:last-child { color: var(--ok); }
.brow.b-new { border-style: dashed; }
.brow.b-dup, .brow.b-old { background: #fff4d6; border-color: #f0d48a; color: #5a3b00; }
.brow.b-bad { opacity: .6; cursor: default; }
:root[data-theme="dark"] .brow.b-dup, :root[data-theme="dark"] .brow.b-old { background: #3a2f14; border-color: #5c4a1e; color: #f5cf7a; }
button.ghost.inline { padding: 4px 10px; margin-top: 6px; font-size: 13px; display: inline-block; }
@media (max-width: 820px) {
  .settings-btn { padding: 6px 9px; }
  .sync { margin-left: auto; }
  .brand { font-size: 15px; }
}
/* narrow phones: title, sync, settings and sign-out stay on one line */
@media (max-width: 420px) {
  .top { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .brand { font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .sync { padding: 4px 9px; font-size: 12px; }
  .settings-btn, .user-btn { padding: 5px 7px; }
}
@media (max-width: 340px) { .brand { font-size: 13px; } }
/* ---------- Cables tab ---------- */
.cb-count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--surface-2); color: var(--muted); font-size: 11px; text-align: center; margin-left: 4px; }
.cb-progress { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 14px; margin-bottom: 12px; font-size: 13px; }
.cb-progress[hidden] { display: none; }
.cb-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.cb-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.cb-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.cb-results { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); position: sticky; top: 72px;
  max-height: calc(100vh - 150px); display: flex; flex-direction: column; overflow: hidden; }
.cb-res-head { padding: 9px 14px; border-bottom: 1px solid var(--line); }
#cbList, #eqList { list-style: none; margin: 0; padding: 4px 0; overflow: auto; }
#cbList li, #eqList li { padding: 8px 14px; cursor: pointer; border-left: 3px solid transparent; }
#cbList li:hover, #eqList li:hover { background: var(--row-hover); }
#cbList li.sel, #eqList li.sel { background: var(--surface-2); border-left-color: var(--accent); }
.cb-r-top { display: flex; align-items: baseline; gap: 8px; }
.cb-r-id { font-weight: 700; }
.cb-r-type { color: var(--muted); font-size: 12px; }
.cb-r-rev { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.cb-r-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cbList mark, #eqList mark { background: transparent; color: var(--accent); font-weight: 700; }
.cb-detail { min-width: 0; display: grid; gap: 12px; }
.cb-detail > * { min-width: 0; max-width: 100%; }      /* long texts (e.g. the revision list) never widen the page */
.cb-detail .empty h3 { color: var(--text); margin: 0 0 6px; }
.cb-back-top { display: none; white-space: nowrap; flex: 0 0 auto; }
.cb-lib-btn { display: inline-flex; align-items: center; justify-content: center; }
.cb-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cb-head .chip { cursor: default; }
.cb-id { font-size: 24px !important; font-weight: 700; letter-spacing: .02em; }
.cb-actions { margin-left: auto; display: flex; gap: 8px; }
.cb-source b { color: var(--text); }
.cb-paper { background: var(--surface); color: var(--text); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 6px; }
.cb-paper svg { display: block; width: 100%; height: auto; }
.cb-paper .cable-id { fill: var(--accent); }
.cb-paper .cable { stroke: var(--accent); }
.cb-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cb-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.cb-card h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.cb-kv { display: grid; grid-template-columns: 100px 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
.cb-kv dt { color: var(--muted); }
.cb-kv dd { margin: 0; overflow-wrap: anywhere; }
.cb-wires { overflow-x: auto; }
.cb-wires table, .cb-lib table { box-shadow: none; border-radius: 0; }
.cb-wires th, .cb-lib th { position: static; cursor: default; }
.cb-wires tbody tr, .cb-lib tbody tr { cursor: default; }
/* PC: search box as wide as the results column (320px), the revision dropdown next to it */
.cb-toolbar { align-items: center; gap: 16px; }
.cb-toolbar #cbSearch { flex: 0 0 320px; width: 320px; }
.cb-rev-slot { flex: 1; min-width: 0; display: flex; align-items: center; }
.cb-rev-slot:empty { visibility: hidden; }
.cb-rev { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; color: var(--muted); }
.cb-rev-slot .cb-rev { flex: 1; }
.cb-rev select { min-width: 0; flex: 1; max-width: 420px; font-size: 13px; padding: 6px 8px; }
.cb-rev > span:first-child { white-space: nowrap; }
.cb-old { display: grid; gap: 8px; padding: 10px; border: 2px dashed var(--warn); border-radius: var(--radius); }
.cb-old-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cb-old .chip.warn { background: var(--warn); color: #1b1d22; border-color: transparent; cursor: default; font-weight: 600; }
@media (max-width: 820px) {
  .cb-toolbar #cbSearch { flex: 1; width: auto; }
  .cb-rev-slot { display: none; }
  .cb-rev { flex-wrap: wrap; }
}
.cb-r-hist { display: inline-block; padding: 0 5px; border-radius: 8px; background: var(--line); color: var(--muted); font-size: 10px; }
.drop-hint { outline: 2px dashed var(--accent); outline-offset: -6px; }
.fDrop { border: 2px dashed var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--muted); text-align: center; }
.fDrop.filled { text-align: left; border-style: solid; }
.fDrop.over { border-color: var(--accent); color: var(--accent); background: var(--surface-2); }
@media (max-width: 820px) {
  .cb-layout { grid-template-columns: 1fr; }
  .cb-results { position: static; max-height: none; }
  .cb-layout .cb-detail { display: none; }
  .cb-layout.show-detail .cb-results { display: none; }
  .cb-layout.show-detail .cb-detail { display: grid; }
  #view-cables.detail-open .cb-back-top, #view-equipment.detail-open .cb-back-top { display: inline-flex; }
  .cb-grid2 { grid-template-columns: 1fr; }
  .cb-paper { overflow-x: auto; }
  .cb-paper svg { min-width: 640px; }
  .cb-actions { margin-left: 0; }
  .cb-id { font-size: 20px !important; }
}

/* Drawings table: open the drawing's PDF */
td.pdf-cell { vertical-align: middle; }
.pdf-btn { font: 600 11px/1 "Segoe UI", system-ui, sans-serif; letter-spacing: .04em; padding: 5px 8px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--surface); color: var(--accent); }
.pdf-btn:hover { background: var(--accent); color: var(--accent-ink); }
.pdf-btn.none { border-color: var(--line); color: var(--muted); background: transparent; opacity: .7; }
.pdf-pair { display: inline-flex; gap: 4px; flex-wrap: nowrap; }
.pdf-btn { white-space: nowrap; }
td.pdf-cell { white-space: nowrap; overflow: visible; }
/* PDF of a revision not officially delivered yet: soft yellow */
.pdf-btn.unofficial { border-color: color-mix(in srgb, var(--warn) 50%, transparent); color: var(--warn);
  background: color-mix(in srgb, var(--surface), var(--warn) 9%); }
.pdf-btn.unofficial:hover { background: color-mix(in srgb, var(--surface), var(--warn) 20%); color: var(--warn); }

/* Cables: the revision shown is not official yet - just a small yellow note */
.cb-unoff-note { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 10px; border-radius: 8px; font-size: 12px;
  background: color-mix(in srgb, var(--surface), var(--warn) 12%); border-left: 3px solid color-mix(in srgb, var(--warn) 60%, transparent); }
.cb-unoff-note span { flex: 1; min-width: 180px; }
.cb-unoff-note button { padding: 4px 9px; font-size: 12px; }
/* Cables: a newer revision is in progress (no PDF yet), this older information may change -
   a light red wash on the page and a calm red note */
#cbDetail.cb-outdated .cb-paper, #cbDetail.cb-outdated .cb-card { background: color-mix(in srgb, var(--surface), var(--unofficial-ink) 6%); }
.cb-newrev-note { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 9px 12px; border-radius: 8px; font-size: 13px;
  background: color-mix(in srgb, var(--surface), var(--unofficial-ink) 10%); border-left: 3px solid color-mix(in srgb, var(--unofficial-ink) 55%, transparent); }
.cb-newrev-note span { flex: 1; min-width: 200px; }
.cb-newrev-note b { color: var(--unofficial-ink); font-weight: 600; }
/* Cables: deleted (not in the newest revision of its drawing) */
.cb-del-tag { display: inline-block; padding: 0 6px; border-radius: 8px; font-size: 10px; font-weight: 600; letter-spacing: .02em;
  color: var(--bad); background: color-mix(in srgb, var(--surface), var(--bad) 14%); }
#cbList li.deleted .cb-r-id, .cb-id-del { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--bad) 70%, transparent); text-decoration-thickness: 2px; }
#cbList li.deleted .cb-r-sub, #cbList li.deleted .cb-r-type { opacity: .7; }
.cb-head .chip.cb-del-chip { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: color-mix(in srgb, var(--surface), var(--bad) 10%); font-weight: 600; }
.cb-del-note { padding: 9px 12px; border-radius: 8px; font-size: 13px;
  background: color-mix(in srgb, var(--surface), var(--bad) 10%); border-left: 3px solid color-mix(in srgb, var(--bad) 60%, transparent); }
.cb-del-note b { color: var(--bad); }
.cb-paper-del { position: relative; }
.cb-paper-del svg { opacity: .5; }
.cb-paper-del::after { content: 'DELETED'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  font: 700 clamp(28px, 7vw, 72px)/1 "Segoe UI", sans-serif; letter-spacing: .2em; color: color-mix(in srgb, var(--bad) 30%, transparent); transform: rotate(-8deg); }
#cbList li.newrev { box-shadow: inset 3px 0 0 color-mix(in srgb, var(--unofficial-ink) 50%, transparent); }
#cbList li.unoff { box-shadow: inset 3px 0 0 color-mix(in srgb, var(--warn) 60%, transparent); }
.pdf-btn.none:hover { background: var(--surface-2); color: var(--muted); }

/* Equipment tab: one equipment on the left, the equipment it is cabled to on the right */
.eq-svg { display: block; width: 100%; height: auto; color: var(--text); }
.eq-svg .cable-id { fill: var(--accent); }    /* the rest is styled like the single-cable drawing */
.eq-svg .cable { stroke: var(--accent); }
.eq-svg .hit { fill: transparent; stroke: none; }
.eq-svg .eq-cable, .eq-svg .eq-remote[data-eq] { cursor: pointer; }
.eq-svg .eq-cable:hover .cable { stroke-width: 0.9; }
.eq-svg .eq-cable:hover .cable-id { text-decoration: underline; }
.eq-svg .eq-remote[data-eq]:hover .eq { fill: color-mix(in srgb, var(--accent) 10%, transparent); stroke: var(--accent); }
.eq-svg .mark { stroke: none; }
.eq-svg .unoff .mark { fill: var(--warn); }
.eq-svg .newrev .mark { fill: var(--unofficial-ink); }
.eq-conn-filter { max-width: 520px; }
.eq-cards { display: none; }
.eq-cardrow { padding: 9px 2px; border-top: 1px solid var(--line); display: grid; gap: 3px; min-width: 0; }
.eq-cardrow:first-child { border-top: 0; }
.eq-c1 { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.eq-c1 a { font-weight: 700; white-space: nowrap; color: var(--accent); text-decoration: none; }
.eq-c1 > .muted { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.eq-rev { margin-left: auto; white-space: nowrap; }
.eq-c2 { overflow-wrap: anywhere; }
.eq-c2 a { color: var(--accent); text-decoration: none; font-weight: 600; }
.eq-c3 { overflow-wrap: anywhere; line-height: 1.35; }
.eq-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.eq-tools .eq-conn-filter { flex: 1; min-width: 220px; }
.eq-sort { display: inline-flex; align-items: center; gap: 8px; }
.eq-sort .seg { margin-left: 0; }
.eq-table a { color: var(--accent); text-decoration: none; }
.eq-table a:hover { text-decoration: underline; }
.eq-table td { vertical-align: top; }
.eq-dot, .eq-key i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; }
.eq-dot.unoff, .eq-key i.unoff { background: var(--warn); }
.eq-dot.newrev, .eq-key i.newrev { background: var(--unofficial-ink); }
.eq-key { margin-left: 10px; white-space: nowrap; }
.eq-key i { margin: 0 3px 0 8px; }
@media (max-width: 820px) {
  .eq-paper { overflow-x: auto; }
  .eq-paper svg { min-width: 560px; }
  .eq-key { display: block; margin: 4px 0 0; }
  /* phone: one small card per cable instead of the table */
  .eq-table { display: none; }
  .eq-cards { display: grid; }
  .eq-key i:first-child { margin-left: 0; }
}
/* PC: Library is a tab of its own, so no Library button inside Cables */
@media (min-width: 821px) { body:not(.phone) #cbLib { display: none; } }
.lib-page { max-width: none; display: grid; gap: 12px; }
.lib-page .cb-lib-list { max-height: calc(100vh - 300px); }
.cb-lib-acts { display: inline-flex; gap: 8px; }
/* Library window: Library / Archive tabs, one list per tab */
dialog.cb-libdlg { width: min(760px, calc(100vw - 24px)); }
dialog.cb-libdlg form { overflow: hidden; }
.cb-lib-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; margin-left: auto; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg .cb-count { margin-left: 6px; }
.cb-lib-list { list-style: none; margin: 0; padding: 0; max-height: 58vh; overflow-y: auto; overflow-x: hidden; border: 1px solid var(--line); border-radius: 8px; }
.cb-lib-list li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; min-width: 0; }
.cb-lib-list li:last-child { border-bottom: 0; }
.cb-lib-list[hidden], .cb-lib-list li[hidden] { display: none; }
.cb-lib-list li:hover { background: var(--surface-2); }
.cb-lib-list li.empty { cursor: default; color: var(--muted); display: block; }
.cb-li-main { flex: 1; min-width: 0; display: grid; }
.cb-li-no { font-weight: 700; font-size: 13px; }
.cb-li-title { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.cb-li-side { display: grid; justify-items: end; text-align: right; white-space: nowrap; font-size: 13px; }
.cb-li-del { padding: 4px 8px; font-size: 12px; color: var(--bad); flex: 0 0 auto; }
@media (max-width: 820px) {
  dialog.cb-libdlg { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  dialog.cb-libdlg form { height: 100%; grid-template-rows: auto auto 1fr auto auto; padding: 14px 12px; box-sizing: border-box; }
  dialog.cb-libdlg .cb-lib-list { max-height: none; min-height: 0; }
  .cb-lib-top .seg { margin-left: 0; width: 100%; }
  .seg button { flex: 1; }
  .cb-lib-list li { padding: 10px; }
}


/* phone Settings: what is kept on the phone */
.off-box { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.off-box h2 { margin-top: 0; }


/* ---- sign-in and accounts ---- */
.login { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.login[hidden] { display: none; }
.login-box { width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px 22px; display: grid; gap: 12px; }
.login-box .brand { font-size: 22px; }
.login-box .actions button { width: 100%; padding: 12px; }
body.signed-out > header, body.signed-out > main, body.signed-out > .fab { visibility: hidden; }
.bad-text { color: var(--bad); margin: 0; min-height: 1em; }
.role-viewer .edit-only { display: none !important; }
.role-viewer #dwList tbody tr, .role-viewer #dwList .card { cursor: default; }
form.readonly input:disabled, form.readonly select:disabled, form.readonly textarea:disabled { opacity: 1; color: var(--text); background: var(--surface-2); }
.acct { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.role-chip { cursor: default; text-transform: capitalize; font-weight: 600; }
.role-chip.role-admin { border-color: var(--accent); color: var(--accent); }
.role-chip.role-editor { border-color: var(--ok); color: var(--ok); }
.actions.left-actions { justify-content: flex-start; flex-wrap: wrap; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }
.panel-head input[type=search] { max-width: 220px; }
.us-panel, .log-panel { grid-column: 1 / -1; }
.us-list { display: grid; gap: 2px; margin-top: 10px; }
.us-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--line); }
.us-row.us-off { opacity: .6; }
.us-who { min-width: 0; }
.us-devs { margin: 4px 0 0; padding-left: 18px; }
.warn-text { color: var(--warn); font-weight: 600; }
.us-acts { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.us-acts select { width: auto; }
.us-acts button { padding: 6px 10px; font-size: 13px; }
.log-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 460px; overflow: auto; }
.log-list li { display: grid; grid-template-columns: 120px 150px 1fr; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.log-list li.log-bad .log-what { color: var(--bad); }
.log-who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 820px) {
  .log-list li { grid-template-columns: 1fr; gap: 0; }
  .us-acts { width: 100%; }
}
/* header: who is signed in + sign out */
.user-btn { display: inline-flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-weight: 600; font-size: 13px; }
.user-btn[hidden] { display: none; }
.user-btn:hover { border-color: var(--accent); color: var(--accent); }
.user-btn .user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-weight: 500; }
body:not(.role-admin) .admin-only { display: none !important; }
@media (max-width: 820px) { .user-btn { padding: 6px 8px; } }
/* windows: a ✕ in the corner; they close only with ✕, Cancel/Close or Esc */
dialog form { position: relative; }
.modal-x { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; z-index: 2; font-size: 15px; color: var(--muted); }
.modal-x:hover { color: var(--text); border-color: var(--accent); }
dialog form > h2:first-of-type, dialog form > .modal-x + h2 { padding-right: 44px; }
.ask-dlg { width: min(440px, calc(100vw - 24px)); }
.ask-msg { margin: 0; line-height: 1.45; }
button.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }