/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f5f5f5;
  padding: 0;
  margin: 0;
  /* A column, so the footer stays at the bottom of the screen on short pages */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

/* Footer */
.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1.5rem;
  width: 100%;
  max-width: 1200px;
  margin: auto auto 0;
  padding: 1.25rem 1rem 1.5rem;
  border-top: 1px solid #e4e4e4;
  color: #888;
  font-size: 0.85rem;
  text-align: center;
}

.site-footer a {
  color: #5a67d8;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* Header */
.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

/* Logo plus the signed-in family's name */
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}

/* The family badge links to My Families. ".header .family-name" outranks the
   generic ".header a" rules (background: none, full width on mobile). */
.header .family-name {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 0.2rem 0.85rem;
  font-size: 0.875rem;
  font-weight: 500;
  width: auto;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header .family-name::after {
  content: " \25BE";
  opacity: 0.8;
}

.header .family-name:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* The title doubles as the link to the dashboard */
.header h1 a {
  padding: 0;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-logo {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: white;
  box-shadow: 0 2px 8px rgba(40, 20, 90, 0.25);
}

.brand-logo img {
  display: block;
}

.header h1 a:hover {
  background-color: transparent;
  opacity: 0.85;
}

.header nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.button_to {
  display: inline;
}

.header a,
.header .nav-button {
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  color: white;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.header a:hover,
.header .nav-button:hover {
  background-color: rgba(255,255,255,0.2);
}

/* The section you're in */
.header nav a.nav-active {
  background-color: rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  font-weight: 600;
}

/* Phones only, and only once application.js has set it up */
.nav-toggle {
  display: none;
}

/* Links on the left of the avatar */
.header nav {
  margin-left: auto;
}

/* A person's initials in a coloured circle */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  user-select: none;
}

.avatar-large {
  width: 40px;
  height: 40px;
  font-size: 0.95rem;
}

.avatar-xl {
  width: 72px;
  height: 72px;
  font-size: 1.6rem;
}

/* The account menu opened from the avatar */
.user-menu {
  position: relative;
}

.user-menu-button {
  display: block;
  list-style: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.55);
}

.user-menu-button::-webkit-details-marker {
  display: none;
}

.user-menu-button:hover,
.user-menu[open] .user-menu-button {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9);
}

.user-menu-button:focus-visible {
  outline: 2px solid white;
  outline-offset: 3px;
}

.user-menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 1000;
  width: min(270px, calc(100vw - 32px));
  padding: 0.35rem 0;
  border-radius: 10px;
  background: white;
  color: #333;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.user-menu-person {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
}

.user-menu-names {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-menu-names strong,
.user-menu-names small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-names small {
  color: #777;
}

.user-menu-section {
  padding: 0.35rem 0;
  border-top: 1px solid #eee;
}

.user-menu-form {
  display: block;
}

/* ".header .user-menu-item" outranks the white header link rules */
.header .user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 0;
  background: none;
  color: #333;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.header .user-menu-item:hover,
.header .user-menu-item:focus-visible {
  background-color: #f2f3fb;
  outline: none;
}

.header .user-menu-item-active {
  color: #5a67d8;
  font-weight: 600;
}

.user-menu-item .icon {
  flex-shrink: 0;
  color: #666;
}

.user-menu-item-active .icon {
  color: #5a67d8;
}

/* Guidance boxes that fold away (details/summary) */
.foldable > summary {
  cursor: pointer;
  list-style: none;
}

.foldable > summary::-webkit-details-marker {
  display: none;
}

/* A chevron: points right when closed, down when open */
.foldable > summary::before {
  content: "";
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  margin: 0 0.65em 0.12em 0.15em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

.foldable[open] > summary::before {
  transform: rotate(45deg);
}

.foldable[open] > summary {
  margin-bottom: 0.5rem;
}

/* Forms */
.form-container {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  max-width: 600px;
  margin: 2rem auto;
}

.form-group {
  margin-bottom: 1.5rem;
}

/* inline-block keeps the required "*" next to its label; the full-width
   field below still starts on its own line */
.form-group label {
  display: inline-block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: #555;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  /* Fields don't pick up the page font on their own (dates and notes showed
     in a typewriter font) */
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.form-group .required {
  color: #e74c3c;
}

.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  /* <button>s (button_to) don't inherit these, so they'd sit shorter than links */
  font-family: inherit;
  line-height: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  transition: all 0.2s;
  font-weight: 500;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background: #5a6268;
}

.btn-danger {
  background: #dc3545;
  color: white;
}

.btn-danger:hover {
  background: #c82333;
}

.btn-success {
  background: #28a745;
  color: white;
}

.btn-success:hover {
  background: #218838;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

/* Table row actions as small icon buttons (view, edit, delete, locked) */
.row-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.row-actions form {
  display: contents;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid #e2e4f0;
  border-radius: 6px;
  background: white;
  color: #5a67d8;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: #f2f3fb;
  border-color: #c7cbef;
}

.icon-btn-danger {
  color: #dc3545;
}

.icon-btn-danger:hover,
.icon-btn-danger:focus-visible {
  background: #fdecee;
  border-color: #f3b8bf;
}

.icon-btn-locked,
.icon-btn-locked:hover {
  background: #f7f7f7;
  border-color: #eee;
  color: #999;
  cursor: help;
}

/* A note cut short; hover shows the whole note */
.short-note {
  cursor: help;
  border-bottom: 1px dotted #bbb;
}

/* Alerts */
.alert {
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.alert-notice {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.alert-alert {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.field-hint {
  display: block;
  margin-top: 0.35rem;
  color: #666;
  font-size: 0.8rem;
}

/* Login / sign-up pages */
/* The app name above the login and sign up forms */
.auth-brand {
  padding: 2.5rem 1rem 0;
  text-align: center;
}

.auth-brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}

.auth-brand-logo {
  display: block;
  filter: drop-shadow(0 6px 14px rgba(139, 92, 246, 0.35));
}

.auth-brand-name {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.auth-brand-tagline {
  margin: 0.25rem 0 0;
  color: #777;
}

.auth-brand + .toast-stack + .container .form-container {
  margin-top: 1.5rem;
}

.auth-subtitle {
  text-align: center;
  color: #666;
  margin-bottom: 1.5rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1.5rem;
  color: #666;
}

.auth-switch a {
  color: #667eea;
  font-weight: 500;
}

.role-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.role-badge-head {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.role-badge-admin {
  background: #e8ebfc;
  color: #4c5bd4;
}

.role-badge-viewer {
  background: #eee;
  color: #555;
}

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge-active {
  background: #e3f6ec;
  color: #1e7b4d;
}

.status-badge-current {
  background: #e8ebfc;
  color: #4c5bd4;
}

.status-badge-revoked {
  background: #fde8ea;
  color: #b0263a;
}

.member-revoked td {
  color: #888;
}

.member-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Keep table action buttons compact on small screens (.btn goes full width there) */
.member-actions .btn {
  width: auto;
  white-space: nowrap;
  font-family: inherit;
  line-height: inherit;
}

.revoked-icon {
  width: 3.5rem;
  height: 3.5rem;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #ee0979 0%, #ff6a00 100%);
  color: white;
  font-size: 2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Owner console (/sekret) */
.role-badge-super-admin {
  background: linear-gradient(135deg, #f7971e 0%, #ffd200 100%);
  color: #5a3d00;
  margin-left: 0.35rem;
}

.status-badge-left {
  background: #eee;
  color: #666;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid #e2e4f0;
  margin-bottom: 1.5rem;
}

.tab {
  padding: 0.65rem 1.25rem;
  color: #666;
  text-decoration: none;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.tab:hover {
  color: #667eea;
}

.tab-active {
  color: #667eea;
  border-bottom-color: #667eea;
}

.settings-card {
  padding: 0.5rem 1.5rem;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  padding: 1.25rem 0;
  border-bottom: 1px solid #eee;
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-text h4 {
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

.setting-text p {
  color: #666;
  font-size: 0.9rem;
}

.setting-text .setting-note {
  font-size: 0.8rem;
  color: #888;
  margin-top: 0.25rem;
}

.setting-text .setting-locked {
  font-size: 0.8rem;
  color: #b0263a;
  margin-top: 0.25rem;
}

/* On/off switch (a submit button, so it works without JavaScript) */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 0.25rem;
  white-space: nowrap;
}

.toggle:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.toggle-track {
  position: relative;
  width: 3rem;
  height: 1.6rem;
  border-radius: 999px;
  background: #ccc;
  transition: background 0.2s;
}

.toggle-thumb {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}

.toggle-on .toggle-track {
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.toggle-on .toggle-thumb {
  transform: translateX(1.4rem);
}

.toggle-label {
  min-width: 1.75rem;
  font-weight: 600;
  color: #555;
}

.toggle:focus-visible .toggle-track {
  outline: 3px solid rgba(102, 126, 234, 0.5);
  outline-offset: 2px;
}

.impersonate-button {
  margin-left: 0.35rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-family: inherit;
}

/* Shown on every page while the Super Admin is impersonating someone */
.impersonation-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-top: -1.5rem;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, #f7971e 0%, #ffd200 100%);
  color: #5a3d00;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.impersonation-stop {
  background: #5a3d00;
  color: white;
  font-family: inherit;
  width: auto;
}

.impersonation-stop:hover {
  background: #3d2900;
}

.membership-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.alert-warning {
  background-color: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

/* Single-line form: fields side by side, wrapping on small screens */
.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  align-items: end;
}

.inline-form .form-group {
  margin-bottom: 0;
}

/* Keep the submit button the same height as the inputs beside it */
.inline-form .btn {
  line-height: 1.2;
}

.inline-form-submit .btn {
  width: 100%;
}

.amount-link {
  text-decoration: none;
}

.amount-link:hover {
  text-decoration: underline;
}

.loan-extension-row td {
  background: #fafafa;
  color: #666;
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
}

.loan-extension-row td:first-child {
  padding-left: 2rem;
}

/* Table */
.table-container {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

table th,
table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid #eee;
}

table th {
  background-color: #f8f9fa;
  font-weight: 600;
  color: #555;
  position: sticky;
  top: 0;
}

table tr:hover {
  background-color: #f8f9fa;
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
}

.badge-credit {
  background-color: #d4edda;
  color: #155724;
}

.badge-debit {
  background-color: #f8d7da;
  color: #721c24;
}

/* Filters */
.filters {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  margin-bottom: 1.5rem;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.filter-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin: 2rem 0;
  flex-wrap: wrap;
}

.pagination a,
.pagination span {
  padding: 0.5rem 1rem;
  border: 1px solid #667eea;
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.25;
}

/* Outlined links; overrides .btn-secondary's grey so the text stays readable */
.pagination a {
  background: white;
  color: #667eea;
}

.pagination a:hover {
  background: #667eea;
  color: white;
}

.pagination .current {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: transparent;
}

/* A list fetching its next page */
[data-ajax-pagination][aria-busy="true"] {
  opacity: 0.6;
  transition: opacity 0.15s;
}

/* Reports */
.report-filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 1rem;
  align-items: end;
}

/* Let date inputs shrink inside the grid instead of pushing it wider */
.report-filter-grid > * {
  min-width: 0;
}

.report-filter-grid .form-group {
  margin-bottom: 0;
}
.report-card {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  margin-bottom: 1.5rem;
}

.report-card h3 {
  margin-bottom: 1rem;
  color: #333;
}

.report-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1.5rem;
  border-radius: 8px;
  text-align: center;
}

.stat-box-credit {
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.stat-box-debit {
  background: linear-gradient(135deg, #ee0979 0%, #ff6a00 100%);
}

.stat-box h4 {
  font-size: 0.875rem;
  opacity: 0.9;
  margin-bottom: 0.5rem;
}

.stat-box .amount {
  font-size: 2rem;
  font-weight: 600;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }

  .header nav {
    width: 100%;
    flex-direction: column;
  }

  .header a {
    width: 100%;
    text-align: center;
  }

  /* With JavaScript: one compact row, the links folded behind Menu */
  .header-js .header-content {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .header-js .brand {
    flex: 1;
  }

  /* Menu and avatar stay on the brand's row; the links open below them */
  .header-js .user-menu {
    order: 2;
  }

  .header-js nav {
    order: 3;
    margin-left: 0;
  }

  .header-js .nav-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: white;
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
  }

  .nav-toggle-icon,
  .nav-toggle-icon::before,
  .nav-toggle-icon::after {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 1px;
    background: currentColor;
  }

  .nav-toggle-icon {
    position: relative;
  }

  .nav-toggle-icon::before,
  .nav-toggle-icon::after {
    content: "";
    position: absolute;
    left: 0;
  }

  .nav-toggle-icon::before {
    top: -5px;
  }

  .nav-toggle-icon::after {
    top: 5px;
  }

  .header-js nav {
    display: none;
    gap: 0.25rem;
  }

  .header-js.nav-open nav {
    display: flex;
  }

  .form-container {
    padding: 1.5rem;
    margin: 1rem;
  }

  .filters-grid {
    grid-template-columns: 1fr;
  }

  .table-container {
    font-size: 0.875rem;
  }

  table th,
  table td {
    padding: 0.5rem;
  }

  .form-actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  /* button_to wraps its button in a form; stretch it like the link buttons */
  .page-actions,
  .page-actions .button_to {
    width: 100%;
  }

  .report-stats {
    grid-template-columns: 1fr;
  }

  .report-filter-grid {
    grid-template-columns: 1fr;
  }

  /* Keep pagination as a compact row, not full-width .btn blocks */
  .pagination .btn {
    width: auto;
  }

  .stat-box .amount {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0.5rem;
  }

  .header {
    padding: 0.75rem;
  }

  .header h1 {
    font-size: 1.25rem;
  }

  .form-container {
    padding: 1rem;
  }

  table {
    font-size: 0.75rem;
  }

  table th,
  table td {
    padding: 0.375rem;
  }
}

/* Utility Classes */
.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* Confirmation dialog (themed replacement for window.confirm) */
.confirm-dialog {
  /* The global reset zeroes margins; auto margins centre the modal */
  margin: auto;
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(440px, calc(100vw - 32px));
  overflow: hidden;
  color: #333;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.confirm-dialog[open] {
  animation: confirm-dialog-in 0.18s ease-out;
}

.confirm-dialog::backdrop {
  background: rgba(40, 32, 80, 0.55);
  backdrop-filter: blur(2px);
}

.confirm-dialog-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  color: white;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.confirm-dialog-danger .confirm-dialog-header {
  background: linear-gradient(135deg, #ee0979 0%, #ff6a00 100%);
}

.confirm-dialog-header h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.confirm-dialog-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  font-weight: 700;
}

.confirm-dialog-message {
  margin: 0;
  padding: 1.25rem 1.25rem 1.5rem;
  line-height: 1.55;
  color: #555;
}

.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0 1.25rem 1.25rem;
}

.confirm-dialog-actions .btn {
  font-family: inherit;
}

.confirm-dialog-actions .btn:focus-visible {
  outline: 3px solid rgba(102, 126, 234, 0.45);
  outline-offset: 2px;
}

@keyframes confirm-dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  .confirm-dialog[open] {
    animation: none;
  }
}

@media (max-width: 480px) {
  .confirm-dialog-actions {
    flex-direction: column-reverse;
  }

  .confirm-dialog-actions .btn {
    width: 100%;
  }
}

/* Businesses */
.alert-info {
  background-color: #e8f1fd;
  color: #1d4f91;
  border: 1px solid #c9ddf8;
}

.alert-info ul {
  margin: 0.4rem 0 0;
  padding-left: 1.25rem;
}

.status-badge-paused {
  background: #fff3cd;
  color: #856404;
}

.status-badge-closed {
  background: #eee;
  color: #666;
}

/* Asset status */
.status-badge-owned {
  background: #e3f6ec;
  color: #1e7b4d;
}

.status-badge-partly-sold {
  background: #fff3cd;
  color: #856404;
}

.status-badge-sold {
  background: #eee;
  color: #666;
}

/* Asset bought on installments */
.status-badge-paying {
  background: #e7f0fb;
  color: #1f5c99;
}

.status-badge-paid {
  background: #e3f6ec;
  color: #1e7b4d;
}

.payment-progress {
  height: 6px;
  margin-top: 0.5rem;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.3);
  overflow: hidden;
}

.payment-progress span {
  display: block;
  height: 100%;
  background: #fff;
}

/* A number with its unit beside it (asset size, quantity sold) */
.inline-fields {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.inline-fields > input {
  flex: 1 1 0;
  min-width: 0;
}

.inline-fields > .select {
  flex: 1 1 0;
  min-width: 0;
}

.inline-unit {
  color: #666;
  white-space: nowrap;
}

.amount-positive {
  color: #11998e;
}

.amount-negative {
  color: #ee0979;
}

.business-details {
  white-space: pre-line;
  color: #555;
  margin-bottom: 1rem;
}

.form-section-title {
  font-size: 1rem;
  margin: 1.5rem 0 0.75rem;
  color: #333;
}

/* One investor per row: name, amount, remove */
.investor-row {
  display: grid;
  grid-template-columns: 1fr 180px auto;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.75rem;
}

.investor-row .form-group {
  margin-bottom: 0;
}

@media (max-width: 480px) {
  .investor-row {
    grid-template-columns: 1fr;
  }
}

.stat-box-note {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  opacity: 0.9;
}

/* Flash toasts: top-right, closing on their own */
.toast-stack {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(380px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 2.4rem 0.95rem 0.9rem;
  border-radius: 8px;
  background: white;
  color: #333;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  border-left: 4px solid #11998e;
  overflow: hidden;
  pointer-events: auto;
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}

.toast-alert {
  border-left-color: #dc3545;
}

.toast-leaving {
  opacity: 0;
  transform: translateX(1rem);
}

.toast-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: #11998e;
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
}

.toast-alert .toast-icon {
  background: #dc3545;
}

.toast-message {
  flex: 1;
  font-size: 0.95rem;
  line-height: 1.45;
}

.toast-close {
  position: absolute;
  top: 0.45rem;
  right: 0.5rem;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 4px;
  background: none;
  color: #888;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.toast-close:hover,
.toast-close:focus-visible {
  background: #f0f0f0;
  color: #333;
}

/* Shrinking bar showing how long until the toast closes */
.toast-timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: currentColor;
  opacity: 0.15;
  transform-origin: left;
  animation: toast-timer linear forwards;
  animation-duration: var(--toast-duration, 5s);
  animation-play-state: paused;
}

.toast-running .toast-timer {
  animation-play-state: running;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-0.5rem);
  }
}

@keyframes toast-timer {
  to {
    transform: scaleX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none;
    transition: none;
  }
}

@media (max-width: 480px) {
  .toast-stack {
    top: 0.75rem;
    right: 1rem;
    left: 1rem;
    width: auto;
  }
}

/* Themed dropdowns. application.js puts a button and option list over each
   <select>; the real select stays in the form (for submitting, validation and
   the field logic) but is shrunk out of sight. */
.select {
  position: relative;
}

.select-native {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1px !important;
  height: 1px;
  padding: 0 !important;
  border: 0 !important;
  clip-path: inset(50%);
  pointer-events: none;
}

.select-button {
  position: relative;
  display: block;
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
  color: #333;
  font: inherit;
  font-size: 1rem;
  /* Same height as the text inputs beside it */
  line-height: 1.15;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.select-value {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-placeholder .select-value {
  color: #888;
}

/* Chevron */
.select-button::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 1rem;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid #667eea;
  border-bottom: 2px solid #667eea;
  transform: translateY(-70%) rotate(45deg);
  transition: transform 0.2s;
}

.select-open .select-button::after {
  transform: translateY(-30%) rotate(-135deg);
}

.select-button:focus-visible,
.select-open .select-button {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.select-button:disabled {
  background: #f5f5f5;
  color: #888;
  cursor: not-allowed;
}

.select-button:disabled::after {
  border-color: #bbb;
}

.select-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 60;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  background: white;
  border: 1px solid #e3e6f5;
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(40, 40, 90, 0.18);
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: select-list-in 0.12s ease-out;
}

.select-list.select-list-up {
  top: auto;
  bottom: calc(100% + 4px);
}

.select-option {
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  color: #333;
  line-height: 1.4;
  cursor: pointer;
  /* Long options wrap instead of widening the list past the screen */
  white-space: normal;
  overflow-wrap: anywhere;
}

.select-option-placeholder {
  color: #888;
}

.select-option-active {
  background: #eef0fc;
}

.select-option[aria-selected="true"] {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-weight: 500;
}

.select-option[aria-disabled="true"] {
  color: #bbb;
  cursor: default;
}

@keyframes select-list-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .select-list {
    animation: none;
  }
}

/* Page title with its buttons; stacked on phones */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
}

/* iPhone Safari draws date fields with its own grey, centred control that
   collapses to a thin line while empty (it shows no dd/mm/yyyy placeholder).
   Use the app's input look and keep the same height as the other inputs. */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  height: 2.75rem;
  background-color: white;
  color: #333;
  line-height: 1.2;
  text-align: left;
}

input[type="date"]::-webkit-date-and-time-value {
  margin: 0;
  text-align: left;
}

/* Form with the Guide panel beside it (desktop); the guide is hidden on
   phones and tablets, where the form looks as before */
.with-guide {
  display: grid;
  grid-template-columns: minmax(0, 600px) 340px;
  justify-content: center;
  align-items: start;
  gap: 2rem;
  margin: 2rem 0;
}

.with-guide .form-container {
  max-width: none;
  margin: 0;
}

.form-guide {
  position: sticky;
  top: 1rem;
  padding: 1.5rem;
  background: white;
  border-radius: 8px;
  border-top: 4px solid #667eea;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-guide h3 {
  margin-bottom: 1rem;
  color: #667eea;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.guide-section + .guide-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #eee;
}

.guide-section h4 {
  margin-bottom: 0.35rem;
  color: #333;
  font-size: 1rem;
}

.guide-section p {
  color: #555;
  font-size: 0.92rem;
  line-height: 1.5;
}

.guide-new {
  margin-top: 0.6rem;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  background: #eef0fc;
  color: #4c5bd4 !important;
}

.guide-preview dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 1rem;
  margin: 0.5rem 0 0;
  font-size: 0.92rem;
}

.guide-preview dt {
  color: #555;
}

.guide-preview dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.guide-warning {
  margin-top: 0.6rem;
  color: #b0263a !important;
  font-weight: 500;
}

/* Two fields side by side in a form (the loan form); one a row on phones */
.form-row-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 1rem;
}

@media (max-width: 600px) {
  .form-row-2 {
    grid-template-columns: 1fr;
  }
}

/* The loan form sits above its list, not in the middle of the page */
.loan-form-with-guide {
  margin-top: 0;
}

/* The guide says the same as these hints, so they show only without it */
@media (min-width: 901px) {
  .guide-duplicate {
    display: none !important;
  }
}

@media (max-width: 900px) {
  .with-guide {
    display: block;
    margin: 0;
  }

  .with-guide .form-container {
    max-width: 600px;
    margin: 2rem auto;
  }

  .form-guide {
    display: none;
  }
}

@media (max-width: 768px) {
  .with-guide .form-container {
    margin: 1rem;
  }
}

/* Reports: Opening and Closing balance above the period's totals */
.balance-summary {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 1rem 1.5rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.balance-figure {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.balance-label {
  color: #666;
  font-size: 0.85rem;
  font-weight: 500;
}

.balance-amount {
  color: #555;
  font-size: 1.15rem;
  font-weight: 600;
}

.balance-figure small {
  color: #888;
  font-size: 0.8rem;
}

.balance-amount.amount-positive {
  color: #11998e;
}

.balance-amount.amount-negative {
  color: #ee0979;
}

/* The takeaway: how much the family has saved by the end of the period */
.balance-closing {
  text-align: right;
}

.balance-closing .balance-amount {
  font-size: 1.6rem;
  font-weight: 700;
}

@media (max-width: 480px) {
  .balance-summary {
    flex-direction: column;
    align-items: stretch;
  }

  .balance-closing {
    text-align: left;
  }
}

/* Profile: the person's own name, email and password */
.profile {
  max-width: 640px;
  margin: 2rem auto;
}

.profile-card {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  margin-bottom: 1.5rem;
}

.profile-card h3 {
  margin-bottom: 1rem;
}

.profile-summary {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.profile-summary-text {
  min-width: 0;
}

.profile-name-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.profile-name-row h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Sits beside the name, not pushed away from it */
.profile-name-row .role-badge {
  margin-left: 0;
}

.profile-summary-text p {
  margin: 0;
  color: #666;
  overflow-wrap: anywhere;
}

.profile-family {
  font-size: 0.9rem;
}

.profile-hint {
  margin: -0.75rem 0 1.5rem;
}

@media (max-width: 600px) {
  .profile {
    margin: 1rem auto;
  }

  .profile-card {
    padding: 1.25rem;
  }

  .profile-summary {
    gap: 1rem;
  }

  .profile-summary .avatar-xl {
    width: 56px;
    height: 56px;
    font-size: 1.25rem;
  }
}

/* Dashboard: filters in a sidebar on the left, records on the right */
.dashboard {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.dashboard-main {
  min-width: 0;
}

/* Stays in view while the records scroll; only its filters scroll */
.filter-sidebar {
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem);
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.filter-sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #eee;
}

.filter-sidebar-header h3 {
  margin: 0 auto 0 0;
  font-size: 1.05rem;
}

.filter-count {
  color: #5a67d8;
}

.filter-clear {
  color: #5a67d8;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.filter-clear:hover {
  text-decoration: underline;
}

.filter-close {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 6px;
  background: none;
  color: #666;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.filter-close:hover,
.filter-close:focus-visible {
  background: #f2f3fb;
  color: #333;
}

.filter-sidebar-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.5rem 1.25rem 1.25rem;
}

.filter-group {
  /* A fieldset grows to fit its widest option by default; a long crop name
     would widen the sidebar and scroll the page sideways */
  min-width: 0;
  margin: 0;
  padding: 0.75rem 0 0;
  border: none;
}

.filter-group + .filter-group {
  margin-top: 0.75rem;
  border-top: 1px solid #f0f0f0;
}

.filter-group legend {
  float: left;
  width: 100%;
  margin-bottom: 0.6rem;
  padding: 0;
  color: #888;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.filter-group legend + * {
  clear: left;
}

.filter-sidebar .form-group {
  margin-bottom: 0.85rem;
}

.filter-sidebar label {
  font-size: 0.85rem;
}

/* The chosen option is cut short with "..."; the open list shows it in full */
.filter-sidebar select {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.filter-group .field-hint {
  margin-top: -0.35rem;
}

.filter-apply {
  margin-top: 1rem;
}

/* With JavaScript, changes apply at once and the sidebar can fold away */
.filters-live .filter-apply {
  display: none;
}

.filter-open {
  margin-bottom: 1rem;
}

.filter-open .filter-count {
  color: inherit;
}

.filter-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1090;
  background: rgba(20, 20, 40, 0.4);
}

@media (min-width: 901px) {
  .filters-live:not(.filters-open) {
    grid-template-columns: minmax(0, 1fr);
  }

  .filters-live:not(.filters-open) .filter-sidebar {
    display: none;
  }

  .filters-live.filters-open .filter-open {
    display: none;
  }
}

/* Phones and tablets: the records take the width; Filters opens a drawer */
@media (max-width: 900px) {
  .dashboard {
    grid-template-columns: minmax(0, 1fr);
  }

  .filters-live .filter-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1100;
    width: min(320px, 88vw);
    max-height: none;
    border-radius: 0 10px 10px 0;
    transform: translateX(-105%);
    visibility: hidden;
  }

  /* Slides only once the page is set up, so it doesn't slide away on load */
  .filters-ready .filter-sidebar {
    transition: transform 0.2s ease, visibility 0.2s;
  }

  .filters-live.filters-open .filter-sidebar {
    transform: none;
    visibility: visible;
  }
}

@media (prefers-reduced-motion: reduce) {
  .filters-ready .filter-sidebar {
    transition: none;
  }
}

/* Family Members: Delete Family */
.danger-zone {
  border: 1px solid #f5c6cb;
  border-left: 4px solid #dc3545;
}

.danger-zone h3 {
  color: #b02a37;
  margin-bottom: 0.5rem;
}

.danger-zone p {
  color: #555;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.danger-zone .btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
