/* PGI Scanner — operations UI for Pi Green Innovations service teams.
   Quiet, data-first layout; the only bold element is the fleet status band. */
:root {
  --ink: #1C2B24;
  --ink-2: #4A5650;
  --ink-3: #78837D;
  --paper: #F3F5F2;
  --surface: #FFFFFF;
  --line: #DCE2DD;
  --pine: #1F3A2E;
  --pine-2: #2B5040;
  --leaf: #2E7D57;
  --leaf-soft: #E3F1E8;
  --amber: #B7791F;
  --amber-soft: #FBF0DC;
  --red: #B3261E;
  --red-soft: #FBE4E2;
  --grey: #8A938D;
  --grey-soft: #ECEFEC;
  --focus: #E9B44C;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--leaf); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
.num, td.num, .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- top bar */
.topbar { background: var(--pine); color: #fff; display: flex; align-items: center; gap: 1.25rem; padding: 0 1.25rem; min-height: 56px; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 650; font-size: 1.05rem; color: #fff; white-space: nowrap; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; background: #fff; border-radius: 50%; width: 38px; height: 38px; }
.brand-mark img { height: 30px; width: auto; display: block; }
.login-logo { display: block; width: 190px; height: auto; margin: 0 auto 1rem; }
.nav { display: flex; gap: .15rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { color: #CFE3D7; padding: .45rem .7rem; border-radius: var(--radius-s); white-space: nowrap; font-size: .93rem; }
.nav a:hover { background: var(--pine-2); color: #fff; text-decoration: none; }
.nav a.active { background: #fff; color: var(--pine); font-weight: 600; }
.nav .sep { width: 1px; background: #3D5F4F; margin: .4rem .35rem; }
.who { display: flex; align-items: center; gap: .6rem; color: #CFE3D7; font-size: .85rem; white-space: nowrap; }
.who button { background: transparent; color: #fff; border: 1px solid #4F7564; }

/* ---------- layout */
main { padding: 1.25rem; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1.5rem; margin: .25rem 0 1rem; }
.page-head .sub { color: var(--ink-3); margin-top: .2rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1rem 1.1rem; }
.panel + .panel { margin-top: 1rem; }
.grid > .panel + .panel { margin-top: 0; }
.panel > h2, .panel > h3 { margin-bottom: .75rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }

/* ---------- fleet status band (the one bold element) */
.band { display: flex; height: 44px; border-radius: var(--radius-m); overflow: hidden; background: var(--grey-soft); margin: .25rem 0 .5rem; }
.band button { border: 0; border-radius: 0; padding: 0 .75rem; color: #fff; font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: .4rem; min-width: 0; overflow: hidden; white-space: nowrap; transition: filter .15s; }
.band button:hover { filter: brightness(1.08); }
.band button[aria-pressed="true"] { box-shadow: inset 0 -4px 0 rgba(255,255,255,.85); }
.band .s-ONLINE { background: var(--leaf); }
.band .s-FAULT { background: var(--red); }
.band .s-PING_MISSING { background: var(--amber); }
.band .s-NO_DATA { background: #9AA39D; }
.band .s-NO_IOT { background: #C3C9C5; color: var(--ink); }
.band-legend { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; font-size: .85rem; color: var(--ink-2); margin-bottom: 1rem; }
.band-legend b { font-variant-numeric: tabular-nums; color: var(--ink); }

/* ---------- status marks */
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .4rem; vertical-align: .05rem; background: var(--grey); }
.st-ONLINE .dot, .dot.ONLINE { background: var(--leaf); }
.st-FAULT .dot, .dot.FAULT { background: var(--red); }
.st-PING_MISSING .dot, .dot.PING_MISSING { background: var(--amber); }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8rem; background: var(--grey-soft); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--leaf-soft); color: var(--leaf); }
.pill.warn { background: var(--amber-soft); color: #8A5A12; }
.pill.bad { background: var(--red-soft); color: var(--red); }

/* ---------- tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--ink-2); background: #F7F9F7; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #F4F8F5; }
tr.st-FAULT td:first-child { box-shadow: inset 4px 0 0 var(--red); }
tr.st-ONLINE td:first-child { box-shadow: inset 4px 0 0 var(--leaf); }
tr.st-PING_MISSING td:first-child { box-shadow: inset 4px 0 0 var(--amber); }
tr.st-NO_DATA td:first-child, tr.st-NO_IOT td:first-child { box-shadow: inset 4px 0 0 #C3C9C5; }
td.faults { max-width: 280px; color: var(--red); }
td.faults.none { color: var(--ink-3); }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--ink-3); font-size: .82rem; }
.more { text-align: center; padding: .75rem; }

/* ---------- forms */
label { display: block; font-size: .85rem; color: var(--ink-2); margin-bottom: .25rem; font-weight: 600; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #C5CDC8; border-radius: var(--radius-s); padding: .45rem .6rem; width: 100%; min-height: 38px; }
textarea { min-height: 120px; font-family: Consolas, "Courier New", monospace; font-size: .85rem; }
input[type="checkbox"] { width: auto; min-height: 0; }
.field { margin-bottom: .8rem; }
.field .hint { font-size: .8rem; color: var(--ink-3); margin-top: .2rem; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; color: var(--ink); }
button, .btn { font: inherit; font-weight: 600; border-radius: var(--radius-s); padding: .45rem .9rem; min-height: 38px; cursor: pointer; border: 1px solid #C5CDC8; background: #fff; color: var(--ink); display: inline-flex; align-items: center; gap: .4rem; text-decoration: none; }
button:hover, .btn:hover { background: #F1F4F2; text-decoration: none; }
button.primary, .btn.primary { background: var(--leaf); border-color: var(--leaf); color: #fff; }
button.primary:hover, .btn.primary:hover { background: #276B4A; }
button.danger { color: var(--red); border-color: #E2B4B0; }
button.danger:hover { background: var(--red-soft); }
button.link { border: 0; background: transparent; color: var(--leaf); padding: 0; min-height: 0; font-weight: 600; }
button:disabled { opacity: .55; cursor: not-allowed; }
.search { max-width: 340px; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; color: var(--ink-2); padding: .5rem .9rem; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--leaf); }
.seg { display: inline-flex; border: 1px solid #C5CDC8; border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 34px; padding: .3rem .7rem; font-weight: 500; }
.seg button + button { border-left: 1px solid #C5CDC8; }
.seg button[aria-pressed="true"] { background: var(--pine); color: #fff; }

/* ---------- machine page */
.machine-head { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: start; }
.serial { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem 1.25rem; margin-top: 1rem; }
.fact .k { font-size: .8rem; color: var(--ink-3); }
.fact .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.big-runtime { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .5rem; }
.readout > div { background: #F7F9F7; border: 1px solid var(--line); border-radius: var(--radius-s); padding: .5rem .65rem; }
.readout .k { font-size: .78rem; color: var(--ink-3); }
.readout .v { font-size: 1.05rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.readout > .wide { grid-column: 1 / -1; }
.readout > .wide .v { font-size: .95rem; font-weight: 550; line-height: 1.45; }
.readout > .alarm .v { color: var(--red); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.4rem; border-left: 2px solid var(--line); margin-left: .4rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: .3rem; width: 12px; height: 12px; border-radius: 50%; background: var(--grey); }
.timeline li.current::before { background: var(--leaf); }
.timeline .t-title { font-weight: 650; }
.raw { font-family: Consolas, "Courier New", monospace; font-size: .8rem; word-break: break-all; color: var(--ink-2); }
.note { background: var(--amber-soft); border-left: 4px solid var(--amber); padding: .6rem .8rem; border-radius: var(--radius-s); font-size: .9rem; margin-bottom: 1rem; }
.note.info { background: var(--leaf-soft); border-left-color: var(--leaf); }
.note.err { background: var(--red-soft); border-left-color: var(--red); }

/* ---------- dialogs */
dialog { border: 0; border-radius: var(--radius-m); padding: 0; width: min(640px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); box-shadow: 0 20px 60px rgba(20, 35, 28, .35); }
dialog::backdrop { background: rgba(20, 35, 28, .45); }
dialog .d-head { padding: 1rem 1.2rem .5rem; }
dialog .d-body { padding: .5rem 1.2rem 1rem; overflow-y: auto; max-height: calc(100vh - 11rem); }
dialog .d-foot { padding: .8rem 1.2rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: .5rem; background: #F7F9F7; }
.pick-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-s); margin-top: .4rem; }
.pick-list button { display: flex; width: 100%; justify-content: space-between; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; font-weight: 500; text-align: left; }
.pick-list button[aria-pressed="true"] { background: var(--leaf-soft); }

/* ---------- status tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { text-align: left; display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: .8rem 1rem; min-height: 0; }
.tile .n { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.tile .l { color: var(--ink-2); font-weight: 500; font-size: .9rem; }
.tile.bad .n { color: var(--red); }
.tile.warn .n { color: var(--amber); }
.tile.ok .n { color: var(--leaf); }
.tile[aria-pressed="true"] { border-color: var(--pine); box-shadow: inset 0 0 0 1px var(--pine); }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(180deg, var(--pine) 0 38%, var(--paper) 38%); }
.login { width: min(400px, 100%); background: var(--surface); border-radius: var(--radius-m); padding: 1.6rem; box-shadow: 0 16px 50px rgba(20, 35, 28, .25); }
.login .brand { color: var(--ink); margin-bottom: 1.2rem; font-size: 1.2rem; }
.login .or { text-align: center; color: var(--ink-3); font-size: .85rem; margin: .9rem 0; }
.google { width: 100%; justify-content: center; }
.err { color: var(--red); font-size: .9rem; margin: .5rem 0; }

/* ---------- toast */
#toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: var(--radius-m); z-index: 100; max-width: calc(100vw - 2rem); box-shadow: 0 8px 30px rgba(0,0,0,.25); }
#toast.bad { background: var(--red); }
.loading { color: var(--ink-3); padding: 2rem 0; }
pre.logs { background: #13201A; color: #D6E6DC; padding: .8rem; border-radius: var(--radius-s); max-height: 420px; overflow: auto; font-size: .78rem; line-height: 1.4; }

@media (max-width: 760px) {
  main { padding: .8rem; }
  .topbar { flex-wrap: wrap; padding: .4rem .8rem; gap: .4rem; }
  .nav { order: 3; flex-basis: 100%; }
  .who .name { display: none; }
  .machine-head { grid-template-columns: 1fr; }
  .serial { font-size: 1.6rem; }
  .band button .lbl { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.fault-lines { display: flex; flex-direction: column; gap: .1rem; color: var(--red); }
.ok-text { color: var(--leaf, #2E7D4F); font-weight: 600; }
td.faults { min-width: 230px; }

/* ---------- v1.4: watchlist stars, admin menu, selection bar, forms, report dialog */
.star { border: 0; background: transparent; min-height: 0; padding: .1rem .3rem; font-size: 1.15rem; line-height: 1; color: #A9B3AD; }
.star[aria-pressed="true"] { color: #D69E2E; }
.star:hover { color: #D69E2E; background: transparent; }
td.star-cell, th.star-cell { width: 1%; padding-left: .5rem; padding-right: .2rem; text-align: center; }
.serial-row { display: flex; align-items: center; gap: .3rem; }
.serial-row .star { font-size: 1.6rem; }

.admin-wrap { position: relative; }
.admin-btn { background: transparent; color: #CFE3D7; border: 0; font-size: .93rem; padding: .45rem .7rem; min-height: 0; }
.admin-btn:hover, .admin-btn[aria-expanded="true"] { background: var(--pine-2); color: #fff; }
.admin-btn.active { background: #fff; color: var(--pine); font-weight: 600; }
.admin-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
  box-shadow: 0 12px 30px rgba(20, 35, 28, .2); min-width: 200px; padding: .3rem; z-index: 40; display: flex; flex-direction: column; }
.admin-menu[hidden] { display: none; }
.admin-menu a { color: var(--ink); padding: .5rem .7rem; border-radius: var(--radius-s); white-space: nowrap; }
.admin-menu a:hover { background: var(--leaf-soft); text-decoration: none; }
.admin-menu a.active { font-weight: 650; color: var(--pine); }

.selbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin: 0 0 .6rem; }
.selbar[hidden] { display: none; }

.form-sec { font-size: .95rem; margin: .9rem 0 .35rem; color: var(--ink-2); border-top: 1px solid var(--line); padding-top: .8rem; }
.col-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .2rem 1rem; margin-top: .3rem; }
.col-check { font-size: .9rem; }
.stack { display: flex; flex-direction: column; gap: .25rem; }
.seg.wrap { flex-wrap: wrap; }
dialog.wide { width: min(860px, calc(100vw - 2rem)); }
.danger-text { color: var(--red); }
@media (max-width: 760px) {
  .admin-menu { right: auto; left: 0; }
  .seg.wrap button { flex: 1 1 auto; }
}
.quick { display: inline-flex; flex-wrap: wrap; gap: .2rem .7rem; align-items: center; }
input[type="radio"], input[type="checkbox"] { width: auto; min-height: 0; padding: 0; margin: 0; flex: none; }
@media (max-width: 760px) {
  table.readings td { display: block; border: 0; padding: .15rem .6rem; }
  table.readings tr { display: block; border-bottom: 1px solid var(--line); padding: .35rem 0; }
  table.readings td.nowrap { font-weight: 600; }
}
