/* ============================================================================
   STYLES LAYER  —  layout + components.
   Reads brand values from theme.css exclusively. Do NOT put literal colours,
   fonts or logo paths in this file; add a variable to theme.css instead.
   ============================================================================ */

/* --- Reset / base --------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-heading); margin: 0; line-height: var(--lh-tight); font-weight: var(--fw-bold); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
:focus-visible { outline: 3px solid var(--brand-ring); outline-offset: 1px; border-radius: var(--radius-sm); }

/* --- App bar -------------------------------------------------------------- */
.appbar {
  height: var(--bar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand__logo {
  width: 34px; height: var(--logo-height);
  background: var(--logo-url) center/contain no-repeat;
}
.brand__name { font-weight: var(--fw-bold); font-size: var(--fs-md); color: var(--text); letter-spacing: -.01em; }
.brand__name span { color: var(--brand); }
.appbar__spacer { flex: 1; }
.appbar__nav { display: flex; gap: var(--space-1); }
.appbar__nav a {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: var(--fw-medium);
  font-size: var(--fs-sm);
}
.appbar__nav a:hover { background: var(--surface-2); text-decoration: none; }
.appbar__nav a.is-active { color: var(--brand); background: var(--brand-light); }
.user {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--fs-sm); color: var(--text-secondary);
}
.user__avatar {
  width: 30px; height: 30px; border-radius: var(--radius-pill);
  background: var(--brand); color: var(--brand-contrast);
  display: grid; place-items: center; font-size: var(--fs-xs); font-weight: var(--fw-bold);
}

/* --- Page shell ----------------------------------------------------------- */
.page { max-width: var(--maxw); margin: 0 auto; padding: var(--space-6) var(--space-5) var(--space-8); }
.page__head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap; }
.page__title { font-size: var(--fs-2xl); letter-spacing: -.02em; }
.page__subtitle { color: var(--text-secondary); margin-top: var(--space-1); font-size: var(--fs-md); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: var(--fs-xs); font-weight: var(--fw-bold); color: var(--text-muted); }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, color .15s;
}
.btn--primary { background: var(--brand); color: var(--brand-contrast); }
.btn--primary:hover { background: var(--brand-dark); }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--subtle { background: transparent; color: var(--brand); }
.btn--subtle:hover { background: var(--brand-light); }
.btn--danger-subtle { background: transparent; color: var(--danger); border-color: transparent; padding: var(--space-2); }
.btn--danger-subtle:hover { background: var(--danger-light); }
.btn--sm { padding: var(--space-2) var(--space-3); font-size: var(--fs-xs); }
.btn__icon { width: 15px; height: 15px; display: inline-block; }

/* --- Cards / panels ------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card__pad { padding: var(--space-5); }

/* --- Dashboard: pipeline -------------------------------------------------- */
.pipeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--space-4);
  border-left: 3px solid var(--stat-color, var(--border-strong));
}
.stat__label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: var(--fw-medium); }
.stat__value { font-size: var(--fs-xl); font-weight: var(--fw-bold); margin-top: var(--space-1); letter-spacing: -.02em; }
.stat__meta { font-size: var(--fs-xs); color: var(--text-secondary); }

/* --- Table ---------------------------------------------------------------- */
.tablewrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.grid th {
  text-align: left; padding: var(--space-3) var(--space-4);
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: var(--fw-bold);
  border-bottom: 1px solid var(--border);
}
table.grid td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tbody tr { cursor: pointer; transition: background .12s; }
table.grid tbody tr:hover { background: var(--brand-light); }
.cell-strong { font-weight: var(--fw-medium); color: var(--text); }
.cell-mono { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-secondary); }
.cell-amount { font-variant-numeric: tabular-nums; font-weight: var(--fw-medium); }

/* --- Status badge --------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-medium);
  background: color-mix(in srgb, var(--badge-color, var(--text-muted)) 14%, white);
  color: color-mix(in srgb, var(--badge-color, var(--text-muted)) 78%, black);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--badge-color, var(--text-muted)); }
.badge--lead        { --badge-color: var(--status-lead); }
.badge--application { --badge-color: var(--status-application); }
.badge--submitted   { --badge-color: var(--status-submitted); }
.badge--approved    { --badge-color: var(--status-approved); }
.badge--funded      { --badge-color: var(--status-funded); }
.badge--declined    { --badge-color: var(--status-declined); }

/* --- Application form: two-column shell ----------------------------------- */
.form-shell { display: grid; grid-template-columns: var(--nav-width) 1fr; gap: var(--space-6); align-items: start; }

/* left section nav */
.section-nav { position: sticky; top: calc(var(--bar-height) + var(--space-5)); }
.section-nav__title { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: var(--fw-bold); padding: 0 var(--space-3) var(--space-2); }
.section-nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: var(--fs-sm); font-weight: var(--fw-medium);
  border-left: 2px solid transparent;
}
.section-nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.section-nav a.is-active { background: var(--brand-light); color: var(--brand); border-left-color: var(--brand); }
.section-nav__count { font-size: var(--fs-xs); color: var(--text-muted); background: var(--surface-2); border-radius: var(--radius-pill); padding: 0 7px; }

/* form body */
.form-body { min-width: 0; display: flex; flex-direction: column; gap: var(--space-5); }
.section { scroll-margin-top: calc(var(--bar-height) + var(--space-5)); }
.section__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.section__title { font-size: var(--fs-lg); letter-spacing: -.01em; }
.section__hint { color: var(--text-secondary); font-size: var(--fs-sm); margin-top: 2px; }

/* --- Form fields ---------------------------------------------------------- */
.field-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--space-4); }
.field { display: flex; flex-direction: column; gap: 6px; grid-column: span 4; min-width: 0; }
.field.col-2  { grid-column: span 2; }
.field.col-3  { grid-column: span 3; }
.field.col-4  { grid-column: span 4; }
.field.col-6  { grid-column: span 6; }
.field.col-8  { grid-column: span 8; }
.field.col-12 { grid-column: span 12; }
.field__label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary); }
.field__label .req { color: var(--danger); margin-left: 2px; }
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); }

.input, .select, .textarea {
  width: 100%; padding: var(--space-3); font-size: var(--fs-base); font-family: inherit;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); outline: none; }
.textarea { resize: vertical; min-height: 92px; line-height: var(--lh-base); }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%), linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%); background-position: calc(100% - 18px) center, calc(100% - 13px) center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: var(--space-6); }
.input-group { position: relative; display: flex; align-items: center; }
.input-group__prefix { position: absolute; left: var(--space-3); color: var(--text-muted); font-size: var(--fs-base); pointer-events: none; }
.input-group .input { padding-left: 26px; }

/* validation states */
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); background: var(--danger-light); }
.field__error { display: none; font-size: var(--fs-xs); color: var(--danger); }
.field.has-error .field__error { display: block; }

/* --- Repeatable applicant block ------------------------------------------- */
.applicant {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; background: var(--surface);
}
.applicant__bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--brand-light); border-bottom: 1px solid var(--border);
}
.applicant__index {
  width: 26px; height: 26px; border-radius: var(--radius-pill);
  background: var(--brand); color: var(--brand-contrast);
  display: grid; place-items: center; font-size: var(--fs-xs); font-weight: var(--fw-bold);
}
.applicant__title { font-weight: var(--fw-bold); font-size: var(--fs-md); }
.applicant__spacer { flex: 1; }
.applicant__body { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-5); }

/* sub-section within an applicant */
.subsection { border-top: 1px dashed var(--border); padding-top: var(--space-4); }
.subsection:first-child { border-top: 0; padding-top: 0; }
.subsection__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.subsection__title { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .05em; font-weight: var(--fw-bold); color: var(--text-secondary); }

/* --- Editable line-item tables (assets, liabilities, etc.) ---------------- */
.linetable { width: 100%; border-collapse: collapse; }
.linetable th {
  text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: var(--fw-bold); padding: 0 var(--space-2) var(--space-2);
}
.linetable td { padding: 3px var(--space-2) 3px 0; vertical-align: top; }
.linetable td:last-child { padding-right: 0; width: 40px; text-align: right; }
.linetable .input, .linetable .select { padding: var(--space-2) var(--space-3); font-size: var(--fs-sm); }
.linetable tfoot td { padding-top: var(--space-3); }
.line-total { display: flex; justify-content: space-between; align-items: center; padding: var(--space-3); background: var(--surface-2); border-radius: var(--radius); margin-top: var(--space-3); }
.line-total__label { font-size: var(--fs-sm); color: var(--text-secondary); font-weight: var(--fw-medium); }
.line-total__value { font-size: var(--fs-md); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }

/* --- Property card (repeatable, within applicant) ------------------------- */
.property {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); padding: var(--space-4); position: relative;
}
.property + .property { margin-top: var(--space-3); }
.property__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.property__label { font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--text-secondary); }
.property__mortgage { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px dashed var(--border-strong); }
.property__mortgage-title { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: var(--fw-bold); margin-bottom: var(--space-3); }

/* --- Sticky action footer ------------------------------------------------- */
.actionbar {
  position: sticky; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  margin-top: var(--space-6);
  padding: var(--space-3) 0;
}
.actionbar__inner { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--space-5); display: flex; align-items: center; gap: var(--space-3); }
.actionbar__status { font-size: var(--fs-sm); color: var(--text-secondary); }
.actionbar__spacer { flex: 1; }

/* --- Validation summary panel --------------------------------------------- */
.validation {
  border-radius: var(--radius); padding: var(--space-4);
  margin-bottom: var(--space-5); display: none; border: 1px solid transparent;
}
.validation.is-visible { display: block; }
.validation--error { background: var(--danger-light); border-color: color-mix(in srgb, var(--danger) 30%, white); }
.validation--ok { background: var(--success-light); border-color: color-mix(in srgb, var(--success) 30%, white); }
.validation__title { font-weight: var(--fw-bold); font-size: var(--fs-md); display: flex; align-items: center; gap: var(--space-2); }
.validation--error .validation__title { color: var(--danger); }
.validation--ok .validation__title { color: var(--success); }
.validation__list { margin: var(--space-3) 0 0; padding-left: var(--space-5); font-size: var(--fs-sm); color: var(--text-secondary); }
.validation__list li { margin-bottom: 3px; }
.validation__list a { font-weight: var(--fw-medium); }

/* --- Toast ---------------------------------------------------------------- */
.toast {
  position: fixed; bottom: var(--space-5); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--surface);
  padding: var(--space-3) var(--space-5); border-radius: var(--radius);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 100;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Empty state ---------------------------------------------------------- */
.empty { text-align: center; padding: var(--space-7) var(--space-5); color: var(--text-muted); }
.empty__title { font-weight: var(--fw-bold); color: var(--text-secondary); margin-bottom: var(--space-2); }

/* --- Utility -------------------------------------------------------------- */
.row-actions { display: flex; gap: var(--space-2); align-items: center; }
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.mt-4 { margin-top: var(--space-4); }

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 900px) {
  .form-shell { grid-template-columns: 1fr; }
  .section-nav { position: static; display: none; }
  .field.col-2, .field.col-3, .field.col-4 { grid-column: span 6; }
  .field.col-6, .field.col-8 { grid-column: span 12; }
  .appbar__nav { display: none; }
}
@media (max-width: 560px) {
  .field { grid-column: span 12 !important; }
  .page { padding: var(--space-4); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============================================================================
   DEMO-WARE COMPONENTS  (login, users, automations, messaging)
   Still 100% theme-variable driven. These screens are mock-ups for the demo;
   the structures here map directly to real product features later — see README.
   ============================================================================ */

/* Demo tag — put on any mock screen so it's never mistaken for live */
.demo-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 11px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-medium);
  background: var(--warning-light);
  color: color-mix(in srgb, var(--warning) 80%, black);
  border: 1px solid color-mix(in srgb, var(--warning) 30%, white);
}
.demo-tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--warning); }

/* Sign-out link in the app bar */
.user__signout { font-size: var(--fs-sm); color: var(--text-secondary); margin-left: var(--space-3); }
.user__signout:hover { color: var(--brand); }

/* --- Login / auth ---------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--space-5); background: var(--bg); }
.auth__card { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: var(--space-7) var(--space-6); }
.auth__brand { display: flex; align-items: center; gap: var(--space-3); justify-content: center; margin-bottom: var(--space-5); }
.auth__logo { width: 40px; height: 40px; background: var(--logo-url) center/contain no-repeat; }
.auth__brandname { font-weight: var(--fw-bold); font-size: var(--fs-lg); }
.auth__brandname span { color: var(--brand); }
.auth__title { text-align: center; font-size: var(--fs-lg); margin-bottom: var(--space-2); }
.auth__sub { text-align: center; color: var(--text-secondary); font-size: var(--fs-sm); margin-bottom: var(--space-5); }
.auth .field { margin-bottom: var(--space-4); }
.auth .btn { width: 100%; justify-content: center; }
.auth__foot { margin-top: var(--space-5); text-align: center; font-size: var(--fs-xs); color: var(--text-muted); }
.auth__demo { display: flex; justify-content: center; margin-bottom: var(--space-5); }

/* --- Toggle switch --------------------------------------------------------- */
.toggle { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle__track { position: absolute; inset: 0; background: var(--border-strong); border-radius: var(--radius-pill); transition: background .15s; cursor: pointer; }
.toggle__track::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: var(--surface); border-radius: 50%; transition: transform .15s; box-shadow: var(--shadow-sm); }
.toggle input:checked + .toggle__track { background: var(--success); }
.toggle input:checked + .toggle__track::before { transform: translateX(16px); }

/* --- Automation rule card -------------------------------------------------- */
.rule { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.rule + .rule { margin-top: var(--space-3); }
.rule__icon { width: 42px; height: 42px; border-radius: var(--radius); display: grid; place-items: center; background: var(--brand-light); color: var(--brand); flex-shrink: 0; }
.rule__icon svg { width: 20px; height: 20px; }
.rule__body { flex: 1; min-width: 0; }
.rule__title { font-weight: var(--fw-bold); font-size: var(--fs-md); }
.rule__meta { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: 2px; }
.rule__side { display: flex; align-items: center; gap: var(--space-4); flex-shrink: 0; }
.channel-pill { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; font-weight: var(--fw-bold); padding: 3px 10px; border-radius: var(--radius-pill); }
.channel-pill--email { background: var(--brand-light); color: var(--brand); }
.channel-pill--sms { background: var(--accent-light); color: color-mix(in srgb, var(--accent) 80%, black); }

/* --- Segmented control + chips (messaging) --------------------------------- */
.seg-toggle { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg-toggle button { padding: var(--space-2) var(--space-5); border: 0; background: var(--surface); cursor: pointer; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary); }
.seg-toggle button.is-active { background: var(--brand); color: var(--brand-contrast); }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip { padding: 7px 15px; border-radius: var(--radius-pill); border: 1px solid var(--border-strong); background: var(--surface); font-size: var(--fs-sm); cursor: pointer; transition: background .12s, border-color .12s; }
.chip:hover { border-color: var(--brand); }
.chip.is-selected { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }
.composer-preview { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); }
.composer-preview__meta { font-size: var(--fs-sm); color: var(--text-secondary); margin-bottom: var(--space-2); }
.recipient-count { font-weight: var(--fw-bold); color: var(--brand); }

/* Section intro row with a demo tag on the right */
.screen-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5); }

/* ============================================================================
   FORM REFINEMENTS  (auto-ID, green section headers, table search/filter)
   ============================================================================ */

/* Auto-generated read-only value (e.g. Transaction ID) */
.input-readonly {
  width: 100%; padding: var(--space-3);
  font-family: var(--font-mono); font-size: var(--fs-sm);
  color: var(--text-secondary); background: var(--surface-2);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}

/* Green header bar on every top-level card section — matches the Applicant bar */
.section.card > .section__head {
  background: var(--brand-light);
  margin: calc(-1 * var(--space-5)) calc(-1 * var(--space-5)) var(--space-5);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* Table search + filter toolbar */
.toolbar { display: flex; gap: var(--space-3); align-items: center; margin-bottom: var(--space-4); flex-wrap: wrap; }
.toolbar__search { position: relative; flex: 1; min-width: 220px; }
.toolbar__search .input { padding-left: 38px; }
.toolbar__search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.toolbar .select { width: auto; min-width: 160px; }
.toolbar__count { font-size: var(--fs-sm); color: var(--text-muted); margin-left: auto; }
