/* ==========================================================================
   Client portal
   ========================================================================== */

/* ---------- Login / password screens ------------------------------------ */
.plogin {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 40px 20px; background: var(--ink);
  background-image: linear-gradient(rgba(12,14,16,.9), rgba(12,14,16,.94)), url('/assets/img/band-trucks.jpg');
  background-size: cover; background-position: center;
}
.plogin__card {
  width: 100%; max-width: 430px; background: #fff; padding: 42px 38px 34px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.plogin__brand { display: flex; align-items: center; gap: 12px; margin-bottom: 30px; }
.plogin__brand:hover { text-decoration: none; }
.plogin__brand strong { display: block; color: var(--ink); font-size: 1.5rem; line-height: 1; }
.plogin__brand em {
  display: block; font-style: normal; color: var(--muted);
  font-size: .58rem; letter-spacing: .2em; margin-top: 4px;
}
.plogin h1 { font-size: 1.6rem; margin-bottom: .3em; }
.plogin__sub { color: var(--muted); font-size: .92rem; margin-bottom: 26px; }
.plogin__help { margin: 22px 0 0; font-size: .84rem; color: var(--muted); text-align: center; }

/* ---------- Shell ------------------------------------------------------- */
.portal { display: flex; min-height: 100vh; background: var(--bg-soft); }

/* The menu is taller than the viewport on the warehouse side, so the nav itself
   scrolls while the logo and the sign-out block stay put. min-height:0 is what
   actually lets a flex child scroll rather than push the container. */
.pside {
  width: 232px; flex: 0 0 232px; background: var(--ink); color: #c3cacf;
  display: flex; flex-direction: column;
  position: sticky; top: 0; overflow: hidden;
  height: 100vh; max-height: 100vh;
  /* dvh accounts for a phone's collapsing address bar, which vh does not. */
  height: 100dvh; max-height: 100dvh;
}
.pside__brand {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px; padding: 18px 22px 16px;
  color: #fff; font-weight: 700; font-size: 1.2rem;
}
.pside__brand:hover { text-decoration: none; }

.pnav {
  display: flex; flex-direction: column;
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: #3a4045 transparent;
}
.pnav::-webkit-scrollbar { width: 8px; }
.pnav::-webkit-scrollbar-thumb { background: #3a4045; border-radius: 4px; }
.pnav::-webkit-scrollbar-track { background: transparent; }

.pnav a {
  color: #b9c1c7; padding: 9px 22px; font-size: .88rem; font-weight: 500;
  border-left: 3px solid transparent; flex: 0 0 auto;
}
.pnav a:hover { color: #fff; background: #1b1e21; text-decoration: none; }
.pnav a.is-active { color: #fff; background: #1b1e21; border-left-color: var(--orange); }

.pside__foot {
  flex: 0 0 auto;
  padding: 14px 22px 18px; border-top: 1px solid #24282c;
  display: flex; flex-direction: column; gap: 7px;
}
.pside__foot a { color: #8a9299; font-size: .84rem; }
.pside__foot a:hover { color: var(--orange); text-decoration: none; }

.pmain { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.ptop {
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 20px 32px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.ptop h1 { font-size: 1.4rem; margin: 0; flex: 1; }
.ptop__who { text-align: right; line-height: 1.3; }
.ptop__who strong { display: block; font-size: .92rem; color: var(--ink); }
.ptop__who span { font-size: .8rem; color: var(--muted); }


/* Shown at every width: on a desktop it collapses the sidebar, on a phone it
   opens the drawer. One control, one mental model. */
.pburger {
  display: block; background: none; border: 0; padding: 8px; cursor: pointer;
  flex: 0 0 auto; border-radius: 3px;
}
.pburger:hover { background: #eef0f2; }
.pburger span {
  display: block; width: 22px; height: 2px; background: var(--ink); margin: 4px 0;
  transition: transform .18s ease, opacity .18s ease;
}

/* Collapsed: the sidebar folds away and the content takes the full width. */
.portal.is-collapsed .pside {
  width: 0; flex-basis: 0; min-width: 0; border: 0;
}
.portal.is-collapsed .pside > * { opacity: 0; pointer-events: none; }
.pside { transition: width .18s ease, flex-basis .18s ease; }
.pside > * { transition: opacity .12s ease; }

.pbody { padding: 28px 32px 60px; }

/* ---------- KPI tiles --------------------------------------------------- */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px; margin-bottom: 26px;
}
.kpi {
  background: #fff; border: 1px solid var(--line); border-top: 3px solid var(--teal);
  padding: 20px 22px;
}
.kpi--warn { border-top-color: var(--orange); }
.kpi__label {
  display: block; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted); font-weight: 600;
}
.kpi__value {
  display: block; font-size: 2rem; line-height: 1.1; color: var(--ink);
  margin: 10px 0 6px; font-weight: 700;
}
.kpi__note { font-size: .8rem; color: var(--muted); }

/* ---------- Panels ------------------------------------------------------ */
.panel {
  background: #fff; border: 1px solid var(--line); padding: 24px 26px; margin-bottom: 22px;
}
.panel h2 { font-size: 1.08rem; margin-bottom: 18px; }
.empty { color: var(--muted); font-size: .92rem; margin: 0; }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.cols--sidebar { grid-template-columns: 2fr 1fr; }

/* ---------- Tables ------------------------------------------------------ */
.tablewrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 0 12px 10px; border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid #f0f2f4; vertical-align: top; }
.table tbody tr:hover { background: #fafbfc; }
.table .num { text-align: right; white-space: nowrap; }
.table tfoot td { padding-top: 14px; border-bottom: 0; font-size: .95rem; }
.table .bad { color: #c4462f; font-weight: 600; }
.table .warn { color: #b8720d; font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .82rem; }
.tablenote { margin: 14px 0 0; font-size: .8rem; color: var(--muted); }
.morelink { display: inline-block; margin-top: 14px; font-size: .85rem; font-weight: 600; }

/* ---------- Pills ------------------------------------------------------- */
.pill {
  display: inline-block; padding: 3px 11px; font-size: .74rem; font-weight: 600;
  background: #eceff1; color: #4a5257; border-radius: 999px; white-space: nowrap;
}
.pill--delivered, .pill--received, .pill--closed, .pill--complete, .pill--restocked { background: #e4f3e8; color: #23663a; }
.pill--picking, .pill--packed, .pill--intransit, .pill--inprogress, .pill--inspecting { background: #fdf0dc; color: #8a5a08; }
.pill--new, .pill--booked { background: #e3eef2; color: #245a68; }
.pill--cancelled, .pill--canceled, .pill--damaged, .pill--onhold { background: #fbe6e2; color: #8a2c1c; }

/* Stock statuses. Deliberately distinct from the order-state colours above so
   "out of stock" never reads as "delivered" at a glance. */
.pill--available, .pill--active { background: #e4f3e8; color: #23663a; }
.pill--fullstock { background: #d8ecdd; color: #17512b; }
.pill--shortstock { background: #fdf0dc; color: #8a5a08; }
.pill--outofstock { background: #fbe6e2; color: #8a2c1c; }
.pill--unavailable, .pill--inactive { background: #e6e8ea; color: #4a5257; text-decoration: line-through; }

/* ---------- Chart ------------------------------------------------------- */
.chart { display: flex; align-items: flex-end; gap: 14px; height: 190px; padding-top: 10px; }
.chart__col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.chart__bar {
  width: 100%; max-width: 62px; background: var(--teal); min-height: 4px;
  transition: background .15s ease;
}
.chart__col:hover .chart__bar { background: var(--orange); }
.chart__val { font-size: .74rem; color: var(--ink); font-weight: 600; margin-top: 7px; }
.chart__lbl { font-size: .7rem; color: var(--muted); margin-top: 2px; }

/* ---------- Toolbar ----------------------------------------------------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar input[type="search"] {
  flex: 1; min-width: 220px; padding: 12px 15px; font: inherit; font-size: .93rem;
  border: 1px solid var(--line); background: #fff;
}
.toolbar input[type="search"]:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

.field select {
  width: 100%; padding: 13px 15px; font: inherit; font-size: .95rem;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.field select:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

/* ---------- Warehouse side ---------------------------------------------- */
.pside--staff .pside__brand span { color: var(--orange); }
.pnav__head {
  display: block; flex: 0 0 auto;
  padding: 14px 22px 5px; font-size: .62rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .14em; color: #6d757b;
}
.lede { color: var(--muted); margin: -6px 0 20px; font-size: .95rem; }

.scanpanel { border-top: 3px solid var(--orange); }
.scanhint { font-size: .84rem; color: var(--muted); margin-bottom: 18px; }
[data-scan] {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 1.05rem; letter-spacing: .04em;
}
[data-scan]:focus { border-color: var(--orange); outline-color: var(--orange); }

.table tr.is-selected { background: #fff6ec; }
.table tr.is-selected td { font-weight: 600; }

.inlineform { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inlineform input, .inlineform select {
  padding: 7px 9px; font: inherit; font-size: .84rem;
  border: 1px solid var(--line); background: #fff;
}
.inlineform .btn { padding: 8px 14px; font-size: .8rem; }

.linkbtn {
  background: none; border: 0; color: var(--teal); font: inherit; font-size: .88rem;
  font-weight: 600; cursor: pointer; padding: 4px 0;
}
.linkbtn:hover { text-decoration: underline; }

.linetable td { vertical-align: middle; }
.linetable select, .linetable input {
  width: 100%; padding: 9px 11px; font: inherit; font-size: .9rem;
  border: 1px solid var(--line); background: #fff;
}

.thumb {
  width: 40px; height: 40px; object-fit: cover; border: 1px solid var(--line);
  background: #f2f4f5; display: block;
}
.thumb--empty { display: block; }

.meta { margin: 22px 0 0; font-size: .86rem; }
.meta dt {
  color: var(--muted); font-size: .68rem; text-transform: uppercase;
  letter-spacing: .09em; font-weight: 600; margin-top: 12px;
}
.meta dd { margin: 3px 0 0; color: var(--ink); }

.bar { background: #eceff1; height: 8px; width: 100%; max-width: 220px; display: block; }
.bar span { display: block; height: 100%; background: var(--teal); }

/* ---------- Tasks & leads ------------------------------------------------ */
.tasktile { border-top: 3px solid var(--orange); }
.tasktile__num {
  display: inline-block; font-size: .66rem; font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: var(--orange); margin-bottom: 8px;
}
.steps { margin: 0 0 0 1.1em; padding: 0; font-size: .92rem; color: var(--muted); }
.steps li { margin-bottom: 8px; }

.checkrow {
  display: flex; align-items: flex-start; gap: 9px; font-size: .89rem;
  margin-bottom: 10px; cursor: pointer; color: var(--ink);
}
.checkrow input { margin-top: 3px; }

.leadtable td { font-size: .84rem; vertical-align: top; }
.leadtable .mono { font-size: .78rem; }
.leadtable tr.is-dupe { background: #fbfbfc; color: var(--muted); }
.muted { color: var(--muted); }

/* ---------- Label printing ---------------------------------------------- */
.labelpage { padding: 24px; }
.labelbar {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding-bottom: 18px; border-bottom: 1px solid var(--line); margin-bottom: 22px;
}
.labelsheet { display: flex; flex-wrap: wrap; gap: 6px; }

/* 2in x 1in thermal stock. */
.label {
  width: 2in; height: 1in; padding: 0.05in 0.06in;
  border: 1px dashed #ccc; background: #fff;
  display: flex; flex-direction: column; justify-content: space-between;
  overflow: hidden; box-sizing: border-box;
}
.label__desc {
  font-size: 7pt; line-height: 1.1; font-weight: 600; color: #000;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.label__bars { width: 100%; height: 0.42in; display: block; }
.label__sku {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 7.5pt; text-align: center; letter-spacing: .06em; color: #000;
}
.label__meta { display: flex; justify-content: space-between; font-size: 6.5pt; color: #000; }

@media print {
  .noprint { display: none !important; }
  .labelpage { padding: 0; }
  .labelsheet { gap: 0; }
  .label { border: 0; page-break-after: always; break-after: page; }
  @page { size: 2in 1in; margin: 0; }
}

/* ---------- Invoice ------------------------------------------------------ */
.invoicepage { padding: 24px; background: var(--bg-soft); min-height: 100vh; }
.invoice {
  background: #fff; max-width: 800px; margin: 0 auto; padding: 48px;
  border: 1px solid var(--line);
}
.invoice__head { display: flex; justify-content: space-between; gap: 30px; margin-bottom: 40px; }
.invoice__head h1 { font-size: 1.7rem; margin: 10px 0 0; }
.invoice__tag {
  font-size: .55rem; letter-spacing: .2em; color: var(--muted);
  margin: 2px 0 14px; font-weight: 600;
}
.invoice__addr { font-size: .82rem; color: var(--muted); margin: 0; line-height: 1.7; }
.invoice__meta { text-align: right; }
.invoice__meta h2 {
  font-size: 1.5rem; margin: 0 0 14px; color: var(--orange);
  text-transform: uppercase; letter-spacing: .06em;
}
.invoice__meta table { border-collapse: collapse; margin-left: auto; }
.invoice__meta th {
  text-align: right; padding: 3px 12px 3px 0; font-size: .72rem;
  text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
.invoice__meta td { text-align: right; padding: 3px 0; font-size: .88rem; font-weight: 600; }

.invoice__to { margin-bottom: 32px; }
.invoice__to h3 {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); margin: 0 0 8px;
}
.invoice__to p { font-size: .9rem; line-height: 1.7; margin: 0; }

.invoice__lines { width: 100%; border-collapse: collapse; font-size: .88rem; }
.invoice__lines th {
  text-align: left; font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 0 10px 10px; border-bottom: 2px solid var(--ink);
}
.invoice__lines td { padding: 11px 10px; border-bottom: 1px solid #eef0f2; }
.invoice__lines .num { text-align: right; white-space: nowrap; }
.invoice__lines tfoot td { border-bottom: 0; padding: 7px 10px; }
.invoice__lines tfoot .total td {
  border-top: 2px solid var(--ink); padding-top: 13px; font-size: 1.05rem;
}
.invoice__notes {
  margin-top: 30px; padding: 14px 18px; background: var(--bg-soft);
  font-size: .86rem; color: var(--muted);
}
.invoice__foot {
  margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line);
  font-size: .8rem; color: var(--muted);
}

@media print {
  .invoicepage { padding: 0; background: #fff; }
  .invoice { border: 0; max-width: none; padding: 0; }
  @page { size: auto; margin: 14mm; }
}

/* ---------- Responsive -------------------------------------------------- */
@media (max-width: 1080px) {
  .cols, .cols--sidebar { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .pside {
    position: fixed; inset: 0 auto 0 0; z-index: 60; width: 260px; flex-basis: 260px;
    transform: translateX(-100%); transition: transform .2s ease;
    -webkit-overflow-scrolling: touch;
  }
  .pside.is-open { transform: translateX(0); box-shadow: 0 0 60px rgba(0,0,0,.4); }
  .ptop { padding: 16px 18px; }
  .ptop h1 { font-size: 1.15rem; }
  .pbody { padding: 20px 18px 50px; }
}

@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi { padding: 15px 16px; }
  .kpi__value { font-size: 1.5rem; }
  .panel { padding: 18px 14px; }
  .ptop__who { display: none; }
  /* On a phone the sidebar is a drawer, so the desktop collapse must not apply. */
  .portal.is-collapsed .pside { width: 260px; flex-basis: 260px; }
  .portal.is-collapsed .pside > * { opacity: 1; pointer-events: auto; }

  /* ---- Stacked tables --------------------------------------------------
     Each row becomes a card and each cell carries its column name, added by
     responsive-tables.js from the table's own header row. */
  .table.is-stacked,
  .table.is-stacked tbody,
  .table.is-stacked tr,
  .table.is-stacked td { display: block; width: 100%; }

  .table.is-stacked thead { display: none; }

  .table.is-stacked tr {
    border: 1px solid var(--line);
    border-radius: 3px;
    margin-bottom: 12px;
    padding: 4px 0;
    background: #fff;
  }
  .table.is-stacked tbody tr:hover { background: #fff; }

  .table.is-stacked td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 14px;
    padding: 8px 13px; border-bottom: 1px solid #f4f6f7; text-align: left;
    font-size: .87rem;
  }
  .table.is-stacked td:last-child { border-bottom: 0; }

  .table.is-stacked td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    font-size: .68rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .07em; color: var(--muted);
  }
  /* Cells with no header (checkboxes, action buttons) fill the row instead. */
  .table.is-stacked td:not([data-label]) { justify-content: flex-start; }
  .table.is-stacked td:not([data-label])::before { content: none; }

  .table.is-stacked td.num { text-align: right; }

  /* An empty cell would otherwise collapse and hide its own label. */
  .table.is-stacked td:empty { display: none; }

  .table.is-stacked .inlineform { width: 100%; }
  .table.is-stacked .inlineform input,
  .table.is-stacked .inlineform select { flex: 1 1 auto; min-width: 0; }

  .table.is-stacked tfoot { display: block; }
  .table.is-stacked tfoot tr { border: 0; }
  .table.is-stacked tfoot td { justify-content: space-between; }

  .tablewrap { overflow-x: visible; }
  .toolbar { gap: 8px; }
  .toolbar input[type="search"] { min-width: 100%; }
  .toolbar .btn, .toolbar select { flex: 1 1 auto; }
  .linetable select, .linetable input { font-size: 16px; } /* stops iOS zooming on focus */
  .plogin__card { padding: 32px 24px 26px; }
  .chart { height: 150px; gap: 8px; }
  .chart__val { font-size: .65rem; }
  .chart__lbl { font-size: .62rem; }
}
