:root {
  --ink: #211F1B;
  --ink-soft: #5A564D;
  --paper: #EFEAE0;
  --paper-raised: #F6F3EC;
  --brass: #B9814F;
  --brass-deep: #8C5F35;
  --slate: #5C7A87;
  --slate-deep: #3E5960;
  --line: #D9D2C2;
  --danger: #A6432F;
  --font-display: 'Source Serif 4', Georgia, serif;
  --font-body: 'Public Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  max-width: 100%;
  overflow-x: hidden;
}

button, input, select, textarea { font-family: inherit; font-size: 1rem; }

a { color: var(--slate-deep); }

.hidden { display: none !important; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}
.header-inner {
  width: 92%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; }
.header-user { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--ink-soft); flex-wrap: wrap; }
.user-role { padding: 2px 8px; border: 1px solid var(--line); border-radius: 3px; }

/* Main */
.app-main {
  width: 92%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

section + section { margin-top: 40px; padding-top: 32px; border-top: 1px solid var(--line); }
.cr-section + .cr-section { margin-top: 16px; padding-top: 16px; }
.cr-section h2, .cr-section .h2-toggle { margin-bottom: 8px; }
.cr-alt-row { padding: 4px 8px; margin: 0 -8px; border-radius: 4px; }
.cr-alt-row-shaded { background: rgba(0, 0, 0, 0.07); }

h1 { font-family: var(--font-display); font-weight: 600; font-size: 1.6rem; margin: 0 0 6px; }
h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; margin: 0 0 16px; }

.h2-toggle {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--ink);
  margin: 0 0 16px;
}
.h2-toggle:hover { color: var(--brass-deep); }
.h2-toggle::after { content: " \25BE"; font-size: 0.9rem; color: var(--ink-soft); }
p.lead { color: var(--ink-soft); margin: 0 0 24px; max-width: 52ch; }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper-raised);
  color: var(--ink);
}
.field textarea { min-height: 72px; resize: vertical; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

button.primary {
  background: var(--brass-deep);
  color: var(--paper-raised);
  border: none;
  border-radius: 4px;
  padding: 4px 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 32px;
  line-height: 1.2;
}
button.primary:hover { background: var(--brass); }
button.primary:disabled { opacity: 0.5; cursor: default; }

button.secondary {
  background: var(--line);
  border: 1px solid var(--ink-soft);
  color: var(--ink);
  border-radius: 4px;
  padding: 3px 12px;
  cursor: pointer;
  min-height: 32px;
  line-height: 1.2;
}
button.secondary:hover { background: #CBC2AC; }

.button-row.nav-row { gap: 0; row-gap: 0; }
.nav-row button {
  min-width: 160px;
  text-align: center;
}

.link-btn {
  background: none;
  border: none;
  color: var(--slate-deep);
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  text-decoration: underline;
}

/* Ledger rows */
.ledger { border-top: 1px solid var(--line); }
.ledger-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.ledger-row .date { color: var(--ink-soft); width: 92px; flex-shrink: 0; }
.ledger-row .category { flex: 1; min-width: 0; overflow-wrap: break-word; }
.ledger-row .amount { font-variant-numeric: tabular-nums; width: 80px; text-align: right; }
.ledger-row .amount-col {
  width: 130px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.ledger-row .amount-col label {
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ledger-row .who { width: 110px; text-align: right; color: var(--ink-soft); font-size: 0.85rem; }
.empty-state { color: var(--ink-soft); padding: 24px 0; }

/* Messages */
.msg { padding: 12px 14px; border-radius: 4px; margin-bottom: 20px; font-size: 0.92rem; }
.msg.info { background: var(--paper-raised); border: 1px solid var(--line); }
.msg.error { background: #F5E6E1; border: 1px solid var(--danger); color: var(--danger); }
.msg.success { background: #E9EFE1; border: 1px solid var(--slate); color: var(--slate-deep); }

/* Sign-in */
.signin-shell {
  max-width: 400px;
  margin: 15vh auto 0;
  padding: 0 20px;
  text-align: center;
}
.signin-shell .brand-logo-large { width: 140px; height: 140px; border-radius: 50%; object-fit: cover; margin-bottom: 20px; }

.identity-card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 18px;
  background: var(--paper-raised);
}
.identity-card.request-alt-row-shaded { background: var(--paper); }

.activity-alt-row { padding: 4px 8px; margin: 0 -8px; border-radius: 4px; }
.activity-alt-row-shaded { background: rgba(92, 122, 135, 0.1); }
.identity-card dt { color: var(--ink-soft); font-size: 0.8rem; margin-top: 10px; }
.identity-card dd { margin: 2px 0 0; }
.action-row { display: flex; justify-content: space-between; align-items: center; }
.button-row { display: flex; gap: 6px; flex-wrap: wrap; row-gap: 6px; }

.identity-card-compact { margin-bottom: 8px; }

.request-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.request-row-head { font-size: 0.78rem; color: var(--ink-soft); padding-bottom: 6px; }
.req-date { width: 90px; flex-shrink: 0; color: var(--ink-soft); }
.req-need { flex: 1; text-align: left; min-width: 0; overflow-wrap: break-word; }
.req-status { width: 130px; flex-shrink: 0; }
.req-amount { width: 80px; flex-shrink: 0; text-align: right; font-variant-numeric: tabular-nums; }
.req-status-feedback { font-size: 0.78rem; color: var(--ink-soft); }

@media (max-width: 480px) {
  .req-status { width: auto; }
}

.file-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(33, 31, 27, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.file-popup-panel {
  background: var(--paper);
  border-radius: 6px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.file-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
}
.file-popup-image {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
}
.file-popup-iframe {
  width: 80vw;
  height: 80vh;
  border: none;
}

.report-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}
.report-row-head { font-size: 0.72rem; color: var(--ink-soft); }
.report-row .report-period { flex: 1; min-width: 0; overflow-wrap: break-word; }
.report-row .report-num { width: 62px; flex-shrink: 0; text-align: right; font-variant-numeric: tabular-nums; }
.report-row .report-aid { width: 100px; flex-shrink: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

@media (max-width: 600px) {
  .report-row { flex-wrap: wrap; row-gap: 4px; font-size: 0.82rem; }
  .report-row .report-period { flex: 1 1 100%; font-weight: 500; }
  .report-row-head.report-row { display: none; }
}

.field .checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  margin-bottom: 6px;
}
.field .checkbox-label input[type="checkbox"], .field .checkbox-label input[type="radio"] {
  width: auto;
  padding: 0;
  border: none;
  background: none;
  flex-shrink: 0;
}

.req-situation {
  width: 100%;
  color: var(--ink-soft);
  margin: 6px 0 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.req-situation strong { color: var(--ink); }

.header-user { position: relative; }
.online-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  min-width: 160px;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

@media print {
  .identity-card, .totals-strip, .people-table, .ledger, .request-row,
  .file-popup-overlay,
  #app-main, #app-header {
    display: none !important;
  }
  body::before {
    content: "Printing has been disabled for this page because it may contain private information.";
    display: block;
    padding: 40px;
    font-size: 1.2rem;
  }
}

/* Totals strip */
.totals-strip {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 28px;
}
.totals-strip .stat {
  flex: 1;
  padding: 14px 16px;
  text-align: left;
}
.totals-strip .stat + .stat { border-left: 1px solid var(--line); }
.totals-strip .stat .label { display: block; font-size: 0.78rem; color: var(--ink-soft); margin-bottom: 4px; }
.totals-strip .stat .value { font-family: var(--font-display); font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.totals-strip .stat .value.value-text { font-family: var(--font-body); font-size: 1rem; font-weight: 500; word-break: break-word; }

/* People table */
.people-table { border-top: 1px solid var(--line); }
.people-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  background: none;
  border-left: none; border-right: none; border-top: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
}

.ledger-row-btn {
  cursor: pointer;
  background: none;
  border-left: none; border-right: none; border-top: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.people-row:hover { background: var(--paper-raised); }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--paper-raised); }
.people-row .who { flex: 1; font-weight: 500; min-width: 0; overflow-wrap: break-word; }
.people-row .date-col { width: 100px; flex-shrink: 0; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.people-row .status-col { width: 120px; flex-shrink: 0; text-align: right; font-weight: 600; }
.people-table-head {
  display: flex; gap: 12px; padding: 0 0 8px; font-size: 0.78rem; color: var(--ink-soft);
}
.people-table-head .who { flex: 1; }
.people-table-head .date-col { width: 100px; flex-shrink: 0; text-align: right; }
.people-table-head .status-col { width: 120px; flex-shrink: 0; text-align: right; }

/* Detail view */
.back-link { display: inline-block; margin-bottom: 20px; }
.address-history { list-style: none; padding: 0; margin: 8px 0 0; }
.address-history li { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.address-history li .move-date { color: var(--ink-soft); font-size: 0.82rem; }

@media (max-width: 480px) {
  .people-row { flex-wrap: wrap; row-gap: 4px; }
  .people-row .who { flex: 1 1 100%; }
  .people-table-head { display: none; }
  .totals-strip { flex-wrap: wrap; }
  .totals-strip .stat { flex: 1 1 50%; }
}

@media (max-width: 480px) {
  .ledger-row { flex-wrap: wrap; row-gap: 4px; }
  .ledger-row .who { width: auto; }
  /* Same fix as request-row below: a squeezed flex:1 column next to
     fixed-width siblings (especially now that amount-col can also
     hold a payment-method select) causes character-by-character
     wrapping rather than wrapping at word boundaries. Each column
     gets its own full-width line instead of fighting for a shared,
     too-narrow row. */
  .ledger-row > * { flex: 1 1 100%; text-align: left; }
  .ledger-row .amount-col { align-items: flex-start; width: auto; }
  .header-inner { flex-wrap: wrap; row-gap: 6px; }
  .header-user { width: 100%; justify-content: flex-end; }
  .user-email { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Multi-field rows (address, date/category/amount, custom offset, etc.)
     stack to one field per line instead of squeezing into slivers. */
  .field-row { flex-wrap: wrap; }
  .field-row .field { flex: 1 1 100%; min-width: 0; }

  /* The request summary row got crowded once quick-log/view-activities
     buttons were added — let it wrap, put each action button on its
     own line, and drop the column header row since alignment stops
     meaning anything once the row wraps. The Open/Closed Requests
     list reuses these same classes with up to 5 columns (Date/Need/
     Status/Votes/Total), which is even less likely to fit one line —
     so every direct child stacks to its own full-width line here,
     not just link buttons, avoiding the narrow-column
     character-by-character wrapping that a squeezed flex:1 column
     causes. */
  .request-row { flex-wrap: wrap; row-gap: 6px; }
  .request-row > * { flex: 1 1 100%; text-align: left; }
  .request-row-head { display: none; }
}

.update-banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--slate-deep);
  color: var(--paper-raised);
  padding: 12px 18px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 500;
  font-size: 0.9rem;
}
.update-banner button.secondary {
  background: var(--paper-raised);
  border: none;
  color: var(--slate-deep);
  font-weight: 600;
}
