/* Global app theme (Bootstrap-friendly) */

:root {
  --app-bg: #f6f7fb;
  --app-surface: #ffffff;
  --app-border: rgba(16, 24, 40, 0.08);
  --app-text: #101828;
  --app-muted: #667085;
  --app-primary: #4f46e5;
  --app-primary-2: #7c3aed;
  --app-shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

[data-theme="dark"] {
  --app-bg: #0b0f17;
  --app-surface: #111827;
  --app-border: rgba(255, 255, 255, 0.08);
  --app-text: #f3f4f6;
  --app-muted: #9ca3af;
  --app-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] body {
  background: radial-gradient(1200px 500px at 20% -10%, rgba(79, 70, 229, 0.12), transparent 60%),
              radial-gradient(900px 450px at 85% 0%, rgba(124, 58, 237, 0.08), transparent 60%),
              var(--app-bg);
}

[data-theme="dark"] .table-striped>tbody>tr:nth-of-type(odd)>* {
  --bs-table-bg-type: rgba(255, 255, 255, 0.03);
}

html, body {
  height: 100%;
}

body {
  background: radial-gradient(1200px 500px at 20% -10%, rgba(79, 70, 229, 0.18), transparent 60%),
              radial-gradient(900px 450px at 85% 0%, rgba(124, 58, 237, 0.14), transparent 60%),
              var(--app-bg);
  color: var(--app-text);
}

/* Shell layout */
main.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

@media (min-width: 992px) {
  main.app-shell {
    flex-direction: row;
  }
}

/* Mobile top bar */
.app-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 1rem;
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.98), rgba(17, 24, 39, 0.94));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.92);
  z-index: 1020;
}

.app-topbar-toggler {
  color: rgba(255, 255, 255, 0.92);
  font-size: 1.5rem;
  line-height: 1;
  padding: .15rem .35rem;
  border: 0;
}

.app-topbar-toggler:hover,
.app-topbar-toggler:focus {
  color: #fff;
}

.app-topbar-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 650;
  letter-spacing: .01em;
}

/* Sidebar */
.app-sidebar {
  width: 270px;
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.98), rgba(17, 24, 39, 0.92));
  border-right: 1px solid rgba(255,255,255,0.08);
}

@media (min-width: 992px) {
  .app-sidebar.offcanvas-lg {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    max-height: 100vh;
    visibility: visible !important;
    transform: none !important;
    z-index: auto;
  }

  .app-sidebar .offcanvas-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

@media (max-width: 991.98px) {
  .app-sidebar.offcanvas-lg {
    --bs-offcanvas-width: min(300px, 88vw);
  }
}

.app-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .25rem .25rem .75rem .25rem;
}

.app-nav-section {
  letter-spacing: .06em;
  text-transform: uppercase;
}

.app-brand-badge {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(79, 70, 229, 1), rgba(124, 58, 237, 1));
  color: #fff;
  box-shadow: 0 10px 20px rgba(79,70,229,0.35);
  flex-shrink: 0;
}

.app-brand-badge--sm {
  width: 28px;
  height: 28px;
  font-size: .9rem;
  border-radius: 8px;
  box-shadow: none;
}

.app-brand-title {
  color: rgba(255,255,255,0.92);
  font-weight: 700;
  letter-spacing: .2px;
  margin: 0;
}

.app-brand-subtitle {
  color: rgba(255,255,255,0.6);
  font-size: .85rem;
  margin: 0;
}

.app-sidebar .nav-link {
  color: rgba(255, 255, 255, 0.78) !important;
  border-radius: 12px;
  padding: .55rem .75rem;
  display: flex;
  align-items: center;
  gap: .6rem;
}

.app-sidebar .nav-link:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.92) !important;
}

.app-sidebar .nav-link.active {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.95), rgba(124, 58, 237, 0.95));
  color: #fff !important;
  box-shadow: 0 10px 20px rgba(79,70,229,0.28);
}

/* Main content surface */
.app-content {
  padding: 18px;
  flex: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.app-surface--dashboard {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.app-content > .app-surface--dashboard {
  min-height: calc(100vh - 36px);
}

/* Dashboard: panneaux à défilement */
.app-dashboard-row {
  align-items: stretch;
}

.app-dashboard-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: min(28rem, calc(100vh - 22rem));
  border: 1px solid var(--app-border);
  border-radius: 14px;
  background: var(--app-surface);
  overflow: hidden;
}

.app-dashboard-panel__head {
  flex-shrink: 0;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--app-border);
  background: rgba(79, 70, 229, 0.03);
}

.app-dashboard-panel__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.app-dashboard-panel__body .table {
  margin-bottom: 0;
}

.app-dashboard-panel__foot {
  flex-shrink: 0;
  padding: .5rem 1rem;
  border-top: 1px solid var(--app-border);
  background: rgba(16, 24, 40, 0.02);
}

.app-upcoming-item {
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--app-border);
}

.app-upcoming-item:last-child {
  border-bottom: none;
}

.app-upcoming-item .charge-amount,
.app-upcoming-item .income-amount {
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: .75rem;
}

.min-w-0 {
  min-width: 0;
}

.min-h-0 {
  min-height: 0;
}

@media (max-width: 992px) {
  .app-dashboard-panel {
    max-height: min(22rem, 45vh);
  }
}

/* Budget: panneaux empilés sans étirement forcé */
.app-dashboard-panel--auto {
  height: auto;
  max-height: none;
}

.app-dashboard-panel--auto .app-dashboard-panel__body {
  overflow: visible;
}

.app-budget-subsection {
  border-bottom: 1px solid var(--app-border);
}

.app-budget-subsection:last-child {
  border-bottom: none;
}

.app-budget-subsection__title {
  padding: .65rem 1rem;
  margin: 0;
  font-size: .8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--bs-secondary-color);
  background: rgba(16, 24, 40, 0.02);
  border-bottom: 1px solid var(--app-border);
}

.app-budget-actions {
  width: 5.5rem;
  white-space: nowrap;
}

/* Budget — répartition entre personnes */
.app-budget-split {
  --split-c1: #4f46e5;
  --split-c2: #0d9488;
  --split-c3: #d97706;
  --split-c4: #db2777;
}

.app-split-stack {
  display: flex;
  height: 0.65rem;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(16, 24, 40, 0.06);
}

.app-split-stack__seg {
  min-width: 2px;
  transition: width 0.2s ease;
}

.app-split-stack__seg--1 { background: var(--split-c1); }
.app-split-stack__seg--2 { background: var(--split-c2); }
.app-split-stack__seg--3 { background: var(--split-c3); }
.app-split-stack__seg--4 { background: var(--split-c4); }

.app-split-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.app-split-legend-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.app-split-legend-item--1 .app-split-legend-dot { background: var(--split-c1); }
.app-split-legend-item--2 .app-split-legend-dot { background: var(--split-c2); }
.app-split-legend-item--3 .app-split-legend-dot { background: var(--split-c3); }
.app-split-legend-item--4 .app-split-legend-dot { background: var(--split-c4); }

.app-split-pct-input {
  width: 6.5rem;
  flex-shrink: 0;
}

.app-split-share-row {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--app-border);
}

.app-split-share-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.app-split-share-row:first-child {
  padding-top: 0;
}

.app-split-share-bar {
  height: 0.35rem;
  border-radius: 999px;
  background: rgba(16, 24, 40, 0.06);
  overflow: hidden;
}

.app-split-share-bar__fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.2s ease;
}

.app-split-share-row--1 .app-split-share-bar__fill { background: var(--split-c1); }
.app-split-share-row--2 .app-split-share-bar__fill { background: var(--split-c2); }
.app-split-share-row--3 .app-split-share-bar__fill { background: var(--split-c3); }
.app-split-share-row--4 .app-split-share-bar__fill { background: var(--split-c4); }

.app-split-share-range {
  height: 1.25rem;
}

.app-split-result-card {
  border: 1px solid var(--app-border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  height: 100%;
  background: var(--app-surface);
  border-top: 3px solid var(--split-c1);
}

.app-split-result-card--1 { border-top-color: var(--split-c1); }
.app-split-result-card--2 { border-top-color: var(--split-c2); }
.app-split-result-card--3 { border-top-color: var(--split-c3); }
.app-split-result-card--4 { border-top-color: var(--split-c4); }

.app-split-result-card__name {
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
}

.app-split-result-card__lines {
  display: grid;
  gap: 0.45rem;
}

.app-split-result-card__line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.app-split-result-card__line dt {
  color: var(--app-muted);
  font-weight: 400;
  margin: 0;
}

.app-split-result-card__line dd {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.app-split-result-card__total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--app-border);
  font-weight: 600;
}

.app-split-result-card__total .split-total {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.bg-body-tertiary {
  background: transparent !important;
}

.app-surface {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: 18px;
  box-shadow: var(--app-shadow);
}

/* Cards */
.card {
  border: 1px solid var(--app-border);
  border-radius: 16px;
  box-shadow: 0 10px 22px rgba(16, 24, 40, 0.06);
}

.card .text-muted {
  color: var(--app-muted) !important;
}

/* Tables */
.table {
  --bs-table-bg: transparent;
  border-color: var(--app-border);
}

.table thead th {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--app-muted);
  border-bottom: 1px solid var(--app-border);
}

.table tbody tr {
  border-color: var(--app-border);
}

.table-striped>tbody>tr:nth-of-type(odd)>* {
  --bs-table-bg-type: rgba(16, 24, 40, 0.02);
}

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--app-primary), var(--app-primary-2));
  border: none;
  box-shadow: 0 10px 20px rgba(79,70,229,0.22);
}

.btn-primary:hover {
  filter: brightness(0.98);
}

.btn-outline-secondary {
  border-color: rgba(16, 24, 40, 0.18);
}

/* Forms */
.form-control, .form-select {
  border-radius: 12px;
  border-color: rgba(16, 24, 40, 0.14);
}

.form-control:focus, .form-select:focus {
  border-color: rgba(79, 70, 229, 0.65);
  box-shadow: 0 0 0 .25rem rgba(79, 70, 229, 0.12);
}

/* Alerts */
.alert {
  border-radius: 14px;
  border: 1px solid var(--app-border);
}

/* Reference data pages (persons, accounts, …) */
.app-page-header {
  margin-bottom: 1.25rem;
}

.app-page-header .app-page-subtitle {
  color: var(--app-muted);
  font-size: .95rem;
  margin: .25rem 0 0;
}

.app-ref-filters {
  background: rgba(79, 70, 229, 0.04);
  border: 1px dashed rgba(79, 70, 229, 0.22);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
}

.app-ref-filters .form-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--app-muted);
  margin-bottom: .35rem;
}

.app-ref-table .btn-icon {
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.app-ref-table tr.is-editing {
  background: rgba(79, 70, 229, 0.06) !important;
}

.app-ref-empty {
  color: var(--app-muted);
  text-align: center;
  padding: 2.5rem 1rem;
}

/* Responsive refinements */
@media (max-width: 991.98px) {
  .app-content {
    padding: 12px;
  }

  .app-content > .app-surface.p-4,
  .app-content > .p-4 {
    padding: 1rem !important;
  }

  .app-content > .app-surface.p-3,
  .app-content > .p-3 {
    padding: .85rem !important;
  }

  .app-page-header {
    margin-bottom: 1rem;
  }

  .app-page-header .h2 {
    font-size: 1.4rem;
  }

  .app-page-header .app-page-subtitle {
    font-size: .9rem;
  }

  .app-ref-filters .col-auto {
    width: 100%;
  }

  .app-ref-filters .col-auto .btn {
    width: auto;
  }

  .app-budget-actions {
    width: auto;
  }

  .modal-xl,
  .modal-lg {
    --bs-modal-width: calc(100vw - 1.5rem);
  }
}

@media (max-width: 575.98px) {
  .app-content {
    padding: 8px;
  }

  .app-content > .app-surface.p-4,
  .app-content > .p-4,
  .app-content > .app-surface.p-3,
  .app-content > .p-3 {
    padding: .75rem !important;
  }

  .app-page-header .h2,
  .app-content h1.h2 {
    font-size: 1.25rem;
  }

  .app-ref-table .table {
    font-size: .875rem;
  }

  .app-ref-table .btn-icon {
    width: 1.85rem;
    height: 1.85rem;
  }

  .card .fs-4 {
    font-size: 1.15rem !important;
  }

  .card .fs-5 {
    font-size: 1.05rem !important;
  }

  .app-auth-card {
    margin: .75rem;
    max-width: none;
  }
}

/* Auth pages (login / register) */
.app-auth-page {
  min-height: 100vh;
}

.app-auth-card {
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--app-border);
  border-radius: 16px;
  background: var(--app-surface);
}

.app-auth-card .app-brand-badge {
  width: 3rem;
  height: 3rem;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--app-primary), var(--app-primary-2));
  color: #fff;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

