* { box-sizing: border-box; }
body { font-family: Inter, -apple-system, system-ui, sans-serif; background: #fafaf9; color: #1a1a1a; margin: 0; font-size: 14px; }
.wrap { max-width: 1400px; margin: 0 auto; padding: 0 24px; }
header { background: white; border-bottom: 1px solid #e5e5e5; padding: 18px 0 14px; position: relative; z-index: 10; }
.title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 28px 0 12px; letter-spacing: -0.01em; }
.hint { font-weight: 400; color: #a3a3a3; font-size: 13px; margin-left: 6px; }
.back-link { color: #737373; text-decoration: none; font-size: 20px; }
.back-link:hover { color: #1a1a1a; }

.cards { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 10px; }
.cards.cards-expected { grid-template-columns: repeat(5, 1fr); }
.section-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: #737373; font-weight: 600; margin: 6px 0 6px; }
.section-label:first-of-type { margin-top: 0; }
.month-selector-row { display: flex; align-items: center; gap: 8px; }
.month-selector-row select { font-size: 12px; padding: 3px 8px; border: 1px solid #e5e5e5; border-radius: 6px; background: white; font-family: inherit; font-weight: 500; color: #1a1a1a; cursor: pointer; text-transform: none; letter-spacing: 0; }
.month-selector-row select:focus { outline: none; border-color: #1a1a1a; }
.tx-header { display: flex; align-items: baseline; justify-content: space-between; }
.tx-totals { font-size: 12px; color: #737373; font-variant-numeric: tabular-nums; }
.card { background: #fafaf9; border: 1px solid #e5e5e5; border-radius: 8px; padding: 12px 14px; }
.card .label { font-size: 10px; text-transform: uppercase; color: #737373; letter-spacing: 0.05em; font-weight: 600; }
.card .val { font-size: 20px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.card .sub { font-size: 11px; color: #737373; margin-top: 2px; }
.card.pos .val { color: #16a34a; }
.card.neg .val { color: #dc2626; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stats { font-size: 12px; color: #737373; font-variant-numeric: tabular-nums; }
.stats b { color: #1a1a1a; font-weight: 600; }

.segmented { display: inline-flex; background: #f5f5f4; border: 1px solid #e5e5e5; border-radius: 8px; padding: 2px; }
.segmented button { background: transparent; border: 0; padding: 6px 12px; font-size: 13px; color: #525252; cursor: pointer; border-radius: 6px; font-family: inherit; }
.segmented button.on { background: white; color: #1a1a1a; box-shadow: 0 1px 2px rgba(0,0,0,0.06); font-weight: 500; }

.btn { padding: 7px 14px; border: 1px solid #e5e5e5; border-radius: 8px; background: white; font-size: 13px; font-family: inherit; cursor: pointer; color: #1a1a1a; font-weight: 500; }
.btn:hover { background: #fafaf9; }
.btn.primary { background: #1a1a1a; color: white; border-color: #1a1a1a; }
.btn.primary:hover { background: #000; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.last-sync { font-size: 11px; color: #a3a3a3; white-space: nowrap; }

input[type=search] { padding: 7px 12px; border: 1px solid #e5e5e5; border-radius: 8px; font-size: 13px; min-width: 220px; background: white; font-family: inherit; }
input[type=search]:focus { outline: none; border-color: #1a1a1a; }

main { padding: 4px 0 80px; }
.tablewrap { background: white; border: 1px solid #e5e5e5; border-radius: 10px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid #f5f5f5; vertical-align: middle; }
th { background: #fafaf9; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #525252; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafaf9; }
tfoot td { background: #fafaf9; font-weight: 600; border-top: 2px solid #e5e5e5; }
.empty { text-align: center; padding: 40px; color: #a3a3a3; }

.amt-neg { color: #dc2626; }
.amt-pos { color: #16a34a; }
.diff-over { color: #dc2626; font-weight: 600; }
.diff-under { color: #16a34a; font-weight: 600; }
.diff-ok { color: #737373; }

select { padding: 5px 8px; border: 1px solid #e5e5e5; border-radius: 6px; background: white; font-size: 13px; font-family: inherit; width: 100%; cursor: pointer; }
select:focus { outline: none; border-color: #1a1a1a; }
select.set { border-color: #1a1a1a; background: #fafaf9; }
select.suggested { border-color: #d97706; background: #fffbeb; color: #92400e; }

.row-suggested { background: #fffbeb !important; }
.row-excluded { background: #f5f5f4 !important; color: #a3a3a3; }
.row-excluded td.amt-neg, .row-excluded td.amt-pos { color: #a3a3a3 !important; }
.sug-label { font-size: 10px; color: #d97706; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; margin-left: 4px; padding: 1px 6px; background: #fef3c7; border-radius: 4px; }
.sug-label.sug-excluded { color: #525252; background: #e5e5e5; }
.acct-tag { font-size: 10px; color: #525252; margin-left: 4px; padding: 1px 6px; background: #f5f5f4; border: 1px solid #e5e5e5; border-radius: 4px; font-weight: 500; }
.muted-cell { color: #d4d4d4; text-align: center; }

.status { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding: 3px 8px; border-radius: 999px; display: inline-block; }
.status.saved { background: #dcfce7; color: #166534; }
.status.saving { background: #fef3c7; color: #92400e; }
.status.err { background: #fee2e2; color: #991b1b; }
.status.idle { background: #f5f5f4; color: #737373; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1a1a1a; color: white; padding: 10px 18px; border-radius: 8px; font-size: 13px; opacity: 0; transition: all 0.2s; pointer-events: none; z-index: 100; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: #dc2626; }

h3.subh { font-size: 13px; font-weight: 600; margin: 4px 0 8px; color: #525252; letter-spacing: -0.01em; }
.split-tables { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
input.date-input { padding: 4px 6px; border: 1px solid #e5e5e5; border-radius: 6px; font-size: 12px; font-family: inherit; background: white; width: 100%; font-variant-numeric: tabular-nums; }
input.date-input:focus { outline: none; border-color: #1a1a1a; }
input.date-input.set { background: #fafaf9; }
.row-cm-red { background: #fef2f2 !important; }
.row-cm-yellow { background: #fffbeb !important; }
.row-cm-green { background: #f0fdf4 !important; }
.auto-mark { color: #d97706; margin-right: 4px; }

.rec-link { color: #1a1a1a; text-decoration: none; border-bottom: 1px dashed #d4d4d4; }
.rec-link:hover { color: #3b82f6; border-color: #3b82f6; }
.rec-link-active { color: #3b82f6; border-bottom: 2px solid #3b82f6; font-weight: 600; }
.rec-active { background: #eff6ff !important; }
.expense-filter-tag { background: #dbeafe; color: #1e40af; padding: 2px 8px; border-radius: 4px; font-weight: 500; font-size: 11px; }
.expense-filter-tag a { color: #1e40af; text-decoration: none; margin-left: 4px; font-weight: 700; }
.expense-filter-tag a:hover { color: #dc2626; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .wrap { padding: 0 12px; }
  header { padding: 12px 0 10px; }
  .title-row { flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
  h1 { font-size: 18px; }
  .title-row > div:last-child { width: 100%; display: flex; gap: 6px; }
  .title-row > div:last-child .btn { flex: 1; font-size: 12px; padding: 6px 10px; }

  .cards { grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 6px; }
  .cards.cards-expected { grid-template-columns: repeat(3, 1fr); }
  .card { padding: 8px 10px; }
  .card .val { font-size: 16px; }
  .card .sub { font-size: 10px; }
  .card .label { font-size: 9px; }
  .section-label { font-size: 9px; }

  .toolbar { gap: 6px; }
  .segmented button { padding: 5px 8px; font-size: 11px; }
  input[type=search] { min-width: 0; width: 100%; order: 10; }
  #autoBtn { font-size: 11px; padding: 6px 10px; order: 11; flex: 1; }
  .stats { width: 100%; text-align: center; order: 12; font-size: 11px; }
  .spacer { display: none; }

  h2 { font-size: 14px; margin: 20px 0 8px; }
  .hint { font-size: 11px; margin-left: 4px; }

  .tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; }
  table { min-width: 600px; }
  th, td { padding: 7px 8px; font-size: 12px; }
  th { font-size: 10px; }

  #cmTbl { min-width: 900px; }
  #recTbl { min-width: 0; }
  #recTbl th:nth-child(2), #recTbl td:nth-child(2),
  #recTbl th:nth-child(3), #recTbl td:nth-child(3),
  #recTbl th:nth-child(5), #recTbl td:nth-child(5),
  #recTbl th:nth-child(8), #recTbl td:nth-child(8) { display: none; }
  #planTbl, #indTbl { min-width: 400px; }

  .split-tables { grid-template-columns: 1fr; gap: 12px; }

  /* Hide cards on mobile */
  /* Expected: hide Per-Client Costs (#2), Expected Expenses (#3), Margin (#5) */
  #expectedCards > .card:nth-child(2),
  #expectedCards > .card:nth-child(3),
  #expectedCards > .card:nth-child(5) { display: none; }
  #expectedCards { grid-template-columns: 1fr 1fr !important; }

  /* Current: hide Expected Expenses (#2), Unlabeled (#6) */
  #cards > .card:nth-child(2),
  #cards > .card:nth-child(6) { display: none; }
  #cards { grid-template-columns: repeat(2, 1fr) !important; }

  /* Previous: hide Expected Expenses (#2), Actual Expenses (#3), Raw Spend (#4), Labeled (#6) */
  #prevCards > .card:nth-child(2),
  #prevCards > .card:nth-child(3),
  #prevCards > .card:nth-child(4),
  #prevCards > .card:nth-child(6) { display: none; }
  #prevCards { grid-template-columns: 1fr 1fr !important; }

  main { padding: 4px 0 40px; }
}

@media (max-width: 480px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .cards.cards-expected { grid-template-columns: repeat(2, 1fr); }
  .card .val { font-size: 15px; }

  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 5px 4px; font-size: 10px; }

  table { min-width: 520px; }
  th, td { padding: 6px 6px; font-size: 11px; }
}
