:root {
  --ink: #20242a;
  --muted: #66707a;
  --line: #d9dee4;
  --line-strong: #aab3bc;
  --surface: #ffffff;
  --surface-soft: #f5f7f9;
  --canvas: #eef1f4;
  --orange: #ef7d00;
  --orange-dark: #a95600;
  --orange-soft: #fff3e5;
  --blue: #2878b8;
  --blue-soft: #eaf3fa;
  --green: #1f7a58;
  --green-soft: #e3f3eb;
  --red: #b44943;
  --red-soft: #fbe9e7;
  --gold: #b77a08;
  --gold-soft: #fff1c9;
  --shadow: 0 8px 24px rgba(26, 34, 43, 0.09);
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(40, 120, 184, 0.28);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }
.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  appearance: none;
  border: 0;
  background: transparent;
  color: #111;
  font-size: 21px;
  font-weight: 800;
  white-space: nowrap;
  padding: 14px 0;
}
.brand span { color: var(--orange); }
.primary-nav { display: flex; align-self: stretch; gap: 4px; }
.nav-button {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: #4f5963;
  min-width: 84px;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 700;
}
.nav-button:hover { background: var(--surface-soft); color: #111; }
.nav-button.active { color: #111; border-bottom-color: var(--orange); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.sample-banner {
  background: var(--gold-soft);
  color: #754c00;
  border: 1px solid #edcd82;
  border-radius: 4px;
  padding: 7px 9px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
.role-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.role-control select { border: 1px solid var(--line-strong); background: #fff; border-radius: 5px; padding: 8px 30px 8px 10px; color: var(--ink); font-weight: 700; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); background: #fff; border-radius: 5px; color: var(--ink); display: inline-grid; place-items: center; }
.menu-button { display: none; font-size: 20px; }
.environment-notice { padding: 9px 28px; background: #fff8e8; border-bottom: 1px solid #efd89d; color: #674b15; font-size: 12px; }
.main-content { width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding: 26px 0 48px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.page-header h1 { margin: 0 0 5px; font-size: 28px; line-height: 1.15; }
.page-header p { margin: 0; color: var(--muted); font-size: 14px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 9px; justify-content: flex-end; }
.button { border: 1px solid #bcc5ce; background: #fff; color: #25313d; border-radius: 5px; padding: 9px 13px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.button:hover { border-color: #8f99a3; background: #f8f9fa; }
.button.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.button.primary:hover { background: #d66f00; }
.button.danger { border-color: #d5a6a3; color: #8c3531; }
.button.small { padding: 6px 9px; font-size: 12px; }
.button:disabled { opacity: .52; cursor: not-allowed; }
.button-link { border: 0; background: transparent; color: var(--blue); font-weight: 700; padding: 0; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric { min-height: 105px; background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--blue); border-radius: 6px; padding: 16px 17px; }
.metric.good { border-left-color: var(--green); }
.metric.warn { border-left-color: #e3aa2f; }
.metric.alert { border-left-color: var(--red); }
.metric-label { color: var(--muted); font-size: 12px; margin-bottom: 9px; }
.metric-value { font-size: 25px; font-weight: 800; font-variant-numeric: tabular-nums; }
.metric-note { margin-top: 6px; color: var(--muted); font-size: 11px; }

.layout-two { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.layout-list-detail { display: grid; grid-template-columns: 390px minmax(0, 1fr); gap: 16px; align-items: start; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.panel + .panel { margin-top: 16px; }
.panel-header { min-height: 52px; padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.panel-header h2 { margin: 0; font-size: 16px; }
.panel-header p, .panel-header span { margin: 0; color: var(--muted); font-size: 11px; }
.panel-body { padding: 16px; }
.empty-state { padding: 34px 20px; text-align: center; color: var(--muted); }

.table-scroll { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th { background: #f0f3f5; color: #59636d; font-size: 11px; padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 10px; border-bottom: 1px solid #e8ebee; font-size: 12px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .total td { font-weight: 800; border-top: 2px solid var(--line-strong); background: #f6f8f9; }
.data-table .selected td, .data-table .attention td { background: #fff8e9; }
.data-table button.row-action { border: 0; background: transparent; color: var(--blue); font-weight: 700; padding: 4px; }
.positive { color: var(--green); font-weight: 700; }
.negative { color: var(--red); font-weight: 700; }
.muted { color: var(--muted); }

.status { display: inline-block; border-radius: 3px; padding: 4px 7px; font-size: 10px; font-weight: 800; text-transform: uppercase; white-space: nowrap; }
.status.active, .status.ready, .status.matched, .status.resolved { background: var(--green-soft); color: #146342; }
.status.sold, .status.review, .status.pending { background: var(--gold-soft); color: #704a00; }
.status.ended, .status.paused { background: #ecebea; color: #605b56; }
.status.open, .status.unmatched, .status.cancelled { background: var(--red-soft); color: #8f312c; }
.status.partial, .status.ending { background: var(--gold-soft); color: #704a00; }
.status.info { background: var(--blue-soft); color: #1c5e91; }

.decision-item { padding: 15px 16px; border-bottom: 1px solid #e8ebee; }
.decision-item:last-child { border-bottom: 0; }
.decision-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.decision-item h3 { margin: 0 0 6px; font-size: 14px; }
.decision-item p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.decision-meta { display: flex; gap: 12px; color: var(--blue); font-size: 11px; font-weight: 700; margin-top: 9px; }

.chart-wrap { padding: 16px; }
#cash-chart { width: 100%; height: 180px; display: block; }
.chart-legend { display: flex; align-items: center; gap: 16px; margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.legend-swatch { width: 18px; height: 3px; background: var(--blue); display: inline-block; margin-right: 5px; vertical-align: middle; }
.legend-swatch.alert { background: var(--red); }

.engagement-list { min-height: 520px; }
.engagement-row { width: 100%; border: 0; border-bottom: 1px solid #e6e9ec; background: #fff; padding: 14px 15px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; text-align: left; }
.engagement-row:hover { background: #f8f9fa; }
.engagement-row.active { background: var(--orange-soft); border-left: 5px solid var(--orange); padding-left: 10px; }
.engagement-row strong { display: block; font-size: 13px; margin-bottom: 5px; }
.engagement-row small { color: var(--muted); font-size: 11px; }
.engagement-detail { min-height: 520px; }
.detail-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px; }
.summary-cell { background: var(--surface-soft); border-left: 4px solid var(--blue); padding: 12px 13px; }
.summary-cell span { display: block; color: var(--muted); font-size: 10px; margin-bottom: 6px; }
.summary-cell strong { font-size: 17px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.detail-field span { display: block; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; margin-bottom: 5px; }
.detail-field strong { font-size: 13px; font-weight: 700; }
.detail-field.wide { grid-column: span 2; }
.forecast-note { margin-top: 16px; background: #fff8e9; border: 1px solid #efd29c; padding: 12px 13px; font-size: 12px; line-height: 1.45; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.field { min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { display: block; color: #5e6872; font-size: 10px; font-weight: 800; text-transform: uppercase; margin-bottom: 6px; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid #c5ccd3; border-radius: 4px; background: #fff; color: var(--ink); padding: 9px 10px; font-size: 13px; }
.field textarea { min-height: 82px; resize: vertical; }
.field .hint { display: block; color: var(--muted); font-size: 10px; margin-top: 5px; text-transform: none; font-weight: 400; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.inline-warning { background: var(--gold-soft); border-left: 4px solid #d89c20; padding: 12px 13px; color: #684a0e; font-size: 12px; line-height: 1.45; }
.inline-info { background: var(--blue-soft); border-left: 4px solid var(--blue); padding: 12px 13px; color: #244e70; font-size: 12px; line-height: 1.45; }
.billing-input { width: 106px; border: 1px solid #c5ccd3; border-radius: 4px; padding: 7px 8px; text-align: right; }
.billing-select { width: 150px; border: 1px solid #c5ccd3; border-radius: 4px; padding: 7px 8px; }
.number-block { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.number-block .summary-cell { border-left-color: var(--orange); }

.search-header { align-items: flex-end; }
.search-input { width: 190px; border: 1px solid #c5ccd3; border-radius: 4px; padding: 8px 9px; font-size: 12px; }
.invoice-panel { margin-top: 16px; }
.invoice-heading { padding: 15px 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 1px solid var(--line); }
.invoice-heading h2 { margin: 3px 0 4px; font-size: 17px; }
.invoice-heading p { margin: 0; color: var(--muted); font-size: 11px; }
.eyebrow { color: var(--orange-dark); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.invoice-totals { display: grid; gap: 7px; text-align: right; font-size: 12px; }
.invoice-totals strong { display: inline-block; min-width: 92px; margin-left: 8px; }
.budget-table { min-width: 1420px; table-layout: auto; }
.budget-table th:first-child, .budget-table td:first-child { position: sticky; left: 0; background: #fff; min-width: 210px; z-index: 1; }
.budget-table thead th:first-child { background: #f0f3f5; z-index: 2; }
.allocation-list { margin-top: 14px; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.allocation-row { min-height: 62px; padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr) 140px; gap: 16px; align-items: center; border-bottom: 1px solid var(--line); }
.allocation-row:last-child { border-bottom: 0; }
.allocation-row small { display: block; color: var(--muted); margin-top: 4px; }
.allocation-row input { width: 100%; border: 1px solid #c5ccd3; border-radius: 4px; padding: 8px 9px; text-align: right; }
[hidden] { display: none !important; }

.change-row { display: grid; grid-template-columns: 110px 150px minmax(0, 1fr) 130px; gap: 12px; padding: 13px 16px; border-bottom: 1px solid #e8ebee; align-items: center; font-size: 12px; }
.change-row:last-child { border-bottom: 0; }
.change-row strong { font-size: 12px; }
.change-row small { color: var(--muted); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(21, 27, 33, .55); z-index: 50; display: grid; place-items: center; padding: 24px; }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(760px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: #fff; border-radius: 7px; box-shadow: var(--shadow); }
.modal-header { min-height: 62px; padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 20px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 60; max-width: 380px; background: #20262d; color: #fff; border-radius: 5px; padding: 13px 15px; box-shadow: var(--shadow); font-size: 13px; }

@media (max-width: 1080px) {
  .topbar { padding: 0 18px; gap: 12px; }
  .primary-nav { position: fixed; left: 0; right: 0; top: 68px; display: none; flex-direction: column; background: #fff; border-bottom: 1px solid var(--line); box-shadow: var(--shadow); padding: 8px 16px 14px; }
  .primary-nav.open { display: flex; }
  .nav-button { min-height: 42px; border-bottom: 0; border-left: 3px solid transparent; text-align: left; }
  .nav-button.active { border-left-color: var(--orange); }
  .menu-button { display: inline-grid; }
  .role-control span { display: none; }
  .layout-two, .layout-list-detail { grid-template-columns: 1fr; }
  .engagement-list { min-height: 0; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 680px) {
  .topbar { min-height: 60px; padding: 0 12px; }
  .brand { font-size: 17px; }
  .sample-banner { display: none; }
  .role-control select { max-width: 92px; }
  .primary-nav { top: 60px; }
  .environment-notice { padding: 8px 12px; }
  .main-content { width: min(100% - 24px, 1480px); padding-top: 18px; }
  .page-header { align-items: stretch; flex-direction: column; gap: 14px; }
  .page-header h1 { font-size: 23px; }
  .toolbar { justify-content: flex-start; }
  .metrics { grid-template-columns: 1fr; }
  .metric { min-height: 88px; }
  .detail-grid, .detail-summary, .form-grid, .number-block { grid-template-columns: 1fr; }
  .detail-field.wide { grid-column: auto; }
  .change-row { grid-template-columns: 1fr; gap: 5px; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .search-header { align-items: stretch; }
  .search-input { width: 100%; }
  .invoice-heading { flex-direction: column; }
  .invoice-totals { text-align: left; }
  .allocation-row { grid-template-columns: 1fr; }
  .billing-input, .billing-select { width: 100%; min-width: 120px; }
  .modal-backdrop { padding: 10px; }
}
