/* iOLABS Automations Cloud — own tokens, light/dark, print. No framework. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --line: #dfe3e8;
  --accent: #0b63ce;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --ok-bg: #e6f4ea;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --info-bg: #e8f0fb;
  --c1: #0b63ce; --c2: #e07a10; --c3: #1a7f37; --c4: #8b3fd1; --c5: #c2185b; --c6: #00838f;
  --radius: 10px;
  --ctl-h: 2.5rem;          /* one height for every input, select and button */
  --ctl-h-sm: 2rem;
  --ctl-radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1e232b; --text: #e6e9ee; --muted: #9aa5b3; --line: #2a313b;
    --accent: #4c9aff; --accent-text: #0b1220; --ok: #4ac26b; --ok-bg: #12301c; --bad: #ff7b72; --bad-bg: #3a1614;
    --warn: #e3b341; --warn-bg: #33270b; --info-bg: #142338;
    --c1: #4c9aff; --c2: #f0a04b; --c3: #4ac26b; --c4: #b98af0; --c5: #f06292; --c6: #4dd0e1;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1e232b; --text: #e6e9ee; --muted: #9aa5b3; --line: #2a313b;
  --accent: #4c9aff; --accent-text: #0b1220; --ok: #4ac26b; --ok-bg: #12301c; --bad: #ff7b72; --bad-bg: #3a1614;
  --warn: #e3b341; --warn-bg: #33270b; --info-bg: #142338;
  --c1: #4c9aff; --c2: #f0a04b; --c3: #4ac26b; --c4: #b98af0; --c5: #f06292; --c6: #4dd0e1;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
code { font-family: var(--mono); font-size: .9em; }
small, .small { font-size: .85em; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.nowrap { white-space: nowrap; }

/* Shell */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 8px; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: .9rem; }
.mainnav, .subnav { display: flex; gap: .25rem; flex-wrap: wrap; }
.mainnav a, .subnav a { padding: .4rem .7rem; border-radius: 8px; color: var(--muted); }
.mainnav a[aria-current="page"], .subnav a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.mainnav a:hover, .subnav a:hover { text-decoration: none; color: var(--text); }
.usermenu { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.usermenu .who small { color: var(--muted); }
.subnav { padding: .4rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.page { max-width: 1280px; margin: 0 auto; padding: 1.2rem 1rem 2rem; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }
.pagehead { display: flex; align-items: baseline; gap: 1rem; justify-content: space-between; margin-bottom: 1rem; flex-wrap: wrap; }
.inline { display: inline-flex; align-items: center; gap: .4rem; margin: 0; vertical-align: middle; }

/* Controls */
.btn, button.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; box-sizing: border-box; height: var(--ctl-h); padding: 0 1rem; line-height: 1; white-space: nowrap; border-radius: var(--ctl-radius); border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; transition: background .12s, border-color .12s; }
.btn.small, button.btn.small { height: var(--ctl-h-sm); padding: 0 .7rem; font-size: .85rem; }
.btn.primary:hover { filter: brightness(1.06); }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.linkbtn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: .2rem .3rem; }
.linkbtn.danger { color: var(--bad); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: var(--ctl-radius); padding: 0 .75rem; min-width: 0; box-sizing: border-box; transition: border-color .12s; }
input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select:not([multiple]) { height: var(--ctl-h); line-height: 1.2; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--line) 50%, var(--muted)); }
textarea { padding: .55rem .75rem; min-height: 6rem; }
select[multiple] { padding: .35rem .5rem; }
select:not([multiple]) { appearance: none; -webkit-appearance: none; padding-right: 2rem; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 1rem) 50%, calc(100% - .7rem) 50%; background-size: .3rem .3rem; background-repeat: no-repeat; }
input[type=date] { padding-right: .5rem; }
input[type=date]::-webkit-calendar-picker-indicator { opacity: .6; cursor: pointer; }
:root[data-theme="dark"] input[type=date], :root:not([data-theme="light"]) input[type=date] { color-scheme: light dark; }
input::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; line-height: 1.4; color: var(--muted); }
label input, label select { color: var(--text); }
.narrow { width: 8rem; }
.field-error { color: var(--bad); font-size: .82rem; }
.alert { background: var(--bad-bg); color: var(--bad); padding: .6rem .8rem; border-radius: 8px; }
.toast { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--ok-bg); color: var(--ok); }
.toast-error { background: var(--bad-bg); color: var(--bad); }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.cards .card { margin: 0; }
.plant-card header { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; margin-bottom: .6rem; }
.plant-card h2 { margin: 0; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: 0 0 .6rem; }
.kpis dt { color: var(--muted); font-size: .82rem; }
.kpis dd { margin: 0; font-size: 1.35rem; font-weight: 600; }
.kpis dd.muted { font-size: .85rem; font-weight: 400; }
.flags { list-style: none; padding: 0; margin: 0 0 .6rem; display: flex; flex-wrap: wrap; gap: .35rem; }
.flag { font-size: .8rem; padding: .15rem .5rem; border-radius: 999px; background: var(--warn-bg); color: var(--warn); }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem; align-items: start; }
.grid-form > div:has(> .btn) { padding-top: calc(.88rem * 1.4 + .25rem); }
.grid-form h2 { grid-column: 1 / -1; margin: 0; }
.inline-form { display: flex; gap: .8rem; align-items: flex-start; flex-wrap: wrap; }
/* Buttons line up with the inputs (not with helper text under them): offset by one label line + gap */
.inline-form > .btn, .inline-form > button { margin-top: calc(.88rem * 1.4 + .25rem); }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; align-items: end; }
.filter-actions { display: flex; gap: .4rem; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; }

/* Badges */
.badge { display: inline-block; font-size: .75rem; padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok, .status-complete { background: var(--ok-bg); color: var(--ok); }
.badge.bad, .status-aborted, .status-deleted { background: var(--bad-bg); color: var(--bad); }
.badge.warn, .status-partial, .source-manual, .source-user_entered { background: var(--warn-bg); color: var(--warn); }
.source-automatic { background: var(--info-bg); color: var(--accent); }

/* Tables */
.tablewrap { overflow-x: auto; }
.tablewrap.card { padding: 0; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.data thead th { background: var(--surface-2); font-weight: 600; font-size: .82rem; color: var(--muted); position: sticky; top: 0; }
table.data tfoot th { border-top: 2px solid var(--line); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr[data-href] { cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.zero td { color: var(--muted); opacity: .6; }
table.data tr.oot td { background: var(--warn-bg); }

/* Production detail = plant printout */
.printout { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; }
.print-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 2px solid var(--text); padding-bottom: .6rem; margin-bottom: .8rem; }
.print-badges { display: flex; gap: .3rem; flex-wrap: wrap; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .5rem 1.2rem; margin: 0 0 1rem; }
.fields div { border-bottom: 1px dotted var(--line); padding: .2rem 0; }
.fields .wide { grid-column: 1 / -1; }
.fields dt { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.fields dd { margin: 0; font-weight: 600; }
.kpi-strip { display: flex; flex-wrap: wrap; gap: .6rem 1.6rem; padding: .7rem .9rem; background: var(--surface-2); border-radius: 8px; margin-bottom: 1rem; }
.batch { margin: 1rem 0; }
.batch h2 small { font-weight: 400; margin-left: .5rem; }
.batch summary { cursor: pointer; font-weight: 600; }
.totals h2 { border-top: 2px solid var(--text); padding-top: .6rem; }
.print-foot { margin-top: 1rem; }

/* Auth */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.6rem; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 1.2rem; }
.auth-card h1 { margin-bottom: 1rem; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.auth-locale { margin-top: 1rem; text-align: center; }

/* Pairing code (shown once) */
.pairing { border-color: var(--accent); }
.pairing-code code { font-size: 2.2rem; letter-spacing: .25em; font-weight: 700; }

@media (max-width: 640px) {
  .usermenu { margin-left: 0; width: 100%; justify-content: flex-end; }
  .kpis dd { font-size: 1.15rem; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  :root, :root[data-theme="dark"] { --bg: #fff; --surface: #fff; --surface-2: #f2f2f2; --text: #000; --muted: #444; --line: #bbb; --warn-bg: #fff3cd; }
  body { background: #fff; font-size: 10.5pt; }
  .topbar, .subnav, .footer, .noprint, .toast { display: none !important; }
  .page { max-width: none; padding: 0; }
  .printout { border: 0; padding: 0; }
  .tablewrap { overflow: visible; }
  table.data { font-size: 9pt; }
  table.data thead th { position: static; }
  .batch { break-inside: avoid; }
  a { color: #000; }
}
table.data th { white-space: nowrap; }

/* Date picker (app.js) */
.dp { position: relative; display: flex; align-items: center; }
.dp .dp-text { width: 100%; padding-right: 2.5rem; font-variant-numeric: tabular-nums; }
.dp .dp-text.is-invalid { border-color: var(--bad); }
.dp-btn { position: absolute; right: .3rem; top: 50%; transform: translateY(-50%); display: grid; place-items: center; width: 2rem; height: 2rem; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.dp-btn:hover { background: var(--surface-2); color: var(--text); }
.dp-pop { position: absolute; z-index: 50; width: 18.5rem; padding: .75rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.08); }
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.dp-title { font-weight: 600; }
.dp-nav { width: 2rem; height: 2rem; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.dp-nav:hover { background: var(--surface-2); }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-wd { text-align: center; font-size: .75rem; color: var(--muted); padding: .25rem 0; }
.dp-day { height: 2.2rem; border: 0; border-radius: 8px; background: transparent; color: var(--text); font: inherit; font-size: .9rem; font-variant-numeric: tabular-nums; cursor: pointer; }
.dp-day:hover { background: var(--surface-2); }
.dp-day.is-out { color: var(--muted); opacity: .55; }
.dp-day.is-today { box-shadow: inset 0 0 0 1px var(--accent); }
.dp-day.is-sel { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.dp-foot { display: flex; justify-content: space-between; margin-top: .5rem; padding-top: .5rem; border-top: 1px solid var(--line); }
.dp-link { border: 0; background: transparent; color: var(--accent); font: inherit; font-size: .88rem; padding: .3rem .4rem; border-radius: 6px; cursor: pointer; }
.dp-link:hover { background: var(--surface-2); }

/* Checkbox list + custom checkbox */
.checklist { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; line-height: 1.4; color: var(--muted); }
.checklist legend { padding: 0; margin-bottom: .25rem; }
.checklist-items { display: flex; flex-direction: column; gap: .15rem; max-height: 9.5rem; overflow-y: auto; padding: .35rem; border: 1px solid var(--line); border-radius: var(--ctl-radius); background: var(--surface); }
label.check { flex-direction: row; align-items: center; gap: .55rem; padding: .35rem .45rem; border-radius: 6px; color: var(--text); cursor: pointer; font-size: .9rem; }
label.check:hover { background: var(--surface-2); }
input[type=checkbox] { appearance: none; -webkit-appearance: none; flex: none; width: 1.1rem; height: 1.1rem; margin: 0; border: 1.5px solid color-mix(in srgb, var(--muted) 70%, transparent); border-radius: 5px; background: var(--surface); display: grid; place-content: center; cursor: pointer; transition: background .12s, border-color .12s; }
input[type=checkbox]::after { content: ""; width: .55rem; height: .32rem; border: 2px solid var(--accent-text); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked::after { opacity: 1; }
