/* Inventory expiry monitor - colour-coded table, print-friendly. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #d8dde2;
  --text: #22292f;
  --text-muted: #667079;
  --accent: #2f3b45;

  --expired-bg: #f8d7da;
  --expired-fg: #8a1c24;
  --critical-bg: #ffe0cc;
  --critical-fg: #8a4200;
  --warning-bg: #fff6cc;
  --warning-fg: #6b5500;
  --ok-bg: #e3f4e6;
  --ok-fg: #1d5c2a;
  --no_date-bg: #ececec;
  --no_date-fg: #4a4a4a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 20px 24px 48px;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --- Header --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.topbar h1 { margin: 0; font-size: 21px; letter-spacing: -0.2px; }
.source { margin: 4px 0 0; color: var(--text-muted); font-size: 12.5px; }

/* --- Buttons --- */
.btn {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.15); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-pdf { background: #a8321f; border-color: #a8321f; }

/* --- Status cards --- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-left-width: 5px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.card:hover { box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12); }
.card-active { outline: 2px solid var(--accent); outline-offset: 1px; }
.card-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.card-count { font-size: 24px; font-weight: 700; line-height: 1.1; }
.card-stock { font-size: 12px; color: var(--text-muted); }

.card-expired { border-left-color: var(--expired-fg); background: var(--expired-bg); }
.card-critical { border-left-color: var(--critical-fg); background: var(--critical-bg); }
.card-warning { border-left-color: var(--warning-fg); background: var(--warning-bg); }
.card-ok { border-left-color: var(--ok-fg); background: var(--ok-bg); }
.card-no_date { border-left-color: var(--no_date-fg); background: var(--no_date-bg); }
.card-total { border-left-color: var(--accent); }

/* --- Filters --- */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.field input[type="search"], .field input[type="number"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
}
.field-search { flex: 1 1 260px; }
.field-search input { width: 100%; }
.field input[type="number"] { width: 110px; }
.field-check { flex-direction: row; align-items: center; gap: 7px; padding-bottom: 8px; }
.field-check span { font-size: 13px; color: var(--text); font-weight: 400; }
.field-actions { display: flex; gap: 8px; }

.active-filter { margin: 0 0 12px; font-size: 13px; color: var(--text-muted); }
.chip {
  display: inline-block;
  padding: 3px 9px;
  margin-left: 5px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.chip-expired, .badge-expired { background: var(--expired-bg); color: var(--expired-fg); }
.chip-critical, .badge-critical { background: var(--critical-bg); color: var(--critical-fg); }
.chip-warning, .badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.chip-ok, .badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.chip-no_date, .badge-no_date { background: var(--no_date-bg); color: var(--no_date-fg); }

/* --- Table --- */
.inventory {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  font-size: 13px;
}
.inventory thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0;
  background: var(--accent);
  text-align: left;
  white-space: nowrap;
}
.inventory thead th a {
  display: block;
  padding: 10px 11px;
  color: #fff;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  text-decoration: none;
}
.inventory thead th a:hover { background: rgba(255, 255, 255, 0.12); }
.th-sorted a { background: rgba(255, 255, 255, 0.18); }
.arrow { font-size: 9px; margin-left: 3px; }

.inventory td {
  padding: 7px 11px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}
.inventory tbody tr:hover td { filter: brightness(0.97); }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.empty { padding: 26px; text-align: center; color: var(--text-muted); }

.row-expired { background: var(--expired-bg); }
.row-critical { background: var(--critical-bg); }
.row-warning { background: var(--warning-bg); }
.row-ok { background: var(--ok-bg); }
.row-no_date { background: var(--no_date-bg); }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.legend { margin-top: 16px; font-size: 12.5px; color: var(--text-muted); }

/* --- Dark mode --- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15191d;
    --surface: #1e2429;
    --border: #333c44;
    --text: #e7ebee;
    --text-muted: #9aa5ae;
    --accent: #3b4a57;

    --expired-bg: #4a1f24;
    --expired-fg: #ffb3ba;
    --critical-bg: #4d2e13;
    --critical-fg: #ffce9e;
    --warning-bg: #45400f;
    --warning-fg: #f2e49a;
    --ok-bg: #1c3a25;
    --ok-fg: #a8e0b7;
    --no_date-bg: #2b3137;
    --no_date-fg: #bcc4cb;
  }
  :root:not([data-theme="light"]) .field input { background: #15191d; }
  :root:not([data-theme="light"]) .btn-pdf { background: #b3402c; border-color: #b3402c; }
}

/* --- Print / browser PDF fallback --- */
@media print {
  body { padding: 0; background: #fff; }
  .filters, .btn, .active-filter { display: none; }
  .inventory thead th { position: static; }
  .inventory, .card { break-inside: avoid; }
  .inventory tbody tr { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 720px) {
  body { padding: 14px 16px 36px; }
  .inventory { font-size: 12px; }
  .inventory td, .inventory thead th a { padding: 6px 7px; }
}
