:root {
  --bg: #121417;
  --panel: #1a1d21;
  --panel-2: #20242a;
  --line: #2c3138;
  --text: #e7e9ec;
  --muted: #8b939e;
  --amber: #ffb020;
  --green: #3ecf8e;
  --blue: #4ea8ff;
  --red: #ff5d5d;
  --violet: #b48cff;
  --yellow: #e8dc4a;
  --grey: #77808b;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --cond: "Barlow Condensed", "Arial Narrow", sans-serif;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px;
  background-image: repeating-linear-gradient(135deg, transparent 0 22px, rgba(255,255,255,.012) 22px 23px);
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }

.top {
  display: flex; align-items: center; gap: 24px; padding: 18px 28px;
  border-bottom: 1px solid var(--line); background: linear-gradient(#16191d, #121417);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 14px; }
.beacon { width: 12px; height: 12px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(62,207,142,.6); animation: pulse 2s infinite; }
.beacon.warn { background: var(--amber); box-shadow: 0 0 0 0 rgba(255,176,32,.6); }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(0,0,0,0); } 100% { box-shadow: 0 0 0 0 rgba(0,0,0,0); } }
h1 { font-family: var(--cond); font-weight: 700; font-size: 28px; letter-spacing: .04em; text-transform: uppercase; margin: 0; line-height: 1; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.sources { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.src { font-family: var(--mono); font-size: 11px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.src::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--grey); }
.src.live { color: var(--text); } .src.live::before { background: var(--green); }
.src.sample::before { background: var(--amber); }
.src.error { color: var(--red, #e5484d); } .src.error::before { background: var(--red, #e5484d); }
.clock { display: flex; align-items: center; gap: 12px; font-family: var(--mono); font-size: 12px; color: var(--muted); }

.btn { border: 1px solid var(--line); background: var(--panel-2); padding: 7px 12px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.btn:hover { border-color: var(--amber); color: var(--amber); }
.btn.ghost { background: transparent; }
a.btn { text-decoration: none; color: inherit; display: inline-block; }
.who { color: var(--text); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.auth-pending > * { visibility: hidden; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.stat { background: var(--panel); padding: 14px 28px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.stat .v { font-family: var(--cond); font-size: 34px; font-weight: 600; line-height: 1.1; }
.stat.alert .v { color: var(--red); }
.stat.amber .v { color: var(--amber); }

.filters { display: flex; flex-wrap: wrap; gap: 18px 28px; align-items: flex-end; padding: 18px 28px; border-bottom: 1px solid var(--line); background: var(--panel); }
.fgroup { display: flex; flex-direction: column; gap: 7px; }
.fgroup.grow { flex: 1; min-width: 200px; }
.flabel { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--bg); padding: 5px 11px; border-radius: 999px; cursor: pointer; font-size: 12px; display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.chip .n { font-family: var(--mono); color: var(--muted); font-size: 11px; }
.chip:hover { border-color: #49505a; }
.chip.on { background: var(--amber); color: #1b1300; border-color: var(--amber); font-weight: 600; }
.chip.on .n { color: #5a3e00; }
.chip .dot { width: 8px; height: 8px; border-radius: 2px; }
.range { display: flex; gap: 8px; align-items: center; margin-top: 4px; color: var(--muted); }
input[type="date"], input[type="search"] { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 6px 10px; color-scheme: dark; }
input[type="search"] { width: 100%; }
input:focus { outline: none; border-color: var(--amber); }

.notice { margin: 14px 28px 0; padding: 10px 14px; border-left: 3px solid var(--amber); background: rgba(255,176,32,.08); font-size: 13px; color: #f3d9a4; }

.board { padding: 14px 28px 60px; overflow-x: auto; }
/* Column headings stay visible while scrolling, just under the sticky top bar (--top-h is set from JS).
   On wide windows the board doesn't need sideways scrolling, so the headings stick to the page; on
   narrow ones the board scrolls on its own (both ways) and the headings stick to its top. */
thead th { position: sticky; top: var(--top-h, 0px); z-index: 3; background: var(--bg); box-shadow: 0 1px 0 var(--line); }
@media (min-width: 920px) { .board { overflow-x: visible; } }
@media (max-width: 919px) {
  .board { overflow: auto; max-height: calc(100vh - var(--top-h, 0px)); padding-top: 0; }
  thead th { top: 0; }
}
table { width: 100%; border-collapse: separate; border-spacing: 0 4px; min-width: 860px; }
th { text-align: left; font-size: 11px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 6px 14px; cursor: pointer; user-select: none; white-space: nowrap; }
th:hover { color: var(--text); }
th.sorted { color: var(--amber); }
th.sorted.asc::after { content: " ▲"; font-size: 9px; }
th.sorted.desc::after { content: " ▼"; font-size: 9px; }
th.num, td.num { text-align: right; }
tbody tr { background: var(--panel); cursor: pointer; transition: background .12s; }
tbody tr:hover { background: var(--panel-2); }
td { padding: 4px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); white-space: nowrap; }
td:first-child { border-left: 4px solid var(--c, var(--grey)); border-radius: 4px 0 0 4px; }
td:last-child { border-right: 1px solid var(--line); border-radius: 0 4px 4px 0; }
.status { font-family: var(--cond); font-weight: 600; font-size: 15px; letter-spacing: .05em; text-transform: uppercase; color: var(--c, var(--text)); }
.mono { font-family: var(--mono); font-size: 13px; }
.equip { font-weight: 500; }
.tstat { font-weight: 500; color: var(--tc, var(--text)); white-space: nowrap; }
.stage { font-family: var(--cond); font-weight: 600; font-size: 14px; letter-spacing: .04em; text-transform: uppercase; color: var(--sc, var(--muted)); white-space: nowrap; }
.due { font-family: var(--mono); font-size: 13px; }
.due small { display: block; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-top: 2px; }
.due.overdue { color: var(--red); } .due.overdue small { color: var(--red); }
.due.today { color: var(--amber); } .due.today small { color: var(--amber); }
.hrs { font-family: var(--cond); font-size: 20px; font-weight: 600; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 60px 0; font-family: var(--mono); }
tfoot td { background: transparent; border: none !important; color: var(--muted); font-size: 12px; padding-top: 4px; }

.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(480px, 100vw); background: var(--panel); border-left: 1px solid var(--line); transform: translateX(100%); transition: transform .22s ease; z-index: 20; overflow-y: auto; }
.drawer.open { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 15; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer-inner { padding: 26px 28px 40px; }
.close { position: absolute; top: 14px; right: 18px; background: none; border: none; font-size: 28px; color: var(--muted); cursor: pointer; }
.close:hover { color: var(--text); }
.d-head .status { font-size: 14px; }
.d-head h2 { font-family: var(--cond); font-size: 32px; margin: 6px 0 2px; letter-spacing: .02em; }
.d-head p { margin: 0; color: var(--muted); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 20px 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.card { border: 1px solid var(--line); border-radius: 6px; margin-top: 18px; background: var(--bg); }
.card h3 { margin: 0; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; display: flex; align-items: center; justify-content: space-between; }
.card .body { padding: 12px 14px; font-size: 13px; }
.card .kv { margin: 0; grid-template-columns: 110px 1fr; }
.tag { font-family: var(--mono); font-size: 10px; padding: 2px 6px; border-radius: 3px; border: 1px solid var(--line); color: var(--muted); text-transform: none; letter-spacing: 0; }
.tag.sample { border-color: var(--amber); color: var(--amber); }
.tag.live { border-color: var(--green); color: var(--green); }
.card a { color: var(--blue); }
.card ul { margin: 6px 0 0; padding-left: 18px; }
.loading { color: var(--muted); font-family: var(--mono); font-size: 12px; }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; padding: 14px 16px; gap: 12px; }
  .sources { margin-left: 0; order: 3; width: 100%; }
  .filters, .board { padding-left: 16px; padding-right: 16px; }
  .stat { padding: 12px 16px; }
}

/* Work order / ticket links to Zoho */
a.zlink { color: var(--blue); text-decoration: none; border-bottom: 1px dotted color-mix(in srgb, var(--blue) 60%, transparent); }
a.zlink:hover, a.zlink:focus-visible { color: var(--text); border-bottom-color: var(--text); outline: none; }
th:focus-visible { color: var(--text); outline: 1px solid var(--amber); outline-offset: 2px; border-radius: 3px; }
.fgroup.full { flex-basis: 100%; }
.fnote { text-transform: none; letter-spacing: 0; margin-left: 4px; color: var(--muted); opacity: .85; }

/* Company logo beside the title */
.brand .logo { height: 38px; width: auto; max-width: 180px; object-fit: contain; display: block; }
.brand .logo + .beacon { margin-left: 2px; }
@media (max-width: 760px) { .brand .logo { height: 30px; } }

/* Location and Stage share the first filter row. */
.frow { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 18px 28px; align-items: flex-end; }

/* "Workorder Only" on/off switch */
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; height: 32px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { position: relative; width: 42px; height: 24px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); transition: background .15s, border-color .15s; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + .track { background: rgba(255,176,32,.18); border-color: var(--amber); }
.switch input:checked + .track .knob { transform: translateX(18px); background: var(--amber); }
.switch input:focus-visible + .track { outline: 1px solid var(--amber); outline-offset: 2px; }
.switch .switch-text::after { content: "Off"; font-size: 12px; color: var(--muted); }
.switch input:checked ~ .switch-text::after { content: "On"; color: var(--amber); }

/* Column widths: Status, Stage, Task, Due Date, Workorder #, Ticket #, Equipment, Qty and Prod. Hrs shrink to
   fit their values; Customer and Material share the rest of the window's width (21/79); Material wraps and Customer is cut off. */
thead th, tbody td { width: 1%; }
th.mat-col, td.mat { white-space: normal; overflow-wrap: anywhere; line-height: 1.3; }
/* Customer gets 21% of the shared space and Material the rest. Long customer names stay on one
   line and end in "…" (max-width: 0 lets the cell shrink below its text's width). */
th.cust-col, td.cust { width: 21%; }
td.cust { max-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th.mat-col, td.mat { width: 79%; }

/* Rows alternate in bands of four (rows 5–8, 13–16, …) to help follow a row across. */
tbody tr:nth-child(8n+5), tbody tr:nth-child(8n+6), tbody tr:nth-child(8n+7), tbody tr:nth-child(8n+8) { background: #202329; }
tbody tr:nth-child(8n+5):hover, tbody tr:nth-child(8n+6):hover, tbody tr:nth-child(8n+7):hover, tbody tr:nth-child(8n+8):hover { background: #272b32; }
