/* Colour roles: green = main actions, red = important warnings, soft yellow = important quotes
   (fix steps, problem descriptions), light grey-white background, #2D2D2D text and structure. */
:root {
  --bg: #f4f5f4; --surface: #ffffff; --surface-2: #eceeec;
  --text: #2d2d2d; --text-2: #5c5c5c; --text-3: #8a8a8a;
  --border: rgba(45,45,45,.12); --border-2: rgba(45,45,45,.22);
  --accent: #2e7d32; --accent-bg: #e6f2e6; --on-accent: #ffffff;
  --ok: #2e7d32; --ok-bg: #e6f2e6; --warn: #8a5300; --warn-bg: #faeeda;
  --bad: #c62828; --bad-bg: #fdeaea;
  --quote: #fff8d6; --quote-border: #ecd98a;
  --a: #1f5fbf; --a-bg: #e6f0fb; --b: #7a3fb0; --b-bg: #f1e9fa;
  --radius: 10px; --tap: 44px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 17px; font-weight: 600; margin: 0; }
h3 { font-size: 15px; font-weight: 600; margin: 24px 0 8px; }
p { margin: 0 0 12px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 8px 6px; }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.err { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 8px; }
.empty { color: var(--text-2); padding: 20px; text-align: center; border: 1px dashed var(--border-2); border-radius: var(--radius); }
.link { color: var(--accent); }
.link:hover { text-decoration: underline; }
.bad { color: var(--bad); font-style: normal; }

/* Shell */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 16px 10px; border-right: 1px solid var(--border); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; padding: 4px 10px 16px; }
.brand.big { font-size: 20px; justify-content: center; padding: 0 0 4px; }
.brand.big .i { width: 26px; height: 26px; color: var(--accent); }
.nav, .side-foot { display: flex; flex-direction: column; gap: 2px; }
.side-foot { margin-top: auto; }
.nav a, .side-foot a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav a:hover, .side-foot a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on, .side-foot a.on { background: var(--surface-2); color: var(--text); font-weight: 500; }
.main-wrap { min-width: 0; }
.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center; padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.search { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 40px; border: 1px solid var(--border-2); border-radius: var(--radius); background: var(--surface); color: var(--text-3); max-width: 640px; }
.search input { flex: 1; border: 0; background: transparent; font: inherit; color: var(--text); outline: none; min-width: 0; height: 100%; padding: 0; }
.search:focus-within { border-color: var(--accent); }
kbd { font: 12px ui-monospace, monospace; color: var(--text-3); border: 1px solid var(--border-2); border-radius: 5px; padding: 1px 5px; }
main#app { padding: 20px 24px 48px; max-width: 1180px; }
.bare { min-height: 100vh; display: grid; place-items: center; padding: 16px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 14px; border: 1px solid var(--border-2); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; touch-action: manipulation; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.icon { padding: 0; width: 36px; min-height: 36px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-3); }
.btn.danger { color: var(--bad); }
.btn.full { width: 100%; min-height: var(--tap); }
form[data-confirm] { display: inline; }

.toast { display: flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: 16px; border-radius: var(--radius); background: var(--ok-bg); color: var(--ok); font-weight: 500; animation: fade 3.5s forwards; }
@keyframes fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; height: 0; padding: 0; margin: 0; overflow: hidden; } }

/* Badges */
.mc { display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 4px; border-radius: 7px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--text-2); flex: none; }
.mc-1 { background: var(--a-bg); color: var(--a); }
.mc-2 { background: var(--b-bg); color: var(--b); }
.mc.lg { min-width: 34px; height: 34px; font-size: 16px; border-radius: 9px; }
.pill { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.st-ok.pill, .is-closed { background: var(--ok-bg); color: var(--ok); }
.st-attention.pill, .is-waiting, .pr-medium { background: var(--warn-bg); color: var(--warn); }
.st-down.pill, .pr-high, .is-open { background: var(--bad-bg); color: var(--bad); }
.pr-low { background: var(--surface-2); color: var(--text-2); }
.code { font: 600 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--accent); }
.code.big { font-size: 15px; min-width: 64px; }

/* Cards */
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; margin-bottom: 16px; }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; text-align: center; padding: 28px 24px; }
.login label { text-align: left; }
.machines { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 16px; }
.mcard { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; transition: border-color .15s; }
.mcard:hover { border-color: var(--border-2); }
.mcard.st-down { border-color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); }
.mcard.st-attention { border-color: var(--warn); }
.mhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 2px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stats > div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.stats span { display: block; font-size: 12px; color: var(--text-2); }
.stats b { font-size: 18px; font-weight: 600; }
.stats.wide { margin: 14px 0 6px; }
.alerts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.alert { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius); background: var(--bad-bg); color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 25%, transparent); font-weight: 500; }
.alert .grow { color: var(--text); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 24px; }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 20px 0 8px; }
.sec-head h3 { margin: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.crumb { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); margin-bottom: 8px; font-size: 14px; }
.crumb .i { width: 16px; height: 16px; }
.prose { white-space: pre-wrap; word-break: break-word; }
.hint, .quote { border-color: var(--quote-border); background: var(--quote); color: var(--text); }
.hint .prose { margin-top: 6px; color: var(--text); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.list > li + li { border-top: 1px solid var(--border); }
.item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; min-height: var(--tap); }
a.item:hover, .list li > a.item:hover { background: var(--surface-2); }
.item > .i { margin-top: 3px; color: var(--text-3); }
.item form { flex: none; align-self: center; }
.grow { flex: 1; min-width: 0; display: block; }
.t { display: block; font-weight: 500; overflow-wrap: anywhere; }
.t a:hover { text-decoration: underline; }
.sub { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--text-2); font-size: 13px; margin-top: 2px; }
.clip { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.desc { color: var(--text-2); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.meta { flex: none; text-align: right; color: var(--text-3); font-size: 12px; line-height: 1.5; }
.thumb { display: block; margin-top: 8px; max-width: 180px; max-height: 140px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); }
.qty { align-self: center; min-width: 36px; text-align: right; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper { display: flex; gap: 4px; }
.due { align-self: center; font-size: 13px; font-weight: 600; color: var(--ok); white-space: nowrap; }
.due.warn { color: var(--warn); }
.due.bad { color: var(--bad); }

/* Segmented controls and tabs */
.seg { display: grid; gap: 6px; margin: 4px 0 8px; }
.seg.two { grid-template-columns: 1fr 1fr; }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg.four { grid-template-columns: repeat(4, 1fr); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg label span, .seg button { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 6px 8px; text-align: center; border: 1px solid var(--border-2); border-radius: var(--radius); background: var(--surface); font: inherit; font-size: 14px; color: var(--text); cursor: pointer; line-height: 1.2; }
.seg input:checked + span { border: 2px solid var(--accent); color: var(--accent); background: var(--accent-bg); font-weight: 500; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg button.on { border: 2px solid var(--accent); background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.status-set button.st-ok.on { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.status-set button.st-attention.on { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.status-set button.st-down.on { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); margin: 16px 0 12px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 10px 12px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 12px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border-2); font-size: 13px; color: var(--text-2); background: var(--surface); }
.chips a.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.form .btn.primary:not(.full) { align-self: flex-start; }
fieldset { border: 0; padding: 0; margin: 0; }
legend, label { display: block; font-size: 13px; color: var(--text-2); font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; }
input:not([type=radio]):not([type=checkbox]):not([type=file]):not(.plain), select, textarea {
  display: block; width: 100%; min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--border-2); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; /* 16px stops iOS zoom-on-focus */ }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.search input:focus { box-shadow: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); font-weight: 400; min-height: var(--tap); }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.file { display: flex; align-items: center; gap: 8px; color: var(--accent); font-size: 14px; cursor: pointer; }
.file input { flex: 1; font-size: 13px; color: var(--text-2); }
.row-actions { display: flex; align-items: center; gap: 12px; }
.inline-search { margin-bottom: 12px; max-width: 520px; }
details.add > summary { display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 500; color: var(--accent); list-style: none; }
details.add > summary::-webkit-details-marker { display: none; }
details.add[open] > summary { margin-bottom: 12px; }
.add { margin-top: 16px; }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.menu a { display: flex; align-items: center; gap: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; font-weight: 500; }
.menu .i { color: var(--text-2); }
.only-sm, .tabbar { display: none; }

/* Device report: ink levels (progress bars keep the CSP free of inline styles) */
.ink { --ink: #2d2d2d; }
.ink-C { --ink: #0099d8; } .ink-M { --ink: #d6006f; } .ink-Y { --ink: #f2c400; } .ink-K { --ink: #2d2d2d; }
.ink progress { -webkit-appearance: none; appearance: none; width: 100%; height: 10px; border: 0; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.ink progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
.ink progress::-webkit-progress-value { background: var(--ink); border-radius: 999px; }
.upload-progress { width: 100%; height: 8px; accent-color: var(--accent); }
.ink progress::-moz-progress-bar { background: var(--ink); border-radius: 999px; }
.dev-grid .ink { display: grid; grid-template-columns: 70px minmax(0, 1fr) 52px; align-items: center; gap: 4px 10px; margin-bottom: 12px; }
.dev-grid .ink .sub { grid-column: 2 / -1; margin: 0; }
.dev-grid .ink b { text-align: right; font-variant-numeric: tabular-nums; }
.ink-name { font-size: 14px; }
.inkbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.inkbar small { display: block; font-size: 12px; color: var(--text-2); margin-top: 2px; font-variant-numeric: tabular-nums; }
.inkbar small.bad { color: var(--bad); font-weight: 600; }
.dev-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.dev-grid .card { margin: 0; }
.facts { display: grid; grid-template-columns: minmax(110px, auto) minmax(0, 1fr); gap: 6px 14px; margin: 0 0 8px; font-size: 14px; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.events { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.events li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px solid var(--border); }
.events li:first-child { border-top: 0; }
.events li span { color: var(--text-2); font-variant-numeric: tabular-nums; }
.two-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
/* To-do */
.todo { align-items: center; }
.todo .sub .i { width: 14px; height: 14px; vertical-align: -2px; }
.todo-check { display: grid; place-items: center; width: 36px; height: 36px; margin: -6px; border: 0; background: none; color: var(--text-3); cursor: pointer; border-radius: 50%; }
.todo-check .i { width: 24px; height: 24px; }
.todo-check:hover { color: var(--accent); background: var(--accent-bg); }
.todo.done .todo-check { color: var(--accent); }
.todo.done .t { color: var(--text-3); text-decoration: line-through; }
.todo a.t:hover { text-decoration: underline; }
.todo-actions { display: flex; gap: 2px; margin: -4px -6px -4px 0; }
.todo-actions .del:hover { color: var(--bad); }
.todo-add { display: flex; flex-direction: column; gap: 12px; }
.todo-add .todo-title { font-size: 17px !important; }
.todo-opts { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 10px; align-items: end; }
.todo-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.todo-quick .todo-notes { flex-basis: 100%; }
.todo-notes { min-height: 0; }
.notes-hint { display: inline-flex; align-items: center; gap: 3px; color: var(--text-3); }
.notes-hint:hover { color: var(--accent); }
.kbd-hint { margin: -4px 0 0; }
@media (hover: none) { .kbd-hint { display: none; } }
.todo-quick input[name=title] { flex: 1; }
.todo-quick .btn { width: 44px; min-height: var(--tap); padding: 0; }
@media (max-width: 860px) { .todo-opts { grid-template-columns: 1fr 1fr; } .todo-opts .btn { grid-column: 1 / -1; min-height: var(--tap); } }
.ref { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-3); }
.tech-form { display: flex; gap: 6px; align-items: center; }
.tech-form input { width: 70px !important; min-height: 32px !important; padding: 4px 8px !important; font-size: 14px !important; }
.row-actions input { max-width: 160px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.passkey-box { display: flex; flex-direction: column; gap: 8px; }
.passkey-box .btn:not(.full) { align-self: flex-start; }
.passkey-box .err { margin: 0; text-align: left; }
[hidden] { display: none !important; }
h3.flush { margin-top: 0; }
.card .list { margin-bottom: 12px; }

/* Phone layout */
@media (max-width: 860px) {
  .shell { display: block; }
  .side { display: none; }
  .hide-sm { display: none; }
  .only-sm { display: grid; }
  .top { padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; }
  .search { max-width: none; }
  .search kbd { display: none; }
  main#app { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; position: fixed; z-index: 10; left: 0; right: 0; bottom: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--border); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--text-3); padding: 4px 0; }
  .tabbar a .i { width: 22px; height: 22px; }
  .tabbar a.on { color: var(--accent); }
  .tabbar .tab-add { justify-self: center; width: 52px; height: 52px; border-radius: 16px; background: var(--accent); color: var(--on-accent); justify-content: center; }
  .tabbar .tab-add .i { width: 26px; height: 26px; stroke-width: 2.4; }
  .cols { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .machines { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .seg.four { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .grid3 > :first-child { grid-column: 1 / -1; }
  h1 { font-size: 20px; }
}
@media (max-width: 420px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .seg.three button { font-size: 13px; padding: 4px; }
  .stats b { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
