/* NIYS ERP — mobile-first. The warehouse floor is a phone; the office is a desktop.
   Every interactive target is >= 44px so it is usable with a thumb and a barcode gun. */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-dim: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }

a { color: var(--primary); text-decoration: none; }

/* ---------------------------------------------------------------- shell */

.app-shell { min-height: 100vh; }

.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h);
  display: flex; align-items: center; gap: .5rem;
  padding: 0 .75rem;
  background: #0f172a; color: #fff; z-index: 60;
}

.brand { display: flex; align-items: center; gap: .55rem; color: #fff; font-weight: 600; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: .9rem;
}
.brand-text { font-size: 1rem; letter-spacing: .02em; }
.brand-dim { opacity: .55; margin-left: 2px; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.who { font-size: .8rem; opacity: .75; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  min-width: 44px; min-height: 44px; display: grid; place-items: center;
  background: transparent; border: 0; color: inherit; cursor: pointer; border-radius: 8px;
}
.icon-btn:hover { background: rgba(255,255,255,.1); }

.burger, .burger::before, .burger::after {
  display: block; width: 18px; height: 2px; background: currentColor; border-radius: 2px;
}
.burger { position: relative; }
.burger::before, .burger::after { content: ""; position: absolute; left: 0; }
.burger::before { top: -6px; }
.burger::after { top: 6px; }

.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  padding: .5rem 0 2rem; overflow-y: auto; z-index: 50;
  transform: translateX(-100%); transition: transform .18s ease;
}
.sidebar-open .sidebar { transform: translateX(0); }

.nav-item {
  display: flex; align-items: center; gap: .6rem;
  min-height: 44px; padding: 0 1rem; color: var(--text);
  border-left: 3px solid transparent; font-size: .92rem;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: #eff6ff; border-left-color: var(--primary); color: var(--primary-dark); font-weight: 600; }
.nav-ico { width: 1.1rem; text-align: center; opacity: .7; }
.nav-section {
  padding: 1rem 1rem .35rem; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-dim); font-weight: 700;
}

.scrim { display: none; }
.sidebar-open .scrim {
  display: block; position: fixed; inset: var(--topbar-h) 0 0 0;
  background: rgba(15,23,42,.45); z-index: 40;
}

.content { padding: calc(var(--topbar-h) + 1rem) 1rem 5rem; }

@media (min-width: 900px) {
  .sidebar { transform: translateX(0); }
  /* The topbar stays fixed at every width, so the content offset must not be dropped here —
     otherwise the page heading sits underneath it. */
  .content {
    margin-left: var(--sidebar-w);
    padding: calc(var(--topbar-h) + 1.5rem) 1.75rem 4rem;
  }
  .scrim { display: none !important; }
  .topbar .icon-btn:first-child { display: none; }
  .who { max-width: none; }
}

/* ---------------------------------------------------------------- page furniture */

.page-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem;
}
.page-head .spacer { flex: 1; }
.subtitle { color: var(--text-dim); font-size: .85rem; margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem;
}
.card-title { font-weight: 600; margin: 0 0 .75rem; font-size: .95rem; }

/* ---------------------------------------------------------------- tiles */

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .85rem; box-shadow: var(--shadow);
}
.tile-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); font-weight: 700; }
.tile-value { font-size: 1.4rem; font-weight: 700; margin-top: .2rem; }
.tile-hint { font-size: .75rem; color: var(--text-dim); }
.tile.ok .tile-value { color: var(--ok); }
.tile.warn .tile-value { color: var(--warn); }
.tile.danger .tile-value { color: var(--danger); }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -.25rem; }

table.data { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.data th {
  text-align: left; padding: .55rem .6rem; border-bottom: 2px solid var(--border);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); white-space: nowrap;
}
table.data td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Codes and SKUs must not break mid-token: the table already scrolls sideways, so wrapping
   just makes a barcode harder to read. */
table.data .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .82rem; white-space: nowrap; }

/* ---------------------------------------------------------------- forms */

.field { margin-bottom: .85rem; }
.field label { display: block; font-size: .78rem; font-weight: 600; margin-bottom: .25rem; color: #334155; }
.field .hint { font-size: .72rem; color: var(--text-dim); margin-top: .2rem; }

input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], input[type=email], input, select, textarea {
  width: 100%; min-height: 44px; padding: .5rem .65rem;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
  font-size: .95rem; font-family: inherit; color: var(--text);
}
input[type=checkbox], input[type=radio]{
  min-width: 25px; min-height:25px; width: 25px; height:25px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
textarea { min-height: 80px; }

.form-grid { display: grid; gap: 0 .75rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-grid .full { grid-column: 1 / -1; }

.inline-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.inline-form .field { margin-bottom: 0; flex: 1 1 150px; }

/* Below ~520px two side-by-side fields squeeze the placeholder text; stack them instead. */
@media (max-width: 519px) {
  .inline-form .field { flex: 1 1 100%; }
  .inline-form > .btn { flex: 1 1 100%; }
}

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: 0 1rem; border-radius: 8px; border: 1px solid transparent;
  font-size: .9rem; font-weight: 600; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
/* Destructive actions inside repeated table rows read as a wall of red if filled. Outline
   keeps them identifiable but quiet; they fill only on hover. */
.btn-ghost-danger {
  background: transparent; color: var(--danger);
  border-color: #fecaca; font-weight: 500;
}
.btn-ghost-danger:hover:not(:disabled) { background: #fef2f2; border-color: #fca5a5; }
.btn-sm { min-height: 36px; padding: 0 .65rem; font-size: .82rem; }
.btn-block { width: 100%; }

/* Row actions sit in a table cell; keep them from crowding the value they follow. */
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }
table.data tr.row-variance { background: #fffdf5; }

.row-actions { display: flex; gap: .35rem; justify-content: flex-end; white-space: nowrap; }

/* Replaces the native file control, which ignores the design system entirely. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.file-trigger {
  display: inline-flex; align-items: center; justify-content: center;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.file-trigger:hover { background: var(--surface-2); }

/* ---------------------------------------------------------------- searchable select
   A native <select> holding hundreds of products is unusable on a phone, and rendering
   one per table row is expensive. This is a text box plus a short list of matches. */

.ss { position: relative; min-width: 200px; }

.ss-control { position: relative; display: flex; align-items: center; }

.ss-input {
  width: 100%; min-height: 44px; padding: .5rem 2rem .5rem .65rem;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
  font-size: .9rem; font-family: inherit; color: var(--text);
}
.ss-input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.ss-input:disabled { background: var(--surface-2); }

.ss-clear {
  position: absolute; right: 4px; width: 32px; height: 32px;
  display: grid; place-items: center; border: 0; border-radius: 6px;
  background: transparent; color: var(--text-dim); font-size: 1.2rem; cursor: pointer;
}
.ss-clear:hover { background: var(--surface-2); color: var(--text); }

.ss-menu {
  position: absolute; z-index: 200; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 260px; overflow-y: auto; overscroll-behavior: contain;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .16);
}

.ss-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  width: 100%; min-height: 44px; padding: .45rem .65rem;
  border: 0; background: transparent; text-align: left; cursor: pointer; font-family: inherit;
}
.ss-option:hover, .ss-option.highlighted { background: #eff6ff; }
.ss-option-text { font-size: .88rem; color: var(--text); }
.ss-option-sub {
  font-size: .74rem; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

.ss-status { padding: .7rem .65rem; font-size: .82rem; color: var(--text-dim); }

/* ---------------------------------------------------------------- unmapped SKU queue
   Cards rather than a table: this is a work queue, and the product picker has to be
   reachable on a phone without scrolling sideways. */

.queue {
  display: grid; gap: .75rem;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.queue-item {
  display: flex; flex-direction: column; gap: .4rem;
  padding: .75rem; border: 1px solid var(--border); border-radius: 10px; background: #fff;
}
.queue-item:has(.ss-input:focus) { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

.queue-head { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.queue-sku {
  font-size: .88rem; font-weight: 600; color: var(--primary-dark);
  word-break: break-word; flex: 1 1 100%;
}
.queue-listing { font-size: .85rem; color: var(--text); }

.queue-meta {
  display: flex; flex-wrap: wrap; gap: .75rem;
  font-size: .76rem; color: var(--text-dim); font-variant-numeric: tabular-nums;
}

.queue-pick { display: flex; align-items: flex-start; gap: .5rem; margin-top: .25rem; }
.queue-pick .ss { flex: 1 1 auto; }
.queue-map { flex: 0 0 auto; }

@media (max-width: 519px) {
  .queue { grid-template-columns: 1fr; }
  .queue-pick { flex-direction: column; align-items: stretch; }
  .queue-map { width: 100%; }
}

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  font-size: .7rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
}
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-approved { background: #dbeafe; color: #1d4ed8; }
.badge-posted { background: #d1fae5; color: #047857; }
.badge-cancelled, .badge-rejected { background: #fee2e2; color: #b91c1c; }
.badge-pendingapproval { background: #fef3c7; color: #b45309; }
.badge-ok { background: #d1fae5; color: #047857; }
.badge-warn { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }

/* ---------------------------------------------------------------- states */

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-dim); }
.loading-full { display: flex; align-items: center; justify-content: center; gap: .6rem; padding: 3rem; color: var(--text-dim); }

.spinner {
  width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert { padding: .75rem .9rem; border-radius: 8px; font-size: .87rem; margin-bottom: .85rem; border: 1px solid; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert ul { margin: .35rem 0 0; padding-left: 1.1rem; }

/* ---------------------------------------------------------------- scan field */

.scanbar { display: flex; gap: .5rem; align-items: stretch; }
.scanbar input { font-family: ui-monospace, Consolas, monospace; font-size: 1rem; letter-spacing: .02em; }
.scanbar .btn { flex: 0 0 auto; }

.scan-status { font-size: .8rem; margin-top: .3rem; }
.scan-status.ok { color: var(--ok); }
.scan-status.err { color: var(--danger); }
.scan-hint { font-size: .72rem; color: var(--text-dim); margin-top: .2rem; }

/* Suggestions under the scan box. Shares the picker's look so the two product pickers read
   as the same control. Each row is a full-height tap target for the warehouse handheld. */
.scan-menu { border: 1px solid var(--border); border-radius: 8px; max-height: 300px; overflow-y: auto; margin-top: .35rem; background: #fff; box-shadow: 0 6px 18px rgba(15, 23, 42, .12); }
.scan-item { display: flex; align-items: baseline; gap: .5rem; width: 100%; text-align: left; min-height: 44px; padding: .5rem .7rem; border: 0; border-bottom: 1px solid var(--border); background: none; cursor: pointer; font-size: .9rem; }
.scan-item:last-child { border-bottom: 0; }
.scan-item:hover, .scan-item.active { background: #eff6ff; }
.scan-item .mono { font-family: ui-monospace, Consolas, monospace; color: var(--primary-dark); flex: 0 0 auto; }
.scan-item .dim { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-item .hint { margin-left: auto; flex: 0 0 auto; }

.picker-list { border: 1px solid var(--border); border-radius: 8px; max-height: 260px; overflow-y: auto; margin-top: .5rem; background: #fff; }
.picker-item { display: block; width: 100%; text-align: left; padding: .55rem .7rem; border: 0; background: none; cursor: pointer; border-bottom: 1px solid var(--border); }
.picker-item:last-child { border-bottom: 0; }
.picker-item:hover { background: #eff6ff; }
.picker-item .code { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; color: var(--primary-dark); }

/* ---------------------------------------------------------------- login */

.login-wrap { min-height: 100vh; display: grid; place-items: center; background: #0f172a; padding: 1.25rem; }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 1.75rem; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-card h1 { margin-bottom: .2rem; }
.login-card .subtitle { margin-bottom: 1.25rem; }

/* ---------------------------------------------------------------- sticky action bar */

.actionbar {
  position: sticky; bottom: 0; margin: 1rem -1rem -5rem; padding: .75rem 1rem;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; gap: .6rem; flex-wrap: wrap; z-index: 20;
}
@media (min-width: 900px) { .actionbar { margin: 1rem 0 0; border-radius: var(--radius); border: 1px solid var(--border); } }
.actionbar .spacer { flex: 1; }