/* ─────────────────────────────────────────────────────────────────────────
   KS Spinning Mills — shared UI components (blocky system, spec 2026-10-05).
   Square, ink rules, colour only for meaning. Mounted after shared.css and
   mobile.css from base.html so it wins over both.
   Breakpoints: phone ≤768px (mobile.css), wide ≥1024px (layouts below).
   ───────────────────────────────────────────────────────────────────────── */

/* ── STAMPS (were pills) ───────────────────────────────────────────────── */
.stamp, .pill {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.1rem 0.4rem;
    border: 2px solid currentColor; border-radius: 0;
    background: #fff;
    font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700;
    letter-spacing: 0.5px; text-transform: uppercase; line-height: 1.35; white-space: nowrap;
    color: var(--ink);
}
.stamp.ok,   .pill-done, .pill-ok     { color: var(--ok); }
.stamp.need, .pill-pending, .pill-skip { color: #8a6414; background: var(--need-bg); }
.stamp.low,  .pill-warn, .pill-err    { color: var(--low); background: var(--low-bg); }
.stamp.ai,   .pill-info               { color: var(--ai); background: var(--ai-bg); }
.stamp.ink,  .pill-active             { color: #fff; background: var(--ink); border-color: var(--ink); }
.pill-icon { min-width: 24px; justify-content: center; padding: 0.1rem 0.3rem; }

/* ── BUTTONS ───────────────────────────────────────────────────────────── */
.btn-primary-action, .btn-secondary-action, .btn-destructive, .btn-plain {
    border: 2px solid var(--ink); border-radius: 0;
    font-family: var(--font-body); font-weight: 700; letter-spacing: 0.2px; text-transform: none;
    padding: 0.6rem 1.1rem; min-height: 48px;
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    cursor: pointer; box-shadow: none; transition: background 0.12s, color 0.12s;
}
.btn-primary-action { background: var(--ks-lime); color: var(--ink); }
.btn-primary-action:hover:not(:disabled) { background: #72c436; color: var(--ink); }
.btn-secondary-action, .btn-plain { background: #fff; color: var(--ink); }
.btn-secondary-action:hover:not(:disabled), .btn-plain:hover:not(:disabled) { background: #f3f5f7; color: var(--ink); }
.btn-destructive { background: #fff; color: var(--low); border-color: var(--low); }
.btn-destructive:hover:not(:disabled) { background: var(--low); color: #fff; }
.btn-primary-action:disabled, .btn-secondary-action:disabled, .btn-destructive:disabled, .btn-plain:disabled {
    background: var(--steel-light); color: var(--ks-text-light); border-color: var(--steel); cursor: not-allowed;
}
.btn-block { display: flex; width: 100%; }
.btn-inline { min-height: 44px; padding: 0.25rem 0.7rem; font-size: 0.8rem; border-radius: 0; }
.btn-link { border: 0; background: none; color: var(--ai); font-weight: 700; padding: 0 0.3rem;
    min-height: 44px; cursor: pointer; text-decoration: none; }
.btn-link:hover { text-decoration: underline; }

/* ── ICONS ─────────────────────────────────────────────────────────────── */
.icon { display: inline-block; font-size: 1.05em; line-height: 1; vertical-align: -1px; margin-right: 0.1em; }
.icon-only { font-size: 1.3em; vertical-align: middle; }

/* ── EMPTY STATES ──────────────────────────────────────────────────────── */
.hint-empty { font-size: 0.85rem; color: var(--ks-text-light); padding: 0.7rem 0.9rem; border-radius: 0;
    background: #fff; border: 1px dashed var(--steel); margin: 0.4rem 0; }
.list-footer { font-size: 0.72rem; color: var(--ks-text-light); text-align: right; padding: 0.4rem 0.2rem 0;
    font-family: var(--font-mono); letter-spacing: 0.4px; }
.heading-sub { font-weight: 400; color: var(--ks-text-light); }

/* ── BOARD: tab bar that carries the page's counts ────────────────────── */
.board { display: grid; grid-template-columns: repeat(var(--board-cols, 4), minmax(0, 1fr));
    border: var(--rule); background: #fff; margin-bottom: 16px; }
.board > button, .board > a, .board > div { position: relative; text-align: left; background: #fff; border: 0;
    border-right: var(--rule); padding: 0.7rem 0.9rem 0.8rem; cursor: pointer; color: var(--ink);
    min-height: 88px; text-decoration: none; display: block; }
.board > :last-child { border-right: 0; }
.board .t { font-weight: 700; font-size: 0.95rem; }
.board .t .hi { font-family: 'Hind', sans-serif; font-weight: 300; margin-left: 0.3rem; }
.board .n { font-family: var(--font-mono); font-weight: 700; font-size: 2rem; line-height: 1.05; margin-top: 0.25rem; }
.board .c { font-size: 0.78rem; color: var(--ks-text-light); }
.board .flag-need .n { color: var(--need); }
.board .flag-low .n { color: var(--low); }
.board .on { background: var(--ink); color: #fff; }
.board .on .c { color: #c9d1d8; }
.board .on::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: var(--ks-lime); }
.board .on.flag-need .n { color: #f0c15a; }
.board .on.flag-low .n { color: #ff8a80; }

/* ── PANEL ─────────────────────────────────────────────────────────────── */
.panel { background: #fff; border: var(--rule); border-radius: 0; margin-bottom: 16px; }
.panel-h { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem;
    padding: 0.7rem 0.9rem; border-bottom: var(--rule); }
.panel-h h2, .panel-h h5 { font-family: var(--font-body); font-size: 1.05rem; font-weight: 700; margin: 0;
    color: var(--ink); text-transform: none; letter-spacing: 0; }
.panel-h .meta { font-size: 0.82rem; color: var(--ks-text-light); }
.panel-b { padding: 0.9rem; }

/* ── SPLIT: side list + main detail on wide screens ───────────────────── */
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.split > .side, .split > .main { min-width: 0; }
@media (min-width: 1024px) {
    .split { grid-template-columns: var(--side, 340px) minmax(0, 1fr); }
    .split.side-right { grid-template-columns: minmax(0, 1fr) var(--side, 340px); }
    .split.side-right > .side { order: 2; }
}
@media (max-width: 1023px) {
    .split.phone-swap.has-sel > .side { display: none; }
    .split.phone-swap:not(.has-sel) > .main { display: none; }
}

/* ── DATA GRID: list rows that are a table in all but name ────────────── */
.dgrid { background: #fff; }
.dgrid-head, .dgrid-row { display: grid; grid-template-columns: var(--cols, minmax(0, 1fr));
    gap: 0 0.8rem; align-items: center; padding: 0.5rem 0.9rem; }
.dgrid-head { font-size: 0.74rem; font-weight: 700; color: var(--ks-text-light);
    border-bottom: var(--rule); background: #f3f5f7; }
.dgrid-row { border-bottom: 1px solid var(--steel-light); border-left: 6px solid transparent; }
.dgrid-row.need { border-left-color: var(--need); background: var(--need-bg); }
.dgrid-row.low  { border-left-color: var(--low);  background: var(--low-bg); }
.dgrid-row.ok   { border-left-color: var(--ok); }
.dgrid-row.sel  { background: #f3f5f7; box-shadow: inset -5px 0 0 var(--ink); }
.dgrid .num, .dgrid .r { font-family: var(--font-mono); text-align: right; }
@media (max-width: 768px) { .dgrid-head { display: none; } }

/* ── FILTER BLOCKS (were chips / segmented toggles) ───────────────────── */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    border-top: var(--rule); border-left: var(--rule); margin-bottom: 12px; }
.filters > button { border: 0; border-right: var(--rule); border-bottom: var(--rule); background: #fff;
    text-align: left; padding: 0.45rem 0.6rem; cursor: pointer; color: var(--ink); min-height: 56px; }
.filters .fn { font-size: 0.78rem; font-weight: 700; display: block; }
.filters .fc { font-family: var(--font-mono); font-weight: 700; font-size: 1.1rem; }
.filters .low .fc { color: var(--low); }
.filters .on { background: var(--ink); color: #fff; }
.filters .on.low .fc { color: #ff8a80; }

/* ── GAUGE: 10 blocks against twice a reference; 5th edge marks it ────── */
.gauge { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; height: 16px; position: relative; }
.gauge i { background: var(--steel-light); }
.gauge i.f { background: var(--ok); }
.gauge.low i.f { background: var(--low); }
.gauge::after { content: ''; position: absolute; left: calc(50% - 1px); top: -3px; bottom: -3px; width: 2px; background: var(--ink); }

/* ── STATE CARDS (QC bill lines, lot picker, dispatch DN) ─────────────── */
.state-card { border: 2px solid var(--steel); border-left-width: 6px; border-radius: 0; background: #fff;
    padding: 0.65rem 0.85rem; margin-bottom: 0.5rem; cursor: pointer;
    display: flex; flex-direction: column; gap: 0.3rem; transition: border-color 0.12s, background 0.12s; }
.state-card:hover { border-color: var(--ink); }
.state-card[data-state="active"] { border-color: var(--ink); border-left-color: var(--need); background: var(--need-bg); }
.state-card[data-state="active"] .state-card-title { font-weight: 700; color: var(--ink); }
.state-card[data-state="done"] { border-color: var(--steel-light); border-left-color: var(--ok); cursor: default; pointer-events: none; }
.state-card[data-state="done"] .state-card-title { color: #6c7a83; text-decoration: line-through; }
.state-card-title { font-size: 0.95rem; color: var(--ink); font-weight: 600; }
.state-card-meta { font-family: var(--font-mono); font-size: 0.74rem; color: var(--ks-text-light); }

/* ── PIPELINE ──────────────────────────────────────────────────────────── */
ol.pipeline { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; counter-reset: pipe-step;
    background: #fff; border: var(--rule); border-radius: 0; overflow: hidden; }
ol.pipeline > li { counter-increment: pipe-step; flex: 1; padding: 0.7rem 0.5rem; text-align: center;
    font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--ks-text-light); background: #fff; border-right: var(--rule); position: relative; line-height: 1.2; }
ol.pipeline > li:last-child { border-right: 0; }
ol.pipeline > li::before { content: counter(pipe-step); display: inline-block; width: 22px; height: 22px;
    border-radius: 0; background: var(--steel-light); color: var(--ink); font-family: var(--font-mono);
    font-weight: 700; line-height: 22px; margin-right: 0.4rem; font-size: 0.78rem; }
ol.pipeline[data-step="1"] > li:nth-child(-n+1), ol.pipeline[data-step="2"] > li:nth-child(-n+2),
ol.pipeline[data-step="3"] > li:nth-child(-n+3), ol.pipeline[data-step="4"] > li:nth-child(-n+4) { color: var(--ink); }
ol.pipeline[data-step="1"] > li:nth-child(-n+1)::before, ol.pipeline[data-step="2"] > li:nth-child(-n+2)::before,
ol.pipeline[data-step="3"] > li:nth-child(-n+3)::before, ol.pipeline[data-step="4"] > li:nth-child(-n+4)::before {
    background: var(--ks-lime); color: var(--ink); }
ol.pipeline[data-step="1"] > li:nth-child(1), ol.pipeline[data-step="2"] > li:nth-child(2),
ol.pipeline[data-step="3"] > li:nth-child(3), ol.pipeline[data-step="4"] > li:nth-child(4) {
    background: var(--ink); color: #fff; box-shadow: inset 0 -5px 0 var(--ks-lime); }

/* ── ADMIN MODAL (shared; was copied into gate, qc, sales) ────────────── */
/* Markup: .admin-modal > .admin-modal-backdrop + .admin-modal-card >
   .admin-modal-head (+ .admin-modal-close) + content. Pages open it with
   style.display = 'flex' and close it with 'none'. */
.admin-modal { position: fixed; inset: 0; z-index: 1050;
    display: none; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; }
.admin-modal.open, .admin-modal.show, .admin-modal[open] { display: flex; }
.admin-modal-backdrop { position: fixed; inset: 0; background: rgba(26,32,40,0.6); }
.admin-modal-card { position: relative; background: #fff; border: var(--rule); border-radius: 0; width: 100%; max-width: 640px;
    padding: 0 0.9rem 0.9rem; box-shadow: var(--shadow-lg); }
.admin-modal-head { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem;
    margin: 0 -0.9rem 0.9rem; padding: 0.7rem 0.9rem; border-bottom: var(--rule); font-weight: 700; color: var(--ink); }
.admin-modal-close { min-width: 44px; min-height: 44px; border: 2px solid var(--ink); border-radius: 0; background: #fff;
    color: var(--ink); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.admin-modal-close:hover { background: var(--ink); color: #fff; }
.admin-modal-body { padding: 0; }
.admin-modal-foot { display: flex; justify-content: flex-end; gap: 0.6rem; margin: 0.9rem -0.9rem -0.9rem;
    padding: 0.7rem 0.9rem; border-top: var(--rule); }

/* ── MOBILE TWEAKS ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .btn-primary-action, .btn-secondary-action, .btn-destructive, .btn-plain { font-size: 0.95rem; padding: 0.6rem 0.9rem; }
    .stamp, .pill { font-size: 0.64rem; }
    ol.pipeline > li { padding: 0.55rem 0.3rem; font-size: 0.65rem; letter-spacing: 0.3px; }
    ol.pipeline > li::before { width: 18px; height: 18px; line-height: 18px; font-size: 0.7rem; margin-right: 0.25rem; }
    .state-card { padding: 0.6rem 0.7rem; }
    .board .n { font-size: 1.5rem; }
    .board > button, .board > a, .board > div { padding: 0.5rem 0.4rem 0.65rem; min-height: 74px; }
    .board .t { font-size: 0.78rem; }
    .board .t .hi { display: block; margin-left: 0; }
    .board .c { display: none; }
}
@media (max-width: 420px) {
    ol.pipeline > li { font-size: 0.6rem; }
    ol.pipeline > li::before { display: block; margin: 0 auto 0.25rem; }
    .btn-primary-action, .btn-secondary-action, .btn-destructive, .btn-plain { font-size: 0.9rem; padding: 0.6rem 0.7rem; }
}
@media (min-width: 769px) {
    ol.pipeline > li { font-size: 0.78rem; padding: 0.85rem 0.5rem; }
    ol.pipeline > li::before { width: 26px; height: 26px; line-height: 26px; font-size: 0.85rem; }
}

/* ── TAP TARGETS (matches the e2e viewport assertion; loads last) ─────── */
.btn, .btn-sm, .btn-lg, .btn-secondary-action, .btn-inline, .btn-link, .remove-btn { min-height: 44px; }
