/* Entirely Procurement.
   Built on the estate's design tokens (web/tokens/, the same copies every staff app carries):
   Sand page, Moss header, white panels, Neon accent, Bagoss Standard headings, Outfit body.
   The layout follows the India books and UAT consoles so the apps read as one product;
   this one is laid out phone-first, like Entirely Expenses, because goods are received where they arrive. */

@import url('tokens/colors.css');
@import url('tokens/fonts.css');
@import url('tokens/spacing.css');
@import url('tokens/typography.css');

/* [hidden] must outrank any later display rule, or the fixed full-screen gate stays on top
   of a rendered app with nothing in the console to say why. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  letter-spacing: var(--tracking-body);
  -webkit-text-size-adjust: 100%;
}

/* ------------------------------------------------------------------ header */
.bar {
  background: var(--surface-moss);
  color: var(--text-on-dark);
  position: sticky;
  top: 0;
  z-index: 2;
  padding-top: env(safe-area-inset-top);
}
.bar-in {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  min-height: 60px;
}
.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.mark { width: var(--stroke-heavy); height: 34px; background: var(--accent); display: block; flex: none; }
.bar h1 {
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  font-size: var(--fs-h3);
  letter-spacing: var(--tracking-h3);
  margin: 0;
}
.bar p { margin: 0; font-size: var(--fs-caption); color: rgba(255, 255, 255, 0.72); }
.who { display: flex; align-items: center; gap: var(--space-3); font-size: var(--fs-caption); color: rgba(255, 255, 255, 0.85); flex-wrap: wrap; }
#whoami { word-break: break-all; }
.tier {
  border: var(--stroke-thin) solid var(--border-on-dark);
  border-radius: var(--radius-capsule);
  padding: 2px var(--space-3);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caption);
  color: var(--accent);
}

.banner {
  background: var(--color-cream);
  color: var(--text-primary);
  font-size: var(--fs-small);
  padding: var(--space-3) var(--space-4);
  text-align: center;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------------ panels */
.panel {
  background: var(--surface-card);
  border: var(--stroke-thin) solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-4);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.panel h2 {
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  font-size: var(--fs-h4);
  letter-spacing: var(--tracking-tight);
  margin: 0 0 var(--space-2);
}
p.lede { margin: 0 0 var(--space-4); color: var(--text-secondary); font-size: var(--fs-small); }
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.banner.warn { border-radius: var(--radius-md); margin: 0 0 var(--space-4); text-align: left; }
.status { font-size: var(--fs-small); color: var(--text-secondary); }
.scan-status {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-heather);
  font-size: var(--fs-small);
}
.scan-status.done { background: var(--color-sage); }
.scan-status.warn { background: var(--color-cream); }
input.scanned, select.scanned { border-color: var(--color-moss); background: var(--color-sage); }

/* ----------------------------------------------------------------- capture */
.add-row { margin-bottom: var(--space-4); }
.receipt-view {
  display: grid;
  place-items: center;
  border: var(--stroke-thin) solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--color-sand);
  overflow: hidden;
  margin-bottom: var(--space-4);
}
.receipt-view img { max-width: 100%; max-height: 360px; display: block; }
.pdf-preview { display: flex; flex-direction: column; width: 100%; }
.pdf-preview iframe { width: 100%; height: min(62vh, 520px); border: 0; background: var(--color-white); display: block; }
.pdf-open { align-self: center; justify-content: center; margin: var(--space-5) var(--space-4) var(--space-2); text-decoration: none; display: inline-flex; align-items: center; font-weight: var(--weight-medium); padding: var(--space-2) var(--space-5); min-height: 44px; border-radius: var(--radius-capsule); background: var(--accent); border: var(--stroke-thin) solid var(--accent); color: var(--text-on-accent); }
.pdf-name { padding: var(--space-2) var(--space-3); font-size: var(--fs-caption); color: var(--text-secondary); word-break: break-all; }
.drafts .pdf-thumb {
  display: grid;
  place-items: center;
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caption);
  background: var(--color-moss);
  color: var(--accent);
  border-radius: var(--radius-sm);
}
label.btn {
  display: inline-flex;
  align-items: center;
  font: inherit;
  font-weight: var(--weight-medium);
  padding: var(--space-2) var(--space-5);
  min-height: 44px;
  border-radius: var(--radius-capsule);
  border: var(--stroke-thin) solid var(--border-subtle);
  background: var(--surface-card);
  color: var(--text-primary);
  cursor: pointer;
  position: relative;
}
label.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }
label.btn:focus-within { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------------ fields */
label.check { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-body); color: var(--text-primary); }
label.check input { width: 20px; height: 20px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin-bottom: var(--space-4); }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field.wide { grid-column: 1 / -1; }
label { font-size: var(--fs-caption); color: var(--text-secondary); font-weight: var(--weight-medium); }
input[type="date"], input[type="text"], select {
  font: inherit;
  /* 16px or more, or iOS Safari zooms the page on focus. */
  font-size: max(16px, var(--fs-body));
  padding: var(--space-2) var(--space-3);
  border: var(--stroke-thin) solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-card);
  color: var(--text-primary);
  width: 100%;
  min-height: 44px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* Capsule CTAs, per the brand's pill UI. */
button.btn {
  font: inherit;
  font-weight: var(--weight-medium);
  padding: var(--space-2) var(--space-5);
  min-height: 44px;
  border-radius: var(--radius-capsule);
  border: var(--stroke-thin) solid var(--border-subtle);
  background: var(--surface-card);
  color: var(--text-primary);
  cursor: pointer;
}
button.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }
button.btn.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
button.btn:disabled { opacity: 0.45; cursor: default; }
button.btn.small { padding: var(--space-1) var(--space-3); min-height: 32px; font-size: var(--fs-caption); }
.who button.btn { background: transparent; border-color: var(--border-on-dark); color: var(--text-on-dark); }

/* ------------------------------------------------------------------ claims */
.group h3 {
  font-size: var(--fs-caption);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caption);
  color: var(--text-secondary);
  margin: var(--space-4) 0 0;
}
.chip {
  display: inline-block;
  font-size: var(--fs-caption);
  font-weight: var(--weight-semibold);
  padding: 2px var(--space-2);
  border-radius: var(--radius-capsule);
  background: var(--color-heather);
  color: var(--text-secondary);
  white-space: nowrap;
}
.chip.approved, .chip.paid { background: var(--color-sage); color: var(--color-moss); }
.chip.pending, .chip.submitted, .chip.sending, .chip.waiting { background: var(--color-cream); color: #6b5a00; }
.chip.awaitingManager { background: var(--color-cream); color: #6b5a00; }
.chip.risk-low { background: var(--color-sage); color: var(--color-moss); }
.chip.risk-medium { background: var(--color-cream); color: #6b5a00; }
.chip.risk-high { background: #fbe9e7; color: #b3261e; }
.chip.failed, .chip.rejected, .chip.managerRejected { background: #fbe9e7; color: #b3261e; }
.drafts .actions { display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; }
.drafts .error { font-size: var(--fs-caption); color: #b3261e; }

.picker { margin-top: var(--space-2); }
.picker input[type="search"] { font: inherit; font-size: max(16px, var(--fs-body)); width: 100%; padding: var(--space-2) var(--space-3);
  border: var(--stroke-thin) solid var(--border-subtle); border-radius: var(--radius-sm); min-height: 44px; }
.pick-list { list-style: none; margin: var(--space-2) 0 0; padding: 0; max-height: 240px; overflow-y: auto;
  border: var(--stroke-thin) solid var(--border-subtle); border-radius: var(--radius-sm); }
.pick-list:empty { display: none; }
.pick-head { font-size: var(--fs-caption); text-transform: uppercase; letter-spacing: var(--tracking-caption); color: var(--text-secondary);
  padding: var(--space-2) var(--space-3) var(--space-1); background: var(--color-sand); }
button.pick { font: inherit; width: 100%; text-align: left; background: none; border: 0; padding: var(--space-2) var(--space-3);
  min-height: 44px; cursor: pointer; border-top: var(--stroke-thin) solid var(--border-subtle); }
button.pick:hover, button.pick:focus-visible { background: var(--color-sage); }
details.collapsible > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary h2 { margin: 0; }
details.collapsible > summary::after { content: '+'; font-size: var(--fs-h4); color: var(--text-secondary); }
details.collapsible[open] > summary::after { content: '–'; }
details.collapsible[open] > summary .status { display: none; }
details.collapsible[open] > summary { margin-bottom: var(--space-3); }
.allow-result { margin-top: var(--space-4); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--color-sand); }
.allow-result h3 { margin: 0 0 var(--space-2); font-family: var(--font-display); font-weight: var(--weight-medium); }
.allow-result ul { margin: 0 0 var(--space-2); padding-left: var(--space-4); font-size: var(--fs-small); }
#allowancePanel input[type="number"], #allowancePanel input[type="datetime-local"] { font: inherit; font-size: max(16px, var(--fs-body));
  padding: var(--space-2) var(--space-3); border: var(--stroke-thin) solid var(--border-subtle); border-radius: var(--radius-sm); min-height: 44px; }
#allowancePanel input[type="number"] { width: 5em; }

/* ------------------------------------------------------------------ detail */
.drafts li.openable { cursor: pointer; }
.drafts li.openable:hover { background: var(--color-sand); }
button.rowlink { font: inherit; font-weight: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
button.rowlink:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
#detail .row.between { margin-bottom: var(--space-4); }
#detail h2 { margin-bottom: var(--space-3); }
.risk-box { border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); margin: 0 0 var(--space-4); background: var(--color-heather); }
.risk-box.risk-low { background: var(--color-sage); }
.risk-box.risk-medium { background: var(--color-cream); }
.risk-box.risk-high { background: #fbe9e7; }
.risk-box h3 { margin: 0 0 var(--space-2); font-size: var(--fs-body); font-family: var(--font-display); font-weight: var(--weight-medium); }
.risk-box ul { margin: 0 0 var(--space-2); padding-left: var(--space-4); font-size: var(--fs-small); }
.risk-box li { padding: 2px 0; white-space: pre-wrap; }
.risk-box .status { margin: 0; }
.risk-box .audit-note { margin: 0 0 var(--space-2); font-weight: var(--weight-medium); color: #b3261e; }
#detail .error { font-size: var(--fs-small); color: #b3261e; margin: 0 0 var(--space-3); }
.facts { margin: 0 0 var(--space-4); display: grid; gap: var(--space-2); }
.facts > div { display: grid; grid-template-columns: 9em 1fr; gap: var(--space-3); }
.facts dt { font-size: var(--fs-caption); color: var(--text-secondary); font-weight: var(--weight-medium); }
.facts dd { margin: 0; word-break: break-word; }
.subhead { font-size: var(--fs-caption); text-transform: uppercase; letter-spacing: var(--tracking-caption); color: var(--text-secondary); margin: var(--space-4) 0 var(--space-2); }
.history { list-style: none; margin: 0 0 var(--space-4); padding: 0; font-size: var(--fs-small); color: var(--text-secondary); }
.history li { padding: var(--space-1) 0; }
#detailActions { margin-top: var(--space-4); }
#detailActions .actions { display: flex; flex-wrap: wrap; justify-content: flex-start; align-items: center; gap: var(--space-3); margin-top: var(--space-3); }
/* The warning takes its own line, and the two buttons sit well apart, so a stray tap cannot hit the red one. */
#detailActions .actions .status { flex: 1 0 100%; }
#detailActions .actions button + button { margin-left: var(--space-3); }
input.reject-note { flex: 1 0 100%; font: inherit; font-size: max(16px, var(--fs-body)); padding: var(--space-2) var(--space-3); border: var(--stroke-thin) solid var(--border-subtle); border-radius: var(--radius-sm); min-height: 44px; }
button.btn.danger { background: #b3261e; border-color: #b3261e; color: #fff; }

/* ------------------------------------------------------------------ drafts */
.drafts { list-style: none; margin: 0; padding: 0; }
.drafts li {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: var(--stroke-thin) solid var(--border-subtle);
}
.drafts li:last-child { border-bottom: 0; }
.drafts img, .drafts .nophoto, .drafts .pdf-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); background: var(--color-heather); }
.drafts .pdf-thumb { background: var(--color-moss); font-size: var(--fs-caption); }
.drafts .amount { font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.drafts .meta { font-size: var(--fs-caption); color: var(--text-secondary); word-break: break-word; }

/* -------------------------------------------------------------------- gate */
.gate {
  position: fixed;
  inset: 0;
  background: var(--surface-page);
  display: grid;
  place-items: center;
  padding: var(--space-5);
  z-index: 5;
}
.gate-card {
  background: var(--surface-card);
  border: var(--stroke-thin) solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-5);
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-sm);
}
.gate-card h2 { font-family: var(--font-display); font-weight: var(--weight-medium); margin: 0 0 var(--space-3); }
.gate-card p { white-space: pre-line; color: var(--text-secondary); margin: 0 0 var(--space-4); }

/* ------------------------------------------------------------- procurement */
.tabs { display: flex; gap: var(--space-2); margin: 0 0 var(--space-4); overflow-x: auto; }
.tab { font: inherit; font-weight: var(--weight-medium); padding: var(--space-2) var(--space-4); min-height: 44px; border-radius: var(--radius-capsule);
  border: var(--stroke-thin) solid var(--border-subtle); background: var(--surface-card); color: var(--text-primary); cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { background: var(--surface-moss); color: var(--text-on-dark); border-color: var(--surface-moss); }
.tab:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.lines { display: grid; gap: var(--space-3); margin: 0 0 var(--space-4); }
.line-card { border: var(--stroke-thin) solid var(--border-subtle); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); background: var(--surface-card); }
.line-card .line-head { display: flex; justify-content: space-between; gap: var(--space-3); align-items: baseline; }
.line-card .line-name { font-weight: var(--weight-semibold); }
.quote-box { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); border: var(--stroke-thin) dashed var(--border-subtle); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); background: var(--color-sand); margin-bottom: var(--space-4); }
.quote-box .status { flex: 1 1 240px; margin: 0; }
.line-card .line-meta { font-size: var(--fs-caption); color: var(--text-secondary); }
.line-card .receive-input { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); flex-wrap: wrap; }
.line-card input[type="number"] { font: inherit; font-size: max(16px, var(--fs-body)); width: 7em; padding: var(--space-2) var(--space-3);
  border: var(--stroke-thin) solid var(--border-subtle); border-radius: var(--radius-sm); min-height: 44px; }
.req-line { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.req-line .field.wide { grid-column: 1 / -1; }
.req-line .remove { justify-self: end; grid-column: 1 / -1; }
.gap-top { margin-top: var(--space-4); }
.actions-row { margin-top: var(--space-3); }
input[type="search"] { font: inherit; font-size: max(16px, var(--fs-body)); width: 100%; padding: var(--space-2) var(--space-3);
  border: var(--stroke-thin) solid var(--border-subtle); border-radius: var(--radius-sm); min-height: 44px; background: var(--surface-card); }
.pick-list { list-style: none; margin: var(--space-2) 0 0; padding: 0; max-height: 220px; overflow-y: auto;
  border: var(--stroke-thin) solid var(--border-subtle); border-radius: var(--radius-sm); }
.pick-list:empty { display: none; }
button.pick { font: inherit; width: 100%; text-align: left; background: none; border: 0; padding: var(--space-2) var(--space-3);
  min-height: 44px; cursor: pointer; border-top: var(--stroke-thin) solid var(--border-subtle); }
button.pick:hover, button.pick:focus-visible { background: var(--color-sage); }
.chip.receivable { background: var(--color-cream); color: #6b5a00; }
.chip.done { background: var(--color-sage); color: var(--color-moss); }
