/* NFI Warehouse System — interface styles
   Built for warehouse use: large tap targets, high contrast, dense tables,
   and no dependency on colour alone to convey status. */

:root {
  --bg:            #f4f6f8;
  --surface:       #ffffff;
  --border:        #d6dce3;
  --border-strong: #b3bcc7;
  --text:          #1a2028;
  --text-muted:    #5c6875;

  --brand:         #14532d;
  --brand-light:   #1d6b3c;
  --accent:        #0b5394;

  --ok:            #146c43;
  --ok-bg:         #e7f4ec;
  --warn:          #8a5a00;
  --warn-bg:       #fdf3e0;
  --danger:        #a02128;
  --danger-bg:     #fbeaeb;
  --info-bg:       #e8f0f9;

  --radius: 5px;
  --shadow: 0 1px 3px rgba(16, 24, 32, .09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

/* ---------------------------------------------------------------- topbar
   A slim strip carrying only what is true of the whole session: who is signed
   in, and which facility they are looking at. Navigation is in the sidebar. */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  background: var(--brand); color: #fff;
  padding: 10px 20px;
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-brand a { color: #fff; text-decoration: none; font-size: 17px; letter-spacing: .3px; }
.topbar-brand span { font-weight: 400; opacity: .85; }
.topbar-controls { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }

.inline-form { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

/* The facility selector is white-on-green because it sits on the brand bar.
   Scoped to .topbar so an .inline-form inside a card keeps normal field
   styling — unscoped, these rules bleed into content forms. */
.topbar .inline-form label {
  font-size: 12px; text-transform: uppercase; letter-spacing: .6px; opacity: .85;
}
.topbar .inline-form select {
  padding: 5px 9px; border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.12); color: #fff;
  font-size: 13px; min-width: 170px;
}
.topbar .inline-form select option { color: #1a2028; background: #fff; }

/* ----------------------------------------------------------------- shell
   Sidebar and content side by side under the topbar. min-width: 0 on the
   content column is what stops a wide table forcing the whole page sideways:
   a flex item's default min-width is its content, not zero. */
.shell {
  display: flex; align-items: flex-start;
  min-height: calc(100vh - 46px);
  /* The sidebar is sticky, so its element is only as tall as its links. This
     paints the column, keeping the green edge running the full height of a
     long page instead of stopping halfway down. */
  background: linear-gradient(to right,
              var(--brand-light) 0, var(--brand-light) 216px, transparent 216px);
}
.shell-main { flex: 1 1 auto; min-width: 0; }

/* --------------------------------------------------------------- sidebar */
.sidebar {
  flex: 0 0 216px; width: 216px;
  background: var(--brand-light); color: #fff;
  position: sticky; top: 0;
  align-self: flex-start;
  max-height: 100vh; overflow-y: auto;
  padding: 14px 0 22px;
  display: flex; flex-direction: column;
}

.sidebar-group { margin-bottom: 14px; }
.sidebar-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .9px;
  color: rgba(255,255,255,.55);
  padding: 6px 18px 5px;
  font-weight: 600;
}

.sidebar a {
  display: block;
  color: rgba(255,255,255,.86); text-decoration: none;
  padding: 8px 18px; font-size: 13.5px;
  border-left: 3px solid transparent;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.sidebar a:hover {
  background: rgba(0,0,0,.16); color: #fff;
  border-left-color: rgba(255,255,255,.35);
}
.sidebar a:focus-visible { outline: 2px solid #ffd166; outline-offset: -2px; }
.sidebar a.active {
  background: rgba(0,0,0,.26); color: #fff;
  border-left-color: #ffd166; font-weight: 600;
}

/* The facility repeated at the foot of the sidebar: on a long page the topbar
   has scrolled away, and "which site am I looking at" is the question most
   worth answering without scrolling back. */
.sidebar-foot {
  margin-top: auto; padding: 14px 18px 0;
  border-top: 1px solid rgba(255,255,255,.16);
  font-size: 11.5px; color: rgba(255,255,255,.6);
}

/* -------------------------------------------------------- sidebar toggle
   A checkbox, not a script: navigation must still open on a phone if the
   JavaScript fails to load. Visually hidden but focusable. */
.nav-toggle-state {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden;
}
.nav-toggle {
  display: none;                 /* desktop: the sidebar is always present */
  align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.10); color: #fff;
  font-size: 13px; cursor: pointer; user-select: none;
}
.nav-toggle:hover { background: rgba(255,255,255,.18); }
.nav-toggle-state:focus-visible + .topbar .nav-toggle {
  outline: 2px solid #ffd166; outline-offset: 2px;
}
.nav-toggle-bars {
  width: 16px; height: 2px; background: #fff; position: relative; display: block;
}
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: ''; position: absolute; left: 0; width: 16px; height: 2px; background: #fff;
}
.nav-toggle-bars::before { top: -5px; }
.nav-toggle-bars::after  { top: 5px; }

/* ------------------------------------------------------------------ page */
.page { max-width: 1400px; margin: 0 auto; padding: 22px 20px 60px; }

h1 { font-size: 21px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 16px; margin: 26px 0 10px; font-weight: 600; }
h3 { font-size: 14px; margin: 18px 0 8px; font-weight: 600; color: var(--text-muted);
     text-transform: uppercase; letter-spacing: .5px; }
.page-sub { color: var(--text-muted); margin: 0 0 20px; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 18px;
}
.card-tight { padding: 0; overflow: hidden; }
.card-head {
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: #fafbfc; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* ----------------------------------------------------------------- stats */
.stat { background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px; color: var(--text-muted); }
.stat-value { font-size: 26px; font-weight: 600; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat-note  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-alert .stat-value { color: var(--danger); }
.stat-warn  .stat-value { color: var(--warn); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 9px 12px; background: #f0f3f6;
  border-bottom: 2px solid var(--border-strong);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted);
  white-space: nowrap;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:hover { background: #f7f9fb; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: "Cascadia Mono", Consolas, "SF Mono", monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.muted { color: var(--text-muted); }
.empty { padding: 34px 18px; text-align: center; color: var(--text-muted); }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 11px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .3px; white-space: nowrap;
}
.badge-ok      { background: var(--ok-bg);     color: var(--ok); }
.badge-warn    { background: var(--warn-bg);   color: var(--warn); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: #eceff2;          color: var(--text-muted); }
.badge-info    { background: var(--info-bg);   color: var(--accent); }

/* ----------------------------------------------------------------- forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted);
               text-transform: uppercase; letter-spacing: .4px; }
input[type=text], input[type=number], input[type=date], input[type=password],
input[type=month], select, textarea {
  width: 100%; padding: 8px 10px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
textarea { min-height: 62px; resize: vertical; }
.field-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 3px; font-weight: 400; text-transform: none; letter-spacing: 0; }

.check { display: flex; align-items: center; gap: 8px; padding: 7px 0; }
.check input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--brand); }
.check label { margin: 0; text-transform: none; letter-spacing: 0; font-size: 13.5px; color: var(--text); font-weight: 400; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-block; padding: 8px 16px; font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; border-radius: var(--radius);
  cursor: pointer; text-decoration: none; font-family: inherit; line-height: 1.4;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-light); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: #f0f3f6; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* ---------------------------------------------------------------- flash */
.flash { padding: 11px 16px; border-radius: var(--radius); margin-bottom: 18px;
         border-left: 4px solid; font-size: 13.5px; }
.flash-success { background: var(--ok-bg);     border-color: var(--ok);     color: var(--ok); }
.flash-error   { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.flash-warn    { background: var(--warn-bg);   border-color: var(--warn);   color: var(--warn); }
.flash-info    { background: var(--info-bg);   border-color: var(--accent); color: var(--accent); }

/* ------------------------------------------------------------ line items */
.lines-table input, .lines-table select { padding: 6px 8px; font-size: 13px; }
.lines-table td { padding: 5px 6px; }
.line-remove { background: none; border: none; color: var(--danger); cursor: pointer;
               font-size: 17px; padding: 0 6px; line-height: 1; }

/* ------------------------------------------------------------------ misc */
.notice {
  background: var(--info-bg); border-left: 4px solid var(--accent);
  padding: 11px 15px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px;
}
.notice-warn { background: var(--warn-bg); border-color: var(--warn); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13.5px; }
.kv dt { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.kv dd { margin: 0; }

/* trace tree */
.tree { list-style: none; padding-left: 0; margin: 0; }
.tree ul { list-style: none; margin: 6px 0 0; padding-left: 26px; border-left: 2px solid var(--border); }
.tree li { padding: 7px 0; position: relative; }
.tree ul li::before {
  content: ""; position: absolute; left: -26px; top: 18px;
  width: 18px; height: 2px; background: var(--border);
}
.tree-node { background: var(--surface); border: 1px solid var(--border);
             border-radius: var(--radius); padding: 9px 13px; display: inline-block; min-width: 320px; }
.tree-node strong { font-size: 13.5px; }
.tree-detail { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }

.balance-row { display: flex; gap: 26px; flex-wrap: wrap; padding: 13px 16px;
               background: #f0f3f6; border-radius: var(--radius); margin-top: 12px; }
.balance-item .stat-label { font-size: 11px; }
.balance-item .stat-value { font-size: 19px; }

/* ---------------------------------------------------------------- footer */
.footer {
  border-top: 1px solid var(--border); padding: 16px 20px;
  color: var(--text-muted); font-size: 12px; text-align: center; background: var(--surface);
  display: flex; flex-direction: column; gap: 3px;
}
.footer-note { opacity: .8; }

@media print {
  .topbar, .mainnav, .sidebar, .nav-toggle, .footer, .btn-row, .no-print {
    display: none !important;
  }
  .shell { display: block; background: none; min-height: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #999; break-inside: avoid; }
}

/* ------------------------------------------------------- signed-in user */
.topbar-user { display: flex; align-items: center; gap: 11px; font-size: 13px; }
.topbar-user-name { font-weight: 600; }
.topbar-user a { color: rgba(255,255,255,.9); text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.35); }
.topbar-user a:hover { color: #fff; border-bottom-color: #fff; }
.topbar-user .badge { background: rgba(255,255,255,.18); color: #fff; }

/* --------------------------------------------------------------------------
   Warehouse floor plan (DOC §6)
   A rack is drawn the way it stands: sections across, levels up, ground level
   at the bottom of the grid rather than the top of the table.
   -------------------------------------------------------------------------- */
.rack-grid { width: 100%; border-collapse: separate; border-spacing: 4px; }
.rack-grid th {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-align: center; padding: 2px 4px; white-space: nowrap;
}
.rack-grid tbody th { text-align: right; }
.rack-grid td { padding: 0; }

.pos {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 1px; min-height: 52px; padding: 5px 4px; border-radius: 5px;
  border: 1px solid var(--border); text-decoration: none; font-size: 10px;
  line-height: 1.25; text-align: center; overflow: hidden;
}
.pos strong { font-size: 11px; }
.pos span { display: block; }
.pos-free { color: var(--text-muted); border-style: dashed; }
.pos-free:hover { border-color: var(--accent); color: var(--accent); }
.pos-full { background: var(--accent-soft, rgba(59,130,246,.10)); color: var(--text); }
.pos-full:hover { border-color: var(--accent); }

.inline-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { max-width: 170px; }

/* -------------------------------------------------------------- responsive
   Below 900px the sidebar stops being a column and becomes a panel dropping
   out of the topbar, so a tablet in portrait does not lose a third of its
   width to navigation. */
@media (max-width: 900px) {
  .shell { display: block; background: none; min-height: 0; }

  /* A warehouse tap target, not a mouse one — 44px is the minimum a gloved
     hand hits reliably. */
  .nav-toggle { display: inline-flex; padding: 11px 13px; min-height: 44px; }

  .sidebar {
    display: none;
    position: static;
    width: auto; max-width: none; flex: none;
    /* A dropdown, not a takeover: the page stays partly visible behind it. */
    max-height: 70vh; overflow-y: auto;
    padding: 10px 0 14px;
    border-bottom: 3px solid rgba(0,0,0,.25);
    box-shadow: var(--shadow);
  }
  .nav-toggle-state:checked ~ .shell .sidebar { display: block; }

  /* Two columns on a tablet: sixteen stacked entries is a long scroll before
     the page itself begins. Grid rather than inline-block, because the
     whitespace between inline-blocks makes two 50% items wrap. */
  .sidebar-group {
    margin-bottom: 6px;
    display: grid; grid-template-columns: 1fr 1fr;
  }
  .sidebar a { padding: 11px 18px; }
  .sidebar-group-label { grid-column: 1 / -1; padding-bottom: 2px; }
  .sidebar-foot { display: none; }

  .topbar { padding: 9px 14px; gap: 10px; }
  .topbar-controls { gap: 12px; width: 100%; justify-content: space-between; }
  .page { padding: 16px 14px 40px; }
}

@media (max-width: 560px) {
  .sidebar-group { grid-template-columns: 1fr; }
  .topbar-user { flex-wrap: wrap; gap: 8px; }
  .topbar .inline-form select { min-width: 0; width: 100%; }
  .topbar .inline-form { width: 100%; }
  .nav-toggle-text { display: none; }
}

/* ---------------------------------------------------------------------------
   Ask AI
   Deliberately small: an input, an answer, a source badge and a table. The
   question box and its button sit on one line, because a question here is one
   sentence, not a paragraph.
   ------------------------------------------------------------------------ */

.ask-card { padding: 14px; }

.ask-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.ask-input {
  flex: 1 1 auto;
  min-width: 0;
  resize: vertical;
  font: inherit;
  line-height: 1.45;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: inherit;
}
.ask-input:focus {
  outline: none;
  border-color: #2f6f4e;
  box-shadow: 0 0 0 3px rgba(47, 111, 78, .14);
}

.ask-button {
  flex: 0 0 auto;
  align-self: stretch;
  padding: 0 26px;
  font-weight: 600;
}

.ask-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* Rounded pills, at reading size rather than fine print — these are meant to
   be scanned and clicked, not squinted at. */
.ask-chip {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f6f7f5;
  font-size: 13.5px;
  line-height: 1.3;
  color: #33453b;
  text-decoration: none;
}
.ask-chip:hover {
  background: #eaf1ec;
  border-color: #9dbcab;
  color: #1f4634;
}

.ask-answer {
  padding: 14px;
  font-size: 15.5px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.ask-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 14px;
}

@media (max-width: 560px) {
  .ask-row { flex-direction: column; }
  .ask-button { align-self: flex-end; padding: 10px 26px; }
}
