/* Marras ERP - one stylesheet, no build step. */

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --ink: #1c1b19;
  --muted: #76726c;
  --line: #e2e0db;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --warn: #9a5b12;
  --warn-bg: #fdf3e3;
  --danger: #a32d24;
  --ok: #2f6b3a;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

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

.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px 64px; }
.container.narrow, .container.login { max-width: 420px; }
.container.login { padding-top: 12vh; text-align: center; }
.container.login h1 { font-weight: 600; letter-spacing: -0.02em; }
.container.login h1 span { color: var(--accent); }

/* --- Top bar --------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
  padding: 14px 0;
  letter-spacing: -0.01em;
}
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  padding: 15px 12px;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.topbar nav a:hover { color: var(--ink); }
.topbar nav a.active { color: var(--ink); border-bottom-color: var(--accent); }
.topbar-user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }

/* --- Headings & stats ------------------------------------------------------ */

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 16px; margin: 28px 0 10px; }
.card h2 { margin-top: 0; }
.crumb { margin: 0 0 4px; font-size: 13px; color: var(--muted); }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}
.stat strong { color: var(--ink); font-size: 15px; margin-right: 4px; }
.stat.warn { background: var(--warn-bg); border-color: #efd9b4; color: var(--warn); }
.stat.warn strong { color: var(--warn); }

.big-stock { text-align: right; }
.big-stock .label { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.big-stock strong { font-size: 36px; font-weight: 600; letter-spacing: -0.03em; }
.big-stock.low strong { color: var(--warn); }

.runs { list-style: none; display: flex; gap: 16px; flex-wrap: wrap; padding: 0; margin: 0 0 20px; font-size: 13px; }
.runs li { display: flex; align-items: center; gap: 6px; }
.runs .job { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* --- Forms ----------------------------------------------------------------- */

.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin: 12px 0;
}
.filters input[type="search"] { min-width: 240px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }

label { display: block; margin-bottom: 12px; font-size: 14px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  color: inherit;
}
.filters input, .filters select { margin-top: 0; width: auto; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  font: inherit;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.1); }
button.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin: 20px 0; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
}

/* --- Tables ---------------------------------------------------------------- */

table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 14px;
}
table.data th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfa;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.low td { background: var(--warn-bg); }
table.data tr.inactive td { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.in { color: var(--ok); }
.out { color: var(--danger); }

.tag {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 4px;
  background: #ecebe7;
  color: var(--muted);
}
.badge {
  display: inline-block;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 10px;
  background: #ecebe7;
  color: var(--muted);
}
.badge-ok { background: #e4f0e6; color: var(--ok); }
.badge-partial { background: var(--warn-bg); color: var(--warn); }
.badge-failed { background: #f8e3e1; color: var(--danger); }
.badge-running { background: #e6eef6; color: #2c5578; }

.pager { display: flex; gap: 16px; align-items: center; padding: 12px 2px; font-size: 14px; }

/* --- Messages -------------------------------------------------------------- */

.flash { list-style: none; padding: 0; margin: 0 0 16px; }
.flash li, .boxed {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 14px;
}
.flash-success { background: #e4f0e6; color: var(--ok); }
.flash-error { background: #f8e3e1; color: var(--danger); }
.error-detail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  table.data { font-size: 13px; }
  .big-stock { text-align: left; }
}

/* --- Stock grid ------------------------------------------------------------ */

.grid-wrap { overflow-x: auto; }

table.grid { min-width: 720px; }
table.grid .product-col { min-width: 260px; }
table.grid .total-col {
  border-left: 1px solid var(--line);
  background: #fbfbfa;
}
table.grid tfoot td {
  border-top: 2px solid var(--line);
  background: #fbfbfa;
  padding: 9px 12px;
  font-variant-numeric: tabular-nums;
}
table.grid tfoot .num { text-align: right; }

.group-row .parent-name { font-weight: 500; }
.group-row.expanded { background: #fbfbfa; }
.group-row td { border-bottom: 1px solid var(--line); }

.toggle {
  border: 0;
  background: none;
  padding: 0;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  cursor: pointer;
  vertical-align: -3px;
}
.toggle:hover { background: none; }
.toggle .chev {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.12s ease;
}
.toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.toggle-spacer { display: inline-block; width: 18px; margin-right: 6px; }

.sub-row td { background: #fcfcfb; border-bottom: 1px dotted var(--line); }
.sub-row .sub-label { padding-left: 36px; color: var(--muted); }
.sub-row .num { color: var(--ink); }

td.absent { background: repeating-linear-gradient(45deg, transparent, transparent 4px, #f4f3f0 4px, #f4f3f0 8px); }
td.absent .dash { color: #bdb9b2; }
td.cell-low { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
td.cell-low a { color: var(--warn); }

.section-head { margin-top: 28px; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented label {
  margin: 0;
  padding: 7px 12px;
  font-size: 14px;
  cursor: pointer;
  background: var(--surface);
  color: var(--muted);
  border-right: 1px solid var(--line);
}
.segmented label:last-child { border-right: 0; }
.segmented label.on { background: var(--accent); color: var(--accent-ink); }
.segmented input { position: absolute; opacity: 0; width: 0; height: 0; }

/* --- External system panels (read-only) ------------------------------------ */

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.panel-link { font-size: 12px; text-transform: none; letter-spacing: 0; white-space: nowrap; }
.panel.loading { opacity: 0.6; }
.panel-note { margin: 0 0 8px; font-size: 13px; line-height: 1.5; }
.panel-error { color: var(--danger); }

.facts {
  display: grid;
  grid-template-columns: minmax(96px, auto) 1fr;
  gap: 5px 14px;
  margin: 0 0 14px;
  font-size: 14px;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.near-list { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
.near-list li { margin-bottom: 2px; }

table.compare { font-size: 13px; }
table.compare th { font-size: 11px; }
table.compare td { padding: 7px 10px; }
.mismatch { color: var(--danger); font-weight: 600; }

.tag-warn { background: var(--warn-bg); color: var(--warn); }

/* Make a whole grid cell the click target. With every number at 0 before the
   first stocktake, a bare "0" is a one-character target and reads as text
   rather than as a way into the product. */
table.grid td .cell-link {
  display: block;
  margin: -9px -12px;
  padding: 9px 12px;
  text-decoration: none;
  color: inherit;
  border-radius: 3px;
}
table.grid td .cell-link:hover,
table.grid td .cell-link:focus-visible {
  background: rgba(47, 93, 80, 0.09);
  text-decoration: underline;
  outline: none;
}

a.parent-name { color: var(--ink); text-decoration: none; }
a.parent-name:hover { color: var(--accent); text-decoration: underline; }

/* Product names read as text but behave as links: underline only on hover,
   so a table of them does not turn into a wall of blue. */
.plain-link { color: inherit; text-decoration: none; }
.plain-link:hover { color: var(--accent); text-decoration: underline; }
