/* Admin shell theme: Inter, Dellrains colors, sidebar, phone tab bar, page headers and tables.
   Every rule sits under .app-shell, which application.html.erb puts on <body> only for a signed-in user.
   The customer area (.ca-page, its own layout) and the sign-in pages (.auth-main) never get that class.
   Tokens map onto Tabler's CSS variables so stock Tabler and DataTables components pick them up.
   Tabler declares some variables on :root from other variables (body font, link color, focus ring),
   so those are declared again here; redefining only the source variable would not reach them. */

/* Inter, self-hosted from app/assets/fonts (SIL OFL 1.1, see Inter-OFL.txt there).
   One variable font file per script covers weights 100 to 900. The family has its own name so it
   applies only where .app-shell (or .ca-page, in customer_area.css) asks for it: Tabler's default
   stack already lists "Inter". */
@font-face {
  font-family: 'Dellrains Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/assets/inter-latin-ext-a4181629.woff2") format('woff2');
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Dellrains Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/assets/inter-latin-5e6b0c47.woff2") format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* START: Tokens */
.app-shell {
  --lr-ink: #0F1D33;
  --lr-navy: #003479;
  --lr-navy-hover: #002557;
  --lr-navy-soft: #E8EEF7;
  --lr-teal: #00737A;
  /* Decoration only (rules, dots, illustrations). Too light for text on white. */
  --lr-brand-teal: #00a3ab;
  --lr-ground: #F4F6FA;
  --lr-line: #E2E7F0;
  --lr-muted: #56637A;
  --lr-danger: #B42318;
  --lr-warning-bg: #FFF4E5;
  --lr-warning-text: #8A4B00;
  --lr-success: #0F7B4B;
  --lr-success-bg: #E6F4EC;
  --lr-radius-card: 12px;
  --lr-radius-control: 10px;
  --lr-tap: 44px;

  --tblr-font-sans-serif: 'Dellrains Inter', Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --tblr-body-font-family: var(--tblr-font-sans-serif);

  --tblr-primary: var(--lr-navy);
  --tblr-primary-rgb: 0, 52, 121;
  --tblr-primary-fg: #ffffff;
  --tblr-primary-darken: var(--lr-navy-hover);
  --tblr-primary-lt: var(--lr-navy-soft);
  --tblr-primary-text-emphasis: var(--lr-navy-hover);
  --tblr-primary-bg-subtle: var(--lr-navy-soft);
  --tblr-primary-border-subtle: #B9C8E0;

  --tblr-body-color: var(--lr-ink);
  --tblr-body-color-rgb: 15, 29, 51;
  --tblr-body-bg: var(--lr-ground);
  --tblr-body-bg-rgb: 244, 246, 250;
  --tblr-emphasis-color: var(--lr-ink);
  --tblr-emphasis-color-rgb: 15, 29, 51;

  --tblr-secondary: var(--lr-muted);
  --tblr-secondary-rgb: 86, 99, 122;
  --tblr-secondary-color: var(--lr-muted);
  --tblr-secondary-color-rgb: 86, 99, 122;
  --tblr-muted: var(--lr-muted);
  --tblr-muted-rgb: 86, 99, 122;

  --tblr-border-color: var(--lr-line);
  --tblr-border-color-translucent: var(--lr-line);
  --tblr-border-radius: var(--lr-radius-control);
  --tblr-border-radius-lg: var(--lr-radius-card);

  --tblr-link-color: var(--lr-navy);
  --tblr-link-color-rgb: 0, 52, 121;
  --tblr-link-hover-color: var(--lr-navy-hover);
  --tblr-link-hover-color-rgb: 0, 37, 87;
  --tblr-focus-ring-color: rgba(0, 52, 121, 0.25);

  --tblr-danger: var(--lr-danger);
  --tblr-danger-rgb: 180, 35, 24;
  --tblr-danger-text-emphasis: var(--lr-danger);
  --tblr-danger-bg-subtle: #FDECEA;
  --tblr-success: var(--lr-success);
  --tblr-success-rgb: 15, 123, 75;
  --tblr-success-text-emphasis: var(--lr-success);
  --tblr-success-bg-subtle: var(--lr-success-bg);
  /* --tblr-warning stays Tabler's orange for fills; text and soft backgrounds use the darker pair. */
  --tblr-warning-text-emphasis: var(--lr-warning-text);
  --tblr-warning-bg-subtle: var(--lr-warning-bg);
  --tblr-form-invalid-border-color: var(--lr-danger);
  --tblr-form-valid-border-color: var(--lr-success);

  font-feature-settings: 'cv11';
}

.app-shell .num {
  font-variant-numeric: tabular-nums;
}

/* Orange text on white fails contrast; the warning text color passes. */
.app-shell .text-warning {
  color: var(--lr-warning-text) !important;
}
/* END: Tokens */

/* START: Cards, buttons, form controls */
.app-shell .card {
  --tblr-card-bg: #ffffff;
  --tblr-card-border-color: var(--lr-line);
  --tblr-card-box-shadow: none;
  border-radius: var(--lr-radius-card);
}

.app-shell .btn {
  min-height: var(--lr-tap);
}

.app-shell .btn-primary {
  --tblr-btn-hover-bg: var(--lr-navy-hover);
  --tblr-btn-active-bg: var(--lr-navy-hover);
}

.app-shell .form-control,
.app-shell .form-select {
  min-height: var(--lr-tap);
}

/* Desktop pointers: the small sizes stay small. Touch screens below lg keep 44px everywhere. */
@media (min-width: 992px) {
  .app-shell .btn-sm,
  .app-shell .form-control-sm,
  .app-shell .form-select-sm {
    min-height: 0;
  }
}
/* END: Cards, buttons, form controls */

/* START: Page header and tables */
.app-shell .page-title {
  font-size: 1.375rem;
  line-height: 1.3;
  font-weight: 600;
  color: var(--lr-ink);
}

@media (min-width: 992px) {
  .app-shell .page-title {
    font-size: 1.5rem;
  }
}

.app-shell .page-pretitle,
.app-shell .page-subtitle {
  color: var(--lr-muted);
}

.app-shell .table {
  --tblr-table-border-color: var(--lr-line);
}

.app-shell .table thead th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  color: var(--lr-muted);
}

/* Height on a cell works as a minimum, so about 52px per row with a 1px line between rows. */
.app-shell .table > tbody > tr > td,
.app-shell .table > tbody > tr > th {
  height: 52px;
  vertical-align: middle;
  border-bottom-color: var(--lr-line);
}
/* END: Page header and tables */

/* START: Sidebar (shared/_sidebar.html.erb), lg and up */
@media (min-width: 992px) {
  .app-shell .app-sidebar {
    --tblr-navbar-bg: #ffffff;
    --tblr-navbar-border-color: var(--lr-line);
    background: #ffffff;
    box-shadow: inset -1px 0 0 0 var(--lr-line);
    color: var(--lr-ink);
  }

  .app-shell .app-sidebar .navbar-brand {
    color: var(--lr-ink);
    font-weight: 600;
    font-size: 1rem;
  }

  .app-shell .app-sidebar .navbar-collapse .navbar-nav {
    gap: 2px;
    padding-inline: 0.75rem;
  }

  .app-shell .app-sidebar .navbar-collapse .navbar-nav .nav-link,
  .app-shell .app-sidebar .navbar-collapse .dropdown-menu .dropdown-item {
    min-height: var(--lr-tap);
    align-items: center;
    border-radius: var(--lr-radius-control);
    color: var(--lr-ink);
    font-size: 0.875rem;
  }

  .app-shell .app-sidebar .navbar-collapse .navbar-nav .nav-link {
    padding: 0 0.75rem;
  }

  .app-shell .app-sidebar .navbar-collapse .dropdown-menu .dropdown-item {
    padding: 0 0.75rem 0 2.75rem;
  }

  .app-shell .app-sidebar .nav-link-icon {
    color: var(--lr-muted);
  }

  .app-shell .app-sidebar .navbar-collapse .navbar-nav .nav-link:hover,
  .app-shell .app-sidebar .navbar-collapse .dropdown-menu .dropdown-item:hover {
    background: var(--lr-ground);
    color: var(--lr-ink);
  }

  /* Active section: soft navy fill instead of Tabler's 3px edge line. */
  .app-shell .app-sidebar .navbar-collapse .nav-item.active::after {
    display: none;
  }

  .app-shell .app-sidebar .navbar-collapse .nav-item.active > .nav-link,
  .app-shell .app-sidebar .navbar-collapse .nav-link[aria-current="page"],
  .app-shell .app-sidebar .navbar-collapse .dropdown-menu .dropdown-item.active {
    background: var(--lr-navy-soft);
    color: var(--lr-navy);
    font-weight: 600;
  }

  .app-shell .app-sidebar .navbar-collapse .nav-item.active > .nav-link .nav-link-icon,
  .app-shell .app-sidebar .navbar-collapse .nav-link[aria-current="page"] .nav-link-icon {
    color: var(--lr-navy);
  }

  .app-shell .app-sidebar .navbar-collapse .nav-link:focus-visible,
  .app-shell .app-sidebar .navbar-collapse .dropdown-item:focus-visible {
    outline: 2px solid var(--lr-navy);
    outline-offset: -2px;
  }

  .app-shell .app-sidebar .badge {
    margin-left: auto !important;
  }
}
/* Tabler pins navbar badges to the corner; keep the count inline at the end of the row. */
.app-shell .app-sidebar .nav-link .badge {
  position: static;
  transform: none;
  margin-left: auto !important;
}
/* END: Sidebar */

/* START: Phone tab bar (shared/_tab_bar.html.erb), below lg */
.app-tab-bar {
  display: none;
}

@media (max-width: 991.98px) {
  .app-shell {
    --lr-tab-bar-height: 4rem;
    --lr-tab-bar-space: calc(var(--lr-tab-bar-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: var(--lr-tab-bar-space);
  }

  .app-shell .app-tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    display: flex;
    height: var(--lr-tab-bar-space);
    padding: 0 4px env(safe-area-inset-bottom, 0px);
    background: #ffffff;
    border-top: 1px solid var(--lr-line);
  }

  .app-shell .app-tab {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    min-height: var(--lr-tap);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--lr-muted);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }

  .app-shell .app-tab:hover {
    color: var(--lr-ink);
    text-decoration: none;
  }

  .app-shell .app-tab.active,
  .app-shell .app-tab[aria-expanded="true"] {
    color: var(--lr-navy);
    font-weight: 600;
  }

  .app-shell .app-tab:focus-visible {
    outline: 2px solid var(--lr-navy);
    outline-offset: -4px;
    border-radius: var(--lr-radius-control);
  }

  .app-shell .app-tab-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-shell .app-tab-badge {
    position: absolute;
    top: 6px;
    left: calc(50% + 4px);
    min-width: 18px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--lr-danger);
    color: #ffffff;
    font-size: 0.625rem;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
  }

  /* "More" opens the sidebar's own menu (#sidebar-menu) as a sheet just above the tab bar. */
  .app-shell .app-sidebar #sidebar-menu {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--lr-tab-bar-space);
    z-index: 1029;
    max-height: calc(100vh - var(--lr-tab-bar-space) - 4rem);
    max-height: calc(100dvh - var(--lr-tab-bar-space) - 4rem);
    overflow-y: auto;
    background: #ffffff;
    border-top: 1px solid var(--lr-line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgba(15, 29, 51, 0.12);
  }

  .app-shell .app-sidebar #sidebar-menu.collapsing {
    overflow: hidden;
  }

  .app-shell .app-sidebar #sidebar-menu .navbar-nav {
    padding: 0.5rem 0.75rem;
  }

  .app-shell .app-sidebar #sidebar-menu .nav-link,
  .app-shell .app-sidebar #sidebar-menu .dropdown-item {
    min-height: 48px;
    display: flex;
    align-items: center;
    border-radius: var(--lr-radius-control);
    color: var(--lr-ink);
  }

  .app-shell .app-sidebar #sidebar-menu .nav-item.active > .nav-link,
  .app-shell .app-sidebar #sidebar-menu .dropdown-item.active {
    background: var(--lr-navy-soft);
    color: var(--lr-navy);
    font-weight: 600;
  }

  .app-shell .app-sidebar #sidebar-menu .nav-item.active::after {
    display: none;
  }

  /* The AI chat button sits above the tab bar instead of on top of it. */
  .app-shell .ai-chat-widget {
    bottom: calc(var(--lr-tab-bar-space) + 0.75rem);
  }

  /* Hide the AI chat button while the More sheet is open, so it does not cover menu rows. */
  .app-shell:has(#sidebar-menu.show, #sidebar-menu.collapsing) .ai-chat-widget {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell .app-sidebar #sidebar-menu.collapsing {
    transition: none;
  }
}
/* END: Phone tab bar */

/* START: Loan status badge (shared/_loan_status_badge.html.erb, LoanStatus) */
.app-shell .lr-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.app-shell .lr-status svg {
  flex-shrink: 0;
}

.app-shell .lr-status--late {
  background: var(--tblr-danger-bg-subtle);
  color: var(--lr-danger);
}

.app-shell .lr-status--waiting {
  background: var(--lr-warning-bg);
  color: var(--lr-warning-text);
}

.app-shell .lr-status--on_track {
  background: var(--lr-success-bg);
  color: var(--lr-success);
}
/* END: Loan status badge */

/* START: Shared page parts for the customer and loan screens */
.app-shell .lr-back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  min-height: var(--lr-tap);
  margin-bottom: 0.75rem;
  padding: 0 14px 0 8px;
  border: 1px solid var(--lr-line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--lr-ink);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
}

.app-shell .lr-back-link svg {
  flex-shrink: 0;
  color: var(--lr-muted);
}

.app-shell .lr-back-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell .lr-back-link:hover {
  border-color: var(--lr-navy);
  color: var(--lr-navy);
}

.app-shell .lr-back-link:hover svg {
  color: var(--lr-navy);
}

/* Borderless version for a screen whose top must stay short. */
.app-shell .lr-back-link--plain {
  min-height: 36px;
  margin-bottom: 0.25rem;
  margin-left: -6px;
  padding: 0 10px 0 6px;
  border-color: transparent;
  background: transparent;
  color: var(--lr-navy);
}

/* A plain back link sits close to the content below it. */
.app-shell .page-header:has(.lr-back-link--plain) {
  margin-top: 12px;
}

.app-shell .page-header:has(.lr-back-link--plain) + .page-body {
  margin-top: 8px;
}

.app-shell .lr-back-link--plain svg {
  color: currentColor;
}

.app-shell .lr-back-link--plain:hover {
  border-color: transparent;
  background: var(--lr-navy-soft);
}

.app-shell .lr-back-link:focus-visible {
  outline: 2px solid var(--lr-navy);
  outline-offset: 2px;
}

.app-shell .lr-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.app-shell .lr-stack-sm {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.app-shell .lr-section-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
}

.app-shell .lr-card-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.app-shell .lr-meta {
  font-size: 0.8125rem;
  color: var(--lr-muted);
}

.app-shell .lr-amount {
  font-size: 1.375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.app-shell .lr-amount-lg {
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.app-shell .lr-progress {
  height: 8px;
  background: var(--lr-navy-soft);
  border-radius: 4px;
}

.app-shell .lr-progress .progress-bar {
  background: var(--lr-teal);
  border-radius: 4px;
}

/* Secondary button for a waiting online payment: warning colors, text says what to do. */
.app-shell .lr-btn-attention {
  --tblr-btn-color: var(--lr-warning-text);
  --tblr-btn-bg: var(--lr-warning-bg);
  --tblr-btn-border-color: #F3D9B1;
  --tblr-btn-hover-color: var(--lr-warning-text);
  --tblr-btn-hover-bg: #FDE9CC;
  --tblr-btn-hover-border-color: #E9C48C;
  font-weight: 600;
}

.app-shell .min-w-0 {
  min-width: 0;
}

/* Fixed main action on phones, just above the tab bar. Desktop shows the same action in the page header. */
.app-shell .lr-action-bar {
  display: none;
}

@media (max-width: 991.98px) {
  .app-shell .lr-page-with-action-bar {
    padding-bottom: calc(var(--lr-tap) + 2rem);
  }

  .app-shell .lr-action-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--lr-tab-bar-space);
    z-index: 1020;
    display: block;
    padding: 0.625rem 1rem;
    background: #ffffff;
    border-top: 1px solid var(--lr-line);
  }

  /* The AI chat button moves up so it does not cover the fixed action. */
  .app-shell:has(.lr-action-bar) .ai-chat-widget {
    bottom: calc(var(--lr-tab-bar-space) + var(--lr-tap) + 2rem);
  }
}
/* END: Shared page parts */

/* START: Customers list (customers/index.html.erb, CustomerDecorator) */
.app-shell .lr-cust-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.app-shell .lr-cust-link {
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.app-shell .lr-cust-link:hover {
  text-decoration: underline;
}

.app-shell .lr-cust-id {
  font-size: 0.8125rem;
}

.app-shell .lr-cust-phone-only,
.app-shell .lr-cust-ongoing-inline {
  display: none;
}

/* 992 to 1024px: the Ongoing loans column is hidden ("desktop" class), so the name cell shows the count. */
@media (min-width: 992px) and (max-width: 1024px) {
  .app-shell #customer-and-loans-table .lr-cust-ongoing-inline {
    display: block;
  }
}

/* Below lg each row is a card: name and status on top, Customer ID, then the loan line.
   The other cells hide; the name link stretches over the whole card, the Pay button sits above it. */
@media (max-width: 991.98px) {
  .app-shell #customer-and-loans-table thead {
    display: none;
  }

  .app-shell #customer-and-loans-table,
  .app-shell #customer-and-loans-table tbody {
    display: block;
    width: 100% !important;
  }

  .app-shell #customer-and-loans-table > tbody > tr {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    min-height: var(--lr-tap);
    padding: 14px 16px;
    border-bottom: 1px solid var(--lr-line);
  }

  .app-shell #customer-and-loans-table > tbody > tr > td {
    display: none !important;
    height: auto;
    padding: 0;
    border: 0;
    white-space: normal;
  }

  .app-shell #customer-and-loans-table > tbody > tr > td.lr-col-name,
  .app-shell #customer-and-loans-table > tbody > tr > td.dt-empty {
    display: block !important;
    flex: 1 1 14rem;
    min-width: 0;
  }

  .app-shell #customer-and-loans-table > tbody > tr > td.lr-col-actions:not(:empty) {
    display: block !important;
    position: relative;
    z-index: 1;
  }

  .app-shell #customer-and-loans-table .lr-cust-phone-only {
    display: block;
  }

  .app-shell #customer-and-loans-table .lr-cust-link {
    font-size: 0.9375rem;
    color: var(--lr-ink);
  }

  .app-shell #customer-and-loans-table .lr-cust-link::after {
    content: '';
    position: absolute;
    inset: 0;
  }

  .app-shell #customer-and-loans-table .lr-cust-link:focus-visible {
    outline: none;
  }

  .app-shell #customer-and-loans-table .lr-cust-link:focus-visible::after {
    outline: 2px solid var(--lr-navy);
    outline-offset: -2px;
  }

  .app-shell #customer-and-loans-table .lr-cust-meta {
    margin-top: 4px;
    font-size: 0.8125rem;
    color: var(--lr-ink);
  }

  .app-shell #customer-and-loans-table .lr-cust-pay {
    min-width: 5.5rem;
  }
}
/* END: Customers list */

/* START: Customer's loans (loans/index.html.erb, loans/_ongoing_loans.html.erb) */
.app-shell .lr-customer-head {
  overflow: hidden;
}

.app-shell .lr-customer-head-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 8px 14px 16px;
}

.app-shell .lr-avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  background: var(--lr-navy-soft);
  color: var(--lr-navy);
  font-weight: 700;
}

.app-shell .lr-customer-name-block {
  flex: 1 1 auto;
  min-width: 0;
}

.app-shell .lr-customer-name {
  margin: 0;
  overflow: hidden;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell .lr-customer-meta {
  margin-top: 2px;
  font-size: 0.8125rem;
  color: var(--lr-muted);
}

.app-shell .lr-customer-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}

.app-shell .lr-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--lr-tap);
  height: var(--lr-tap);
  padding: 0;
  border: 0;
  border-radius: var(--lr-radius-control);
  background: transparent;
  box-shadow: none;
  color: var(--lr-muted);
}

.app-shell .lr-icon-btn:hover,
.app-shell .lr-icon-btn[aria-expanded="true"] {
  background: var(--lr-ground);
  color: var(--lr-ink);
}

.app-shell .lr-contact-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 16px 14px;
}

.app-shell .lr-contact-buttons .btn {
  color: var(--lr-navy);
  font-weight: 600;
}

/* Balance, ongoing and completed: three columns under a line. */
.app-shell .lr-customer-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--lr-line);
}

.app-shell .lr-customer-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 12px 16px;
  color: var(--lr-ink);
}

.app-shell .lr-customer-stat + .lr-customer-stat {
  border-left: 1px solid var(--lr-line);
}

.app-shell .lr-customer-stat-label {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--lr-muted);
}

.app-shell .lr-customer-stat-value {
  overflow: hidden;
  font-size: 1.0625rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell .lr-customer-stat-link {
  text-decoration: none;
}

.app-shell .lr-customer-stat-link .lr-customer-stat-value {
  color: var(--lr-navy);
}

.app-shell .lr-customer-stat-link:hover {
  background: var(--lr-ground);
  text-decoration: none;
}

@media (min-width: 992px) {
  .app-shell .lr-customer-head-row { padding: 18px 20px; gap: 16px; }
  .app-shell .lr-avatar { width: 56px; height: 56px; font-size: 1.125rem; }
  .app-shell .lr-customer-name { font-size: 1.375rem; }
  .app-shell .lr-customer-stat { padding: 14px 20px; }
  .app-shell .lr-customer-stat-label { font-size: 0.8125rem; }
  .app-shell .lr-customer-stat-value { font-size: 1.375rem; }
}

.app-shell .lr-loan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
  gap: 16px;
}

.app-shell .lr-loan-card .card-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Wraps so a long status badge drops under the title on a narrow card instead of running off its edge. */
.app-shell .lr-loan-card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px 12px;
}

.app-shell .lr-loan-card-top > .min-w-0 {
  flex: 1 1 12rem;
}

.app-shell .lr-loan-thumb {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--lr-line);
}

.app-shell .lr-loan-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-shell .lr-loan-title {
  margin: 0 0 2px;
  font-size: 1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.app-shell .lr-balance-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.app-shell .lr-loan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Phones: Record payment on its own row, the other buttons two per row, text wraps instead of clipping.
   dense lets More fill the gap next to Payments & photos when Review online payment takes a full row. */
@media (max-width: 991.98px) {
  .app-shell .lr-loan-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row dense;
  }

  .app-shell .lr-loan-actions .btn {
    width: 100%;
    white-space: normal;
    line-height: 1.25;
  }

  .app-shell .lr-loan-actions-main,
  .app-shell .lr-loan-actions .lr-btn-attention {
    grid-column: 1 / -1;
  }
}
/* END: Customer's loans */

/* START: Loan detail (loans/show.html.erb) */
.app-shell .lr-detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 16px;
  margin-top: 4px;
}

.app-shell .lr-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: 16px;
  align-items: start;
}

.app-shell .lr-dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 16px;
  margin: 0;
}

.app-shell .lr-dl dt {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--lr-muted);
}

.app-shell .lr-dl dd {
  margin: 0 0 12px;
  font-size: 0.875rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.app-shell .lr-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.app-shell .lr-thumb {
  display: block;
  width: 140px;
  height: 104px;
  border: 1px solid var(--lr-line);
  border-radius: var(--lr-radius-control);
  overflow: hidden;
  background: var(--lr-navy-soft);
}

.app-shell .lr-thumb-wide {
  width: 200px;
  background: #ffffff;
}

.app-shell .lr-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-shell .lr-thumb-wide img {
  object-fit: contain;
}

.app-shell .lr-thumb:focus-visible {
  outline: 2px solid var(--lr-navy);
  outline-offset: 2px;
}

@media (max-width: 575.98px) {
  .app-shell .lr-thumb {
    width: 96px;
    height: 72px;
  }

  .app-shell .lr-thumb-wide {
    width: 120px;
  }
}
/* END: Loan detail */

/* START: Forms (loans/new, additional_loans/new, payments/new, the loan detail edit card) */
/* 48px inputs with the label above. 16px text on phones so iOS does not zoom into a field. */
.app-shell .lr-form .form-label {
  margin-bottom: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--lr-ink);
}

.app-shell .lr-form .form-control,
.app-shell .lr-form .form-select {
  min-height: 48px;
  border-color: #CBD3E1;
  border-radius: var(--lr-radius-control);
}

.app-shell .lr-form textarea.form-control {
  min-height: 0;
}

.app-shell .lr-form .input-group-text {
  border-color: #CBD3E1;
  background: var(--lr-ground);
  color: var(--lr-muted);
}

.app-shell .lr-form .form-control.is-invalid,
.app-shell .lr-form .form-select.is-invalid {
  border-color: var(--lr-danger);
}

.app-shell .lr-form .invalid-feedback {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--lr-danger);
}

.app-shell .lr-form .form-hint,
.app-shell .lr-hint {
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--lr-muted);
}

@media (max-width: 991.98px) {
  .app-shell .lr-form .form-control,
  .app-shell .lr-form .form-select {
    font-size: 1rem;
  }
}

.app-shell .lr-form-narrow {
  max-width: 820px;
}

.app-shell .lr-form-section {
  padding: 20px 24px;
}

@media (max-width: 575.98px) {
  .app-shell .lr-form-section {
    padding: 16px;
  }
}

.app-shell .lr-form-section-title {
  margin: 0 0 16px;
  font-size: 1rem;
  font-weight: 600;
}

.app-shell .lr-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: 16px;
}

/* Form buttons: in the page flow on desktop, fixed just above the tab bar on phones.
   The page adds .lr-page-with-action-bar so the last field does not hide under the bar. */
.app-shell .lr-form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 991.98px) {
  .app-shell .lr-form-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--lr-tab-bar-space);
    z-index: 1020;
    padding: 0.625rem 1rem;
    background: #ffffff;
    border-top: 1px solid var(--lr-line);
  }

  .app-shell .lr-form-actions .btn {
    flex: 1 1 0;
  }

  .app-shell:has(.lr-form-actions) .ai-chat-widget {
    bottom: calc(var(--lr-tab-bar-space) + var(--lr-tap) + 2rem);
  }
}

/* Record payment: loan summary, big amount, quick amounts, method cards, balance after. */
.app-shell .lr-pay-summary {
  display: flex;
  flex-direction: row; /* .card is a column flexbox in Tabler */
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.app-shell .lr-pay-summary-name {
  font-size: 0.9375rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.app-shell .lr-pay-summary-balance {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
  gap: 2px;
}

.app-shell .lr-amount-field {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 64px;
  padding: 0 16px;
  border: 2px solid var(--lr-navy);
  border-radius: var(--lr-radius-card);
  background: #ffffff;
}

.app-shell .lr-amount-field:focus-within {
  box-shadow: 0 0 0 0.25rem var(--tblr-focus-ring-color);
}

.app-shell .lr-amount-field-unit {
  font-size: 1.75rem;
  color: var(--lr-muted);
}

.app-shell .lr-form .lr-amount-field .form-control {
  flex: 1;
  min-width: 0;
  min-height: 60px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  font-size: 1.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.app-shell .lr-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.app-shell .lr-chip {
  min-height: var(--lr-tap);
  padding: 0 14px;
  border: 1px solid #CBD3E1;
  border-radius: 999px;
  background: #ffffff;
  color: var(--lr-ink);
  font-size: 0.875rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.app-shell .lr-chip:hover {
  border-color: var(--lr-navy);
}

.app-shell .lr-chip.active {
  border-color: var(--lr-navy);
  background: var(--lr-navy-soft);
  color: var(--lr-navy);
  font-weight: 600;
}

.app-shell .lr-chip:focus-visible {
  outline: 2px solid var(--lr-navy);
  outline-offset: 2px;
}

.app-shell .lr-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.app-shell .lr-fieldset legend {
  float: none;
  width: auto;
  margin-bottom: 8px;
  padding: 0;
  font-size: 0.875rem;
  font-weight: 500;
}

.app-shell .lr-radio-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr));
  gap: 8px;
}

.app-shell .lr-radio-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid #CBD3E1;
  border-radius: var(--lr-radius-control);
  background: #ffffff;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.app-shell .lr-radio-card input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--lr-navy);
}

.app-shell .lr-radio-card:has(input:checked) {
  border: 2px solid var(--lr-navy);
  padding: 0 11px;
  background: var(--lr-navy-soft);
  font-weight: 600;
}

.app-shell .lr-radio-card:has(input:focus-visible) {
  outline: 2px solid var(--lr-navy);
  outline-offset: 2px;
}

.app-shell .lr-balance-after {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--lr-radius-control);
  background: var(--lr-success-bg);
  color: var(--lr-success);
  font-size: 0.875rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.app-shell .lr-balance-after.is-over {
  background: var(--tblr-danger-bg-subtle);
  color: var(--lr-danger);
}

@media (max-width: 991.98px) {
  .app-shell .lr-pay-submit {
    min-height: 52px;
    font-size: 1rem;
  }
}
/* Phone step flow on the loan forms (loan_wizard_controller.js). Steps hide only under the phone
   query and only after the controller adds .lr-wizard--on, so desktop and no-JS keep one page. */
.app-shell .lr-wizard-phone-only {
  display: none;
}

.app-shell .lr-wizard-group {
  display: contents;
}

.app-shell .signature-canvas {
  max-width: 100%;
}

@media (max-width: 991.98px) {
  .app-shell .lr-wizard--on .lr-wizard-phone-only {
    display: block;
  }

  .app-shell .lr-wizard--on .lr-wizard-summary.lr-wizard-phone-only {
    display: flex;
  }

  .app-shell .lr-wizard--on .btn.lr-wizard-phone-only {
    display: inline-flex;
  }

  .app-shell .lr-wizard--on [hidden],
  .app-shell .lr-wizard--on .lr-wizard-desktop-only,
  .app-shell .lr-wizard--on .lr-wizard-off-step,
  .app-shell .lr-wizard--on [data-loan-wizard-target~="step"]:not(.is-current),
  .app-shell .lr-wizard--on .lr-form-section:has([data-loan-wizard-target~="step"]):not(:has(.is-current)) {
    display: none !important;
  }

  .app-shell .lr-wizard--on .space-y > [data-loan-wizard-target~="step"].is-current {
    margin-top: 0;
  }

  .app-shell .lr-wizard-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .app-shell .lr-wizard-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--lr-navy);
  }

  .app-shell .lr-wizard-progress {
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    gap: 4px;
  }

  .app-shell .lr-wizard-progress span {
    height: 4px;
    border-radius: 2px;
    background: var(--lr-line);
  }

  .app-shell .lr-wizard-progress span.is-done {
    background: var(--lr-navy);
  }

  .app-shell .lr-wizard-summary {
    flex-direction: row; /* .card is a column flexbox in Tabler */
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
  }

  .app-shell .lr-wizard-summary-label {
    font-size: 0.75rem;
    color: var(--lr-muted);
  }

  .app-shell .lr-wizard-summary-value {
    font-size: 0.9375rem;
    font-weight: 600;
    overflow-wrap: anywhere;
  }

  .app-shell .lr-wizard-summary .btn-link {
    min-height: var(--lr-tap);
    font-weight: 600;
  }

  .app-shell .lr-wizard-message {
    margin: 0;
  }

  .app-shell .lr-form-actions [data-loan-wizard-target="back"] {
    flex: 0 0 auto;
  }
}
/* END: Forms */

/* START: Dashboard (dashboards/index.html.erb and its partials) */
.app-shell .lr-dashboard-header .page-subtitle {
  margin-top: 2px;
  font-size: 0.875rem;
}

/* Online payment review alert: warning colors with readable text. */
.app-shell .lr-alert-attention {
  background: var(--lr-warning-bg);
  border: 1px solid #F3D9B1;
  border-radius: var(--lr-radius-card);
  color: var(--lr-warning-text);
}

.app-shell .lr-alert-attention strong {
  color: inherit;
}

/* AI insights panel: header, stale note, summary, key numbers, sections by urgency. */
.app-shell .ai-insights-card {
  border: 1px solid var(--lr-line);
  border-radius: var(--lr-radius-card);
  overflow: hidden;
}

.app-shell .ai-insights-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 0.875rem;
  padding: 1.125rem 1.5rem;
}

.app-shell .ai-insights-spark {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--lr-radius-control);
  background: var(--lr-navy-soft);
  color: var(--lr-navy);
}

.app-shell .ai-insights-heading {
  flex: 1 1 12rem;
  min-width: 0;
}

.app-shell .ai-insights-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--lr-ink);
}

.app-shell .ai-insights-meta {
  margin: 0.125rem 0 0;
  font-size: 0.8125rem;
  color: var(--lr-muted);
}

.app-shell .ai-insights-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-shell .ai-insights-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  border-radius: var(--lr-radius-control);
  font-weight: 500;
}

.app-shell .ai-insights-ask,
.app-shell .ai-insights-toggle {
  border: 1px solid var(--lr-line);
  background: #fff;
  color: var(--lr-ink);
}

.app-shell .ai-insights-toggle {
  width: 2.5rem;
  padding: 0;
  justify-content: center;
  color: var(--lr-muted);
}

.app-shell .ai-insights-generate {
  font-weight: 600;
}

.app-shell .ai-insights-generate:disabled {
  opacity: 0.75;
}

.app-shell .ai-insights-chevron {
  transition: transform 0.2s ease;
}

.app-shell .ai-insights-toggle[aria-expanded="false"] .ai-insights-chevron {
  transform: rotate(180deg);
}

.app-shell .ai-insights-error {
  margin: 0 1.5rem 1rem;
}

.app-shell .ai-insights-stale {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 1.5rem;
  padding: 0.625rem 0.75rem 0.625rem 0.875rem;
  border-radius: var(--lr-radius-control);
  background: var(--lr-warning-bg);
  color: var(--lr-warning-text);
  font-size: 0.875rem;
}

.app-shell .ai-insights-stale svg {
  flex-shrink: 0;
}

.app-shell .ai-insights-stale-text {
  flex: 1 1 12rem;
  min-width: 0;
}

.app-shell .ai-insights-stale strong {
  font-weight: 600;
}

.app-shell .ai-insights-headline {
  max-width: 58rem;
  margin: 0;
  padding: 1.375rem 1.5rem 0.25rem;
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--lr-ink);
  text-wrap: pretty;
}

.app-shell .ai-insights-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 1.125rem 1.5rem 1.5rem;
}

.app-shell .ai-kpi {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--lr-line);
  border-radius: var(--lr-radius-card);
}

.app-shell .ai-kpi-label {
  font-size: 0.8125rem;
  color: var(--lr-muted);
}

.app-shell .ai-kpi-value {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--lr-ink);
  font-variant-numeric: tabular-nums;
}

.app-shell .ai-kpi-bars {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0.5rem 0 0;
}

.app-shell .ai-kpi-bar {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.app-shell .ai-kpi-bar dt {
  font-weight: 400;
  color: var(--lr-muted);
}

.app-shell .ai-kpi-bar dd {
  display: grid;
  grid-template-columns: minmax(1.5rem, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.app-shell .ai-kpi-track {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: #EDF1F7;
  overflow: hidden;
}

.app-shell .ai-kpi-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
}

.app-shell .ai-kpi-fill--primary { background: var(--lr-navy); }
.app-shell .ai-kpi-fill--muted { background: #9AA8BE; }

.app-shell .ai-kpi-num {
  font-weight: 600;
  color: var(--lr-ink);
  font-variant-numeric: tabular-nums;
}

.app-shell .ai-section {
  --ai-tone: var(--lr-navy);
  --ai-tone-bg: var(--lr-navy-soft);
  --ai-dot: var(--lr-navy);
  border-top: 1px solid var(--lr-line);
}

.app-shell .ai-section--critical { --ai-tone: var(--lr-danger); --ai-tone-bg: #FDECEA; --ai-dot: var(--lr-danger); }
.app-shell .ai-section--warning { --ai-tone: var(--lr-warning-text); --ai-tone-bg: var(--lr-warning-bg); --ai-dot: #D98A00; }
.app-shell .ai-section--good { --ai-tone: var(--lr-success); --ai-tone-bg: var(--lr-success-bg); --ai-dot: var(--lr-success); }

.app-shell .ai-section-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 1.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ai-tone);
  cursor: pointer;
  list-style: none;
}

.app-shell .ai-section-head::-webkit-details-marker {
  display: none;
}

.app-shell .ai-section-head:focus-visible {
  outline: 2px solid var(--lr-navy);
  outline-offset: -2px;
}

.app-shell .ai-section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.375rem;
  border-radius: 999px;
  background: var(--ai-tone-bg);
  font-size: 0.75rem;
}

.app-shell .ai-section-show {
  margin-left: auto;
  font-weight: 500;
  color: var(--lr-muted);
}

.app-shell .ai-section-chevron {
  color: var(--lr-muted);
  transition: transform 0.2s ease;
}

.app-shell .ai-section[open] .ai-section-show {
  visibility: hidden;
}

.app-shell .ai-section[open] .ai-section-chevron {
  transform: rotate(180deg);
}

.app-shell .ai-section-list {
  margin: 0;
  padding: 0 0 0.375rem;
  list-style: none;
}

.app-shell .ai-insight-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
}

.app-shell .ai-insight-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ai-dot);
}

.app-shell .ai-insight-text {
  flex: 1 1 auto;
  min-width: 0;
}

.app-shell .ai-insight-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--lr-ink);
}

.app-shell .ai-insight-why {
  margin: 0.125rem 0 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--lr-muted);
}

.app-shell .ai-insight-cta {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.25rem;
  min-height: 2.5rem;
  padding: 0 0.75rem 0 0.875rem;
  border: 1px solid #C9D5E8;
  border-radius: var(--lr-radius-control);
  background: #fff;
  color: var(--lr-navy);
  font-size: 0.875rem;
  font-weight: 600;
}

.app-shell .ai-insight-cta:hover {
  background: var(--lr-navy-soft);
  color: var(--lr-navy-hover);
}

.app-shell .ai-insights-foot {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--lr-line);
  background: #F8FAFC;
  font-size: 0.8125rem;
  color: var(--lr-muted);
}

.app-shell .ai-insights-foot-note {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.app-shell .ai-insights-sources {
  margin-top: 0.5rem;
}

.app-shell .ai-insights-sources summary {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
  color: var(--lr-navy);
  font-weight: 500;
  cursor: pointer;
}

.app-shell .ai-insights-sources dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.375rem 2rem;
  margin: 0.25rem 0 0.5rem;
}

.app-shell .ai-insights-sources dl > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.app-shell .ai-insights-sources dt {
  font-weight: 400;
}

.app-shell .ai-insights-sources dd {
  margin: 0;
  font-weight: 600;
  color: var(--lr-ink);
  font-variant-numeric: tabular-nums;
}

.app-shell .ai-insights-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0 1.5rem 1.5rem;
}

.app-shell .ai-insights-empty-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--lr-ink);
}

.app-shell .ai-insights-empty-text {
  margin: 0;
  color: var(--lr-muted);
}

@media (max-width: 1199.98px) {
  .app-shell .ai-insights-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Phone: icon-only Ask, cards for each insight with a full-width button. */
@media (max-width: 767.98px) {
  /* Header: icon, title and collapse button on row one; Ask and Refresh share row two. */
  .app-shell .ai-insights-header { gap: 0.75rem; padding: 1rem; }
  .app-shell .ai-insights-actions { display: contents; }
  .app-shell .ai-insights-heading { flex: 1 1 calc(100% - 2.5rem - 2.75rem - 1.5rem); order: 1; }
  .app-shell .ai-insights-toggle { order: 2; width: 2.75rem; }
  .app-shell .ai-insights-ask,
  .app-shell .ai-insights-generate { order: 3; flex: 1 1 calc(50% - 0.375rem); justify-content: center; }
  .app-shell .ai-insights-btn { min-height: 2.75rem; }
  .app-shell .ai-insights-stale { margin: 0 1rem; }
  .app-shell .ai-insights-headline { padding: 1rem 1rem 0; font-size: 1.0625rem; }
  .app-shell .ai-insights-kpis { gap: 0.625rem; padding: 1rem; }
  .app-shell .ai-kpi { padding: 0.75rem; }
  .app-shell .ai-kpi-value { font-size: 1.25rem; }
  .app-shell .ai-kpi-bar { grid-template-columns: minmax(0, 1fr); gap: 0.125rem; }
  .app-shell .ai-section-head { padding: 0.5rem 1rem; font-size: 0.875rem; }
  .app-shell .ai-section-list { display: flex; flex-direction: column; gap: 0.5rem; padding: 0 1rem 1rem; }
  .app-shell .ai-insight-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.875rem;
    border: 1px solid var(--lr-line);
    border-radius: var(--lr-radius-card);
  }
  .app-shell .ai-insight-dot { display: none; }
  .app-shell .ai-insight-cta { justify-content: center; min-height: 2.75rem; }
  .app-shell .ai-insights-foot { padding: 0.75rem 1rem; }
  .app-shell .ai-insights-sources dl { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell .ai-insights-chevron,
  .app-shell .ai-section-chevron { transition: none; }
}

.app-shell .lr-dashboard-list .card-header {
  border-bottom-color: var(--lr-line);
}

/* Trends: section title and the filter row above the charts. */
/* Show/hide button for a dashboard section (Key Metrics). */
.app-shell .lr-collapse-toggle {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: var(--lr-tap);
  height: var(--lr-tap);
  padding: 0;
  border: 1px solid var(--lr-line);
  border-radius: var(--lr-radius-control);
  background: #ffffff;
  color: var(--lr-muted);
}

.app-shell .lr-collapse-toggle:hover {
  color: var(--lr-navy);
  background: var(--lr-ground);
}

.app-shell .lr-collapse-chevron {
  margin: 0;
  transition: transform 0.2s ease;
}

.app-shell .lr-collapse-toggle[aria-expanded="false"] .lr-collapse-chevron {
  transform: rotate(180deg);
}

.app-shell .lr-trends-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 1rem;
}

.app-shell .lr-chart-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.app-shell .lr-segmented {
  display: flex;
  flex-shrink: 0;
  gap: 2px;
  padding: 3px;
  background: #ffffff;
  border: 1px solid var(--lr-line);
  border-radius: var(--lr-radius-control);
}

.app-shell .lr-segment {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--lr-muted);
  text-decoration: none;
  white-space: nowrap;
}

.app-shell .lr-segment:hover {
  color: var(--lr-navy);
  background: var(--lr-ground);
}

.app-shell .lr-segment.is-active {
  background: var(--lr-navy-soft);
  color: var(--lr-navy);
  font-weight: 600;
}

.app-shell .lr-segment:focus-visible {
  outline: 2px solid var(--lr-navy);
  outline-offset: 1px;
}

.app-shell .lr-collector-filter {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
  margin: 0;
}

.app-shell .lr-filter-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--lr-tap);
  padding-left: 12px;
  background: #ffffff;
  border: 1px solid var(--lr-line);
  border-radius: var(--lr-radius-control);
}

.app-shell .lr-filter-label {
  font-size: 0.8125rem;
  color: var(--lr-muted);
  white-space: nowrap;
}

.app-shell .lr-filter-field .form-select {
  min-width: 10rem;
  border: 0;
  background-color: transparent;
  box-shadow: none;
}

/* Chart cards: two per row from lg, one per row below. */
.app-shell .lr-chart-card .card-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.app-shell .lr-chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.app-shell .lr-chart-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.app-shell .lr-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.75rem;
  color: var(--lr-muted);
}

.app-shell .lr-chart-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.app-shell .lr-chart-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.app-shell .lr-chart-swatch--positive { background: var(--lr-success); }
.app-shell .lr-chart-swatch--negative { background: var(--lr-danger); }

.app-shell .lr-chart-plot {
  min-width: 0;
}

.app-shell .lr-chart-details summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--lr-tap);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--lr-navy);
  cursor: pointer;
}

.app-shell .lr-chart-details summary:focus-visible {
  outline: 2px solid var(--lr-navy);
  outline-offset: 2px;
  border-radius: 4px;
}

.app-shell .lr-chart-table-wrap {
  max-height: 20rem;
  overflow-y: auto;
  border: 1px solid var(--lr-line);
  border-radius: var(--lr-radius-control);
}

.app-shell .lr-chart-table {
  margin: 0;
  caption-side: top;
}

.app-shell .lr-chart-table caption {
  padding: 8px 12px;
  font-size: 0.8125rem;
  color: var(--lr-muted);
}

.app-shell .lr-chart-table th[scope="row"] {
  font-weight: 500;
  white-space: nowrap;
}

@media (max-width: 991.98px) {
  /* The filter row scrolls sideways inside itself; the page never does. */
  .app-shell .lr-trends-head {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
  }

  /* Range on one full-width row, collector on the next, so nothing is cut off. */
  .app-shell .lr-chart-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .app-shell .lr-segment {
    flex: 1 1 0;
    justify-content: center;
  }

  .app-shell .lr-filter-field {
    flex: 1 1 auto;
  }

  .app-shell .lr-filter-field .form-select {
    flex: 1 1 auto;
    min-width: 0;
  }

  .app-shell .lr-chart-plot > div {
    height: 220px !important;
  }

  /* Room at the end of the page so the AI chat button does not cover the last card. */
  .app-shell .lr-dashboard-body {
    padding-bottom: calc(var(--ai-chat-clearance) + 0.5rem);
  }
}
/* Loans due this week (dashboards/_loans_due.html.erb). */
.app-shell .lr-due {
  overflow: hidden;
}

.app-shell .lr-due-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  padding: 12px 12px;
}

.app-shell .lr-due-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  min-height: 72px;
  padding: 8px 0;
  border: 1px solid var(--lr-line);
  border-radius: var(--lr-radius-control);
  background: #ffffff;
  color: var(--lr-ink);
  font: inherit;
  cursor: pointer;
}

.app-shell .lr-due-day:hover {
  border-color: var(--lr-navy);
}

.app-shell .lr-due-day:focus-visible {
  outline: 2px solid var(--lr-navy);
  outline-offset: 2px;
}

.app-shell .lr-due-day[aria-selected="true"] {
  border-color: var(--lr-navy);
  background: var(--lr-navy);
  color: #ffffff;
}

.app-shell .lr-due-dow {
  font-size: 0.6875rem;
  font-weight: 500;
}

.app-shell .lr-due-date {
  font-size: 1rem;
  font-weight: 600;
}

.app-shell .lr-due-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--lr-navy-soft);
  color: var(--lr-navy);
  font-size: 0.6875rem;
  font-weight: 600;
}

.app-shell .lr-due-count.is-empty {
  background: transparent;
  color: var(--lr-muted);
}

.app-shell .lr-due-day[aria-selected="true"] .lr-due-count {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.app-shell .lr-due-missed {
  margin: 0 16px 12px;
  border-radius: var(--lr-radius-control);
  background: var(--lr-danger-bg, #fdecec);
}

.app-shell .lr-due-missed summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--lr-tap);
  padding: 0 12px;
  color: var(--lr-danger, #b42318);
  font-size: 0.8125rem;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.app-shell .lr-due-missed summary::-webkit-details-marker {
  display: none;
}

.app-shell .lr-due-missed-chevron {
  transition: transform 0.2s ease;
}

.app-shell .lr-due-missed[open] .lr-due-missed-chevron {
  transform: rotate(180deg);
}

.app-shell .lr-due-missed .lr-due-list {
  border-radius: 0 0 var(--lr-radius-control) var(--lr-radius-control);
  background: #ffffff;
}

.app-shell .lr-due-heading {
  margin: 0;
  padding: 4px 16px 6px;
  color: var(--lr-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.app-shell .lr-due-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-shell .lr-due-list li {
  border-top: 1px solid var(--lr-line);
}

.app-shell .lr-due-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--lr-tap);
  border-top: 1px solid var(--lr-line);
  color: var(--lr-navy);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}

.app-shell .lr-due-more:hover {
  background: var(--lr-ground);
  text-decoration: none;
}

.app-shell .lr-due-more-left {
  color: var(--lr-muted);
  font-weight: 500;
}

.app-shell turbo-frame[busy] .lr-due-more {
  color: var(--lr-muted);
  pointer-events: none;
}

.app-shell .lr-due-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 16px;
  color: var(--lr-ink);
  text-decoration: none;
}

.app-shell .lr-due-row:hover {
  background: var(--lr-ground);
  text-decoration: none;
}

.app-shell .lr-due-tag {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.app-shell .lr-due-tag--weekly {
  background: var(--lr-navy-soft);
  color: var(--lr-navy);
}

.app-shell .lr-due-tag--monthly {
  background: var(--lr-warning-bg);
  color: var(--lr-warning-text);
}

.app-shell .lr-due-who {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
}

.app-shell .lr-due-name {
  overflow: hidden;
  font-size: 0.9375rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell .lr-due-detail {
  overflow: hidden;
  margin-top: 2px;
  color: var(--lr-muted);
  font-size: 0.8125rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell .lr-due-amount {
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.9375rem;
  font-weight: 600;
}

.app-shell .lr-due-status {
  margin-top: 2px;
  font-size: 0.75rem;
  font-weight: 600;
}

.app-shell .lr-due-status--due { color: var(--lr-warning-text); }
.app-shell .lr-due-status--paid { color: var(--lr-success); }
.app-shell .lr-due-status--upcoming { color: var(--lr-muted); }
.app-shell .lr-due-status--missed { color: var(--lr-danger, #b42318); }

.app-shell .lr-due-empty {
  margin: 0;
  padding: 16px;
  border-top: 1px solid var(--lr-line);
  color: var(--lr-muted);
  font-size: 0.875rem;
}

/* END: Dashboard */
