:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f0f3f6;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --success: #1a7f37;
  --warn: #9a6700;
  --danger: #cf222e;
  --shadow: 0 6px 24px rgba(31,35,40,.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }

.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand h1 { font-size: 16px; margin: 0; font-weight: 600; }
.brand .sub { font-size: 12px; color: var(--muted); }
.logo { font-size: 18px; }

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; border: 1px solid transparent;
  color: var(--muted); padding: 6px 12px; border-radius: 6px;
  cursor: pointer; font-size: 14px;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--panel-2); color: var(--text); border-color: var(--border);
}

.sort-controls {
  display: flex; align-items: center; gap: 4px;
  margin-left: auto;
}
.sort-label { font-size: 12px; color: var(--muted); margin-right: 4px; }
.sort-btn {
  background: transparent; border: 1px solid transparent;
  color: var(--muted); padding: 6px 12px; border-radius: 6px;
  cursor: pointer; font-size: 13px; font: inherit;
}
.sort-btn:hover { color: var(--text); }
.sort-btn[aria-pressed="true"] {
  background: var(--panel-2); color: var(--text); border-color: var(--border);
}
.status { margin-left: 0; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
#conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn); display: inline-block;
}
#conn-dot.ok { background: var(--success); }
#conn-dot.bad { background: var(--danger); }

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 1fr);
  gap: 12px;
  padding: 16px 20px;
  overflow-x: auto;
  min-height: calc(100vh - 60px);
}

.lane {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex; flex-direction: column;
  min-height: 200px;
}
.lane-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.lane-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.lane-count { font-size: 11px; color: var(--muted); }
.lane-list { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; overflow-y: auto; }
.lane-search { margin: 0 0 8px; }
.lane-search-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
}
.lane-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(9,105,218,.15);
}
.lane-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}
.lane-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 2px;
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  user-select: none;
}
.card:hover { border-color: var(--accent); }
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.card-meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 12px; }
.card-meta .pill {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
}
.card-amount { color: var(--success); font-variant-numeric: tabular-nums; }
.card-due.urgent { color: var(--danger); }
.card-created { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Modal / read-only detail */
.modal { position: fixed; inset: 0; background: rgba(31,35,40,.35); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(640px, 92vw);
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow);
}
.modal-card header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-card header h2 { margin: 0; font-size: 15px; }
.modal-card .icon { background: transparent; color: var(--muted); border: 0; font-size: 22px; cursor: pointer; line-height: 1; }

.card-detail { padding: 14px 18px; display: flex; flex-direction: column; gap: 12px; }
.detail-row { display: flex; flex-direction: column; gap: 4px; }
.detail-label { font-size: 12px; color: var(--muted); }
.detail-value { font-size: 14px; color: var(--text); }
.detail-pre { white-space: pre-wrap; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#id-fields.proc .reimb, #id-fields.reimb .proc { display: none; }
.detail-links { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.detail-links li { padding: 2px 0; }
.detail-links a { color: var(--accent); }
.muted-hint { color: var(--muted); font-size: 12px; font-style: italic; }

.modal-actions {
  display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap;
  padding: 12px 0 0; border-top: 1px solid var(--border); margin-top: 4px;
}
.modal-actions button,
a.setforce-btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font: inherit;
  text-decoration: none; display: inline-block;
}
.modal-actions button:hover,
a.setforce-btn:hover { border-color: var(--accent); }
a.setforce-btn.primary,
.modal-actions button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
a.setforce-btn.primary:hover { background: var(--accent-hover); }
a.setforce-btn.secondary { font-size: 13px; }
.spacer { flex: 1; min-width: 8px; }

.setforce-actions { display: flex; flex-direction: column; gap: 8px; }
.setforce-block { display: flex; flex-direction: column; gap: 4px; }
.classic-fallback { font-size: 11px; color: var(--muted); }
.classic-fallback a { color: var(--accent); }

.activity-panel { padding: 0 18px 18px; }
.activity-panel.hidden { display: none; }
.activity-panel h3 { font-size: 13px; margin: 8px 0; color: var(--muted); }
#activity-list { list-style: none; padding: 0; margin: 0; font-size: 12px; }
#activity-list li {
  border-top: 1px solid var(--border);
  padding: 6px 0;
  display: flex; gap: 10px;
}
#activity-list .when { color: var(--muted); width: 130px; flex-shrink: 0; }
#activity-list .what { color: var(--text); }
.card-items-badge { color: var(--accent); }
.card-items {
  list-style: none; margin: 4px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 2px;
  font-size: 12px; line-height: 1.3; color: var(--muted);
}
.card-items li {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-items-more { color: var(--accent); font-weight: 500; }
.items-section { display: flex; flex-direction: column; gap: 8px; }
.items-preview { font-size: 12px; color: var(--muted); }
.items-preview table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.items-preview th, .items-preview td {
  text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--border); font-size: 11px;
}
.items-preview th { color: var(--muted); font-weight: 600; }
.items-preview .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- mobile ---- */
@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 10px 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .brand { flex: 1 1 auto; min-width: 0; }
  .brand .sub { display: none; }
  .tabs { order: 3; flex: 1 1 100%; }
  .tab { flex: 1; text-align: center; padding: 10px 8px; min-height: 44px; }
  .status { margin-left: 0; }

  .board {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 10px;
    padding: 12px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    min-height: calc(100dvh - 110px);
  }
  .lane {
    flex: 0 0 min(86vw, 340px);
    max-width: min(86vw, 340px);
    scroll-snap-align: start;
    max-height: calc(100dvh - 130px);
    min-height: 0;
  }
  .lane-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
    padding-bottom: 8px;
  }
  .card { padding: 12px; }
  .card-title { font-size: 15px; }

  .modal { align-items: flex-end; }
  .modal-card {
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 100%);
    border-radius: 14px 14px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .detail-grid { grid-template-columns: 1fr; }
  .modal-actions { flex-direction: column; align-items: stretch; }
  .modal-actions .spacer { display: none; }
  a.setforce-btn, .modal-actions button {
    width: 100%;
    text-align: center;
    padding: 12px 14px;
    min-height: 44px;
  }
  #activity-list li { flex-direction: column; gap: 2px; }
  #activity-list .when { width: auto; }
  .items-preview { overflow-x: auto; }
}

@media (max-width: 480px) {
  .brand h1 { font-size: 15px; }
  .board { padding: 10px; gap: 8px; }
  .lane { flex-basis: 88vw; max-width: 88vw; }
}

@media (hover: none) {
  .card:hover { border-color: var(--border); }
  .card:active { border-color: var(--accent); }
}

.card-receipt.pending { color: var(--warn); }
.card-receipt.received { color: var(--success); }

.card-epro { color: #0969da; }
.epro-block { margin-top: 4px; }
.epro-block .detail-value a { color: #0969da; text-decoration: none; }
.epro-block .detail-value a:hover { text-decoration: underline; }


/* ---- Amount POs strip (persistent, not a lane) ---- */
.amount-pos-strip {
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  padding: 4px 20px 6px;
  position: sticky;
  top: 52px;
  z-index: 4;
}
.amount-pos-strip-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 4px;
}
.amount-pos-toggle {
  background: transparent; border: 0; color: var(--text);
  font: inherit; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  cursor: pointer; padding: 0; color: var(--muted);
}
.amount-pos-toggle:hover { color: var(--text); }
.amount-pos-strip-hint { font-size: 11px; color: var(--muted); }
.amount-pos-strip.collapsed .amount-pos-panel { display: none; }
.amount-pos-strip.collapsed .amount-pos-strip-head { margin-bottom: 0; }
.amount-pos-strip.collapsed .amount-pos-toggle { /* caret flipped via text */ }

.amount-pos-panel {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.amount-po-card {
  flex: 1 1 100%;
  max-width: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
.amount-po-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
}
.amount-po-summary-id {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  min-width: 0;
}
.amount-po-title {
  margin: 0; font-size: 13px; font-weight: 600;
  white-space: nowrap;
}
.amount-po-sub {
  margin: 2px 0 10px; font-size: 12px; color: var(--muted);
}
.amount-po-totals {
  margin-top: 10px; padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  font-size: 12px; font-variant-numeric: tabular-nums;
  align-items: center;
}
.amount-po-totals--inline {
  margin: 0; padding: 0; border: 0;
  font-size: 12px; gap: 6px 12px;
  color: var(--muted);
}
.amount-po-totals .total-remaining,
.amount-po-totals--inline .total-remaining {
  font-weight: 600; color: var(--success);
}
.amount-po-chips {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 4px; flex: 1 1 auto; min-width: 0;
}
.amount-po-chip {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  white-space: nowrap;
}
.amount-po-chip-mfr { font-weight: 600; color: var(--text); }
.amount-po-chip-rem { color: var(--success); font-weight: 600; }
.amount-po-chip.warn {
  border-color: #d4a72c;
  background: #fff8c5;
}
.amount-po-chip.warn .amount-po-chip-rem { color: var(--warn); }
.amount-po-chip.critical {
  border-color: var(--danger);
  background: #ffebe9;
}
.amount-po-chip.critical .amount-po-chip-rem { color: var(--danger); }
.amount-po-details-toggle {
  background: transparent; border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 8px;
  font: inherit; font-size: 11px; font-weight: 600;
  color: var(--muted); cursor: pointer;
  text-transform: uppercase; letter-spacing: .03em;
  flex-shrink: 0;
  margin-left: auto;
}
.amount-po-details-toggle:hover {
  border-color: var(--accent); color: var(--accent);
}
.amount-po-details {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.amount-po-details[hidden] { display: none !important; }
.amount-po-lines {
  display: flex; flex-direction: column; gap: 6px;
}
.amount-po-line {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 6px 10px;
  align-items: center;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.amount-po-line.warn {
  border-color: #d4a72c;
  background: #fff8c5;
}
.amount-po-line.critical {
  border-color: var(--danger);
  background: #ffebe9;
}
.amount-po-mfr { font-size: 13px; font-weight: 600; }
.amount-po-nums {
  display: flex; flex-wrap: wrap; gap: 8px 14px;
  font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.amount-po-nums .remaining {
  color: var(--success); font-weight: 600;
}
.amount-po-line.warn .remaining { color: var(--warn); }
.amount-po-line.critical .remaining { color: var(--danger); }
.amount-po-bar {
  grid-column: 1 / -1;
  height: 5px; border-radius: 999px;
  background: #eaeef2; overflow: hidden;
}
.amount-po-bar > span {
  display: block; height: 100%;
  background: var(--accent);
  border-radius: 999px;
  max-width: 100%;
}
.amount-po-line.warn .amount-po-bar > span { background: #bf8700; }
.amount-po-line.critical .amount-po-bar > span { background: var(--danger); }
.amount-po-actions {
  display: flex; gap: 4px; flex-shrink: 0;
}
.amount-po-actions button {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 8px; font: inherit; font-size: 11px;
  cursor: pointer; color: var(--text);
}
.amount-po-actions button:hover { border-color: var(--accent); color: var(--accent); }
.amount-po-updated {
  margin-top: 6px; color: var(--muted); font-size: 11px;
  text-align: right;
}
.amount-pos-empty { font-size: 12px; color: var(--muted); padding: 4px 0; }

.amount-po-charges {
  grid-column: 1 / -1;
  margin-top: 2px;
}
.amount-po-charges-toggle {
  background: transparent; border: 0; padding: 0;
  font: inherit; font-size: 11px; font-weight: 600;
  color: var(--muted); cursor: pointer;
  text-transform: uppercase; letter-spacing: .03em;
}
.amount-po-charges-toggle:hover { color: var(--accent); }
.amount-po-charges-empty {
  margin-top: 6px; font-size: 12px; color: var(--muted);
  font-style: italic;
}
.amount-po-charges-list {
  list-style: none; margin: 6px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.amount-po-charge-row {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: 6px 12px;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.amount-po-charge-row.credit { opacity: 0.75; }
.amount-po-charge-po { font-weight: 600; color: var(--text); }
.amount-po-charge-po.muted { font-weight: 500; color: var(--muted); font-style: italic; }
.amount-po-charge-po-link {
  background: transparent; border: 0; padding: 0;
  font: inherit; font-size: 12px; font-weight: 600;
  color: var(--accent); cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px;
}
.amount-po-charge-po-link:hover { color: var(--text); }
.amount-po-charge-amt { font-weight: 600; color: var(--text); }
.amount-po-charge-amt.credit { color: var(--muted); font-weight: 500; }
.amount-po-charge-date { color: var(--muted); }
.amount-po-charge-note { color: var(--muted); font-style: italic; }


@media (max-width: 900px) {
  .amount-pos-strip {
    top: auto; position: relative; z-index: 1;
    padding: 4px 12px 6px;
  }
  .amount-po-summary { gap: 6px 8px; }
  .amount-po-details-toggle { margin-left: 0; }
  .amount-po-line {
    grid-template-columns: 1fr auto;
  }
  .amount-po-mfr { grid-column: 1 / -1; }
  .amount-po-bar { grid-column: 1 / -1; }
  .amount-po-charges { grid-column: 1 / -1; }
}
