/* PHM-OS design tokens — locked, do not restyle. */
:root {
  --navy:        #0a1428;
  --navy-soft:   #142647;
  --gold:        #c9a23b;
  --gold-soft:   #e3c577;
  --cream:       #f5f1e8;
  --cream-soft:  #fbf8f1;
  --text:        #0a1428;
  --text-muted:  #5a6679;
  --rule:        #d9d2bf;
  --danger:      #b3261e;
  --ok:          #2c7a3b;
  --shadow:      0 2px 6px rgba(10, 20, 40, 0.06);
  --shadow-lg:   0 8px 24px rgba(10, 20, 40, 0.12);
  --radius:      8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'DM Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--navy);
  margin: 0 0 0.5em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; }

a { color: var(--navy); text-decoration: underline; text-underline-offset: 3px; }
a:hover { color: var(--gold); }

.mono, code, td.money, .money, td.num {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

/* Top nav */
.topnav {
  background: var(--navy);
  color: var(--cream);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
/* Sprint 6.8 Stage C — reserve a slot on the right for the floating
   Desktop/iPhone toggle (which is `position: fixed; top: 16px; right: 20px`).
   Without this, the user name + Sign out button slide under it. */
@media (min-width: 768px) {
  .topnav { padding-right: 250px; }
}
.topnav .brand {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--cream);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.topnav .brand .accent { color: var(--gold); }
.topnav .tenant {
  font-size: 0.9rem;
  color: var(--gold-soft);
  font-weight: 500;
}
.topnav .spacer { flex: 1; }
.topnav .user {
  font-size: 0.85rem;
  color: var(--cream);
  opacity: 0.85;
}
.topnav form { margin: 0; }
.topnav button.logout {
  background: transparent;
  border: 1px solid var(--cream);
  color: var(--cream);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.topnav button.logout:hover { background: var(--cream); color: var(--navy); }

/* Main container */
.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* Cards */
.card {
  background: white;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.cards-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
@media (max-width: 720px) { .cards-3 { grid-template-columns: 1fr; } }

.stat .label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat .value { font-family: 'Fraunces', serif; font-size: 2.25rem; color: var(--navy); margin-top: 0.25rem; }
.stat .sub { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.5rem; }

/* Tables */
.table-wrap { background: white; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.lots { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
table.lots th, table.lots td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--rule); }
table.lots th { background: var(--cream-soft); color: var(--text-muted); font-weight: 500; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
table.lots tr:last-child td { border-bottom: none; }
table.lots tr.row-link { cursor: pointer; }
table.lots tr.row-link:hover { background: var(--cream-soft); }
table.lots td.money, table.lots td.num { text-align: right; }
@media (max-width: 720px) {
  table.lots, table.lots thead, table.lots tbody, table.lots tr, table.lots td, table.lots th { display: block; }
  table.lots thead { display: none; }
  table.lots tr { padding: 1rem; border-bottom: 1px solid var(--rule); }
  table.lots td { padding: 0.25rem 0; border: none; }
  table.lots td::before { content: attr(data-label); display: inline-block; min-width: 110px; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
}

/* Status pills */
.pill { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
.pill.received  { background: #e7eef8; color: #314e88; }
.pill.shipped   { background: #efe4c0; color: #6e5410; }
.pill.assayed   { background: #d8eddd; color: #2c5a3a; }
.pill.settled   { background: #dde1f1; color: #2f3c75; }
.pill.paid      { background: #cfe8d2; color: #1f5e2c; }
.pill.cancelled { background: #ead7d5; color: #7a2e25; }

/* Buttons */
.btn { display: inline-block; padding: 0.6rem 1.1rem; border-radius: var(--radius); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; border: 1px solid transparent; }
.btn.primary { background: var(--gold); color: var(--navy); }
.btn.primary:hover { background: var(--gold-soft); color: var(--navy); }
.btn.outline { background: transparent; border-color: var(--navy); color: var(--navy); }
.btn.outline:hover { background: var(--navy); color: var(--cream); }
.btn.danger { background: white; border-color: var(--danger); color: var(--danger); }

/* Forms */
.form { background: white; padding: 1.5rem; border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); max-width: 640px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.form .row.single { grid-template-columns: 1fr; }
@media (max-width: 560px) { .form .row { grid-template-columns: 1fr; } }
.form label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.form input, .form select, .form textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: inherit;
  font-size: 0.95rem;
  background: var(--cream-soft);
  color: var(--text);
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--gold); border-color: var(--gold); background: white; }
.form .actions { display: flex; gap: 0.75rem; margin-top: 0.75rem; }

/* Login */
.login {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-soft) 100%);
}
.login-box {
  width: 100%;
  max-width: 380px;
  background: white;
  padding: 2.25rem 2rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-box .wordmark { font-family: 'Fraunces', serif; font-size: 1.6rem; color: var(--navy); margin-bottom: 0.25rem; }
.login-box .wordmark .accent { color: var(--gold); }
.login-box .tag { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.75rem; line-height: 1.45; }
.login-box .btn { display: block; width: 100%; margin-bottom: 0.75rem; padding: 0.7rem; }
.login-box .btn.outline.google { border-color: #4285f4; color: #1f3a85; }
.login-box .btn.outline.microsoft { border-color: #2f2f2f; color: #2f2f2f; }
.login-box .err { background: #fce7e6; color: var(--danger); border: 1px solid #f3b7b3; padding: 0.6rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.85rem; }

/* Section heading */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-header h2 { margin: 0; }

/* Detail */
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem 2rem; background: white; padding: 1.25rem; border: 1px solid var(--rule); border-radius: var(--radius); }
@media (max-width: 560px) { .kv-grid { grid-template-columns: 1fr; } }
.kv .k { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kv .v { font-size: 1rem; color: var(--navy); margin-top: 0.15rem; }
.kv .v.mono { font-family: 'JetBrains Mono', monospace; font-size: 0.92rem; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty h3 { color: var(--navy); margin-bottom: 0.35rem; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.danger { color: var(--danger); }
.ok { color: var(--ok); }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

/* Top-nav extras */
.topnav .nav-links { display: flex; gap: 1rem; }
.topnav .nav-links a { color: var(--cream); text-decoration: none; opacity: 0.9; font-size: 0.92rem; }
.topnav .nav-links a:hover { color: var(--gold); opacity: 1; }
@media (max-width: 720px) { .topnav .nav-links { display: none; } }

/* Lot detail show-page extras */
.show-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.status-pill { font-size: 0.85rem; padding: 0.3rem 0.8rem; }
.show-notes-heading, .show-status-heading { margin-top: 2rem; }
.status-form { gap: 0.75rem; flex-wrap: wrap; }
.status-select {
  padding: 0.55rem 0.75rem; border: 1px solid var(--rule); border-radius: 6px;
  font: inherit; background: var(--cream-soft);
}
.form-err { display: none; margin-top: 1rem; }

/* Optimize page */
.back-row { margin-bottom: 0.75rem; }
.optimize-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1.5rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.optimize-header h1 { margin: 0.25rem 0 0; }
.big-money { font-size: 2.4rem; color: var(--navy); }
.value-display { text-align: right; }
@media (max-width: 560px) {
  .optimize-header { flex-direction: column; align-items: flex-start; }
  .value-display { text-align: left; }
  .big-money { font-size: 2rem; }
}

.banner {
  padding: 0.85rem 1rem; border-radius: var(--radius);
  background: var(--cream-soft); border: 1px solid var(--rule);
  font-size: 0.92rem; margin-bottom: 1.25rem;
}
.banner.warn { background: #fff5e3; border-color: #efd198; color: #6e5410; }

.recommend-banner {
  background: linear-gradient(135deg, #fcefb4 0%, var(--gold-soft) 100%);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}
.recommend-label {
  font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: #6e5410; margin-bottom: 0.35rem;
}
.recommend-name {
  font-family: 'Fraunces', serif; font-size: 1.65rem; font-weight: 600;
  color: var(--navy); display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.recommend-headline {
  font-family: 'DM Sans', sans-serif; font-size: 0.85rem; font-weight: 500;
  background: var(--navy); color: var(--cream); padding: 0.2rem 0.7rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.recommend-rationale {
  font-size: 1.02rem; line-height: 1.5; color: var(--navy);
  margin: 0.75rem 0 1rem; max-width: 70ch;
}
.wc-mini { display: flex; gap: 2rem; flex-wrap: wrap; }
.wc-mini-item { display: flex; flex-direction: column; gap: 0.1rem; }
.wc-label { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: #6e5410; }
.wc-value { font-size: 1.05rem; color: var(--navy); font-weight: 500; }
.wc-value.danger { color: var(--danger); }

.offers-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 1rem; align-items: stretch;
}
@media (max-width: 960px) { .offers-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .offers-grid { grid-template-columns: 1fr; } }
.offer-card {
  background: white; border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 1.1rem 1.1rem 1.25rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.offer-card.recommended { border-color: var(--gold); border-width: 2px; box-shadow: var(--shadow-lg); }
.offer-card.ineligible { opacity: 0.55; }
.offer-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.85rem; }
.offer-name { font-family: 'Fraunces', serif; font-size: 1.15rem; color: var(--navy); font-weight: 600; }
.offer-headline { font-size: 0.7rem; padding: 0.15rem 0.55rem; }
.offer-headline.fast-cash { background: #fcefb4; color: #6e5410; }
.offer-headline.balanced { background: #dde1f1; color: #2f3c75; }
.offer-headline.optimize-price { background: #d8eddd; color: #2c5a3a; }
.offer-headline.no-advance { background: #ead7d5; color: #7a2e25; }
.ineligible-note { color: var(--danger); font-size: 0.8rem; margin-bottom: 0.75rem; }
.offer-amount-row { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.75rem; }
.offer-amount { font-size: 1.7rem; color: var(--navy); font-weight: 500; }
.offer-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem 0.85rem; font-size: 0.83rem; margin: 0 0 1rem; }
.offer-meta dt { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
.offer-meta dd { margin: 0.1rem 0 0; color: var(--navy); }
.offer-card .btn { margin-top: auto; }

.route-msg {
  margin-top: 1.5rem; padding: 0.75rem 1rem; border-radius: var(--radius);
  font-size: 0.95rem;
}
.route-msg.ok { background: #d8eddd; color: var(--ok); border: 1px solid #a9d4b5; }
.route-msg.err { background: #fce7e6; color: var(--danger); border: 1px solid #f3b7b3; }

/* Forecast page */
.cash-week {
  background: white; border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; box-shadow: var(--shadow);
}
.cash-week.shortfall { border-color: #f3b7b3; background: #fff7f6; }
.cw-label { font-size: 0.78rem; letter-spacing: 0.07em; color: var(--text-muted); text-transform: uppercase; margin-bottom: 0.65rem; }
.cw-row { display: flex; gap: 2rem; flex-wrap: wrap; }
.cw-stat { display: flex; flex-direction: column; gap: 0.1rem; }
.cw-stat-l { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.cw-stat-v { font-size: 1.3rem; color: var(--navy); }
.cw-stat.danger .cw-stat-v { color: var(--danger); }
.cw-stat.ok .cw-stat-v { color: var(--ok); }

.chart-wrap {
  background: white; border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); margin-top: 0.5rem;
}
.bucket-chart { width: 100%; height: auto; max-height: 280px; }

/* Alert banner (dashboard) */
.alert-banner {
  border-radius: var(--radius);
  padding: 1.1rem 1.4rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}
.alert-banner.severity-warning {
  background: linear-gradient(135deg, #fcefb4 0%, var(--gold-soft) 100%);
  border: 1px solid var(--gold);
}
.alert-banner.severity-critical {
  background: linear-gradient(135deg, #ffd4d0 0%, #fce7e6 100%);
  border: 1px solid var(--danger);
}
.alert-banner .alert-label {
  font-size: 0.78rem; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--navy); font-weight: 500; margin-bottom: 0.35rem;
}
.alert-banner.severity-critical .alert-label { color: var(--danger); }
.alert-banner .alert-reason {
  font-size: 1.05rem; line-height: 1.45; color: var(--navy);
  margin: 0 0 0.85rem; max-width: 80ch;
}
.alert-banner .alert-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.alert-info-note { margin-top: -0.5rem; }

/* Settings form */
.settings-form .settings-section {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin: 0 0 1.25rem;
  background: var(--cream-soft);
}
.settings-form legend {
  padding: 0 0.5rem;
  font-family: 'Fraunces', serif;
  font-size: 1.1rem;
  color: var(--navy);
  margin-left: -0.5rem;
}
.settings-form .hint { margin-top: 0.35rem; }
.settings-form input[readonly] { background: #eee; color: var(--text-muted); }
.checkbox-row {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.95rem; color: var(--text);
}
.checkbox-row input[type="checkbox"] { width: auto; margin: 0; }

/* Modal dialog */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 20, 40, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 1rem;
}
.dialog {
  background: white;
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  max-width: 540px; width: 100%;
  max-height: 90vh; overflow-y: auto;
}
.dialog h3 { margin-top: 0; }
.dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.dialog .row.single { grid-template-columns: 1fr; }
@media (max-width: 540px) { .dialog .row { grid-template-columns: 1fr; } }
.dialog label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.dialog input, .dialog select, .dialog textarea {
  width: 100%; padding: 0.55rem 0.75rem;
  border: 1px solid var(--rule); border-radius: 6px;
  font: inherit; font-size: 0.95rem; background: var(--cream-soft);
}
.dialog .actions { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.5rem; flex-wrap: wrap; }

/* Hedges */
.filter-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-pill {
  padding: 0.35rem 0.85rem; border-radius: 999px;
  font-size: 0.85rem; text-decoration: none;
  border: 1px solid var(--rule); color: var(--text-muted);
  background: white;
}
.filter-pill:hover { color: var(--navy); border-color: var(--navy); }
.filter-pill.active { background: var(--navy); color: var(--cream); border-color: var(--navy); }

.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 880px) { .review-grid { grid-template-columns: 1fr; } }
.review-source h3, .review-fields h3 { margin-top: 0; }
.source-frame {
  width: 100%; height: 600px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: white;
}
.source-image { max-width: 100%; max-height: 600px; border: 1px solid var(--rule); border-radius: var(--radius); }

.attached-hedges-cta { margin-top: 0.5rem; }

/* Lots list filter row */
.filter-row { display: flex; gap: 0.5rem; align-items: center; margin: 0 0 1rem; flex-wrap: wrap; }
.filter-row .filter-pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.35rem 0.85rem; border-radius: 999px; font-size: 0.86rem;
  background: var(--cream-soft); color: var(--text); text-decoration: none;
  border: 1px solid var(--rule);
}
.filter-row .filter-pill:hover { background: white; border-color: var(--navy); }
.filter-row .filter-pill.active {
  background: var(--navy); color: var(--cream); border-color: var(--navy);
}
.filter-pill-count {
  font-family: 'JetBrains Mono', monospace; font-size: 0.74rem;
  background: rgba(0,0,0,0.08); padding: 0.04rem 0.4rem; border-radius: 999px;
}
.filter-row .filter-pill.active .filter-pill-count { background: rgba(255,255,255,0.15); }
.filter-spacer { flex: 1; }
.filter-sort { display: inline-flex; gap: 0.5rem; flex-wrap: wrap; }

.adv-pill {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.1rem; height: 1.1rem; border-radius: 999px;
  background: var(--gold); color: var(--navy);
  font-size: 0.62rem; font-weight: 700;
  vertical-align: middle;
}

.pagination {
  display: flex; gap: 0.6rem; align-items: center; justify-content: center;
  margin: 1.25rem 0 2rem; flex-wrap: wrap;
}
.pagination-info { font-size: 0.85rem; color: var(--text-muted); }

.material-cell { max-width: 26ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Lot detail header */
.lot-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; margin: 0.4rem 0 1.4rem; flex-wrap: wrap;
}
.lot-header h1 { margin: 0; }
.lot-header-sub { margin-top: 0.2rem; max-width: 60ch; }
.lot-section-h { margin: 1.7rem 0 0.6rem; font-size: 1.05rem; }

/* Cash-flow recommendation hero */
.cash-flow-reco {
  border-radius: var(--radius); padding: 1.1rem 1.3rem;
  margin: 0 0 1.6rem;
  box-shadow: var(--shadow);
}
.cash-flow-reco.kind-take_advance {
  background: linear-gradient(135deg, #fcefb4 0%, var(--gold-soft) 100%);
  border: 1px solid var(--gold);
}
.cash-flow-reco.kind-consider_advance {
  background: var(--cream-soft);
  border: 1px solid var(--gold);
}
.cash-flow-reco.kind-wait {
  background: linear-gradient(135deg, #dde8d8 0%, #cfe4cb 100%);
  border: 1px solid #6b9a5e;
}
.cash-flow-reco.kind-settled {
  background: var(--cream-soft);
  border: 1px solid var(--rule);
}
.reco-label {
  font-size: 0.74rem; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 0.3rem;
}
.reco-headline {
  font-family: 'Fraunces', serif; font-size: 1.5rem; font-weight: 600;
  color: var(--navy); margin-bottom: 0.4rem;
}
.cash-flow-reco.kind-wait .reco-headline { color: #285530; }
.reco-detail {
  font-size: 1.02rem; line-height: 1.5; color: var(--navy);
  margin: 0 0 0.6rem; max-width: 70ch;
}
.reco-tenant-tag {
  font-size: 0.82rem; color: var(--text-muted);
  border-top: 1px solid rgba(0,0,0,0.08); padding-top: 0.5rem;
}
.reco-tenant-tag strong { color: var(--navy); }

/* PGM hero — Section 3 */
.pgm-hero {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.85rem;
  margin: 0.4rem 0;
}
@media (max-width: 720px) { .pgm-hero { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 460px) { .pgm-hero { grid-template-columns: 1fr; } }
.pgm-card {
  background: white; border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
  display: flex; flex-direction: column; gap: 0.15rem;
}
.pgm-card.pgm-total {
  background: linear-gradient(180deg, var(--gold-soft) 0%, #f5e5b8 100%);
  border-color: var(--gold);
}
.pgm-label {
  font-size: 0.78rem; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-muted);
}
.pgm-card.pgm-total .pgm-label { color: #6e5410; }
.pgm-oz {
  font-family: 'Fraunces', serif; font-size: 1.8rem; line-height: 1.1;
  color: var(--navy);
}
.pgm-unit {
  font-size: 0.75rem; color: var(--text-muted); margin-top: -0.15rem;
}
.pgm-pct {
  font-size: 0.78rem; color: var(--text-muted); margin-top: 0.35rem;
}

/* Advance vs reconcile grid — Section 4 */
.adv-rec-grid {
  background: white; border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 0.5rem 0.85rem;
}
.adv-rec-row {
  display: grid; grid-template-columns: 60px 1fr 1fr; gap: 0.5rem;
  padding: 0.4rem 0; align-items: center;
}
.adv-rec-row.header { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; border-bottom: 1px solid var(--rule); }
.adv-rec-row:not(.header) + .adv-rec-row { border-top: 1px dashed var(--rule); }
.adv-rec-row.has-advance { background: rgba(201, 162, 59, 0.08); }
.adv-rec-metal {
  font-weight: 500; color: var(--navy);
  font-family: 'Fraunces', serif; font-size: 1rem;
}

/* Tenant switcher dropdown — top nav + mobile drawer */
.topnav .tenant-switcher {
  background: rgba(255, 255, 255, 0.08); color: var(--cream);
  border: 1px solid rgba(245, 241, 232, 0.25); border-radius: 6px;
  padding: 0.32rem 0.6rem; font: inherit; font-size: 0.85rem;
  max-width: 260px; cursor: pointer;
}
.topnav .tenant-switcher:hover { border-color: var(--gold); }
.topnav .tenant-switcher option { background: var(--navy); color: var(--cream); }
.mobile-drawer .drawer-label {
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--gold-soft); margin-top: 0.4rem;
}
.mobile-drawer .tenant-switcher-mobile {
  width: 100%; background: rgba(0,0,0,0.25); color: var(--cream);
  border: 1px solid rgba(245, 241, 232, 0.25); border-radius: 6px;
  padding: 0.45rem 0.6rem; font: inherit; font-size: 0.92rem;
}
.mobile-drawer .tenant-switcher-mobile option { background: var(--navy); color: var(--cream); }

/* ════════════════ Mobile chrome (RepOS-style) ════════════════
   Two pieces of chrome render on every authenticated page:
     - .mobile-topbar  + .mobile-drawer   (top of the frame, hamburger menu)
     - .bottom-tabs                        (bottom of the frame, tab bar)
   They're hidden by default (desktop view). Two triggers reveal them:
     - real mobile (<768px viewport)
     - html.view-phone class set by the Desktop/iPhone toggle
   The toggle itself is a fixed pill at top-right of the viewport. */

/* Floating Desktop / iPhone toggle — top-right fixed on the cream backdrop */
.view-toggle-fixed {
  position: fixed; top: 16px; right: 20px; z-index: 60;
  display: inline-flex; align-items: stretch;
  border: 1px solid rgba(10, 20, 40, 0.15); border-radius: 999px;
  background: white;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(10, 20, 40, 0.12);
}
.view-toggle-fixed .vt-btn {
  background: transparent; border: 0; cursor: pointer;
  color: var(--text-muted); font: inherit; font-size: 0.78rem;
  padding: 0.35rem 0.75rem; line-height: 1.1; letter-spacing: 0.02em;
}
.view-toggle-fixed .vt-btn:hover:not(.active) { color: var(--navy); }
.view-toggle-fixed .vt-btn.active {
  background: var(--gold); color: var(--navy); font-weight: 500;
}

/* Mobile topbar — RepOS pattern */
.mobile-topbar {
  display: none;
  align-items: center; gap: 0.75rem;
  background: var(--navy); color: var(--cream);
  padding: 0.85rem 1rem;
  position: sticky; top: 0; z-index: 50;
}
.mobile-topbar .hamburger-btn {
  background: transparent; border: 0; color: var(--cream);
  font-size: 1.4rem; cursor: pointer; padding: 0.1rem 0.5rem;
  line-height: 1;
}
.mobile-topbar .hamburger-btn:hover { color: var(--gold-soft); }
.mobile-topbar .brand-mobile {
  font-family: 'Fraunces', serif; font-weight: 600;
  color: var(--cream); text-decoration: none; font-size: 1.1rem;
  letter-spacing: 0.02em;
}
.mobile-topbar .brand-mobile .accent { color: var(--gold); }
.mobile-topbar .tenant-mobile-tag {
  font-size: 0.74rem; color: var(--gold-soft);
  margin-left: auto; padding: 0.18rem 0.6rem;
  background: rgba(255, 255, 255, 0.08); border-radius: 999px;
  max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Slide-down drawer attached under the mobile topbar */
.mobile-drawer {
  display: none;
  background: var(--navy-soft); color: var(--cream);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.75rem 1rem 0.85rem;
  flex-direction: column; gap: 0.4rem;
  position: sticky; top: 60px; z-index: 49;
}
.mobile-drawer.open { display: flex; }
.mobile-drawer .drawer-user {
  font-size: 0.78rem; color: var(--gold-soft);
  padding-bottom: 0.45rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 0.35rem;
}
.mobile-drawer .drawer-link {
  color: var(--cream); text-decoration: none;
  padding: 0.55rem 0.55rem; border-radius: 6px;
  font-size: 0.95rem;
}
.mobile-drawer .drawer-link:hover { background: rgba(255, 255, 255, 0.08); color: var(--gold-soft); }
.mobile-drawer .drawer-logout-form { margin: 0.5rem 0 0; }
.mobile-drawer .drawer-logout {
  background: transparent; color: var(--cream);
  border: 1px solid rgba(245, 241, 232, 0.5); border-radius: 6px;
  padding: 0.5rem 0.75rem; font: inherit; font-size: 0.88rem;
  cursor: pointer; width: 100%;
}
.mobile-drawer .drawer-logout:hover { background: var(--cream); color: var(--navy); }

/* Bottom tab bar — RepOS pattern (always-visible primary nav inside the frame) */
.bottom-tabs {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--navy);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0.4rem 0.3rem 0.55rem;
  z-index: 50;
}
.bottom-tabs .bt-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 0.18rem; padding: 0.35rem 0.25rem;
  color: rgba(245, 241, 232, 0.55); text-decoration: none;
  font-size: 0.66rem; letter-spacing: 0.04em;
}
.bottom-tabs .bt-item:hover { color: var(--gold-soft); }
.bottom-tabs .bt-item.active { color: var(--gold); }
.bottom-tabs .bt-icon { font-size: 1.3rem; line-height: 1; }
.bottom-tabs .bt-label { font-size: 0.68rem; }

/* ---- Real mobile (<768px): hide toggle, hide desktop nav, show mobile chrome ---- */
@media (max-width: 767px) {
  .view-toggle-fixed { display: none; }
  .topnav { display: none; }
  .mobile-topbar { display: flex; }
  .bottom-tabs { display: flex; }
  main.container { padding-bottom: 5.5rem; }
}

/* ---- Phone view on desktop (>=768px, html.view-phone): show frame + mobile chrome ---- */
@media (min-width: 768px) {
  /* Desktop view (explicit) — default visuals, hide mobile chrome */
  html.view-desktop .mobile-topbar,
  html.view-desktop .mobile-drawer,
  html.view-desktop .bottom-tabs { display: none; }

  /* Phone view — full mobile chrome inside a 390px phone frame */
  html.view-phone body { background: #efe9d8; min-height: 100vh; }
  html.view-phone .topnav { display: none; }

  html.view-phone .mobile-topbar {
    display: flex;
    max-width: 390px; margin: 28px auto 0;
    border-radius: 24px 24px 0 0;
    border: 12px solid #1a1a1a; border-bottom: 0;
    padding: 0.75rem 0.85rem;
    position: relative; top: auto;
    box-shadow: 0 -2px 0 #1a1a1a; /* visual continuity into frame below */
  }
  html.view-phone .mobile-drawer.open {
    max-width: 390px; margin: 0 auto;
    border-left: 12px solid #1a1a1a; border-right: 12px solid #1a1a1a;
    position: relative; top: auto;
  }
  html.view-phone main.container {
    max-width: 390px; margin: 0 auto 0;
    background: var(--cream);
    border-left: 12px solid #1a1a1a;
    border-right: 12px solid #1a1a1a;
    border-radius: 0;
    box-shadow: 0 0 0 transparent;
    padding-bottom: 5.5rem;
    min-height: 60vh;
    /* Sprint 6.8 Stage C — clip content inside the phone frame. Wide tables,
       cards, sparklines, and the view-as banner would otherwise bleed past
       the 12px black bezels. overflow-x:auto preserves horizontal scrolling
       for content that genuinely needs it (wide tables). */
    overflow-x: auto;
    overflow-y: visible;
  }
  /* The sticky view-as banner is full-page width by default — constrain it
     to the phone frame in phone view so it doesn't escape the bezel. */
  html.view-phone .view-as-banner {
    max-width: 390px; margin: 0 auto;
    border-left: 12px solid #1a1a1a; border-right: 12px solid #1a1a1a;
    border-radius: 0;
  }
  html.view-phone .bottom-tabs {
    display: flex;
    position: relative; bottom: auto; left: auto; right: auto;
    max-width: 390px; margin: 0 auto 56px;
    border: 12px solid #1a1a1a; border-top: 0;
    border-radius: 0 0 24px 24px;
    box-shadow: 0 20px 60px rgba(10, 20, 40, 0.35);
    padding: 0.4rem 0.3rem 0.6rem;
  }

  /* Mirror real-mobile responsive layout inside the frame */
  html.view-phone .cards-3,
  html.view-phone .offers-grid,
  html.view-phone .review-grid,
  html.view-phone .form .row,
  html.view-phone .form .row.single,
  html.view-phone .dialog .row,
  html.view-phone .kv-grid { grid-template-columns: 1fr; }
  html.view-phone .optimize-header { flex-direction: column; align-items: flex-start; }
  html.view-phone .value-display { text-align: left; }
  html.view-phone .big-money { font-size: 2rem; }

  html.view-phone table.lots,
  html.view-phone table.lots thead,
  html.view-phone table.lots tbody,
  html.view-phone table.lots tr,
  html.view-phone table.lots td,
  html.view-phone table.lots th { display: block; }
  html.view-phone table.lots thead { display: none; }
  html.view-phone table.lots tr { padding: 1rem; border-bottom: 1px solid var(--rule); }
  html.view-phone table.lots td { padding: 0.25rem 0; border: none; text-align: left; }
  html.view-phone table.lots td.num,
  html.view-phone table.lots td.money { text-align: left; }
  html.view-phone table.lots td::before {
    content: attr(data-label); display: inline-block; min-width: 110px;
    color: var(--text-muted); font-size: 0.75rem;
    text-transform: uppercase; letter-spacing: 0.05em;
  }
}

