:root {
  color-scheme: dark;
  --bg: #12140f;
  --panel: #1b1f17;
  --panel-raised: #242a20;
  --border: #3a4334;
  --text: #e8eadf;
  --muted: #a9b09d;
  --accent: #c7a85a;
  --accent-strong: #e0c478;
  --danger: #ef8a7a;
  --ok: #8fce9b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1c2218 0, var(--bg) 48rem);
  color: var(--text);
  font: 16px/1.55 "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent-strong); }
a:hover { color: #fff0c0; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid var(--border);
  background: rgba(18, 20, 15, 0.88);
}

.brand {
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  text-decoration: none;
}
.brand span { color: var(--accent); }
.site-header nav { display: flex; align-items: center; gap: 1rem; }
.inline-form { display: inline; margin: 0; }
.link-button {
  appearance: none;
  border: 0;
  background: none;
  color: var(--accent-strong);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.link-button:hover { color: #fff0c0; text-decoration: underline; }

main.card {
  width: min(68rem, calc(100% - 2rem));
  margin: clamp(1.5rem, 5vh, 4rem) auto;
  padding: clamp(1.25rem, 3vw, 2.5rem);
  background: linear-gradient(160deg, var(--panel-raised), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
main.card.narrow { width: min(26rem, calc(100% - 2rem)); }
main.card.setup-card { width: min(46rem, calc(100% - 2rem)); }

h1, h2 {
  margin: 0 0 0.5rem;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  line-height: 1.2;
}
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
h2 { margin-top: 1.5rem; font-size: 1.25rem; color: var(--accent-strong); }
p { margin: 0.5rem 0 1rem; }
.muted, .help { color: var(--muted); }
.help { display: block; font-size: 0.85rem; margin-top: 0.2rem; }
.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.stack { display: grid; gap: 1rem; }
label { display: block; font-weight: 600; }
.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }

input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #10130e;
  color: var(--text);
  font: inherit;
}
textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #10130e;
  color: var(--text);
  font: inherit;
  resize: vertical;
}
input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
input[type="checkbox"] { width: auto; }

button, .link.primary {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}
button.primary, .link.primary {
  background: var(--accent);
  color: #17180f;
}
button.primary:hover, .link.primary:hover { background: var(--accent-strong); color: #10120c; }
button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
button.secondary:hover { border-color: var(--accent); }

.wizard-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.alert {
  margin: 1rem 0;
  padding: 0.75rem 0.9rem;
  border-radius: 6px;
  border: 1px solid;
}
.alert-error { border-color: var(--danger); background: rgba(239, 138, 122, 0.1); color: #ffd7cf; }
.alert-ok { border-color: var(--ok); background: rgba(143, 206, 155, 0.1); color: #dcf6df; }
.alert-warn { border-color: var(--accent); background: rgba(199, 168, 90, 0.12); color: #f6e7bd; }
.field-error { margin: 0.25rem 0 0; color: var(--danger); font-size: 0.85rem; }

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 1.5rem 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.steps li {
  padding-top: 0.65rem;
  border-top: 3px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
.steps li.active { border-color: var(--accent); color: var(--text); }

.test-result { min-height: 1.5rem; margin-top: 0.75rem; font-size: 0.9rem; }
.test-result.ok { color: var(--ok); }
.test-result.error { color: var(--danger); }

.site-footer {
  margin-top: auto;
  padding: 1.5rem clamp(1rem, 4vw, 3rem);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
}

.auth-page main.card { margin-top: clamp(2rem, 10vh, 6rem); }

@media (max-width: 560px) {
  .steps { grid-template-columns: repeat(2, 1fr); }
  .site-header { align-items: flex-start; flex-direction: column; }
  .wizard-actions { justify-content: stretch; }
  .wizard-actions button { flex: 1 1 auto; }
}

/* Phase 3 import review */
.import-upload { margin-top: 1rem; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.import-table { width: 100%; border-collapse: collapse; min-width: 44rem; }
.import-table caption { padding: 0.7rem 0.9rem; color: var(--muted); text-align: left; }
.import-table th, .import-table td { padding: 0.55rem 0.7rem; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
.import-table th { background: rgba(0, 0, 0, 0.16); color: var(--accent-strong); font-size: 0.85rem; }
.import-table tbody tr:hover { background: rgba(199, 168, 90, 0.06); }
.import-table input[type="checkbox"] { margin: 0; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 0.85rem; }
.failure { display: block; max-width: 26rem; margin-top: 0.2rem; color: var(--danger); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.failure-detail { max-height: 14rem; overflow: auto; padding: 0.75rem; border: 1px solid var(--danger); border-radius: 6px; background: #10130e; white-space: pre-wrap; }
.status-badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.status-Uploaded { color: var(--accent-strong); border-color: var(--accent); }
.status-Processing { color: #f0d693; border-color: #a88e4d; }
.status-Completed { color: var(--ok); border-color: var(--ok); }
.status-Failed { color: var(--danger); border-color: var(--danger); }
.status-Issued { color: var(--accent-strong); border-color: var(--accent); }
/* Request lifecycle badges. Completed reuses .status-Completed; the other three
   have text labels, so colour is never the only signal. */
.request-status-Pending { color: #f0d693; border-color: #a88e4d; }
.request-status-Denied { color: var(--danger); border-color: var(--danger); }
.request-status-Cancelled { color: var(--muted); border-color: var(--border); }
button.danger { border-color: var(--danger); color: var(--danger); }
button.danger:hover { border-color: var(--danger); background: rgba(239, 138, 122, 0.12); }
.batch-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0.75rem; margin: 1rem 0 1.5rem; padding: 0; }
.batch-meta div { padding: 0.65rem 0.8rem; border: 1px solid var(--border); border-radius: 6px; background: rgba(0, 0, 0, 0.12); }
.batch-meta dt { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }
.batch-meta dd { margin: 0.25rem 0 0; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0.7rem; }
.summary-card { padding: 0.7rem 0.85rem; border: 1px solid var(--border); border-radius: 6px; background: rgba(0, 0, 0, 0.12); }
.summary-label { display: block; color: var(--muted); font-size: 0.78rem; }
.summary-value { display: block; margin-top: 0.2rem; color: var(--accent-strong); }
.import-layout { display: grid; grid-template-columns: minmax(13rem, 17rem) minmax(0, 1fr); gap: 1.25rem; margin-top: 1.5rem; align-items: start; }
.location-panel, .row-panel { min-width: 0; }
.location-list { display: grid; gap: 0.35rem; max-height: 34rem; overflow: auto; padding-right: 0.25rem; }
.location-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1rem; margin-top: 1rem; }
.action-group { display: flex; flex-direction: column; gap: 0.25rem; }
.action-group-label { color: var(--muted); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.button-group { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.location-actions button { padding: 0.4rem 0.65rem; font-size: 0.82rem; }
.action-group-reset { margin-left: auto; }
.location-item { padding: 0.35rem 0.45rem; border: 1px solid var(--border); border-radius: 6px; }
.location-toggle { font-weight: 500; }
.location-toggle input { margin-right: 0.35rem; }
.location-item .help { margin: 0.15rem 0 0 1.25rem; }
.filter-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0.65rem; align-items: end; margin-bottom: 0.85rem; }
.filter-row label { font-size: 0.85rem; }
.filter-row select, .filter-row input { margin-top: 0.2rem; padding: 0.5rem 0.6rem; }
select { display: block; width: 100%; border: 1px solid var(--border); border-radius: 6px; background: #10130e; color: var(--text); font: inherit; }
.pager { display: flex; align-items: center; gap: 0.7rem; margin-top: 0.75rem; flex-wrap: wrap; }
.commit-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.commit-bar .help { max-width: 38rem; margin: 0; }
.warning-badge { display: inline-block; padding: 0.1rem 0.4rem; border: 1px solid var(--accent); border-radius: 4px; color: var(--accent-strong); font-size: 0.75rem; }
button:disabled, input:disabled { opacity: 0.55; cursor: not-allowed; }
@media (max-width: 900px) {
  .import-layout { grid-template-columns: 1fr; }
  .location-list { max-height: none; }
  .commit-bar { align-items: flex-start; flex-direction: column; }
  .action-group-reset { margin-left: 0; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
main.card.inventory-card { width: min(120rem, calc(100% - 1.5rem)); }
.inventory-filters { margin: 1rem 0 0.5rem; padding: 0.9rem; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(0, 0, 0, 0.12); }
.filter-grid { display: grid; grid-template-columns: minmax(14rem, 2fr) repeat(4, minmax(9rem, 1fr)); gap: 0.75rem; align-items: start; }
.filter-grid label { font-size: 0.85rem; }
.filter-grid input, .filter-grid select { margin-top: 0.25rem; padding: 0.55rem 0.65rem; }
.filter-grid select:focus, .inventory-pager a:focus, .inventory-table a:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filter-actions { display: flex; align-items: center; gap: 0.85rem; min-height: 2.6rem; }
.result-summary { color: var(--muted); font-size: 0.9rem; }
.inventory-table { width: 100%; min-width: 58rem; border-collapse: collapse; font-size: 0.9rem; }
.inventory-table th, .inventory-table td { padding: 0.65rem 0.6rem; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
.inventory-table th { background: rgba(0, 0, 0, 0.16); color: var(--accent-strong); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.inventory-table tbody tr:hover { background: rgba(199, 168, 90, 0.06); }
.item-identity { display: block; margin-top: 0.2rem; color: var(--muted); font-size: 0.76rem; }
.unknown { color: #d9c89a; }
.unknown-note { display: block; margin-top: 0.2rem; color: var(--muted); font-size: 0.74rem; }
.availability-badge { display: inline-block; padding: 0.15rem 0.55rem; border: 1px solid var(--border); border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.availability-upcoming { color: var(--accent-strong); border-color: var(--accent); }
.availability-open { color: var(--ok); border-color: var(--ok); }
.availability-bazaar { color: #b9c6e8; border-color: #7f92bd; }
.empty-state { padding: 1.25rem; border: 1px dashed var(--border); border-radius: var(--radius); background: rgba(0, 0, 0, 0.1); }
.empty-state p { margin: 0.25rem 0; }
.inventory-pager { margin-top: 1rem; }
.inventory-pager a, .page-current { min-width: 2rem; padding: 0.25rem 0.45rem; border: 1px solid var(--border); border-radius: 5px; text-align: center; text-decoration: none; }
.page-current { background: var(--accent); color: #17180f; font-weight: 700; }
.detail-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.75rem; margin: 1.25rem 0; }
.detail-list div { padding: 0.7rem 0.85rem; border: 1px solid var(--border); border-radius: 6px; background: rgba(0, 0, 0, 0.12); }
.detail-list dt { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; }
.detail-list dd { margin: 0.25rem 0 0; }
@media (max-width: 1100px) {
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .filter-grid { grid-template-columns: 1fr; }
  .filter-actions { align-items: flex-start; flex-direction: column; }
  .site-header { align-items: flex-start; flex-direction: column; }
}

/* Phase 5 administrative inventory and public inventory UI amendments */

/* PD5-33: content expands with the desktop viewport instead of an 80 rem cap. */
main.card.admin-card {
  width: min(120rem, calc(100% - 1.5rem));
}

/* Administration landing: one navigation entry for every operational tool.
   Cards are links, so the whole tile is a comfortable target and the section
   headings provide the information architecture without another menu layer. */
main.card.admin-home {
  width: min(82rem, calc(100% - 2rem));
}
.admin-home-section { margin-top: 1.75rem; }
.admin-home-section h2 { margin: 0 0 0.75rem; }
.admin-home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0.85rem;
}
.admin-home-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-height: 9rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.14);
  color: var(--text);
  text-decoration: none;
}
.admin-home-card:hover {
  border-color: var(--accent);
  background: rgba(199, 168, 90, 0.08);
  color: var(--text);
}
.admin-home-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.admin-home-title {
  color: var(--accent-strong);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
}
.admin-home-copy { flex: 1; color: var(--muted); font-size: 0.9rem; }
.admin-home-stat { color: var(--text); font-size: 0.85rem; }
.admin-home-clear { color: var(--ok); }

/* PD5-35: one compact multi-column filter grid for the admin screens. */
.admin-filter-grid {
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}
.admin-filter-grid .filter-actions { min-height: 2.6rem; }

.admin-table { min-width: 72rem; }
/* UX review round 1: action links are compact icons with native tooltips. The
   final column is sticky so a narrow window can scroll the data while the
   actions stay reachable. */
.actions-cell { text-align: right; }
.action-links { display: inline-flex; align-items: center; justify-content: flex-end; gap: 0.25rem; }
.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--accent-strong);
  text-decoration: none;
}
.action-link:hover { border-color: var(--accent); background: rgba(199, 168, 90, 0.12); color: #fff0c0; }
.action-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.action-icon-svg { display: block; }
.admin-table th:last-child, .admin-table td:last-child {
  position: sticky;
  right: 0;
  z-index: 1;
  background: var(--panel);
  box-shadow: -1px 0 0 var(--border);
}
.admin-table th:last-child { background: #171b13; }
.account-actions { margin-bottom: 1.25rem; }
.group-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
  font-size: 0.78rem;
}
/* Lifecycle-state shortcuts above the admin list. Each tab is one mutually
   exclusive state (Active, Issued, Removed, All) and keeps the active filters. */
.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0 0.25rem;
}
.status-tab {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.status-tab:hover { border-color: var(--accent); color: #fff0c0; }
.status-tab.current {
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.12);
  color: var(--accent-strong);
  font-weight: 600;
}
.status-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row-removed { opacity: 0.72; }
.row-removed td a { color: var(--muted); }
.row-edit { margin-left: 0.45rem; font-size: 0.78rem; }

/* AI-01: page-local bulk removal controls. The bar stays below the table and
   the whole selection is re-validated server-side. */
.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.1rem 0.25rem;
}
.bulk-bar .help { max-width: 60ch; margin: 0; }
.admin-table td:first-child input[type="checkbox"] { margin: 0; }

/* PD5-36: icon-only external link. */
.external-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--accent-strong);
  text-decoration: none;
}
.external-link:hover { border-color: var(--accent); color: #fff0c0; }
.external-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.external-link-icon { display: block; }
.cell-link { text-align: center; }

/* Admin audit tables stay readable without forcing the inventory width. */
.audit-table { width: 100%; min-width: 64rem; border-collapse: collapse; font-size: 0.85rem; }
.audit-table th, .audit-table td { padding: 0.55rem 0.6rem; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
.audit-table th { background: rgba(0, 0, 0, 0.16); color: var(--accent-strong); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.audit-json { display: block; max-width: 24rem; max-height: 8rem; overflow: auto; font-family: "Cascadia Mono", Consolas, monospace; font-size: 0.75rem; white-space: pre-wrap; word-break: break-word; }

/* PD5-38: dense single-line cells on desktop; natural wrapping below 900 px. */
@media (min-width: 900px) {
  .inventory-table .cell-nowrap { white-space: nowrap; }
}
@media (max-width: 900px) {
  .admin-table, .audit-table { min-width: 44rem; }
}

/* P0 name-first identity: unresolved-identity badge and ambiguity picker. */
.identity-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--danger);
  border-radius: 999px;
  color: var(--danger);
  font-size: 0.72rem;
  vertical-align: middle;
}
.candidate-list {
  margin: 0.5rem 0 0;
  padding: 0.6rem 0.8rem;
  border: 1px dashed var(--muted);
  border-radius: 6px;
}
.candidate-list legend {
  padding: 0 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.candidate { display: block; margin: 0.25rem 0; }
.candidate input[type="radio"] { margin-right: 0.4rem; }

/* Phase 4 officer request queue. The age bands make the oldest request
   visible at two and seven days; chips label public and self rows without
   restricting anyone. */
.nav-count {
  display: inline-block;
  min-width: 1.25rem;
  margin-left: 0.25rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: #17180f;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}
.chip {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.age-fresh { color: var(--muted); }
.age-warning { color: #f0d693; font-weight: 600; }
.age-critical { color: var(--danger); font-weight: 700; }
.checkbox-row { display: flex; align-items: center; gap: 0.45rem; min-height: 2.6rem; }
.checkbox-row span { line-height: 1.25; }
.checkbox-row input[type="checkbox"] { width: auto; margin: 0; }
