/* =============================================================================
   Silver Arrow Lending — application stylesheet
   Palette:  #1F4E78 (primary blue)  #B4B2A9 (warm gray)
   Typography: system font stack, ~13-14px base
   ============================================================================= */

:root { color-scheme: light; }
* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f5f6f8;
}

a { color: #1F4E78; }
a:hover { color: #163a5a; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* -----------------------------------------------------------------------------
   Top chrome: header + nav
   ----------------------------------------------------------------------------- */
.sal-header {
  background: #1F4E78;
  color: white;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sal-logo { display: flex; align-items: center; gap: 14px; }
.sal-logo img, .sal-logo svg {
  width: 44px; height: 44px; flex-shrink: 0;
  background: #F5F3EC;          /* cream chip so the blue brackets read on navy */
  padding: 5px;
  border-radius: 7px;
}
.sal-logo-text { font-size: 17px; font-weight: 700; letter-spacing: 0.12em; line-height: 1.15; }
.sal-logo-text small { display: block; font-size: 10px; font-weight: 500; letter-spacing: 0.32em; color: #C8C7C0; margin-top: 3px; }

.user-menu { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.user-menu .avatar { width: 30px; height: 30px; border-radius: 50%; background: #B4B2A9; color: #1F4E78; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; }
.user-menu a { color: white; text-decoration: none; }
.user-menu a:hover { text-decoration: underline; }

.sal-nav { background: white; border-bottom: 1px solid #e4e5e8; padding: 0 24px; display: flex; gap: 2px; }
.sal-nav a { padding: 14px 18px; font-size: 14px; font-weight: 500; color: #5F5E5A; text-decoration: none; border-bottom: 2px solid transparent; }
.sal-nav a:hover { color: #1F4E78; }
.sal-nav a.active { color: #1F4E78; border-bottom-color: #1F4E78; }

.sal-main { flex: 1; padding: 20px 24px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* -----------------------------------------------------------------------------
   Page headings
   ----------------------------------------------------------------------------- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-header h1 { margin: 0; font-size: 22px; font-weight: 600; color: #1F4E78; }
.page-header .subtitle { font-size: 13px; color: #5F5E5A; margin-top: 2px; }

/* -----------------------------------------------------------------------------
   Buttons
   ----------------------------------------------------------------------------- */
.btn-primary   { background: #1F4E78; color: white; border: none; padding: 9px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; }
.btn-primary:hover   { background: #163a5a; }
.btn-secondary { background: white; color: #1F4E78; border: 1px solid #1F4E78; padding: 8px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; }
.btn-secondary:hover { background: #E6F1FB; }
.btn-danger    { background: white; color: #A32D2D; border: 1px solid #E24B4A; padding: 8px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; }
.btn-danger:hover    { background: #FCEBEB; }
/* Base ghost button — lives on light page bodies. Subtle outline, navy
   text, soft cream hover. The dark-header variant (Sign out) is scoped
   below under .sal-header. */
.btn-ghost     { background: transparent; border: 1px solid #D4D5D8; color: #1F4E78; padding: 8px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; text-decoration: none; display: inline-block; }
.btn-ghost:hover { background: #F4F1E5; border-color: #1F4E78; }
.sal-header .btn-ghost       { border-color: rgba(255,255,255,0.3); color: white; padding: 6px 12px; font-size: 12px; }
.sal-header .btn-ghost:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.5); }
.btn-sm        { padding: 4px 9px; font-size: 12px; border-radius: 4px; border: 1px solid #d4d5d8; background: white; color: #444441; }
.btn-sm:hover  { border-color: #1F4E78; color: #1F4E78; }

/* -----------------------------------------------------------------------------
   Toolbars, tables, badges, chips (shared with admin pages)
   ----------------------------------------------------------------------------- */
.toolbar { background: white; border: 1px solid #e4e5e8; border-radius: 8px; padding: 12px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1; min-width: 220px; padding: 8px 12px; border: 1px solid #d4d5d8; border-radius: 6px; }
.toolbar select { padding: 8px 10px; border: 1px solid #d4d5d8; border-radius: 6px; background: white; font-size: 13px; }
.toolbar label { font-size: 12px; color: #5F5E5A; margin-right: -4px; }

.status-line { font-size: 12px; color: #5F5E5A; margin: 6px 2px 10px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.b-active    { background: #EAF3DE; color: #3B6D11; }
.b-dnc       { background: #FCEBEB; color: #A32D2D; }
.b-archived  { background: #F1EFE8; color: #5F5E5A; }
.b-onhold    { background: #FAEEDA; color: #854F0B; }
.b-completed { background: #DCE8F5; color: #1F4E78; }
.b-enriched { background: #E6F1FB; color: #185FA5; }
.b-desc     { background: #FAEEDA; color: #854F0B; }
.b-added    { background: #EEEDFE; color: #3C3489; }

.chip { display: inline-block; background: #F1EFE8; color: #444441; padding: 2px 7px; border-radius: 4px; font-size: 11px; margin-right: 3px; margin-bottom: 2px; }

/* -----------------------------------------------------------------------------
   Form elements (generic — used by login, setup, change_password, admin)
   ----------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 500; color: #5F5E5A; }
.field input, .field select, .field textarea {
  padding: 9px 11px;
  border: 1px solid #d4d5d8;
  border-radius: 5px;
  font-size: 14px;
  background: white;
  /* Force inputs to fill their grid/flex cell. Without this they fall back
     to the browser's default ~200px width and look tiny in wider containers
     (notably the inline contact-edit row on /admin/lender_edit). */
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: #1F4E78;
  box-shadow: 0 0 0 2px #E6F1FB;
}
.field .hint { font-size: 11px; color: #888; font-style: italic; }
.field textarea { min-height: 60px; resize: vertical; }

/* -----------------------------------------------------------------------------
   Flash messages
   ----------------------------------------------------------------------------- */
.flash { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; border: 1px solid; }
.flash.info    { background: #E6F1FB; border-color: #B8D8EE; color: #185FA5; }
.flash.success { background: #EAF3DE; border-color: #BFD69B; color: #3B6D11; }
.flash.warn    { background: #FAEEDA; border-color: #EF9F27; color: #854F0B; }
.flash.error   { background: #FCEBEB; border-color: #E24B4A; color: #A32D2D; }

/* -----------------------------------------------------------------------------
   Login-style centered card (used by login, setup, change_password)
   ----------------------------------------------------------------------------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #1F4E78 0%, #163a5a 100%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: white;
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.auth-card .auth-logo { display: flex; flex-direction: column; align-items: center; margin-bottom: 24px; }
.auth-card .auth-logo img, .auth-card .auth-logo svg { width: 84px; height: 84px; margin-bottom: 14px; }
.auth-card .auth-logo h1 { font-size: 22px; margin: 0; color: #1F4E78; letter-spacing: 0.14em; font-weight: 700; }
.auth-card .auth-logo .sub { font-size: 11px; color: #A5A6AA; letter-spacing: 0.32em; text-transform: uppercase; margin-top: 6px; font-weight: 500; }
.auth-card h2 { font-size: 16px; color: #1F4E78; margin: 0 0 16px; }
.auth-card .remember-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; font-size: 13px; color: #5F5E5A; }
.auth-card button[type="submit"] { width: 100%; padding: 11px; font-size: 14px; }
.auth-card .foot { font-size: 12px; color: #5F5E5A; margin-top: 18px; text-align: center; }

/* -----------------------------------------------------------------------------
   Lender list table — two-row layout (data row + desc row beneath)
   ----------------------------------------------------------------------------- */
.lenders-table-wrap {
  background: white; border: 1px solid #e4e5e8; border-radius: 8px;
  overflow: auto; box-shadow: 0 1px 2px rgba(16, 30, 54, 0.04);
}
.lenders-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.lenders-table thead th {
  background: #F7F7F7; text-align: left; padding: 10px 12px;
  border-bottom: 1px solid #e4e5e8; font-weight: 600; color: #5F5E5A;
  font-size: 12px; letter-spacing: 0.02em; text-transform: uppercase;
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.lenders-table tbody td { padding: 10px 12px; vertical-align: top; }
.lenders-table .lender-name { font-weight: 600; color: #1F4E78; font-size: 13.5px; }
.lenders-table .muted { color: #888; font-style: italic; }
.money { font-variant-numeric: tabular-nums; }

/* Any row with a click-through handler should advertise itself as clickable */
.lenders-table tbody tr[onclick] { cursor: pointer; }
.lenders-table tbody tr[onclick]:hover { background: #F9FBFE; }

/* Primary data row */
.lender-row { cursor: pointer; }
.lender-row:hover,
.lender-row:hover + .lender-desc-row { background: #F9FBFE; }
.lender-row > td { padding-bottom: 6px; border-top: none; }

/* Desc sub-row — visually attached to the data row above */
.lender-desc-row { cursor: pointer; background: #FBFAF6; }
.lender-desc-row > td {
  padding: 2px 14px 12px 14px;
  font-size: 12px;
  line-height: 1.5;
  color: #5F5E5A;
  border-bottom: 1px solid #EDEBE3;
}
.lender-desc-row .desc-label {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: #8C8A82;
  margin-right: 8px;
  padding: 1px 6px;
  background: #F1EFE8;
  border-radius: 3px;
  vertical-align: 1px;
}
.lender-desc-row .muted { font-size: 12px; }

/* -----------------------------------------------------------------------------
   Lender edit / detail form
   ----------------------------------------------------------------------------- */
.detail-wrap { background: white; border: 1px solid #e4e5e8; border-radius: 8px; padding: 0; }
.detail-head { padding: 18px 22px; border-bottom: 1px solid #e4e5e8; display: flex; align-items: center; justify-content: space-between; }
.detail-head h2 { margin: 0 0 3px; font-size: 20px; color: #1F4E78; font-weight: 600; }
.detail-head .breadcrumb { font-size: 12px; color: #5F5E5A; }

.detail-body { padding: 18px 22px; }
.form-section { margin-bottom: 22px; }
.form-section h3 {
  margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #1F4E78; font-weight: 600; padding-bottom: 6px; border-bottom: 1px solid #e4e5e8;
}
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.one { grid-template-columns: 1fr; }

.detail-footer {
  padding: 14px 22px; border-top: 1px solid #e4e5e8; background: #F9FAFB;
  display: flex; gap: 10px; justify-content: flex-end; align-items: center;
  border-radius: 0 0 8px 8px;
}

/* Checkbox grids for multi-value pickers (loan_types, property_types, geography) */
.chk-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 4px 10px; padding: 8px 10px; border: 1px solid #d4d5d8; border-radius: 5px;
  background: white; max-height: 180px; overflow-y: auto;
}
.chk-grid label.chk {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 400; color: #333;
  padding: 2px 4px; border-radius: 3px; cursor: pointer;
}
.chk-grid label.chk:hover { background: #F0F6FC; }
.chk-grid input[type="checkbox"] { accent-color: #1F4E78; }

/* Contacts panel */
.contacts-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.contacts-table th {
  background: #F7F7F7; text-align: left; padding: 8px 10px; border-bottom: 1px solid #e4e5e8;
  font-size: 11px; color: #5F5E5A; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
}
.contacts-table td { padding: 8px 10px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
.contacts-table .row-actions { display: flex; gap: 6px; }
.btn-sm.danger:hover { border-color: #E24B4A; color: #A32D2D; background: #FCEBEB; }
.empty-state { padding: 30px 20px; text-align: center; color: #888; font-size: 13px; font-style: italic; }

/* -----------------------------------------------------------------------------
   Responsive — tablet + phone
   ----------------------------------------------------------------------------- */

/* Tablet + smaller laptop */
@media (max-width: 900px) {
  .sal-main { padding: 16px 14px; }
  .form-grid, .form-grid.two { grid-template-columns: 1fr; }
  .detail-head { padding: 14px 16px; flex-wrap: wrap; gap: 8px; }
  .detail-body { padding: 14px 16px; }
  .detail-footer { padding: 12px 16px; flex-wrap: wrap; }
  .chk-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

/* Phone */
@media (max-width: 640px) {
  /* Header — pack the logo + wordmark; hide the email (kept on avatar tooltip) */
  .sal-header { padding: 10px 12px; gap: 8px; }
  .sal-logo { gap: 10px; }
  .sal-logo img, .sal-logo svg { width: 38px; height: 38px; padding: 4px; border-radius: 6px; }
  .sal-logo-text { font-size: 14px; letter-spacing: 0.1em; }
  .sal-logo-text small { font-size: 9px; letter-spacing: 0.26em; margin-top: 2px; }
  .user-menu { gap: 8px; font-size: 12px; }
  .user-menu > span { display: none; }          /* drop the long email */
  .user-menu .btn-ghost { padding: 5px 10px; font-size: 11px; }

  /* Nav — horizontal swipe instead of wrapping to 2 rows */
  .sal-nav {
    padding: 0 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sal-nav::-webkit-scrollbar { display: none; }
  .sal-nav a { padding: 12px 12px; font-size: 13px; white-space: nowrap; }

  /* Main chrome */
  .sal-main { padding: 12px 10px; }
  .page-header { flex-wrap: wrap; gap: 10px; align-items: flex-start; }
  .page-header h1 { font-size: 19px; }
  .page-header .subtitle { font-size: 12px; }
  .toolbar { padding: 10px; gap: 6px; }
  .toolbar input[type="search"] { flex-basis: 100%; min-width: 0; }
  .toolbar select { flex: 1 1 auto; }
  .btn-primary, .btn-secondary, .btn-danger { padding: 8px 12px; font-size: 13px; }

  /* Lender list — transform each row-pair into a stacked card.
     Scoped via :has(.lender-row) so the users / contacts / audit tables
     (which share .lenders-table but don't have .lender-row children)
     fall back to horizontal scroll instead. */
  .lenders-table-wrap:has(.lender-row) {
    border: none; background: transparent; box-shadow: none; border-radius: 0;
  }
  .lenders-table-wrap:has(.lender-row) .lenders-table,
  .lenders-table-wrap:has(.lender-row) .lenders-table thead,
  .lenders-table-wrap:has(.lender-row) .lenders-table tbody,
  .lenders-table-wrap:has(.lender-row) .lenders-table tr,
  .lenders-table-wrap:has(.lender-row) .lenders-table td { display: block; }
  .lenders-table-wrap:has(.lender-row) .lenders-table thead { display: none; }
  .lenders-table-wrap:has(.lender-row) .lenders-table tr { width: 100%; }

  .lender-row {
    background: white;
    border: 1px solid #e4e5e8;
    border-radius: 8px 8px 0 0;
    padding: 10px 14px 8px;
    margin-top: 10px;
    position: relative;
  }
  .lender-row > td { padding: 3px 0 !important; border: none; }
  /* Name cell (first td) — leave room for the ranking pill anchored top-right */
  .lender-row > td:nth-child(1) { padding-right: 46px !important; font-size: 14px; }
  /* Ranking — small pill in the top-right corner of the card */
  .lender-row > td:nth-child(2) {
    position: absolute; top: 10px; right: 14px;
    background: #EAF3DE; color: #3B6D11;
    padding: 2px 10px !important; border-radius: 12px;
    font-size: 12px !important;
  }
  .lender-row > td:nth-child(3) { padding-top: 6px !important; }      /* status */
  .lender-row > td:nth-child(4) { font-size: 12px; color: #5F5E5A; }  /* classification */
  .lender-row > td:nth-child(4)::before { content: "Class: "; color: #8C8A82; }
  .lender-row > td:nth-child(6) { font-size: 12px; color: #5F5E5A; }  /* size */
  .lender-row > td:nth-child(6)::before { content: "Size: "; color: #8C8A82; }
  .lender-row > td:nth-child(7) { font-size: 12px; }                  /* geo */
  .lender-row > td:nth-child(7)::before { content: "Geo: "; color: #8C8A82; font-size: 11px; margin-right: 4px; }
  .lender-row > td:nth-child(8) { display: none; }                    /* hide contact count */

  .lender-desc-row {
    background: #FBFAF6;
    border: 1px solid #e4e5e8;
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 8px 14px 10px;
  }
  .lender-desc-row > td { padding: 0 !important; border: none; font-size: 12px; }

  /* Other tables (users / contacts / audit) — keep as tables but let them
     scroll horizontally if they overflow the viewport. */
  .lenders-table-wrap:not(:has(.lender-row)) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .lenders-table-wrap:not(:has(.lender-row)) .lenders-table { min-width: 640px; }
  .contacts-table { font-size: 12px; }
  .contacts-table th, .contacts-table td { padding: 6px 8px; }

  /* Lender edit page */
  .detail-head h2 { font-size: 17px; }
  /* 16px+ on inputs is what actually prevents iOS auto-zoom when focusing
     a field. 15px (the previous value) was below threshold — Safari + iOS
     Chrome would zoom the page on tap, throwing off the rest of the form. */
  .field input, .field select, .field textarea { font-size: 16px; }
  .chk-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); max-height: 240px; }

  /* Form sections: a little more vertical room so cards don't feel cramped
     once the grid collapses to one column. */
  .form-section { margin-bottom: 18px; }
  .form-section h3 {
    font-size: 12px; letter-spacing: 0.08em;
    margin-bottom: 12px; padding-bottom: 8px;
  }
  .field { margin-bottom: 12px; }
  .detail-body { padding: 14px 14px; }
  .detail-footer { padding: 12px 14px; gap: 8px; }

  /* Match results — stacked lender cards already work; just tighten padding */
  .match-result { padding: 10px 12px !important; }
  .match-result h3 { font-size: 14px !important; }

  /* Auth card — full-width on phone */
  .auth-wrap { padding: 10px; }
  .auth-card { padding: 22px 18px; border-radius: 10px; }
}

/* Very narrow phones (iPhone SE, old Androids) */
@media (max-width: 380px) {
  .sal-logo-text { font-size: 13px; }
  .sal-logo-text small { font-size: 8px; letter-spacing: 0.22em; }
  .user-menu .avatar { width: 26px; height: 26px; font-size: 11px; }
  .sal-nav a { padding: 11px 9px; font-size: 12px; }
}

/* -----------------------------------------------------------------------------
   Scenarios detail (v6): key/value grid, append-only notes, filter bar
   ----------------------------------------------------------------------------- */
.filter-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.filter-bar input[type="text"] {
  height: 34px; padding: 0 10px; border: 1px solid #d4d5d8; border-radius: 5px;
  font-size: 13px; background: white;
}

/* Key/value summary grid on the scenario detail page */
.kv-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 22px;
}
.kv-grid > div {
  display: flex; flex-direction: column; gap: 2px;
  font-size: 13px; color: #3B3A36;
  padding: 6px 0;
  border-bottom: 1px dashed #EDEBE3;
}
.kv-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #5F5E5A;
  font-weight: 600;
}

/* Append-only notes feed */
.note-list {
  list-style: none;
  margin: 0 0 4px;
  padding: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.note-item {
  background: #FBFAF6;
  border: 1px solid #E9E6DB;
  border-radius: 6px;
  padding: 10px 12px;
}
.note-meta {
  font-size: 12px;
  color: #3B3A36;
  margin-bottom: 4px;
}
.note-meta .muted { color: #888; font-weight: 400; }
.note-body {
  font-size: 13px;
  color: #2A2926;
  line-height: 1.45;
  white-space: pre-wrap;
}
.note-form textarea {
  width: 100%;
  resize: vertical;
}

/* Mobile: collapse the kv-grid to a single column */
@media (max-width: 640px) {
  .kv-grid { grid-template-columns: 1fr; gap: 0; }
  .kv-grid > div { padding: 8px 0; }
}

/* -----------------------------------------------------------------------------
   Loans (v7): status tabs, event timeline, email preview, linked loans
   ----------------------------------------------------------------------------- */

/* Tab strip on /loans (v7) and /scenarios filter (v8) — same visual,
   two selectors so changing one doesn't accidentally drag the other. */
.loan-status-tabs,
.scn-filter-tabs {
  display: flex; gap: 2px; background: #F1EFE8; border-radius: 6px; padding: 3px;
}
.loan-status-tabs a,
.scn-filter-tabs a {
  padding: 6px 12px;
  font-size: 12px;
  color: #5F5E5A;
  text-decoration: none;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.1s;
}
.loan-status-tabs a:hover,
.scn-filter-tabs a:hover { background: #E8E5DA; color: #2A2926; }
.loan-status-tabs a.active,
.scn-filter-tabs a.active {
  background: white;
  color: #1F4E78;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 30, 54, 0.06);
}
.loan-status-tabs a .ct,
.scn-filter-tabs a .ct {
  font-size: 11px; padding: 1px 6px; border-radius: 8px;
  background: #E8E5DA; color: #5F5E5A; font-weight: 500;
}
.loan-status-tabs a.active .ct,
.scn-filter-tabs a.active .ct { background: #DCE8F5; color: #1F4E78; }

/* Archived-row dim on /scenarios list */
.lenders-table tr.row-archived { opacity: 0.65; }
.lenders-table tr.row-archived:hover { opacity: 1; }

/* "Client" badge on scenarios from public intake (v9) */
.badge.b-client { background: #E6F4EA; color: #1B5E20; border: 1px solid #B7DFC2; }

/* Unviewed-client-submission counter on the Scenarios nav link (v9.5) */
.sal-nav .nav-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  background: #C0392B;        /* assertive red — easy to spot in the nav */
  border-radius: 9px;
  vertical-align: 1px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

/* "New" tab on /scenarios pulses the count chip when it's > 0 */
.scn-filter-tabs a.has-new .ct {
  background: #FAEEDA;
  color: #854F0B;
  font-weight: 600;
}
.scn-filter-tabs a.has-new.active .ct {
  background: #DCE8F5;
  color: #1F4E78;
}

/* -----------------------------------------------------------------------------
   Public intake page (/intake) — used by clients/borrowers, no auth (v9)
   ----------------------------------------------------------------------------- */
body.public-page {
  background: #f5f6f8;            /* match staff pages */
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: #2A2926;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.public-header {
  background: white;
  border-bottom: 1px solid #E9E6DB;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.public-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.public-logo img { height: 36px; width: auto; }
.public-logo-text {
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #1F4E78;
  font-size: 17px;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.public-logo-text small {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: #5F5E5A;
  font-weight: 500;
  margin-top: 2px;
}
.public-nav a { font-size: 13px; text-decoration: none; }
.public-nav a:hover { color: #1F4E78; text-decoration: underline; }

.public-main {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 24px 48px;
  flex: 1;
  width: 100%;
  box-sizing: border-box;
}
.intake-intro h1 {
  font-size: 28px;
  margin: 0 0 6px;
  color: #1F4E78;
  letter-spacing: -0.01em;
}
.intake-intro p {
  margin: 0 0 22px;
  color: #3B3A36;
  font-size: 15px;
  line-height: 1.55;
}
.intake-thanks {
  background: white;
  border: 1px solid #E9E6DB;
  border-radius: 10px;
  padding: 36px 28px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(16, 30, 54, 0.04);
}
.intake-thanks h1 {
  margin: 0 0 14px;
  color: #1F4E78;
  font-size: 26px;
}
.intake-thanks p {
  margin: 0 auto;
  max-width: 520px;
  color: #3B3A36;
  line-height: 1.6;
  font-size: 15px;
}
.public-footer {
  text-align: center;
  padding: 18px 24px;
  color: #5F5E5A;
  font-size: 12px;
  border-top: 1px solid #E9E6DB;
  background: white;
}

@media (max-width: 640px) {
  .public-header {
    padding: 10px 14px;
    gap: 8px;                /* keep logo + Staff Login from kissing */
  }
  .public-logo { gap: 8px; min-width: 0; }
  .public-logo img { height: 28px; flex-shrink: 0; }
  .public-logo-text { font-size: 14px; letter-spacing: 0.04em; min-width: 0; }
  .public-logo-text small { font-size: 9px; letter-spacing: 0.22em; }
  .public-nav a { font-size: 12px; white-space: nowrap; }

  .public-main { padding: 18px 14px 32px; }
  .intake-intro h1 { font-size: 22px; line-height: 1.18; }
  .intake-intro p { font-size: 14px; margin-bottom: 16px; }

  .intake-thanks { padding: 26px 18px; }
  .intake-thanks h1 { font-size: 22px; }
  .intake-thanks p { font-size: 14px; }
}

/* Extra-narrow phones */
@media (max-width: 380px) {
  .public-header { padding: 8px 12px; }
  .public-logo img { height: 24px; }
  .public-logo-text { font-size: 13px; }
  .public-logo-text small { font-size: 8px; }
  .public-nav a { font-size: 11px; }
  .public-main { padding: 14px 10px 28px; }
}

/* -----------------------------------------------------------------------------
   Shared public-page nav (v10.6) — used by lib/public_header.php on
   /, /intake, and /login. The homepage's own inline <style> block defines
   matching rules; these duplicate them so intake/login pages, which load
   styles.css instead of inlining, get the same look.
   ----------------------------------------------------------------------------- */
.nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 56px;
  background: #ffffff;
  border-bottom: 1px solid #e6e8eb;
  position: sticky; top: 0; z-index: 100;
  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.nav .logo {
  display: inline-flex; align-items: center; gap: 12px;
  text-decoration: none;
}
.nav .logo-mark { width: 40px; height: 40px; flex-shrink: 0; }
.nav .logo-text {
  display: flex; flex-direction: column; gap: 4px; line-height: 1;
}
.nav .logo-text .one {
  font-weight: 600; letter-spacing: 0.14em; font-size: 15px; color: #0e2c46;
}
.nav .logo-text .two {
  font-weight: 500; letter-spacing: 0.32em; font-size: 10px;
  color: #0e2c46; opacity: 0.78;
}
.nav-links {
  display: flex; align-items: center; gap: 32px;
  font-size: 14px; font-weight: 500; color: #0e2c46;
}
.nav-links a {
  text-decoration: none; color: inherit;
  transition: color 0.15s ease;
}
.nav-links a:hover { color: #204e78; }
.nav-links a.active { color: #204e78; font-weight: 600; }
.nav-links a.btn-cta,
.btn-cta {
  display: inline-flex; align-items: center; gap: 10px;
  background: #204e78; color: #ffffff;
  border: none; border-radius: 2px;
  padding: 12px 20px;
  font-weight: 600; font-size: 14px;
  text-decoration: none; cursor: pointer;
  transition: background-color 0.15s ease;
}
.nav-links a.btn-cta:hover,
.btn-cta:hover { background: #1458a5; color: #ffffff; }
.btn-cta .arrow, .nav .arrow {
  display: inline-block; width: 14px; height: 14px;
}

@media (max-width: 960px) {
  .nav { padding: 14px 24px; }
  .nav-links { gap: 18px; font-size: 13px; }
  /* On mobile, keep the most important links visible (Staff Login + CTA).
     Hide the in-page anchors which only make sense on the homepage anyway. */
  .nav-links a[href="/"],
  .nav-links a[href="/#about"],
  .nav-links a[href="/#contact"] { display: none; }
}
@media (max-width: 480px) {
  .nav { padding: 12px 16px; }
  .nav-links { gap: 12px; }
  .nav .logo-mark { width: 34px; height: 34px; }
  .nav .logo-text .one { font-size: 13px; letter-spacing: 0.1em; }
  .nav .logo-text .two { font-size: 9px; letter-spacing: 0.24em; }
  .btn-cta { padding: 9px 14px; font-size: 13px; }
}

/* Email preview pre-block on /loans/detail */
.email-preview {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  background: #FBFAF6;
  border: 1px solid #E9E6DB;
  border-radius: 6px;
  padding: 12px 14px;
  color: #2A2926;
  white-space: pre-wrap;
  line-height: 1.5;
  margin: 0;
  max-height: 280px;
  overflow: auto;
}

/* Collapsible + editable email body on /loans/detail */
.email-body-toggle {
  margin: 0;
  border: 1px solid #E9E6DB;
  border-radius: 6px;
  background: #FBFAF6;
  overflow: hidden;
}
.email-body-toggle > summary {
  list-style: none;          /* hide default disclosure marker (Firefox) */
  cursor: pointer;
  padding: 8px 12px;
  font-size: 12px;
  color: #2A2926;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  background: #F4F1E5;
  border-bottom: 1px solid transparent;
}
.email-body-toggle > summary::-webkit-details-marker { display: none; } /* Safari/Chrome */
.email-body-toggle > summary::before {
  content: "";
  display: inline-block;
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #5F5E5A;
  transition: transform 0.15s ease;
  transform: rotate(-90deg);  /* points right when closed */
}
.email-body-toggle[open] > summary::before {
  transform: rotate(0deg);    /* points down when open */
}
.email-body-toggle[open] > summary {
  border-bottom-color: #E9E6DB;
}
.email-body-toggle .eb-hide { display: none; }
.email-body-toggle[open] .eb-show { display: none; }
.email-body-toggle[open] .eb-hide { display: inline; }

.email-body-edit {
  display: block;
  width: 100%;
  box-sizing: border-box;
  /* Calibri matches Outlook's default body font. Carlito is an open-source
     metric-compatible clone bundled on many Linux distros; the rest is the
     standard system-UI fallback for Mac / mobile. */
  font-family: Calibri, Carlito, -apple-system, BlinkMacSystemFont,
               "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 11pt;            /* matches Outlook 11pt body */
  line-height: 1.45;
  color: #2A2926;
  background: #FBFAF6;
  border: 0;
  border-radius: 0;
  padding: 12px 14px;
  margin: 0;
  resize: vertical;
  min-height: 180px;
  outline: none;
}
.email-body-edit:focus {
  background: #FFFDF6;
  box-shadow: inset 0 0 0 2px #DCE8F5;
}

/* Linked-loans pill list on /scenarios/detail */
.linked-loan-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.linked-loan-list li {
  background: #FBFAF6;
  border: 1px solid #E9E6DB;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
}
.linked-loan-list a:hover { background: #F4F1E5; }
.linked-loan-list .badge { margin-right: 8px; }

/* Event log on /loans/detail */
.event-list {
  list-style: none; margin: 0 0 4px; padding: 0;
  display: flex; flex-direction: column; gap: 0;
  position: relative;
}
.event-item {
  display: flex; gap: 12px;
  padding: 8px 0;
  position: relative;
}
.event-item:not(:last-child)::before {
  /* Vertical timeline guideline behind the bullets */
  content: "";
  position: absolute;
  left: 5px;
  top: 22px;
  bottom: -2px;
  width: 2px;
  background: #E9E6DB;
}
.event-bullet {
  flex: 0 0 12px;
  width: 12px; height: 12px;
  margin-top: 4px;
  border-radius: 50%;
  background: #C9CCD2;
  border: 2px solid white;
  box-shadow: 0 0 0 1px #C9CCD2;
  position: relative;
  z-index: 1;
}
.event-item.auto .event-bullet   { background: #1F4E78; box-shadow: 0 0 0 1px #1F4E78; }
.event-item.manual .event-bullet { background: #854F0B; box-shadow: 0 0 0 1px #854F0B; }

.event-body { flex: 1; min-width: 0; }
.event-meta {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  font-size: 11px; color: #5F5E5A;
}
.event-when { font-variant-numeric: tabular-nums; color: #2A2926; font-weight: 500; }
.event-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  background: #DCE8F5;
  color: #1F4E78;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.event-tag.manual { background: #FAEEDA; color: #854F0B; }
.event-headline {
  font-size: 13px;
  color: #2A2926;
  font-weight: 500;
  margin-top: 1px;
}
.event-text {
  font-size: 13px;
  color: #3B3A36;
  white-space: pre-wrap;
  margin-top: 2px;
  line-height: 1.45;
}

@media (max-width: 640px) {
  .loan-status-tabs,
  .scn-filter-tabs { flex-wrap: wrap; }
  .loan-status-tabs a,
  .scn-filter-tabs a { padding: 5px 8px; font-size: 11px; }
  .email-preview { font-size: 11px; padding: 10px 12px; }
  .email-body-edit { font-size: 11pt; padding: 10px 12px; min-height: 220px; }
  .email-body-toggle > summary { font-size: 11px; padding: 7px 10px; }
}
