/* Empower ERP app shell. Layout: fixed left sidebar (modules) + top bar (search, user) + content column. */
:root {
  --bg: #f3f6f8; --surface: #ffffff; --surface-2: #f8fafb; --fg: #10262e; --muted: #5f7680; --line: #dfe7eb; --line-2: #eef3f5;
  --brand: #0e7490; --brand-ink: #0b5c72; --brand-soft: #e3f3f7; --accent: #f59e0b; --accent-soft: #fef3dc;
  --side: #0b2f3a; --side-fg: #b9d3db; --side-active: #134754;
  --ok: #15803d; --ok-soft: #e5f5ea; --warn: #c2410c; --warn-soft: #fdeee4; --bad: #b91c1c; --bad-soft: #fde8e8; --info: #1d4ed8; --qc: #7c3aed;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,38,46,.06), 0 1px 1px rgba(16,38,46,.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1a20; --surface: #13252d; --surface-2: #172c35; --fg: #e2eef2; --muted: #93adb6; --line: #24404a; --line-2: #1b333c;
    --brand: #22d3ee; --brand-ink: #67e8f9; --brand-soft: #0f3340; --accent-soft: #3a2c0c; --side: #08161b; --side-active: #12313b;
    --ok-soft: #10301c; --warn-soft: #3a2010; --bad-soft: #3a1515; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.side { background: var(--side); color: var(--side-fg); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 14px 10px 30px; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff !important; font-weight: 800; font-size: 18px; padding: 4px 10px 16px; text-decoration: none !important; }
.brand i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.nav-group { margin-top: 10px; }
.nav-head { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: #e8f4f7; font-weight: 600; cursor: pointer; user-select: none; }
.nav-head:hover { background: var(--side-active); }
.nav-head .ic { width: 18px; text-align: center; opacity: .85; }
.nav-items { padding-left: 26px; display: grid; gap: 1px; margin-top: 2px; }
.nav-items a { color: var(--side-fg); padding: 5px 10px; border-radius: 6px; font-size: 13.5px; }
.nav-items a:hover { background: var(--side-active); color: #fff; text-decoration: none; }
.nav-items a.on { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-single { display: flex; gap: 8px; align-items: center; padding: 7px 10px; border-radius: 8px; color: #e8f4f7; font-weight: 600; }
.nav-single:hover, .nav-single.on { background: var(--side-active); text-decoration: none; color: #fff; }
.side .foot { margin-top: 26px; padding: 0 10px; font-size: 12px; }
.side .foot a { color: var(--side-fg); }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 10px 24px; }
.top form { flex: 1; max-width: 520px; }
.top input[type=search] { width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font: inherit; color: var(--fg); }
.top .who { margin-left: auto; display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 13px; }
.burger { display: none; background: none; border: 0; font-size: 22px; color: var(--fg); cursor: pointer; }
.content { padding: 22px 24px 60px; max-width: 1400px; width: 100%; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .burger { display: block; }
  .content { padding: 16px 14px 60px; }
  .top { padding: 10px 14px; }
}

/* page header */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; font-weight: 700; }
.page-head .crumb { color: var(--muted); font-size: 13px; width: 100%; }
.page-head .spacer { flex: 1; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--fg) !important; padding: 7px 14px; border-radius: 8px; font: 600 13px var(--font); cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff !important; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff !important; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff !important; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.big { font-size: 17px; padding: 14px 24px; border-radius: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; margin: 0; }

/* cards / panels */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.kpi { padding: 14px 16px; display: block; color: inherit !important; text-decoration: none !important; }
a.kpi:hover { border-color: var(--brand); }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .v { font-size: 24px; font-weight: 750; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi.alert .v { color: var(--warn); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; margin: 22px 0 10px; }

/* badges */
.erp-badge, .badge { display: inline-block; color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: #6c757d; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--fg) !important; text-decoration: none !important; }
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-ink) !important; font-weight: 600; }
.chip .n { color: var(--muted); font-size: 12px; }

/* list */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; font: inherit; color: var(--fg); min-width: 240px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg a { padding: 6px 12px; color: var(--muted); font-weight: 600; font-size: 13px; }
.seg a.on { background: var(--brand-soft); color: var(--brand-ink); }
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; background: var(--surface); }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr.row { cursor: pointer; }
.tbl tr.row:hover td { background: var(--brand-soft); }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* kanban */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.kcol { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.kcol h3 { font-size: 13px; display: flex; justify-content: space-between; margin: 2px 4px 10px; }
.kcard { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; color: inherit !important; text-decoration: none !important; box-shadow: var(--shadow); }
.kcard:hover { border-color: var(--brand); }
.kcard b { display: block; }
.kcard .m { color: var(--muted); font-size: 12.5px; }

/* detail */
.doc-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.doc-head .spacer { flex: 1; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 32px; padding: 6px 18px 14px; }
.fields .f { display: grid; grid-template-columns: 160px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line-2); align-items: baseline; min-width: 0; }
.fields .f > span:first-child { color: var(--muted); font-size: 13px; }
.fields .f > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.panel-title { font-weight: 700; padding: 14px 18px 4px; font-size: 14px; }
.steps { display: flex; gap: 0; overflow-x: auto; padding: 14px 10px; }
.step { flex: 1; min-width: 100px; text-align: center; position: relative; }
.step::after { content: ""; position: absolute; top: 14px; left: calc(50% + 16px); right: calc(-50% + 16px); height: 3px; background: var(--line); }
.step:last-child::after { display: none; }
.step.done::after { background: var(--ok); }
.step .dot { width: 30px; height: 30px; border-radius: 50%; margin: 0 auto 6px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; background: var(--surface-2); color: var(--muted); border: 2px solid var(--line); }
.step.done .dot { background: var(--ok); color: #fff; border-color: var(--ok); }
.step.current .dot { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.step.blocked .dot { background: var(--bad); color: #fff; border-color: var(--bad); }
.step .lbl { font-weight: 600; font-size: 12.5px; }
.step .sub { color: var(--muted); font-size: 11.5px; }
.banner { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-weight: 600; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.totals { margin-left: auto; min-width: 280px; padding: 10px 18px 16px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-size: 17px; font-weight: 800; border-top: 2px solid var(--fg); margin-top: 4px; padding-top: 6px; }
.related a { display: inline-block; margin: 0 4px 4px 0; }

/* forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px 22px; padding: 14px 18px 18px; }
.form-grid label, .lbl-txt { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.form-grid .wide { grid-column: 1 / -1; }
.fld, .form-grid input:not([type=checkbox]), .form-grid select, .form-grid textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; color: var(--fg); background: var(--surface); }
.fld:focus, input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.help { color: var(--muted); font-size: 12px; margin-top: 3px; }
.errorlist { color: var(--bad); margin: 4px 0 0; padding: 0; list-style: none; font-size: 12.5px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500 !important; color: var(--fg) !important; }
table.lines { width: 100%; border-collapse: collapse; }
.lines th { text-align: left; font-size: 11.5px; text-transform: uppercase; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.lines td { padding: 6px; border-bottom: 1px solid var(--line-2); vertical-align: top; min-width: 90px; }
.lines td.prod { min-width: 240px; }
.lines td.del { min-width: 0; width: 36px; text-align: center; }
.lines .fld { padding: 6px 8px; }
.lines tr.deleted { opacity: .35; }
.add-line { margin: 10px 6px; }
.form-actions { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 18px; display: flex; gap: 10px; border-radius: 0 0 var(--radius) var(--radius); }
.na { background: var(--surface-2) !important; color: var(--muted) !important; }
.scope-hint { color: var(--warn); font-size: 12px; font-weight: 600; margin-top: 4px; }
.scope-attention { outline: 2px solid var(--accent) !important; border-radius: 8px; }

/* Tom Select theming */
.ts-wrapper .ts-control { border: 1px solid var(--line) !important; border-radius: 8px !important; padding: 7px 10px !important; background: var(--surface) !important; color: var(--fg); box-shadow: none !important; min-height: 36px; }
.ts-wrapper.focus .ts-control { border-color: var(--brand) !important; }
.ts-dropdown { border: 1px solid var(--line) !important; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.12) !important; background: var(--surface) !important; color: var(--fg); z-index: 60; }
.ts-dropdown .active { background: var(--brand-soft) !important; color: var(--fg) !important; }
.ts-dropdown .option { padding: 7px 10px; }
.lines .ts-wrapper .ts-control { padding: 5px 8px !important; min-height: 32px; }

/* messages */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; max-width: 420px; }
.toast { background: var(--fg); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-weight: 500; }
.toast.error { background: var(--bad); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
.toast.warning { background: var(--warn); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--side), #0e5566); padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { font-size: 22px; margin-bottom: 4px; }
.login input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: inherit; margin: 4px 0 12px; background: var(--surface); color: var(--fg); }

@media print { .side, .top, .doc-actions, .toasts { display: none !important; } .shell { display: block; } }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* shop floor (tablet first) */
.sf-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.sf { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .sf { grid-template-columns: 1fr; } }
.sf-mos { display: grid; gap: 8px; }
.sf-mo { display: block; padding: 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: inherit !important; text-decoration: none !important; }
.sf-mo.on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.sf-mo .bar { height: 6px; background: var(--line-2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.sf-mo .bar i { display: block; height: 100%; background: var(--ok); }
.sf-pill { float: right; background: var(--warn); color: #fff; border-radius: 999px; padding: 0 9px; font-size: 12px; font-weight: 700; }
.sf-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding: 16px 18px; }
.sf-head h2 { font-size: 20px; }
.sf-step { margin-top: 14px; overflow: hidden; }
.sf-step-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.sf-step-head h3 { flex: 1; font-size: 16px; }
.sf-num { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
.sf-num.done { background: var(--ok); } .sf-num.run { background: var(--accent); } .sf-num.qc { background: var(--qc); }
.sf-instr { padding: 10px 18px; color: var(--muted); border-bottom: 1px solid var(--line-2); }
.sf-check { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line-2); }
@media (max-width: 700px) { .sf-check { grid-template-columns: 1fr; } }
.sf-check h4 { margin: 0 0 3px; font-size: 15px; }
.sf-spec { display: inline-block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 10px; font-weight: 700; margin-top: 6px; }
.sf-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.sf-actions input[type=number] { font-size: 22px; width: 150px; padding: 10px; border-radius: 10px; border: 2px solid var(--line); text-align: center; background: var(--surface); color: var(--fg); }
.sf-actions input.in { border-color: var(--ok); background: var(--ok-soft); }
.sf-actions input.out { border-color: var(--bad); background: var(--bad-soft); }
.sf-note { width: 100%; max-width: 420px; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: inherit; background: var(--surface); color: var(--fg); }
.res { font-weight: 800; font-size: 16px; } .res.pass { color: var(--ok); } .res.fail { color: var(--bad); }
.comp { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 18px; font-size: 13px; }

/* polish */
.shell { background: linear-gradient(to right, var(--side) 232px, transparent 232px); }
@media (max-width: 900px) { .shell { background: none; } }
.tbl th.num, .tbl td.num { text-align: right; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
.ts-wrapper.fld { border: 0 !important; padding: 0 !important; background: transparent !important; outline: 0 !important; }
.nav-group.closed .nav-items { display: none; }
.nav-head::after { content: "▾"; margin-left: auto; opacity: .5; font-size: 11px; }
.nav-group.closed .nav-head::after { content: "▸"; }
form.card { padding-bottom: 0; }
.form-actions { margin-top: 18px; }

/* traceability panel (shared with the admin) */
.erp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.erp-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.erp-card .k-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.erp-card .k-value { font-size: 24px; font-weight: 750; margin-top: 4px; }
.erp-badge.recall { background: var(--bad); }
.tr-cols { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 16px; }
@media (max-width: 1000px) { .tr-cols { grid-template-columns: 1fr; } }
.tr-col h3 { font-size: 12.5px; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.tr-item { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 8px; padding: 9px 12px; margin-bottom: 8px; font-size: 13px; }
.tr-item.up { border-left-color: #0284c7; } .tr-item.self { border-left-color: var(--accent); } .tr-item.down { border-left-color: var(--bad); }
.tr-item .kind { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
.tr-item .what { font-weight: 600; }
