/* TechFab Production UI kit. Brand: navy #1f3a5f, accent #e08a1e. No build step. */
:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1c2430; --muted: #5d6878; --line: #dde1e7;
  --brand: #1f3a5f; --brand-2: #2e5eaa; --accent: #e08a1e;
  --ok: #1e7b4a; --ok-bg: #e3f4ea; --warn: #9a5b00; --warn-bg: #fdf0d9;
  --bad: #b3261e; --bad-bg: #fbe4e2; --idle: #6b7280; --idle-bg: #eef0f3;
  --radius: 8px; --sidebar: 244px; --sidebar-mini: 68px; --topbar: 56px;
  --touch: 44px;
}
* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
[hidden] { display: none !important; }  /* fields / buttons a script hides (e.g. an empty Sub-type) */
html { font-size: 15px; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", "Noto Sans Devanagari", Arial, sans-serif;
       background: var(--bg); color: var(--ink); line-height: 1.4; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { flex: none; vertical-align: middle; }

/* ------------------------------------------------------------------ shell: side menu + top bar */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: var(--brand); color: #d6e0ee; flex: none; position: sticky; top: 0;
           height: 100vh; overflow-y: auto; z-index: 30; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 14px; font-size: .95rem; height: var(--topbar); color: #fff; font-weight: 700;
         letter-spacing: .3px; white-space: nowrap; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand:hover { text-decoration: none; }
.brand-mark { background: var(--accent); color: #fff; border-radius: 6px; width: 34px; height: 34px; display: grid;
              place-items: center; font-size: .9rem; flex: none; }
.brand em { font-style: normal; color: var(--accent); }
.sidebar nav { padding: 8px 8px 24px; display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .6px; color: #9fb1c9; padding: 14px 10px 4px; }
.nav-item { display: flex; align-items: center; gap: 12px; color: #d6e0ee; padding: 0 12px; min-height: var(--touch);
            border-radius: 6px; border-left: 3px solid transparent; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; border-left-color: var(--accent); font-weight: 600; }
.nav-scrim { display: none; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar); background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center;
          gap: 12px; padding: 0 18px; position: sticky; top: 0; z-index: 20; }
.topbar-title { flex: 1; font-weight: 600; color: var(--brand); }
.topbar .menu-btn { display: none; }
.icon-btn { background: none; border: 0; color: inherit; width: var(--touch); height: var(--touch); display: grid;
            place-items: center; border-radius: 6px; cursor: pointer; }
.icon-btn:hover { background: var(--idle-bg); }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--line); border-radius: 999px;
            padding: 6px 12px; min-height: 40px; font: inherit; color: var(--ink); cursor: pointer; }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line);
            border-radius: var(--radius); box-shadow: 0 8px 24px rgba(20,30,50,.15); min-width: 230px; padding: 6px; z-index: 40; }
.dropdown-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.dropdown a, .dropdown button { display: block; width: 100%; text-align: left; padding: 10px; border-radius: 6px; color: var(--ink);
            background: none; border: 0; font: inherit; cursor: pointer; }
.dropdown a:hover, .dropdown button:hover { background: var(--idle-bg); text-decoration: none; }
.dropdown form { margin: 0; }
.dropdown .lang { display: flex; gap: 6px; padding: 6px 10px 8px; }
.dropdown .lang button { width: auto; border: 1px solid var(--line); padding: 6px 12px; }
.dropdown .lang button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

main { padding: 18px; width: 100%; max-width: 1500px; margin: 0 auto; }
main.auth { max-width: none; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------------ panels & grids */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.panel > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: block; color: inherit; }
.kpi:hover { text-decoration: none; border-color: var(--brand-2); }
.kpi .v { font-size: 1.7rem; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.kpi.bad .v { color: var(--bad); }

/* ------------------------------------------------------------------ buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink);
       padding: 8px 14px; min-height: 38px; border-radius: 6px; font: inherit; font-size: .95rem; cursor: pointer;
       white-space: nowrap; line-height: 1.2; }
.btn:hover { text-decoration: none; border-color: var(--brand-2); }
.btn-primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn-primary:hover { background: var(--brand); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--bad); }
.btn-danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-link { border-color: transparent; background: none; color: var(--brand-2); }
.btn-sm { padding: 4px 9px; min-height: 30px; font-size: .85rem; }
.btn-lg { padding: 12px 20px; min-height: var(--touch); font-size: 1.05rem; }
.inline-form { display: inline; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { padding: 8px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #eef1f5; font-size: .8rem; text-transform: uppercase; letter-spacing: .3px; color: #3b4656; white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: #f8fafc; }
tfoot td { font-weight: 700; background: #f6f7f9; }
tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
tr.clickable { cursor: pointer; }
.data-table { padding: 0; }
.data-table .toolbar { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.data-table #table-region { padding: 0 0 4px; }
.data-table .pagination { padding: 10px 14px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.toolbar .search { flex: 1 1 240px; position: relative; display: flex; align-items: center; margin: 0; }
.toolbar .search .icon { position: absolute; left: 10px; color: var(--muted); }
.toolbar .search input { padding-left: 36px; }
.toolbar-field { min-width: 150px; }
.toolbar-field label { font-size: .78rem; color: var(--muted); font-weight: 600; }
.pagination { display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); display: grid; justify-items: center; gap: 8px; }
.empty-title { font-weight: 600; color: var(--ink); font-size: 1.05rem; }

/* ------------------------------------------------------------------ status chips (unchanged colours) */
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.chip-done, .chip-completed { background: var(--ok-bg); color: var(--ok); }
.chip-in_progress, .chip-in_production { background: var(--warn-bg); color: var(--warn); }
.chip-pending, .chip-released, .chip-draft { background: var(--idle-bg); color: var(--idle); }
.chip-hold, .chip-cancelled, .chip-overdue { background: var(--bad-bg); color: var(--bad); }
.chip-skipped { background: transparent; color: var(--idle); border: 1px dashed #b5bcc7; }
.chip-active { background: var(--ok-bg); color: var(--ok); }
.chip-inactive { background: var(--idle-bg); color: var(--idle); }

/* order x stage grid cells */
.cell { min-width: 92px; font-size: .8rem; }
.cell .bar { height: 6px; background: var(--idle-bg); border-radius: 3px; overflow: hidden; margin: 3px 0 2px; }
.cell .bar i { display: block; height: 100%; background: var(--warn); }
.cell.st-done .bar i { background: var(--ok); }
.cell.st-done { color: var(--ok); }
.cell.st-pending { color: var(--idle); }
.cell.st-skipped { color: #a0a7b2; font-style: italic; }
.cell.current { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }
.cell .q { font-variant-numeric: tabular-nums; }
.progress { height: 8px; background: var(--idle-bg); border-radius: 4px; overflow: hidden; min-width: 70px; }
.progress i { display: block; height: 100%; background: var(--brand-2); }

/* ------------------------------------------------------------------ forms */
.field { margin: 0 0 14px; }
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.req { color: var(--bad); }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], input[type=email],
input[type=tel], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 9px 10px; min-height: 40px; border: 1px solid #c8ced8; border-radius: 6px; font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: var(--brand-2); }
.has-error input, .has-error select, .has-error textarea, .has-error .ts-control { border-color: var(--bad); background: #fffafa; }
.field-error { color: var(--bad); font-size: .85rem; margin-top: 4px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.help, .helptext { display: block; color: var(--muted); font-size: .8rem; margin-top: 3px; font-weight: 400; }
.errorlist { color: var(--bad); margin: 4px 0; padding: 0; list-style: none; font-size: .85rem; }
.form-errors { background: var(--bad-bg); color: var(--bad); border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.form-section { border: 0; border-top: 1px solid var(--line); margin: 6px 0 0; padding: 14px 0 0; }
.form-section legend { font-weight: 700; color: var(--brand); padding: 0 8px 0 0; font-size: .95rem; margin-bottom: 8px; }
@media (min-width: 900px) { .form-grid .span-2 { grid-column: span 2; } }
label.check, .checks label { display: flex; gap: 8px; align-items: center; font-weight: 500; min-height: var(--touch); cursor: pointer; }
label.check input, .checks input { width: 20px; height: 20px; accent-color: var(--brand-2); }
.check-field { display: flex; flex-direction: column; justify-content: flex-end; }
.checks ul, ul.checks { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0 18px; }
.checks > div { display: flex; flex-wrap: wrap; gap: 0 18px; }
.with-add { display: flex; gap: 6px; align-items: flex-start; }
.with-add > select, .with-add > .ts-wrapper { flex: 1; min-width: 0; }
.with-add .btn { min-height: 40px; }
.ts-wrapper .ts-control { min-height: 40px; border-color: #c8ced8; border-radius: 6px; font: inherit; }
.ts-dropdown { font: inherit; z-index: 60; }
.ts-dropdown .option { padding: 8px 10px; }

/* key/value spec */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .92rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* tabs + history */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a, .tabs button { padding: 10px 14px; color: var(--muted); border: 0; border-bottom: 3px solid transparent; background: none;
                        font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tabs a.active, .tabs button.active { color: var(--brand); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--brand); }
ul.changes { margin: 0; padding-left: 16px; }

/* ------------------------------------------------------------------ drawer, modal, confirm, toasts */
.overlay-backdrop { position: fixed; inset: 0; background: rgba(15,25,40,.45); z-index: 50; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--panel); z-index: 55;
          box-shadow: -8px 0 24px rgba(15,25,40,.2); overflow-y: auto; padding: 18px 20px 28px; }
.drawer-in { animation: slide-in .18s ease-out; }
.drawer-out { animation: slide-in .12s ease-in reverse; }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-close { position: absolute; top: 10px; right: 10px; }
.drawer h2, .modal h2 { margin: 0 44px 14px 0; font-size: 1.25rem; }
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal-box { position: relative; background: var(--panel); border-radius: 10px; width: min(560px, 100%); max-height: 90vh;
             overflow-y: auto; padding: 20px; box-shadow: 0 16px 40px rgba(15,25,40,.3); }
.modal-box:has(.jc-preview) { width: min(1280px, 100%); max-height: 94vh; padding: 24px 28px; }
.jc-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; }
.jc-preview > h2, .jc-preview > p, .jc-preview > .form-actions { grid-column: 1 / -1; }
@media (max-width: 760px) { .jc-preview { grid-template-columns: 1fr; } }
.modal .small-box { width: min(420px, 100%); text-align: center; }
.modal.confirm { background: rgba(15,25,40,.45); z-index: 80; }
.confirm-icon { color: var(--warn); }
.confirm-text { font-size: 1.05rem; margin: 8px 0 12px; }
.modal.confirm .form-actions { justify-content: center; border: 0; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 90; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 12px 16px; border-radius: 8px; background: var(--brand); color: #fff; box-shadow: 0 6px 20px rgba(15,25,40,.25);
         cursor: pointer; font-weight: 500; border-left: 5px solid var(--accent); }
.toast-success { background: #16603b; border-left-color: #7fd6a4; }
.toast-error { background: var(--bad); border-left-color: #ffb4ad; }
.toast-warning { background: var(--warn); }

.login-box { max-width: 380px; margin: 8vh auto; }

/* ------------------------------------------------------------------ shop floor: big touch targets */
.touch input, .touch select, .touch textarea, .touch .ts-control { min-height: 52px; font-size: 1.1rem; }
.touch label { font-size: .95rem; }
.touch .btn-lg { min-height: 56px; font-size: 1.15rem; padding: 14px 26px; }
.touch .form-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stage-info { background: var(--idle-bg); border-radius: 6px; padding: 10px 12px; margin: -2px 0 14px; font-weight: 600; }
.stage-info:empty { display: none; }

/* ------------------------------------------------------------------ tablet: icon-only side menu */
@media (max-width: 1100px) {
  .sidebar { width: var(--sidebar-mini); }
  .brand-text, .nav-item span, .nav-group { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .brand { justify-content: center; padding: 0; }
  .shell.nav-open .sidebar { width: var(--sidebar); position: fixed; box-shadow: 8px 0 24px rgba(0,0,0,.25); }
  .shell.nav-open .brand-text, .shell.nav-open .nav-item span, .shell.nav-open .nav-group { display: initial; }
  .shell.nav-open .nav-item { justify-content: flex-start; padding: 0 12px; }
  .shell.nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(15,25,40,.35); }
  .topbar .menu-btn { display: grid; }
}

/* ------------------------------------------------------------------ phone: off-canvas side menu */
@media (max-width: 700px) {
  html { font-size: 16px; }
  main { padding: 12px; }
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .18s; width: var(--sidebar); }
  .shell.nav-open .sidebar { transform: none; }
  .brand-text, .nav-item span, .nav-group { display: initial; }
  .nav-item { justify-content: flex-start; padding: 0 12px; }
  .user-name { display: none; }
  .btn-lg, .form-actions .btn { flex: 1 1 auto; justify-content: center; }
  .page-head .actions { width: 100%; }
  .kv { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------ photos / videos */
input[type=file][data-attach-preview] { width: 100%; min-height: var(--touch); padding: 10px; border: 2px dashed var(--line);
  border-radius: var(--radius); background: var(--bg); cursor: pointer; }
.attach-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attach-preview .pick { width: 96px; font-size: .78rem; color: var(--muted); overflow-wrap: anywhere; }
.attach-preview .pick img, .attach-preview .pick .vid { width: 96px; height: 72px; object-fit: cover; border-radius: 6px;
  background: var(--idle-bg); display: grid; place-items: center; }
.attach-preview .pick.too-big { color: var(--bad); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.tile { margin: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel);
  display: flex; flex-direction: column; }
.tile-media { display: block; width: 100%; aspect-ratio: 4 / 3; background: #10161f; }
.tile-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
video.tile-media { object-fit: contain; }
.tile-file { display: grid; place-items: center; align-content: center; gap: 6px; color: #fff; text-align: center; padding: 8px; }
.tile figcaption { padding: 8px 10px; display: grid; gap: 3px; }
.tile figcaption .btn-link { padding: 0; min-height: 0; color: var(--bad); }
.att-count { color: var(--muted); white-space: nowrap; }
@media (max-width: 700px) { .gallery { grid-template-columns: repeat(2, 1fr); gap: 8px; } }

/* ------------------------------------------------------------------ print */
@media print {
  .sidebar, .topbar, .no-print, .toasts, .tabs, .toolbar, .pagination { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .panel { border: 0; padding: 0; }
  th { position: static; }
}

/* Product type form: stages in order */
.stage-order-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.stage-order-list li { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.stage-order-no { min-width: 1.6em; color: var(--muted, #667); text-align: right; }
.stage-order-actions { margin-left: auto; display: flex; }
.stage-order-add { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
