:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a64;
  --line: #dcd9d2;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --ok: #2e7d4f;
  --warn: #b26a00;
  --bad: #b3261e;
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

header.top {
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  flex-wrap: wrap;
}
header.top .brand { font-weight: 700; color: #fff; text-decoration: none; letter-spacing: .02em; }
header.top nav { display: flex; gap: 14px; flex-wrap: wrap; flex: 1; }
header.top nav a { color: #e7e5df; text-decoration: none; font-size: 15px; }
header.top nav a:hover { color: #fff; text-decoration: underline; }
header.top .user { font-size: 14px; color: #bdbab2; }
header.top form { display: inline; }
header.top button.link { background: none; border: 0; color: #e7e5df; cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 28px 0 10px; }
.sub { color: var(--muted); margin: 0 0 20px; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 8px; background: #e8f1f8; border: 1px solid #c5dbec; }
.messages li.success { background: #e7f4ec; border-color: #bfe0cb; }
.messages li.error { background: #fbe9e7; border-color: #f2c4bf; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-decoration: none; color: var(--ink); }
.tile:hover { border-color: var(--accent); }
.tile strong { display: block; font-size: 17px; margin-bottom: 4px; }
.tile span { color: var(--muted); font-size: 14px; }
.tile .count { font-size: 28px; font-weight: 700; color: var(--accent); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: #faf9f6; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid; }
.badge.open { color: var(--warn); border-color: #e9c48a; background: #fff6e6; }
.badge.closed { color: var(--ok); border-color: #b5dcc3; background: #eef8f2; }
.badge.reserved { color: var(--accent); border-color: #b9d2e6; background: #eef5fb; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0 20px; }
.btn { display: inline-block; padding: 10px 16px; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); text-decoration: none; font: inherit; font-weight: 600; cursor: pointer; }
.btn.secondary { background: var(--surface); color: var(--accent); }
.btn:hover { filter: brightness(1.08); }

form .field { margin-bottom: 14px; }
form label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=datetime-local], input[type=password], select, textarea {
  width: 100%; max-width: 420px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: #fff;
}
table input[type=text], table input[type=number], table select { max-width: none; min-width: 90px; }
.helptext, .help { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }
.errorlist { color: var(--bad); list-style: none; padding: 0; margin: 4px 0; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 24px; }

.photos { display: flex; gap: 10px; flex-wrap: wrap; }
.photos a { display: block; width: 140px; }
.photos img { width: 140px; height: 105px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.photos .cap { font-size: 12px; color: var(--muted); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); font-size: 14px; }
dl.facts dd { margin: 0; }

@media (max-width: 600px) {
  h1 { font-size: 21px; }
  main { padding: 16px 12px 40px; }
  th, td { padding: 8px; }
}

table select[name$="stock_item"], table select[name$="-part"] { min-width: 190px; }

/* Phones: tables marked .stack turn into labelled cards so no column is hidden. */
@media (max-width: 600px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { border: 0; padding: 5px 12px 5px calc(38% + 12px); text-align: left; position: relative; min-height: 30px; }
  table.stack td[data-label]::before { content: attr(data-label); position: absolute; left: 12px; top: 6px; width: 36%; font-size: 13px; color: var(--muted); font-weight: 600; }
  table.stack td.num { text-align: left; }
  table.stack td:not([data-label]) { padding-left: 12px; }
  table.stack input, table.stack select { min-width: 0 !important; width: 100%; }
}
