/* PLAN-T internal tools.
   One hand-written stylesheet, no build step. The palette is derived from the
   logo: a single navy (#004477) plus neutrals. Colour is used to mean
   something — brand chrome, a state, a warning — never as decoration. */

:root {
  --brand: #004477;
  --brand-deep: #00325a;
  --brand-tint: #eef3f8;
  --brand-line: #cfdded;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dfe4ea;
  --text: #16202b;
  --muted: #61707f;
  --faint: #8b97a4;

  --ok-bg: #e8f5ec;
  --ok-line: #4f9e6a;
  --ok-text: #17603a;
  --error-bg: #fdedec;
  --error-line: #c0564d;
  --error-text: #8c2019;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(16, 32, 48, 0.06);
  --shadow: 0 2px 4px rgba(16, 32, 48, 0.06), 0 8px 24px rgba(16, 32, 48, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 1140px; margin: 0 auto; padding: 32px 24px 80px; }

h1 { font-size: 24px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 14px; letter-spacing: -0.005em; }

a { color: var(--brand); }

.sub { color: var(--muted); margin: 0 0 22px; }
.hint { color: var(--faint); font-size: 13px; margin: 12px 0 0; }
.empty { color: var(--muted); }

/* ------------------------------------------------------------------ top bar */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  /* The brand rule under the bar carries the navy without drowning the logo,
     which is navy itself and would vanish on a dark chrome. */
  box-shadow: inset 0 -3px 0 var(--brand), var(--shadow-sm);
}

.topbar-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  min-height: 68px;
}

.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; }
.brand-mark { display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }

.brand-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--brand);
}

.brand-tagline {
  font-size: 9.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--faint);
}

.topbar-nav { display: flex; gap: 4px; flex: 1; align-self: stretch; align-items: stretch; }

.topbar-nav a {
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  margin-bottom: -3px;
}

.topbar-nav a:hover { color: var(--brand); background: var(--brand-tint); }
.topbar-nav a.is-current { color: var(--brand); border-bottom-color: var(--brand); }

.session { display: flex; align-items: center; gap: 12px; }
.session form { margin: 0; }

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.who { display: flex; flex-direction: column; line-height: 1.2; }
.who-name { font-size: 13px; font-weight: 500; }
.who-role { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.07em; }

/* -------------------------------------------------------------- sign-in page */

/* min-height, or the gradient stops where the content stops and leaves a
   visible seam across the page. */
.page-auth {
  min-height: 100vh;
  background: linear-gradient(180deg, var(--brand-tint) 0%, var(--bg) 340px);
  background-repeat: no-repeat;
}

.auth { max-width: 400px; margin: 72px auto 0; }
.auth-logo { display: block; margin: 0 auto 30px; height: auto; max-width: 260px; }
.auth-card { box-shadow: var(--shadow); padding: 30px 30px 32px; }
.auth-card h1 { font-size: 20px; }

.auth-footnote { text-align: center; color: var(--faint); font-size: 13px; margin-top: 20px; }

/* --------------------------------------------------------------- containers */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 26px;
  box-shadow: var(--shadow-sm);
}

.card-narrow { max-width: 440px; margin: 56px auto; box-shadow: var(--shadow); padding: 28px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head .sub { margin: 0; }

/* ------------------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 30px;
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 18px 22px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--brand);
}

.stat-value {
  display: block;
  font-size: 32px;
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

label {
  display: block;
  margin: 14px 0 5px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

input, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0, 68, 119, 0.13);
}

input::placeholder { color: var(--faint); }

button {
  margin-top: 16px;
  padding: 9px 16px;
  border: 1px solid var(--brand);
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { background: var(--brand-deep); border-color: var(--brand-deep); }
button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn-block { width: 100%; margin-top: 24px; padding: 11px; }

.btn-ghost, .btn-quiet {
  background: transparent;
  color: var(--brand);
  border-color: var(--border);
  margin-top: 0;
}

.btn-ghost:hover, .btn-quiet:hover { background: var(--brand-tint); border-color: var(--brand-line); color: var(--brand-deep); }

.linklike {
  background: none;
  border: none;
  color: var(--brand);
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-decoration: underline;
}

/* Give every control the same explicit height rather than hoping an input and
   a select measure alike — they do not, and the labels above them step by a
   few pixels when the row is bottom-aligned. */
.row-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; }
.row-form > div { display: flex; flex-direction: column; }
.row-form label { margin: 0 0 5px; }
.row-form input, .row-form select, .row-form button { height: 38px; }
.row-form input, .row-form select { width: auto; min-width: 170px; }
.row-form button { margin-top: 0; }
.row-form .linklike { align-self: flex-end; height: 38px; }

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

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.grid { width: 100%; border-collapse: collapse; }

.grid th, .grid td { text-align: left; padding: 11px 14px; vertical-align: middle; }

.grid th {
  background: var(--brand-tint);
  border-bottom: 1px solid var(--brand-line);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--brand);
  white-space: nowrap;
}

.grid td { border-bottom: 1px solid var(--border); font-size: 14px; }
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr:hover td { background: #fafcfe; }
.grid tr.inactive td { color: var(--faint); }
.grid .num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* The action controls are the widest thing in the table, so they are kept
   deliberately tight — a clipped button reads as broken even when the row is
   scrollable. */
.grid td.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.grid td.actions form { display: flex; gap: 5px; align-items: center; margin: 0; }
.grid td.actions button { margin-top: 0; padding: 5px 9px; font-size: 13px; }

.grid td.actions input, .grid td.actions select {
  min-width: 0;
  width: 112px;
  padding: 5px 7px;
  font-size: 13px;
}

.grid td.actions select { width: 88px; }

/* --------------------------------------------------------- invoice detail */

.invoice-top { display: flex; justify-content: space-between; align-items: flex-start; }
.invoice-title { color: var(--brand); letter-spacing: 0.04em; margin: 0; }
.invoice-balance { text-align: right; }
.invoice-balance .label { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.invoice-balance .value { font-size: 20px; font-weight: 600; }

.invoice-parties {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 28px;
  margin-top: 18px;
}
.party-label { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.party-body { font-size: 14px; line-height: 1.5; }
.invoice-meta { display: grid; grid-template-columns: auto auto; gap: 4px 16px; margin: 0; font-size: 14px; align-content: start; }
.invoice-meta dt { color: var(--muted); }
.invoice-meta dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.invoice-shipcode { margin-top: 16px; }

.invoice-totals {
  display: grid;
  grid-template-columns: auto 140px;
  gap: 6px 20px;
  justify-content: end;
  margin: 16px 0 0;
  font-size: 14px;
}
.invoice-totals dt { color: var(--muted); text-align: right; }
.invoice-totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.invoice-totals .grand { font-weight: 700; font-size: 16px; color: var(--text); border-top: 1px solid var(--border); padding-top: 6px; }

@media (max-width: 720px) {
  .invoice-parties { grid-template-columns: 1fr; }
}

/* ----------------------------------------------------- selection + export */

.list-actions { display: flex; justify-content: flex-end; margin: 0 0 12px; }

.grid th.pick, .grid td.pick { width: 34px; text-align: center; padding-right: 0; }
.grid td.pick input, .grid th.pick input { margin: 0; cursor: pointer; }

/* -------------------------------------------------------------------- tabs */

/* Section tabs. A hidden tab is a courtesy, never the access control — the
   router refuses the page regardless of what was rendered here. */
.tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--border);
}

.tabs .tab {
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tabs .tab:hover { color: var(--brand); background: var(--brand-tint); }

.tabs .tab.is-current {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

/* ------------------------------------------------------------------- chips */

.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.chip-admin { background: var(--brand-tint); color: var(--brand); border-color: var(--brand-line); }
.chip-user { background: #f2f4f7; color: var(--muted); border-color: var(--border); }
.chip-active { background: var(--ok-bg); color: var(--ok-text); border-color: #bfe0ca; }
.chip-inactive { background: #f2f4f7; color: var(--faint); border-color: var(--border); }

/* Invoice status. Overdue is the only one that should catch the eye — paid and
   open are ordinary states and must not compete with it. */
.chip-paid { background: var(--ok-bg); color: var(--ok-text); border-color: #bfe0ca; }
.chip-open { background: #f2f4f7; color: var(--muted); border-color: var(--border); }
.chip-overdue { background: var(--error-bg); color: var(--error-text); border-color: var(--error-line); }

/* --------------------------------------------------------- quick periods */

.quick-periods { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }

.quick-periods .quick-period {
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.quick-periods .quick-period:hover {
  border-color: var(--brand-line);
  background: var(--brand-tint);
  color: var(--brand);
}

.quick-periods .quick-period.is-current {
  background: var(--brand-tint);
  border-color: var(--brand-line);
  color: var(--brand);
  font-weight: 600;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  background: #f2f5f8;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- messages */

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  margin: 0 0 22px;
  font-size: 14px;
}

.flash-ok { background: var(--ok-bg); border-left-color: var(--ok-line); color: var(--ok-text); }
.flash-error { background: var(--error-bg); border-left-color: var(--error-line); color: var(--error-text); }

/* ------------------------------------------------------------------ pager */

.pager { display: flex; gap: 10px; margin-top: 18px; align-items: center; }

.pager a {
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-decoration: none;
  font-size: 14px;
}

.pager a:hover { background: var(--brand-tint); border-color: var(--brand-line); }

/* ---------------------------------------------------------------- narrow */

@media (max-width: 820px) {
  .topbar-inner { flex-wrap: wrap; gap: 12px; min-height: 0; padding: 12px 18px; }
  .topbar-nav { order: 3; width: 100%; flex: none; overflow-x: auto; }
  .topbar-nav a { padding: 10px 12px; }
  .session { margin-left: auto; }
  .who { display: none; }
  main { padding: 22px 18px 60px; }
  .grid td.actions { flex-direction: column; align-items: stretch; }
}

/* --- Customer directory & detail ---------------------------------------- */

.filter-box {
  width: 100%;
  max-width: 340px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.customer-card h2 { margin: 0 0 2px; }
.customer-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 14px 0 0;
  font-size: 14px;
}
.customer-meta dt { color: var(--muted); }
.customer-meta dd { margin: 0; color: var(--text); }

.section-controls { display: flex; gap: 14px; align-items: center; }
.section-controls .linklike { font-size: 13px; }

/* The search stays reachable while a long product list scrolls under it. */
.product-search {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  padding: 4px 0 12px;
}
.product-search input {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
}

/* Each category is a collapsible section, collapsed by default. */
.cat-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}
.cat-section > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  background: var(--brand-tint);
  color: var(--brand-deep);
}
.cat-section > summary::-webkit-details-marker { display: none; }
.cat-section > summary::before {
  content: "▸";
  color: var(--faint);
  font-size: 12px;
  transition: transform 0.12s ease;
}
.cat-section[open] > summary::before { transform: rotate(90deg); }
.cat-name { flex: 1; }
.cat-count {
  min-width: 22px;
  text-align: center;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--brand-line);
  color: var(--brand);
  font-size: 12px;
  font-weight: 600;
}

.product-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.item-name { font-weight: 500; }
.qty { font-weight: 600; }

.pack-tag {
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: #f2f4f7;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
}

/* A confusable-item pill. Its colour is supplied inline as --pill, validated
   as a hex value before it ever reaches this style. */
.item-pill {
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--pill, var(--muted));
  white-space: nowrap;
}
