:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel-2: #f9fafb; --ink: #16181d; --muted: #5b6270; --line: #dfe2e7;
  --brand: #2457c5; --brand-ink: #ffffff; --brand-soft: #e8eefb;
  --ok: #1d7a4a; --ok-bg: #e3f4ea; --warn: #9a5b00; --warn-bg: #fdf1dc; --crit: #b42b22; --crit-bg: #fbe5e3;
  --plan: #5a3fc0; --plan-bg: #ece8fb; --info: #3a5f8f; --info-bg: #e6eef8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --panel: #1a1d23; --panel-2: #20242b; --ink: #eceef1; --muted: #a1a8b3; --line: #2f343d;
    --brand: #7ea6ff; --brand-ink: #0d1424; --brand-soft: #1e2a44;
    --ok: #5fd197; --ok-bg: #16301f; --warn: #f0b85a; --warn-bg: #352812; --crit: #ff8a80; --crit-bg: #3b1a18;
    --plan: #b7a5ff; --plan-bg: #262043; --info: #9dc0ef; --info-bg: #1b2738;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- header */
header.top { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); }
.top-row { max-width: 1280px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 16px; }
.brand small { display: block; font-weight: 500; font-size: 12.5px; color: var(--muted); line-height: 1.2; }
.spacer { flex: 1; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 15px; }
.conn { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; }
.conn::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.conn.ok { color: var(--ok); background: var(--ok-bg); }
.conn.ok::before { animation: pulse 2s infinite; }
.conn.bad { color: var(--crit); background: var(--crit-bg); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .conn.ok::before { animation: none; } }

nav.tabs { max-width: 1280px; margin: 0 auto; padding: 0 20px; display: flex; gap: 4px; }
nav.tabs a { display: inline-flex; align-items: center; gap: 8px; padding: 12px 16px; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; }
nav.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--brand); }
nav.tabs a:hover { color: var(--ink); }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--crit); color: #fff; font-size: 13px; display: inline-grid; place-items: center; }
.badge.soft { background: var(--line); color: var(--ink); }
.badge:empty { display: none; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 20px 80px; }
h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 19px; margin: 28px 0 12px; }
h3 { font-size: 16px; margin: 0 0 6px; }
.sub { color: var(--muted); margin: 0 0 16px; }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { min-height: 52px; font-size: 17px; padding: 12px 24px; }
.btn.danger { color: var(--crit); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .55; cursor: progress; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- story bar */
.story { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 20px; }
.story-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.story-head h2 { margin: 0; font-size: 17px; }
.story-head span { color: var(--muted); font-size: 14px; }
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; list-style: none; padding: 0; margin: 0; }
.steps li { position: relative; padding: 10px 12px 10px 46px; border-radius: 10px; background: var(--panel-2); color: var(--muted); min-height: 58px; }
.steps li .n { position: absolute; left: 10px; top: 12px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; background: var(--line); color: var(--ink); }
.steps li b { display: block; color: var(--ink); font-size: 15px; }
.steps li small { font-size: 13px; }
.steps li.done .n { background: var(--ok); color: #fff; }
.steps li.now { background: var(--brand-soft); color: var(--ink); outline: 2px solid var(--brand); }
.steps li.now .n { background: var(--brand); color: var(--brand-ink); }
.next { margin-top: 12px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 15.5px; }
.next strong { color: var(--brand); }
@media (max-width: 820px) { .steps { grid-template-columns: 1fr 1fr; } }

/* ---------- cards */
.grid { display: grid; gap: 14px; }
.grid.lines { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.machines { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
button.card, a.card { text-align: left; cursor: pointer; color: inherit; text-decoration: none; width: 100%; display: block; }
button.card:hover, a.card:hover { border-color: var(--brand); }
.line-card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.oee { font-size: 38px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; margin-top: 8px; }
.oee small { font-size: 14px; color: var(--muted); font-weight: 500; letter-spacing: 0; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 8px 0 6px; position: relative; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.bar i.low { background: var(--warn); }
.bar .target { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--ink); opacity: .6; }
.meta { color: var(--muted); font-size: 14px; }

.machine-card { position: relative; border-left-width: 6px; }
.machine-card.s-ok { border-left-color: var(--ok); }
.machine-card.s-warning { border-left-color: var(--warn); }
.machine-card.s-critical { border-left-color: var(--crit); }
.machine-card.s-planned { border-left-color: var(--plan); }
.machine-card .icon { font-size: 22px; line-height: 1; }
.machine-card h3 { margin: 6px 0 2px; }
.machine-card .headline { margin: 8px 0 0; font-size: 15px; }
.machine-card.focus { grid-column: span 2; }
@media (max-width: 600px) { .machine-card.focus { grid-column: auto; } }
.machine-card .go { position: absolute; right: 14px; top: 14px; color: var(--muted); font-size: 14px; }

/* ---------- status pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.pill.ok, .pill.running { color: var(--ok); background: var(--ok-bg); }
.pill.warning, .pill.idle { color: var(--warn); background: var(--warn-bg); }
.pill.critical, .pill.down { color: var(--crit); background: var(--crit-bg); }
.pill.planned { color: var(--plan); background: var(--plan-bg); }
.pill.info, .pill.unknown { color: var(--info); background: var(--info-bg); }

/* ---------- alerts */
.alert { display: grid; grid-template-columns: 6px 1fr; gap: 0 16px; padding: 0; overflow: hidden; margin-bottom: 14px; }
.alert > .stripe { background: var(--warn); }
.alert.critical > .stripe { background: var(--crit); }
.alert.planned > .stripe { background: var(--plan); }
.alert .body { padding: 16px 16px 16px 0; }
.alert .top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.alert h3 { font-size: 18px; margin: 0; }
.alert .when { color: var(--muted); font-size: 14px; margin-left: auto; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin: 12px 0 14px; }
.facts div { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.facts dt { font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.facts dd { margin: 0; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 42px; }
.empty h3 { color: var(--ink); font-size: 18px; margin-top: 8px; }

/* ---------- work board */
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .board { grid-template-columns: 1fr; } }
.col { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-height: 160px; }
.col h3 { display: flex; justify-content: space-between; font-size: 15px; margin: 2px 4px 10px; }
.wo { margin-bottom: 10px; }
.wo h4 { margin: 4px 0; font-size: 16px; }
.who { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.due { font-size: 14px; font-weight: 600; }
.due.late { color: var(--crit); }

/* ---------- machine page */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-weight: 600; margin-bottom: 10px; }
.machine-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 16px; }
.machine-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
@media (max-width: 960px) { .machine-layout { grid-template-columns: 1fr; } }
.chart-card h3 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
canvas.chart { width: 100%; height: 280px; display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--c); margin-right: 6px; vertical-align: middle; }
.legend span.dash::before { border-top-style: dashed; }
.gauge { margin-bottom: 14px; }
.gauge .value { font-size: 30px; font-weight: 750; font-variant-numeric: tabular-nums; }
.gauge .value small { font-size: 15px; color: var(--muted); font-weight: 500; }
.zones { display: flex; height: 10px; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; position: relative; }
.zones i { display: block; height: 100%; }
.zones .needle { position: absolute; top: -4px; width: 4px; height: 18px; background: var(--ink); border-radius: 2px; transform: translateX(-2px); transition: left .6s; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 90px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; }
.plans li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.plans { list-style: none; padding: 0; margin: 0; }

/* ---------- modal, drawer, toast */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(520px, 94vw); background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 14, 22, .55); }
.modal-body { padding: 22px 24px; }
.modal-body h2 { margin: 0 0 4px; }
.slot { background: var(--brand-soft); border-radius: 12px; padding: 16px; margin: 16px 0; }
.slot .when { font-size: 22px; font-weight: 750; }
.modal-foot { padding: 14px 24px 22px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
textarea { width: 100%; min-height: 90px; font: inherit; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 40; transform: translateX(100%); transition: transform .25s; overflow-y: auto; visibility: hidden; }
.drawer.open { transform: none; visibility: visible; box-shadow: -10px 0 40px rgba(0,0,0,.15); }
.drawer header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.drawer header h2 { margin: 0; font-size: 18px; }
.drawer .inner { padding: 16px 18px; }
.scenario { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.scenario.main { border: 2px solid var(--brand); }
.scenario p { margin: 6px 0 10px; color: var(--muted); font-size: 14.5px; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress i { display: block; height: 100%; background: var(--brand); transition: width .8s; }
details summary { cursor: pointer; font-weight: 600; padding: 8px 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 12px; font-weight: 600; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: 90vw; }
.toast.bad { background: var(--crit); color: #fff; }
.hidden { display: none !important; }
