/* LoyerManager SPA global styles - generated from legacy CSS during 20260523 refactor. */
/* css/style.css */
:root {
  color-scheme: dark;
  --bg: #050506;
  --bg-soft: #0d0d10;
  --panel: rgba(22, 22, 25, 0.88);
  --panel-solid: #161619;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f7f7f4;
  --muted: #a8a8a0;
  --muted-2: #73736b;
  --accent: #ffb323;
  --accent-2: #ff7a1a;
  --green: #45d483;
  --red: #ff5e57;
  --blue: #70a7ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

/* Premium SaaS refresh inspired by the reference interface. */
:root {
  --bg: #0b0b0c;
  --bg-soft: #121214;
  --panel: #171719;
  --panel-solid: #171719;
  --border: rgba(255, 255, 255, 0.11);
  --text: #f7f7f5;
  --muted: rgba(247, 247, 245, 0.58);
  --muted-2: rgba(247, 247, 245, 0.38);
  --accent: #f87171;
  --accent-2: #fb923c;
  --green: #34d399;
  --red: #fb7185;
  --blue: #93c5fd;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.28);
  --radius: 8px;
}

body {
  background: linear-gradient(180deg, #0b0b0c 0%, #101012 52%, #0b0b0c 100%);
}

.sidebar {
  background: #050505;
  border-right-color: rgba(255, 255, 255, 0.08);
  padding: 22px 20px;
}

.brand {
  padding: 4px 2px;
}

.brand-mark {
  border-radius: 8px;
  color: #0b0b0c;
  background: #ffffff;
  box-shadow: none;
}

.brand strong {
  font-size: 1.18rem;
  letter-spacing: 0;
}

.brand span {
  color: var(--accent);
  font-size: 0.82rem;
}

.nav-list {
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  min-height: 46px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.58);
  padding: 0 14px;
}

.nav-item:hover {
  color: white;
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.is-active {
  color: #050505;
  background: #ffffff;
  border-color: #ffffff;
  box-shadow: none;
  font-weight: 800;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
  padding: 18px 2px 2px;
  background: transparent;
}

.sidebar-footer strong {
  color: #ffffff;
}

.main-content {
  max-width: 1520px;
  padding: 32px;
}

.topbar {
  margin-bottom: 24px;
}

.eyebrow {
  color: var(--accent);
}

h1 {
  font-size: clamp(2rem, 3.4vw, 3rem);
  font-weight: 680;
  line-height: 1.04;
}

h2 {
  font-weight: 700;
}

.panel,
.stat-card,
.tenant-controls,
.tenant-card,
.archive-card,
.contract-card,
.payment-group,
.payment-card,
.auth-card,
dialog {
  background: var(--panel);
  border-color: var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.035), var(--shadow);
}

.panel,
.stat-card {
  padding: 20px;
}

.stat-card {
  min-height: 126px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02)), var(--panel);
}

.stat-card::after {
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.14);
}

.stat-card strong {
  font-weight: 760;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.mini-button,
.round-add-button,
.filter-toggle,
.quick-filter-row button,
.segmented-control,
.segmented-control button,
.tenant-action-picker select {
  border-radius: 8px;
}

.primary-button {
  color: #0b0b0c;
  background: #ffffff;
  border-color: #ffffff;
  box-shadow: 0 10px 28px rgba(255, 255, 255, 0.08);
}

.secondary-button,
.icon-button,
.mini-button,
.filter-toggle,
.tenant-action-picker select {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border);
}

.danger-button,
.mini-button.danger {
  color: #fecdd3;
  background: rgba(251, 113, 133, 0.13);
  border-color: rgba(251, 113, 133, 0.32);
}

.segmented-control {
  background: rgba(255, 255, 255, 0.07);
  padding: 4px;
}

.segmented-control button.is-active,
.quick-filter-row button.is-active {
  color: #0b0b0c;
  background: #ffffff;
  border-color: #ffffff;
}

input,
select,
textarea,
.soft-input {
  border-radius: 8px;
  background: #101012;
  border-color: rgba(255, 255, 255, 0.12);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(248, 113, 113, 0.72);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.14);
}

.insight-list div,
.summary-card,
.compact-item,
.ai-import-box,
.toggle-line,
.payment-calc-summary,
.mini-stats-grid div {
  background: #101012;
  border-color: rgba(255, 255, 255, 0.1);
}

.tenant-icon {
  border-radius: 8px;
  background: #101012;
}

.round-add-button {
  color: #0b0b0c;
  background: #ffffff;
  border-color: #ffffff;
}

.server-error {
  margin: -8px 0 18px;
  padding: 13px 15px;
  border: 1px solid rgba(251, 113, 133, 0.42);
  border-radius: 8px;
  color: #fecdd3;
  background: rgba(251, 113, 133, 0.12);
}

.auth-gate {
  background: rgba(5, 5, 5, 0.78);
}

.auth-card {
  background: #111113;
}

.table-wrap {
  background: #111113;
}

th {
  background: #101012;
}

td {
  color: rgba(247, 247, 245, 0.88);
}

@media (max-width: 720px) {
  body {
    background: #0b0b0c;
  }

  .main-content {
    padding: 14px 12px calc(86px + env(safe-area-inset-bottom));
  }

  .sidebar {
    background: rgba(5, 5, 5, 0.88);
    border-radius: 8px;
  }

  .nav-item,
  .nav-item.is-active,
  .quick-filter-row button,
  .search-field input,
  .filter-toggle,
  .compact-tenant-card,
  .annual-tenant-card {
    border-radius: 8px;
  }

  .nav-item.is-active {
    color: #050505;
    background: #ffffff;
  }

  .compact-tenant-card {
    background: #171719;
  }
}

/* Final mobile page menu overrides: keep after legacy mobile rules. */
@media (max-width: 430px) {
  .mobile-more-trigger {
    display: inline-grid;
  }

  body.auth-required .mobile-more-trigger,
  body.document-viewer-open .mobile-more-trigger,
  body.mobile-menu-open .global-fab {
    display: none !important;
  }

  .mobile-page-menu {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: block;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 220ms ease, visibility 220ms ease;
  }

  .mobile-page-menu.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .mobile-page-menu-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(8px);
  }

  .mobile-page-menu-sheet {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: calc(86px + env(safe-area-inset-bottom));
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: rgba(18, 18, 20, 0.94);
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.52);
    backdrop-filter: blur(28px);
    transform: translateY(16px) scale(0.98);
    transition: transform 240ms ease;
  }

  .mobile-page-menu.is-open .mobile-page-menu-sheet {
    transform: translateY(0) scale(1);
  }

  html[data-theme="light"] .mobile-page-menu-sheet {
    background: rgba(255, 255, 255, 0.94);
  }

  .mobile-page-menu-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 40px;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
  }

  .mobile-page-menu-head strong,
  .mobile-page-menu-head span {
    display: block;
  }

  .mobile-page-menu-head span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.78rem;
  }

  .mobile-page-menu-head button {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
    font: inherit;
    font-size: 1.2rem;
  }

  .mobile-page-menu-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-page-menu-grid button {
    min-height: 58px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: 9px;
    border: 1px solid var(--border);
    border-radius: 18px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    text-align: left;
    font: inherit;
    padding: 0 12px;
  }

  .mobile-page-menu-grid button span {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: #0b0b0c;
    background: #ffffff;
    font-size: 1rem;
  }

  html[data-theme="light"] .mobile-page-menu-grid button span {
    color: #ffffff;
    background: #101012;
  }

  .mobile-page-menu-grid button strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.86rem;
  }
}

/* Final mobile page menu overrides: keep after legacy mobile rules. */
@media (max-width: 430px) {
  .mobile-more-trigger {
    display: inline-grid;
  }

  body.auth-required .mobile-more-trigger,
  body.document-viewer-open .mobile-more-trigger,
  body.mobile-menu-open .global-fab {
    display: none !important;
  }

  .mobile-page-menu {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: block;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 220ms ease, visibility 220ms ease;
  }

  .mobile-page-menu.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .mobile-page-menu-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(8px);
  }

  .mobile-page-menu-sheet {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: calc(86px + env(safe-area-inset-bottom));
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: rgba(18, 18, 20, 0.94);
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.52);
    backdrop-filter: blur(28px);
    transform: translateY(16px) scale(0.98);
    transition: transform 240ms ease;
  }

  .mobile-page-menu.is-open .mobile-page-menu-sheet {
    transform: translateY(0) scale(1);
  }

  html[data-theme="light"] .mobile-page-menu-sheet {
    background: rgba(255, 255, 255, 0.94);
  }

  .mobile-page-menu-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 40px;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
  }

  .mobile-page-menu-head strong,
  .mobile-page-menu-head span {
    display: block;
  }

  .mobile-page-menu-head span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.78rem;
  }

  .mobile-page-menu-head button {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
    font: inherit;
    font-size: 1.2rem;
  }

  .mobile-page-menu-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-page-menu-grid button {
    min-height: 58px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: 9px;
    border: 1px solid var(--border);
    border-radius: 18px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    text-align: left;
    font: inherit;
    padding: 0 12px;
  }

  .mobile-page-menu-grid button span {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: #0b0b0c;
    background: #ffffff;
    font-size: 1rem;
  }

  html[data-theme="light"] .mobile-page-menu-grid button span {
    color: #ffffff;
    background: #101012;
  }

  .mobile-page-menu-grid button strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.86rem;
  }
}

/* Mobile complete page menu + PDF viewer safety overrides */
.mobile-more-trigger,
.mobile-page-menu {
  display: none;
}

body.document-viewer-open .mobile-more-trigger,
body.document-viewer-open .mobile-bottom-nav,
body.document-viewer-open .global-fab,
body.mobile-menu-open .global-fab {
  display: none !important;
}

@media (max-width: 430px) {
  .mobile-more-trigger {
    display: inline-grid;
  }

  body.auth-required .mobile-more-trigger {
    display: none !important;
  }

  .mobile-page-menu {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: block;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 220ms ease, visibility 220ms ease;
  }

  .mobile-page-menu.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .mobile-page-menu-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(8px);
  }

  .mobile-page-menu-sheet {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: calc(86px + env(safe-area-inset-bottom));
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: rgba(18, 18, 20, 0.94);
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.52);
    backdrop-filter: blur(28px);
    transform: translateY(16px) scale(0.98);
    transition: transform 240ms ease;
  }

  .mobile-page-menu.is-open .mobile-page-menu-sheet {
    transform: translateY(0) scale(1);
  }

  html[data-theme="light"] .mobile-page-menu-sheet {
    background: rgba(255, 255, 255, 0.94);
  }

  .mobile-page-menu-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 40px;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
  }

  .mobile-page-menu-head strong,
  .mobile-page-menu-head span {
    display: block;
  }

  .mobile-page-menu-head span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.78rem;
  }

  .mobile-page-menu-head button {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
    font: inherit;
    font-size: 1.2rem;
  }

  .mobile-page-menu-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-page-menu-grid button {
    min-height: 58px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: 9px;
    border: 1px solid var(--border);
    border-radius: 18px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    text-align: left;
    font: inherit;
    padding: 0 12px;
  }

  .mobile-page-menu-grid button span {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: #0b0b0c;
    background: #ffffff;
    font-size: 1rem;
  }

  html[data-theme="light"] .mobile-page-menu-grid button span {
    color: #ffffff;
    background: #101012;
  }

  .mobile-page-menu-grid button strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.86rem;
  }
}

/* In-app PDF/quittance viewer for iPhone PWA */
.document-viewer {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #0b0b0c;
  opacity: 0;
  visibility: hidden;
  transform: translateX(18px);
  transition: opacity 220ms ease, transform 260ms ease, visibility 220ms ease;
}

.document-viewer.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

.document-viewer-bar {
  min-height: calc(64px + env(safe-area-inset-top));
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(12, 12, 14, 0.92);
  backdrop-filter: blur(24px);
}

.document-viewer-bar strong,
.document-viewer-bar span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-viewer-bar strong {
  color: #f7f7f5;
  font-size: 0.94rem;
}

.document-viewer-bar span {
  margin-top: 2px;
  color: rgba(247, 247, 245, 0.48);
  font-size: 0.72rem;
}

.document-back-button,
.document-print-button {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  color: #f7f7f5;
  background: rgba(255, 255, 255, 0.08);
  font: inherit;
  font-weight: 800;
}

.document-back-button {
  padding: 0 12px;
}

.document-print-button {
  min-width: 54px;
  padding: 0 12px;
  color: #0b0b0c;
  background: #ffffff;
  border-color: #ffffff;
}

.document-viewer iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #f4f4f5;
}

body.document-viewer-open {
  overflow: hidden;
}

body.document-viewer-open .mobile-bottom-nav,
body.document-viewer-open .global-fab {
  display: none !important;
}

html[data-theme="light"] .document-viewer {
  background: #f5f5f7;
}

html[data-theme="light"] .document-viewer-bar {
  background: rgba(255, 255, 255, 0.88);
  border-bottom-color: rgba(16, 16, 18, 0.1);
}

html[data-theme="light"] .document-viewer-bar strong,
html[data-theme="light"] .document-back-button {
  color: #101012;
}

html[data-theme="light"] .document-viewer-bar span {
  color: rgba(16, 16, 18, 0.52);
}

html[data-theme="light"] .document-back-button {
  background: rgba(16, 16, 18, 0.06);
  border-color: rgba(16, 16, 18, 0.1);
}

html[data-theme="light"] .document-print-button {
  color: #ffffff;
  background: #101012;
  border-color: #101012;
}

@media (max-width: 430px) {
  .document-viewer-bar {
    min-height: calc(60px + env(safe-area-inset-top));
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  }

  .document-back-button,
  .document-print-button {
    min-height: 40px;
    border-radius: 13px;
    font-size: 0.86rem;
  }

  .document-back-button {
    padding: 0 10px;
  }

  .document-print-button {
    min-width: 50px;
    padding: 0 10px;
  }

  .document-viewer-bar strong {
    font-size: 0.86rem;
  }

  .document-viewer-bar span {
    font-size: 0.66rem;
  }
}

/* iPhone 13 Pro overrides must stay last. */
@media (max-width: 430px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    overflow-x: hidden;
  }

  body.auth-required .mobile-bottom-nav,
  body.auth-required .global-fab {
    display: none !important;
  }

  .auth-gate {
    align-items: center;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  }

  .auth-card {
    width: 100%;
    max-width: 364px;
    padding: 18px;
    border-radius: 22px;
  }

  .auth-brand {
    display: flex;
    margin-bottom: 18px;
  }

  .auth-card h1 {
    font-size: 1.7rem;
    line-height: 1.05;
  }

  .auth-card p,
  .auth-form label {
    font-size: 0.9rem;
  }

  .auth-form input {
    min-height: 46px;
    border-radius: 14px;
  }

  .auth-actions .primary-button {
    min-height: 48px;
    border-radius: 14px;
  }

  .app-shell,
  .main-content,
  .page,
  .page.is-visible,
  .panel,
  .tenant-controls,
  .tenant-card-grid,
  .payment-list,
  .contract-list {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .main-content {
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(102px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 10px;
    margin-bottom: 10px;
  }

  body[data-page="tenants"] .topbar {
    display: grid;
  }

  .topbar h1 {
    max-width: 100%;
    font-size: 1.65rem;
    line-height: 1.05;
    overflow-wrap: anywhere;
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  .topbar-actions {
    width: auto;
    display: flex;
    gap: 7px;
    justify-content: flex-end;
  }

  .topbar-actions .icon-button {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border-radius: 14px;
  }

  .theme-toggle {
    font-size: 0;
  }

  .theme-toggle::before {
    content: "◐";
    font-size: 1rem;
  }

  .network-status {
    max-width: 100%;
    margin: 0 0 10px;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .page.is-visible {
    gap: 12px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-card {
    min-height: 104px;
    padding: 13px;
    border-radius: 18px;
  }

  .stat-card strong {
    font-size: 1.05rem;
    line-height: 1.12;
    overflow-wrap: anywhere;
  }

  .stat-card span {
    font-size: 0.72rem;
    line-height: 1.2;
  }

  .panel {
    padding: 14px;
    border-radius: 20px;
  }

  .panel-header,
  .panel-header.with-actions {
    gap: 10px;
    margin-bottom: 12px;
  }

  .panel-header h2,
  .tenant-screen-head h2 {
    font-size: 1.35rem;
    line-height: 1.08;
  }

  .panel-header p,
  .tenant-screen-head p {
    font-size: 0.82rem;
    line-height: 1.35;
  }

  .segmented-control {
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-flow: column;
    border-radius: 16px;
  }

  .segmented-control button {
    min-height: 36px;
    padding: 0 5px;
    border-radius: 12px;
    font-size: 0.72rem;
  }

  .dashboard-grid,
  .two-columns,
  .form-grid,
  .filters-grid,
  .contract-form,
  .mini-stats-grid,
  .dialog-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide,
  .filters-grid .wide,
  .contract-form .wide {
    grid-column: auto;
  }

  input,
  select,
  textarea,
  .soft-input {
    min-height: 46px;
    border-radius: 14px;
    font-size: 16px;
  }

  .tenant-screen-head {
    padding: 4px 0 0;
  }

  .tenant-controls .filters-grid {
    grid-template-columns: minmax(0, 1fr) 50px;
    gap: 9px;
  }

  .search-field input {
    min-height: 52px;
    border-radius: 18px;
  }

  .search-field span {
    bottom: 15px;
  }

  .filter-toggle {
    min-height: 52px;
    border-radius: 17px;
  }

  .quick-filter-row {
    gap: 7px;
    margin-top: 10px;
    padding-bottom: 5px;
  }

  .quick-filter-row button {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 0.8rem;
  }

  .compact-tenant-card {
    min-height: 104px;
    padding: 12px 50px 12px 10px;
    border-radius: 20px;
  }

  .tenant-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .tenant-main strong,
  .tenant-money strong {
    font-size: 0.96rem;
  }

  .tenant-main span,
  .tenant-main small,
  .tenant-money span,
  .tenant-money small,
  .payment-card span,
  .payment-card small {
    font-size: 0.76rem;
  }

  .tenant-action-picker,
  .tenant-action-picker select {
    width: 36px;
    height: 38px;
    border-radius: 14px;
  }

  .payment-group,
  .payment-card,
  .compact-list-card,
  .contract-card,
  .annual-tenant-card {
    border-radius: 18px;
  }

  .payment-group-actions {
    grid-template-columns: 1fr 1fr;
  }

  .payment-calc-summary {
    grid-template-columns: 1fr;
  }

  .inline-expand-panel,
  .form-panel {
    left: 0;
    right: 0;
    border-radius: 24px 24px 0 0;
  }

  .inline-expand-panel.is-open,
  .form-panel:not(.hidden) {
    max-height: 86dvh;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom));
  }

  .mobile-bottom-nav {
    left: 10px;
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    min-height: 66px;
    padding: 7px;
    gap: 3px;
    border-radius: 24px;
  }

  .mobile-bottom-nav button {
    border-radius: 18px;
    gap: 3px;
  }

  .mobile-bottom-nav button span {
    font-size: 1.12rem;
  }

  .mobile-bottom-nav button strong {
    max-width: 100%;
    font-size: 0.58rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .global-fab {
    right: 18px;
    bottom: calc(86px + env(safe-area-inset-bottom));
    width: 54px;
    height: 54px;
    border-radius: 19px;
    font-size: 1.85rem;
  }

  .toast-host {
    left: 12px;
    right: 12px;
    bottom: calc(86px + env(safe-area-inset-bottom));
  }
}

/* iPhone 13 Pro final fit: 390 x 844 CSS px */
@media (max-width: 430px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    overflow-x: hidden;
  }

  body.auth-required .mobile-bottom-nav,
  body.auth-required .global-fab {
    display: none !important;
  }

  .auth-gate {
    align-items: center;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  }

  .auth-card {
    width: 100%;
    max-width: 364px;
    padding: 18px;
    border-radius: 22px;
  }

  .auth-brand {
    display: flex;
    margin-bottom: 18px;
  }

  .auth-card h1 {
    font-size: 1.7rem;
    line-height: 1.05;
  }

  .auth-card p,
  .auth-form label {
    font-size: 0.9rem;
  }

  .auth-form input {
    min-height: 46px;
    border-radius: 14px;
  }

  .auth-actions .primary-button {
    min-height: 48px;
    border-radius: 14px;
  }

  .app-shell,
  .main-content,
  .page,
  .page.is-visible,
  .panel,
  .tenant-controls,
  .tenant-card-grid,
  .payment-list,
  .contract-list {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .main-content {
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(102px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 10px;
    margin-bottom: 10px;
  }

  .topbar h1 {
    max-width: 100%;
    font-size: 1.65rem;
    line-height: 1.05;
    overflow-wrap: anywhere;
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  .topbar-actions {
    width: auto;
    display: flex;
    gap: 7px;
    justify-content: flex-end;
  }

  .topbar-actions .icon-button {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border-radius: 14px;
  }

  .theme-toggle {
    font-size: 0;
  }

  .theme-toggle::before {
    content: "◐";
    font-size: 1rem;
  }

  .network-status {
    max-width: 100%;
    margin: 0 0 10px;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .page.is-visible {
    gap: 12px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-card {
    min-height: 104px;
    padding: 13px;
    border-radius: 18px;
  }

  .stat-card strong {
    font-size: 1.05rem;
    line-height: 1.12;
    overflow-wrap: anywhere;
  }

  .stat-card span {
    font-size: 0.72rem;
    line-height: 1.2;
  }

  .panel {
    padding: 14px;
    border-radius: 20px;
  }

  .panel-header,
  .panel-header.with-actions {
    gap: 10px;
    margin-bottom: 12px;
  }

  .panel-header h2,
  .tenant-screen-head h2 {
    font-size: 1.35rem;
    line-height: 1.08;
  }

  .panel-header p,
  .tenant-screen-head p {
    font-size: 0.82rem;
    line-height: 1.35;
  }

  .segmented-control {
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-flow: column;
    border-radius: 16px;
  }

  .segmented-control button {
    min-height: 36px;
    padding: 0 5px;
    border-radius: 12px;
    font-size: 0.72rem;
  }

  .dashboard-grid,
  .two-columns,
  .form-grid,
  .filters-grid,
  .contract-form,
  .mini-stats-grid,
  .dialog-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide,
  .filters-grid .wide,
  .contract-form .wide {
    grid-column: auto;
  }

  input,
  select,
  textarea,
  .soft-input {
    min-height: 46px;
    border-radius: 14px;
    font-size: 16px;
  }

  .tenant-screen-head {
    padding: 4px 0 0;
  }

  .tenant-controls .filters-grid {
    grid-template-columns: minmax(0, 1fr) 50px;
    gap: 9px;
  }

  .search-field input {
    min-height: 52px;
    border-radius: 18px;
  }

  .search-field span {
    bottom: 15px;
  }

  .filter-toggle {
    min-height: 52px;
    border-radius: 17px;
  }

  .quick-filter-row {
    gap: 7px;
    margin-top: 10px;
    padding-bottom: 5px;
  }

  .quick-filter-row button {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 0.8rem;
  }

  .compact-tenant-card {
    min-height: 104px;
    padding: 12px 50px 12px 10px;
    border-radius: 20px;
  }

  .tenant-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .tenant-main strong,
  .tenant-money strong {
    font-size: 0.96rem;
  }

  .tenant-main span,
  .tenant-main small,
  .tenant-money span,
  .tenant-money small,
  .payment-card span,
  .payment-card small {
    font-size: 0.76rem;
  }

  .tenant-action-picker,
  .tenant-action-picker select {
    width: 36px;
    height: 38px;
    border-radius: 14px;
  }

  .payment-group,
  .payment-card,
  .compact-list-card,
  .contract-card,
  .annual-tenant-card {
    border-radius: 18px;
  }

  .payment-group-actions {
    grid-template-columns: 1fr 1fr;
  }

  .payment-calc-summary {
    grid-template-columns: 1fr;
  }

  .inline-expand-panel,
  .form-panel {
    left: 0;
    right: 0;
    border-radius: 24px 24px 0 0;
  }

  .inline-expand-panel.is-open,
  .form-panel:not(.hidden) {
    max-height: 86dvh;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom));
  }

  .mobile-bottom-nav {
    left: 10px;
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    min-height: 66px;
    padding: 7px;
    gap: 3px;
    border-radius: 24px;
  }

  .mobile-bottom-nav button {
    border-radius: 18px;
    gap: 3px;
  }

  .mobile-bottom-nav button span {
    font-size: 1.12rem;
  }

  .mobile-bottom-nav button strong {
    max-width: 100%;
    font-size: 0.58rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .global-fab {
    right: 18px;
    bottom: calc(86px + env(safe-area-inset-bottom));
    width: 54px;
    height: 54px;
    border-radius: 19px;
    font-size: 1.85rem;
  }

  .toast-host {
    left: 12px;
    right: 12px;
    bottom: calc(86px + env(safe-area-inset-bottom));
  }
}

/* PWA premium shell */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f7;
  --bg-soft: #ffffff;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-solid: #ffffff;
  --border: rgba(18, 18, 20, 0.1);
  --text: #101012;
  --muted: rgba(16, 16, 18, 0.6);
  --muted-2: rgba(16, 16, 18, 0.42);
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.1);
}

html[data-theme="light"] body {
  color: var(--text);
  background:
    radial-gradient(circle at 15% 0%, rgba(248, 113, 113, 0.12), transparent 32rem),
    linear-gradient(180deg, #fbfbfd 0%, #f2f2f7 100%);
}

html[data-theme="light"] .sidebar {
  color: #101012;
  background: rgba(255, 255, 255, 0.78);
  border-color: rgba(16, 16, 18, 0.08);
}

html[data-theme="light"] .nav-item {
  color: rgba(16, 16, 18, 0.58);
}

html[data-theme="light"] .nav-item:hover,
html[data-theme="light"] .secondary-button,
html[data-theme="light"] .icon-button,
html[data-theme="light"] .mini-button,
html[data-theme="light"] .filter-toggle,
html[data-theme="light"] .tenant-action-picker select {
  color: #101012;
  background: rgba(16, 16, 18, 0.06);
}

html[data-theme="light"] .nav-item.is-active,
html[data-theme="light"] .primary-button,
html[data-theme="light"] .round-add-button,
html[data-theme="light"] .segmented-control button.is-active,
html[data-theme="light"] .quick-filter-row button.is-active {
  color: #ffffff;
  background: #101012;
  border-color: #101012;
}

html[data-theme="light"] .panel,
html[data-theme="light"] .stat-card,
html[data-theme="light"] .tenant-controls,
html[data-theme="light"] .tenant-card,
html[data-theme="light"] .archive-card,
html[data-theme="light"] .contract-card,
html[data-theme="light"] .payment-group,
html[data-theme="light"] .payment-card,
html[data-theme="light"] .auth-card,
html[data-theme="light"] dialog {
  color: var(--text);
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(16, 16, 18, 0.1);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.1);
  backdrop-filter: blur(22px);
}

html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea,
html[data-theme="light"] .soft-input,
html[data-theme="light"] .insight-list div,
html[data-theme="light"] .summary-card,
html[data-theme="light"] .compact-item,
html[data-theme="light"] .ai-import-box,
html[data-theme="light"] .toggle-line,
html[data-theme="light"] .payment-calc-summary,
html[data-theme="light"] .mini-stats-grid div,
html[data-theme="light"] .tenant-icon {
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  border-color: rgba(16, 16, 18, 0.1);
}

.app-loader {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  background: #0b0b0c;
  transition: opacity 280ms ease, visibility 280ms ease;
}

.app-loader.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.loader-card {
  display: grid;
  place-items: center;
  gap: 14px;
  color: #f7f7f5;
  font-weight: 850;
  animation: loaderFloat 1100ms ease-in-out infinite alternate;
}

@keyframes loaderFloat {
  from { transform: translateY(3px) scale(0.98); opacity: 0.72; }
  to { transform: translateY(-3px) scale(1); opacity: 1; }
}

.network-status {
  width: fit-content;
  margin: -10px 0 18px auto;
  padding: 7px 11px;
  border: 1px solid rgba(52, 211, 153, 0.22);
  border-radius: 999px;
  color: var(--green);
  background: rgba(52, 211, 153, 0.09);
  font-size: 0.78rem;
  font-weight: 800;
}

body.is-offline .network-status {
  color: #fecdd3;
  border-color: rgba(251, 113, 133, 0.34);
  background: rgba(251, 113, 133, 0.12);
}

.theme-toggle {
  width: auto;
  min-width: 104px;
  padding: 0 14px;
  font-size: 0.82rem;
}

.mobile-bottom-nav,
.global-fab {
  display: none;
}

body.auth-required .mobile-bottom-nav,
body.auth-required .global-fab {
  display: none !important;
}

.pwa-guide {
  display: grid;
  gap: 5px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.045);
}

.pwa-guide strong {
  color: var(--text);
}

.page.is-visible,
.panel,
.stat-card,
.tenant-card,
.payment-card,
.contract-card {
  animation: premiumIn 260ms cubic-bezier(.2, .8, .2, 1) both;
}

@keyframes premiumIn {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (min-width: 721px) {
  .panel,
  .stat-card,
  .tenant-controls,
  .tenant-card,
  .archive-card,
  .contract-card,
  .payment-group,
  .payment-card {
    backdrop-filter: blur(18px);
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  html,
  body {
    overflow-x: hidden;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .main-content {
    min-height: 100dvh;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(106px + env(safe-area-inset-bottom));
  }

  .topbar {
    display: flex;
    margin-bottom: 12px;
  }

  body[data-page="tenants"] .topbar {
    display: flex;
  }

  .topbar h1 {
    font-size: 1.9rem;
  }

  .topbar-actions {
    display: flex;
    align-self: stretch;
    width: 100%;
    justify-content: flex-end;
  }

  .topbar-actions .icon-button {
    display: inline-grid;
  }

  .topbar-actions .secondary-button {
    display: none;
  }

  .network-status {
    margin: -2px 0 12px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-card {
    min-height: 112px;
    border-radius: 22px;
  }

  .panel,
  .tenant-controls,
  .tenant-card,
  .archive-card,
  .contract-card,
  .payment-group,
  .payment-card {
    border-radius: 22px;
    background: rgba(23, 23, 25, 0.76);
    backdrop-filter: blur(22px);
  }

  html[data-theme="light"] .panel,
  html[data-theme="light"] .tenant-controls,
  html[data-theme="light"] .tenant-card,
  html[data-theme="light"] .archive-card,
  html[data-theme="light"] .contract-card,
  html[data-theme="light"] .payment-group,
  html[data-theme="light"] .payment-card {
    background: rgba(255, 255, 255, 0.84);
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 70;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    min-height: 68px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 26px;
    background: rgba(12, 12, 14, 0.78);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(28px);
  }

  html[data-theme="light"] .mobile-bottom-nav {
    background: rgba(255, 255, 255, 0.78);
  }

  .mobile-bottom-nav button {
    min-width: 0;
    border: 0;
    border-radius: 19px;
    color: var(--muted);
    background: transparent;
    display: grid;
    place-items: center;
    gap: 2px;
    padding: 5px 2px;
  }

  .mobile-bottom-nav button span {
    font-size: 1.2rem;
    line-height: 1;
  }

  .mobile-bottom-nav button strong {
    font-size: 0.62rem;
    line-height: 1;
    font-weight: 800;
  }

  .mobile-bottom-nav button.is-active {
    color: #0b0b0c;
    background: #ffffff;
  }

  html[data-theme="light"] .mobile-bottom-nav button.is-active {
    color: #ffffff;
    background: #101012;
  }

  .global-fab {
    position: fixed;
    right: 22px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    z-index: 75;
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 20px;
    color: #0b0b0c;
    background: #ffffff;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
    font-size: 2rem;
    font-weight: 700;
  }

  html[data-theme="light"] .global-fab {
    color: #ffffff;
    background: #101012;
  }

  .inline-expand-panel,
  .form-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    max-height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0 16px;
    border-radius: 28px 28px 0 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    opacity: 0;
    transform: translateY(18px);
    pointer-events: none;
    transition: max-height 300ms ease, opacity 220ms ease, transform 300ms ease, padding 220ms ease;
  }

  .inline-expand-panel.is-open,
  .form-panel:not(.hidden) {
    max-height: min(88dvh, 920px);
    overflow-y: auto;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 0 -22px 70px rgba(0, 0, 0, 0.5);
  }

  .payment-sheet-form,
  #tenantForm {
    padding-top: 14px;
  }

  .sheet-close-button,
  #closeTenantForm {
    border-radius: 14px;
  }

  dialog {
    width: 100vw;
    max-width: none;
    margin: auto 0 0;
    border-radius: 28px 28px 0 0;
  }

  dialog::backdrop {
    background: rgba(0, 0, 0, 0.52);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  background:
    radial-gradient(circle at top left, rgba(255, 179, 35, 0.12), transparent 34rem),
    linear-gradient(145deg, #050506 0%, #111114 50%, #050506 100%);
  color: var(--text);
}

body.auth-required .app-shell {
  filter: blur(8px);
  pointer-events: none;
  user-select: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--border);
  background: rgba(5, 5, 6, 0.78);
  backdrop-filter: blur(24px);
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand,
.topbar,
.panel-header,
.form-actions,
.settings-actions,
.import-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #15100a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 900;
  box-shadow: 0 10px 28px rgba(255, 138, 26, 0.24);
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 0.9rem;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  text-align: left;
  padding: 13px 14px;
  border-radius: var(--radius);
  transition: 180ms ease;
}

.nav-item:hover,
.nav-item.is-active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border);
}

.nav-item.is-active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--muted);
  display: grid;
  gap: 6px;
}

.sidebar-footer strong {
  color: var(--green);
}

.main-content {
  padding: 32px;
  max-width: 1480px;
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
  margin: 0 auto;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}

.eyebrow {
  color: var(--accent);
  margin: 0 0 4px;
  text-transform: uppercase;
  font-size: 0.76rem;
  letter-spacing: 0;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.8rem);
}

h2 {
  margin-bottom: 0;
  font-size: 1.07rem;
}

.topbar-actions,
.panel-header.with-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.page {
  display: none;
  animation: fadeIn 220ms ease both;
}

.page.is-visible {
  display: grid;
  gap: 18px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 22px;
  min-height: 134px;
  display: grid;
  align-content: space-between;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: "";
  position: absolute;
  inset: auto 18px 18px auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 179, 35, 0.16);
}

.stat-card span {
  color: var(--muted);
}

.stat-card strong {
  font-size: clamp(1.45rem, 2vw, 2.35rem);
  line-height: 1.1;
}

.stat-card.income strong {
  color: var(--green);
}

.stat-card.expense strong {
  color: var(--red);
}

.stat-card.net strong {
  color: var(--accent);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.7fr);
  gap: 18px;
}

.two-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.panel {
  padding: 20px;
}

.panel-header {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-header p {
  color: var(--muted);
  margin: 5px 0 0;
  font-size: 0.92rem;
}

.chart-panel canvas {
  width: 100%;
  min-height: 280px;
}

.insight-list,
.summary-stack,
.compact-list {
  display: grid;
  gap: 10px;
}

.insight-list div,
.summary-card,
.compact-item {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  border-radius: var(--radius);
  padding: 14px;
}

.insight-list span,
.summary-card span,
.compact-item span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.insight-list strong,
.summary-card strong,
.compact-item strong {
  display: block;
  margin-top: 5px;
}

.compact-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.compact-item small {
  color: var(--muted-2);
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 999px;
  min-height: 42px;
  padding: 0 18px;
  color: var(--text);
  transition: 180ms ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #14110d;
  font-weight: 850;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border);
}

.danger-button {
  background: rgba(255, 94, 87, 0.13);
  border-color: rgba(255, 94, 87, 0.3);
}

.icon-button {
  width: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border);
  font-size: 1.2rem;
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.drop-zone {
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 9px;
  border: 1px dashed rgba(255, 179, 35, 0.45);
  border-radius: var(--radius);
  background: rgba(255, 179, 35, 0.055);
  padding: 24px;
}

.drop-zone input,
.file-button input {
  display: none;
}

.drop-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 179, 35, 0.13);
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 2rem;
}

.drop-zone small,
.warning {
  color: var(--muted);
}

.ai-import-box {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
}

.ai-import-box h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.ai-import-box p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.warning {
  margin-top: 14px;
  border: 1px solid rgba(255, 179, 35, 0.22);
  background: rgba(255, 179, 35, 0.08);
  padding: 12px 14px;
  border-radius: var(--radius);
}

.hidden {
  display: none !important;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(5, 5, 6, 0.72);
  backdrop-filter: blur(22px);
}

.auth-gate.is-visible {
  display: grid;
}

.auth-card {
  width: min(460px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(18, 18, 21, 0.96);
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-brand {
  margin-bottom: 20px;
}

.auth-card h1 {
  font-size: 2rem;
  margin-bottom: 8px;
}

.auth-card p {
  color: var(--muted);
  margin-bottom: 18px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.setup-box {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid rgba(255, 179, 35, 0.22);
  border-radius: var(--radius);
  background: rgba(255, 179, 35, 0.07);
}

.setup-box h2 {
  font-size: 1rem;
}

.setup-box p {
  margin: 0;
  font-size: 0.88rem;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.local-button {
  width: 100%;
  margin-top: 12px;
}

.import-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.form-grid,
.filters-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.form-grid .wide,
.filters-grid .wide {
  grid-column: span 2;
}

.form-section-title {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0;
  padding-top: 8px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
}

input,
select,
textarea,
.soft-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  padding: 12px 13px;
  outline: none;
}

select[multiple] {
  min-height: 120px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(255, 179, 35, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 179, 35, 0.1);
}

.form-actions {
  justify-content: flex-end;
  gap: 10px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 850;
  background: rgba(255, 255, 255, 0.04);
}

.select-column {
  width: 46px;
  text-align: center;
}

.select-column input {
  min-width: auto;
}

td {
  color: #ecece8;
  font-size: 0.92rem;
}

tr:last-child td {
  border-bottom: 0;
}

td input,
td select {
  min-width: 120px;
  padding: 9px 10px;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  min-height: 32px;
  padding: 0 11px;
}

.mini-button.danger {
  border-color: rgba(255, 94, 87, 0.34);
  color: #ffb2ae;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  white-space: nowrap;
}

.pill.loyer {
  color: var(--green);
}

.pill.dépense {
  color: var(--red);
}

.pill.ignorée {
  color: var(--muted);
}

.settings-actions {
  gap: 10px;
  flex-wrap: wrap;
}

.dashboard-actions .panel-header {
  margin-bottom: 0;
}

.segmented-control {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
}

.segmented-control button {
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
}

.segmented-control button.is-active {
  color: #15100a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 850;
}

.form-panel {
  border-color: rgba(255, 179, 35, 0.28);
  background: rgba(255, 179, 35, 0.055);
}

.form-panel .panel-header {
  margin-bottom: 0;
}

.tenant-screen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tenant-screen-head h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.tenant-screen-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.round-add-button {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: var(--shadow);
  font-size: 2rem;
  line-height: 1;
}

.payment-screen-head {
  margin-bottom: 0;
}

.inline-expand-panel {
  max-height: 0;
  min-height: 0;
  overflow: hidden;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-color: transparent;
  box-shadow: none;
  pointer-events: none;
  transform: translateY(-6px);
  transition:
    max-height 280ms ease,
    opacity 220ms ease,
    padding 220ms ease,
    border-color 220ms ease,
    transform 220ms ease;
}

.inline-expand-panel.is-open {
  max-height: 980px;
  opacity: 1;
  padding-top: 18px;
  padding-bottom: 18px;
  border-color: rgba(255, 179, 35, 0.28);
  box-shadow: var(--shadow);
  pointer-events: auto;
  transform: translateY(0);
}

.sheet-close-button {
  position: absolute;
  right: 16px;
  top: 14px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  font-size: 1.2rem;
  z-index: 1;
}

.payment-sheet-form {
  position: relative;
  padding-top: 8px;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.toggle-line input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

input.is-readonly {
  color: var(--accent);
  border-color: rgba(255, 179, 35, 0.34);
  background: rgba(255, 179, 35, 0.08);
}

.payment-calc-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 179, 35, 0.22);
  border-radius: var(--radius);
  background: rgba(255, 179, 35, 0.075);
}

.payment-calc-summary div {
  min-width: 0;
}

.payment-calc-summary span,
.payment-calc-summary strong {
  display: block;
}

.payment-calc-summary span {
  color: var(--muted);
  font-size: 0.75rem;
}

.payment-calc-summary strong {
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.tenant-controls {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.desktop-tenant-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.desktop-tenant-title p {
  color: var(--muted);
  margin: 5px 0 0;
  font-size: 0.92rem;
}

.search-field {
  position: relative;
}

.search-field span {
  position: absolute;
  left: 14px;
  bottom: 13px;
  color: var(--muted);
  font-size: 1.2rem;
  z-index: 1;
}

.search-field input {
  padding-left: 42px;
}

.filter-toggle {
  display: none;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  font-size: 1.2rem;
}

.tenant-card-grid,
.archive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.quick-filter-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  overflow-x: auto;
  padding-bottom: 3px;
  -webkit-overflow-scrolling: touch;
}

.quick-filter-row button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

.quick-filter-row button span {
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  color: #15100a;
  background: var(--accent);
  font-size: 0.76rem;
  font-weight: 900;
}

.quick-filter-row button[data-filter="late"] span {
  background: var(--red);
  color: #fff;
}

.quick-filter-row button[data-filter="paid"] span {
  background: var(--green);
  color: #09130d;
}

.quick-filter-row button.is-active {
  color: #15100a;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 850;
}

.tenant-card,
.archive-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.045);
  box-shadow: var(--shadow);
}

.compact-tenant-card {
  position: relative;
  min-height: 104px;
  grid-template-columns: 54px minmax(0, 1fr) auto 44px;
  align-items: center;
  gap: 12px;
  padding: 12px;
  cursor: pointer;
}

.tenant-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent);
  font-weight: 900;
  font-size: 1.25rem;
}

.tenant-icon.paid {
  color: var(--green);
  background: rgba(69, 212, 131, 0.08);
}

.tenant-icon.late {
  color: var(--red);
  background: rgba(255, 94, 87, 0.08);
}

.tenant-main,
.tenant-money {
  min-width: 0;
}

.tenant-main strong,
.tenant-money strong {
  font-size: 1rem;
  line-height: 1.15;
}

.tenant-main span,
.tenant-main small,
.tenant-money span,
.tenant-money small {
  color: var(--muted);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tenant-money {
  text-align: right;
}

.status-text.paid {
  color: var(--green);
}

.status-text.partial {
  color: var(--accent);
}

.status-text.late {
  color: var(--red);
}

.action-menu {
  position: relative;
  justify-self: end;
}

.action-menu summary {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.065);
  list-style: none;
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
}

.action-menu summary::-webkit-details-marker {
  display: none;
}

.action-menu > div {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 50;
  width: 174px;
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(16, 16, 19, 0.98);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.5);
}

.action-menu button {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  padding: 0 10px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.action-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.action-menu button.danger {
  color: #ff827c;
}

.table-menu {
  display: inline-grid;
}

.contract-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.contract-list,
.template-editor {
  display: grid;
  gap: 10px;
}

.contract-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.045);
}

.contract-card strong,
.contract-card span,
.contract-card small {
  display: block;
}

.contract-card span,
.contract-card small {
  margin-top: 4px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contract-menu > div {
  width: 190px;
}

.template-editor textarea {
  min-height: 180px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
  line-height: 1.45;
}

.tenant-action-picker {
  position: relative;
  justify-self: end;
  align-self: center;
  width: 42px;
  height: 42px;
  display: block;
}

.tenant-action-picker select {
  width: 42px;
  height: 42px;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  text-align: center;
  font-weight: 900;
  appearance: none;
  -webkit-appearance: none;
}

.tenant-card-head,
.tenant-card-body {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.tenant-card strong,
.tenant-card span,
.archive-card span {
  display: block;
}

.tenant-card span,
.archive-card p {
  color: var(--muted);
  margin: 0;
}

.status-dot {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 850;
}

.status-dot.paid,
.annual-cell.paid {
  background: rgba(69, 212, 131, 0.18);
  color: var(--green);
}

.status-dot.partial,
.annual-cell.partial {
  background: rgba(255, 179, 35, 0.18);
  color: var(--accent);
}

.status-dot.late,
.annual-cell.late {
  background: rgba(255, 94, 87, 0.16);
  color: var(--red);
}

.status-dot.future,
.status-dot.none,
.annual-cell.future,
.annual-cell.none {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.mini-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.mini-stats-grid div {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(255, 255, 255, 0.045);
}

.mini-stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.mini-stats-grid strong {
  display: block;
  margin-top: 5px;
}

.compact-action {
  width: fit-content;
  margin-bottom: 10px;
}

.annual-grid-wrap {
  width: 100%;
  overflow-x: auto;
  touch-action: pan-x pan-y;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.annual-mobile-list {
  display: none;
}

.annual-table {
  min-width: 980px;
}

.annual-table th,
.annual-table td {
  text-align: center;
}

.annual-table td:first-child,
.annual-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
  background: #17171a;
}

.annual-table td:first-child span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.annual-cell {
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 50%;
  font-weight: 900;
}

.annual-month-cell.paid {
  background: rgba(69, 212, 131, 0.16);
  color: var(--green);
}

.annual-month-cell.partial {
  background: rgba(255, 179, 35, 0.16);
  color: var(--accent);
}

.annual-month-cell.late {
  background: rgba(255, 94, 87, 0.14);
  color: var(--red);
}

.annual-month-cell.future,
.annual-month-cell.none {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.rent-toolbar .panel-header {
  margin-bottom: 0;
}

.rent-form-panel {
  border-color: rgba(255, 179, 35, 0.28);
  background: rgba(255, 179, 35, 0.055);
}

.rent-form-panel .panel-header {
  margin-bottom: 0;
}

.add-button {
  white-space: nowrap;
}

.tenant-files {
  display: grid;
  gap: 12px;
}

.tenant-file {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.045);
  overflow: hidden;
}

.tenant-file summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
}

.tenant-file summary::-webkit-details-marker {
  display: none;
}

.tenant-file summary span,
.tenant-file-latest span,
.payment-card span,
.payment-card small {
  color: var(--muted);
}

.tenant-file summary strong,
.tenant-file summary span {
  display: block;
}

.tenant-file-metrics {
  text-align: right;
}

.tenant-file-latest {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 0 14px 14px;
  border-bottom: 1px solid var(--border);
}

.payment-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.payment-group {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
}

.payment-group-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.payment-group-head strong,
.payment-group-head span {
  display: block;
}

.payment-group-head span {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
}

.payment-group-head > div:last-child {
  text-align: right;
}

.payment-group-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.payment-group-list {
  display: grid;
  gap: 8px;
}

.payment-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.12);
}

.compact-list-card {
  min-height: 82px;
  padding: 12px 12px 12px 14px;
}

.payment-card strong,
.payment-card span,
.payment-card small {
  display: block;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toast-host {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  display: grid;
  gap: 10px;
}

.toast {
  width: min(360px, calc(100vw - 40px));
  padding: 14px 16px;
  border-radius: var(--radius);
  background: rgba(24, 24, 27, 0.94);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: toastIn 260ms ease both;
}

.toast.error {
  border-color: rgba(255, 94, 87, 0.34);
}

@keyframes toastIn {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
}

dialog {
  width: min(720px, calc(100vw - 28px));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: var(--shadow);
}

body.modal-open {
  overflow: hidden;
}

dialog.dialog-fallback {
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  max-height: calc(100dvh - 24px);
  overflow: auto;
}

dialog.dialog-fallback::before {
  content: "";
  position: fixed;
  inset: -100vmax;
  z-index: -1;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
}

.dialog-card {
  padding: 20px;
  display: grid;
  gap: 14px;
}

.dialog-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 26px;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 14px;
  }

  .nav-list {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }

  .sidebar-footer {
    display: none;
  }

  .stats-grid,
  .dashboard-grid,
  .two-columns {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 720px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: pan-y;
  }

  body {
    background: linear-gradient(180deg, #050506 0%, #111114 55%, #050506 100%);
  }

  .app-shell {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .main-content {
    height: 100dvh;
    width: 100%;
    max-width: 100vw;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 14px 12px calc(82px + env(safe-area-inset-bottom));
  }

  .sidebar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    top: auto;
    z-index: 30;
    height: 68px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(13, 13, 16, 0.86);
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.46);
    overflow: hidden;
    backdrop-filter: blur(22px);
  }

  .brand {
    display: none;
  }

  .auth-brand {
    display: flex;
  }

  .nav-list {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
    overflow: visible;
  }

  .nav-item {
    min-width: 0;
    min-height: 52px;
    padding: 0 4px;
    border-radius: 999px;
    text-align: center;
    font-size: 0;
    display: grid;
    place-items: center;
    line-height: 1.05;
  }

  .nav-item::before {
    font-size: 1.25rem;
    line-height: 1;
    color: currentColor;
  }

  .nav-item[data-page="dashboard"]::before {
    content: "⌂";
  }

  .nav-item[data-page="tenants"]::before {
    content: "◎";
  }

  .nav-item[data-page="contracts"]::before {
    content: "▤";
  }

  .nav-item[data-page="payments"]::before {
    content: "$";
  }

  .nav-item[data-page="year"]::before {
    content: "▦";
  }

  .nav-item[data-page="expenses"]::before {
    content: "−";
  }

  .nav-item[data-page="transactions"]::before {
    content: "≡";
  }

  .nav-item[data-page="settings"]::before {
    content: "⚙";
  }

  .nav-item.is-active {
    color: #15100a;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent;
    box-shadow: none;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 18px;
  }

  body[data-page="tenants"] .topbar {
    display: none;
  }

  #page-tenants,
  #page-year,
  #page-contracts {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .topbar-actions {
    width: auto;
    align-self: flex-end;
  }

  .topbar-actions .secondary-button,
  .topbar-actions .primary-button {
    display: none;
  }

  .stats-grid,
  .two-columns,
  .form-grid,
  .contract-form,
  .filters-grid,
  .tenant-card-grid,
  .contract-list,
  .archive-grid,
  .mini-stats-grid,
  .dialog-grid {
    grid-template-columns: 1fr;
  }

  .tenant-card-grid {
    display: grid;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: 10px;
  }

  .segmented-control {
    width: 100%;
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tenant-card-head,
  .tenant-card-body {
    display: grid;
    grid-template-columns: 1fr;
  }

  .annual-grid-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: visible;
    border: 0;
  }

  .annual-desktop-table {
    display: none;
  }

  .annual-mobile-list {
    display: grid;
    gap: 10px;
    width: 100%;
    min-width: 0;
  }

  .annual-tenant-card {
    display: grid;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.045);
  }

  .annual-tenant-head {
    display: grid;
    gap: 3px;
  }

  .annual-tenant-head span {
    color: var(--muted);
    font-size: 0.78rem;
  }

  .annual-month-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    width: 100%;
    min-width: 0;
  }

  .annual-month-cell {
    min-width: 0;
    min-height: 46px;
    display: grid;
    place-items: center;
    gap: 1px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
  }

  .annual-month-cell span {
    font-size: 0.68rem;
    color: currentColor;
  }

  .annual-month-cell strong {
    font-size: 0.9rem;
    line-height: 1;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .form-grid .wide,
  .contract-form .wide,
  .filters-grid .wide {
    grid-column: auto;
  }

  .inline-expand-panel.is-open {
    max-height: 1200px;
    padding: 14px;
  }

  .payment-calc-summary {
    grid-template-columns: 1fr 1fr;
  }

  .toggle-line {
    font-size: 0.86rem;
  }

  .contract-card {
    grid-template-columns: minmax(0, 1fr) 42px;
    min-height: 78px;
    padding: 12px;
  }

  .contract-card span,
  .contract-card small {
    white-space: normal;
    line-height: 1.25;
  }

  .template-editor textarea {
    min-height: 150px;
  }

  .panel,
  .stat-card {
    padding: 14px;
  }

  h1 {
    font-size: 2rem;
  }

  .stat-card {
    min-height: 96px;
  }

  .stat-card strong {
    font-size: 1.22rem;
  }

  .stat-card span {
    font-size: 0.78rem;
  }

  .stat-card::after {
    width: 34px;
    height: 34px;
    right: 12px;
    bottom: 12px;
  }

  .page.is-visible {
    gap: 12px;
  }

  .chart-panel canvas {
    min-height: 190px;
    height: 210px;
  }

  .insight-list {
    gap: 8px;
  }

  .insight-list div,
  .summary-card,
  .compact-item {
    padding: 12px;
  }

  .panel-header,
  .panel-header.with-actions,
  .import-actions,
  .form-actions,
  .settings-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-header h2 {
    line-height: 1.25;
  }

  .primary-button,
  .secondary-button,
  .danger-button {
    width: 100%;
    min-height: 46px;
  }

  .icon-button {
    min-width: 42px;
  }

  .drop-zone {
    min-height: 190px;
  }

  .compact-item {
    grid-template-columns: 1fr;
  }

  .quick-filter-row {
    width: 100%;
    max-width: 100%;
    margin: 12px 0 0;
    padding: 0 2px 4px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .quick-filter-row button {
    min-height: 38px;
    padding: 0 13px;
    font-size: 0.88rem;
    background: rgba(255, 255, 255, 0.07);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
  }

  .tenant-screen-head {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 14px 2px 2px;
  }

  .tenant-screen-head h2 {
    font-size: 2.15rem;
    line-height: 1;
  }

  .tenant-screen-head p {
    font-size: 1rem;
  }

  .round-add-button {
    width: 58px;
    height: 58px;
    background: rgba(255, 255, 255, 0.055);
    backdrop-filter: blur(18px);
  }

  .tenant-controls {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .desktop-tenant-title {
    display: none;
  }

  .tenant-controls .filters-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 54px;
    gap: 10px;
    width: 100%;
    min-width: 0;
  }

  .tenant-controls .filters-grid > * {
    min-width: 0;
  }

  .tenant-controls .filters-grid label:not(.search-field) {
    display: none;
  }

  #page-tenants.filters-open .tenant-controls .filters-grid label:not(.search-field) {
    display: grid;
    grid-column: 1 / -1;
  }

  .search-field {
    font-size: 0;
  }

  .search-field input {
    min-height: 58px;
    border-radius: 22px;
    padding-left: 44px;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.075);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  }

  .search-field span {
    bottom: 18px;
  }

  .filter-toggle {
    display: grid;
    place-items: center;
    min-height: 58px;
    border-radius: 20px;
    font-size: 1.35rem;
  }

  .compact-tenant-card {
    position: relative;
    min-height: 108px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    grid-template-columns: 46px minmax(0, 1fr);
    grid-template-areas:
      "icon main"
      "icon money";
    gap: 5px 10px;
    padding: 12px 52px 12px 10px;
    border-radius: 22px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035));
    overflow: visible;
  }

  .tenant-icon {
    grid-area: icon;
    width: 42px;
    height: 42px;
    font-size: 1.12rem;
    border: 2px solid rgba(255, 255, 255, 0.08);
  }

  .tenant-main {
    grid-area: main;
  }

  .tenant-money {
    grid-area: money;
    text-align: left;
  }

  .compact-tenant-card .action-menu,
  .compact-tenant-card .tenant-action-picker {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    align-self: center;
  }

  .tenant-action-picker,
  .tenant-action-picker select {
    width: 34px;
    height: 40px;
  }

  .tenant-main strong,
  .tenant-money strong {
    font-size: 1rem;
  }

  .tenant-main span,
  .tenant-main small,
  .tenant-money span,
  .tenant-money small {
    font-size: 0.78rem;
    max-width: 100%;
  }

  .tenant-money {
    align-self: center;
  }

  .tenant-money strong,
  .tenant-money span,
  .tenant-money small {
    display: inline;
  }

  .tenant-money span {
    margin-left: 4px;
  }

  .tenant-money small {
    display: block;
  }

  .action-menu summary {
    width: 34px;
    height: 40px;
    border-radius: 14px;
  }

  .action-menu > div {
    position: fixed;
    left: 14px;
    right: 14px;
    top: auto;
    bottom: calc(86px + env(safe-area-inset-bottom));
    width: auto;
    max-height: min(360px, 48dvh);
    overflow-y: auto;
    z-index: 80;
    border-radius: 18px;
    padding: 10px;
    background: rgba(14, 14, 17, 0.98);
    backdrop-filter: blur(18px);
  }

  .action-menu button {
    min-height: 46px;
    font-size: 1rem;
    padding: 0 16px;
  }

  .payment-list {
    padding: 0;
  }

  .payment-group {
    padding: 10px;
    border-radius: 16px;
  }

  .payment-group-head {
    grid-template-columns: 1fr;
  }

  .payment-group-head > div:last-child {
    text-align: left;
  }

  .payment-group-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .payment-card,
  .compact-list-card {
    grid-template-columns: minmax(0, 1fr) 38px;
    min-height: 78px;
    padding: 10px 10px 10px 12px;
    text-align: left;
  }

  .payment-card strong {
    font-size: 0.95rem;
  }

  .payment-card span,
  .payment-card small {
    font-size: 0.78rem;
  }

  .table-wrap {
    margin-inline: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  #page-expenses tr {
    position: relative;
    min-height: 82px;
    padding: 10px 54px 10px 12px;
  }

  #page-expenses td {
    display: block;
    grid-template-columns: none;
    border-bottom: 0;
    padding: 2px 0;
  }

  #page-expenses td::before {
    content: "";
    display: none;
  }

  #page-expenses td[data-label="Date"],
  #page-expenses td[data-label="Catégorie"] {
    color: var(--muted);
    font-size: 0.78rem;
  }

  #page-expenses td[data-label="Montant"] {
    position: absolute;
    right: 54px;
    top: 10px;
    text-align: right;
  }

  #page-expenses td[data-label="Actions"] {
    position: absolute;
    right: 10px;
    top: 22px;
  }

  table {
    min-width: 0;
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    display: grid;
    gap: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.045);
  }

  td {
    display: grid;
    grid-template-columns: minmax(92px, 0.42fr) minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding: 11px 0;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.76rem;
    text-transform: uppercase;
    font-weight: 850;
  }

  td:last-child {
    border-bottom: 0;
  }

  td input,
  td select {
    min-width: 0;
    width: 100%;
  }

  td.empty-state {
    display: block;
    text-align: center;
    padding: 18px;
  }

  td.empty-state::before {
    content: "";
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .tenant-file summary,
  .payment-card,
  .tenant-file-latest {
    grid-template-columns: 1fr;
    text-align: left;
  }

  .tenant-file-metrics {
    text-align: left;
  }

  .payment-card .row-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .annual-desktop-table {
    display: none;
  }

  .payment-card,
  .compact-list-card {
    grid-template-columns: minmax(0, 1fr) 38px;
    min-height: 78px;
    padding: 10px 10px 10px 12px;
  }

  #page-expenses tr {
    position: relative;
    min-height: 82px;
    padding: 10px 54px 10px 12px;
  }

  #page-expenses td {
    display: block;
    grid-template-columns: none;
    border-bottom: 0;
    padding: 2px 0;
  }

  #page-expenses td::before {
    content: "";
    display: none;
  }

  #page-expenses td[data-label="Date"],
  #page-expenses td[data-label="Catégorie"] {
    color: var(--muted);
    font-size: 0.78rem;
  }

  #page-expenses td[data-label="Montant"] {
    position: absolute;
    right: 54px;
    top: 10px;
    text-align: right;
  }

  #page-expenses td[data-label="Actions"] {
    position: absolute;
    right: 10px;
    top: 22px;
  }

  .mini-button {
    min-height: 40px;
  }

  .toast-host {
    left: 14px;
    right: 14px;
    bottom: calc(92px + env(safe-area-inset-bottom));
  }

  .toast {
    width: 100%;
  }

  .auth-card {
    padding: 18px;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
  }

  .auth-card h1 {
    font-size: 1.75rem;
  }

  .auth-actions {
    grid-template-columns: 1fr;
  }
}

/* Final visual pass: keep the reference-like premium SaaS treatment after legacy rules. */
body {
  background: linear-gradient(180deg, #0b0b0c 0%, #101012 52%, #0b0b0c 100%);
}

.sidebar {
  background: #050505;
  border-right-color: rgba(255, 255, 255, 0.08);
}

.brand-mark,
.primary-button,
.round-add-button,
.segmented-control button.is-active,
.quick-filter-row button.is-active {
  color: #0b0b0c;
  background: #ffffff;
  border-color: #ffffff;
  box-shadow: none;
}

.brand-mark,
.panel,
.stat-card,
.tenant-controls,
.tenant-card,
.archive-card,
.contract-card,
.payment-group,
.payment-card,
.auth-card,
.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.mini-button,
.round-add-button,
.filter-toggle,
.quick-filter-row button,
.segmented-control,
.segmented-control button,
.tenant-action-picker select,
input,
select,
textarea,
.soft-input,
.server-error {
  border-radius: 8px;
}

.brand span,
.eyebrow {
  color: var(--accent);
}

.nav-item {
  display: flex;
  align-items: center;
  min-height: 46px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.58);
}

.nav-item:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.is-active {
  color: #050505;
  background: #ffffff;
  border-color: #ffffff;
  box-shadow: none;
  font-weight: 800;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
  background: transparent;
}

.sidebar-footer strong {
  color: #ffffff;
}

.panel,
.stat-card,
.tenant-controls,
.tenant-card,
.archive-card,
.contract-card,
.payment-group,
.payment-card,
.auth-card,
dialog {
  background: #171719;
  border-color: rgba(255, 255, 255, 0.11);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.035), 0 16px 42px rgba(0, 0, 0, 0.28);
}

.stat-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02)), #171719;
}

.stat-card::after {
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.14);
}

.secondary-button,
.icon-button,
.mini-button,
.filter-toggle,
.tenant-action-picker select {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.11);
}

.danger-button,
.mini-button.danger {
  color: #fecdd3;
  background: rgba(251, 113, 133, 0.13);
  border-color: rgba(251, 113, 133, 0.32);
}

input,
select,
textarea,
.soft-input {
  background: #101012;
  border-color: rgba(255, 255, 255, 0.12);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(248, 113, 113, 0.72);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.14);
}

.insight-list div,
.summary-card,
.compact-item,
.ai-import-box,
.toggle-line,
.payment-calc-summary,
.mini-stats-grid div,
.tenant-icon {
  background: #101012;
  border-color: rgba(255, 255, 255, 0.1);
}

.server-error {
  margin: -8px 0 18px;
  padding: 13px 15px;
  border: 1px solid rgba(251, 113, 133, 0.42);
  color: #fecdd3;
  background: rgba(251, 113, 133, 0.12);
}

@media (max-width: 720px) {
  body {
    background: #0b0b0c;
  }

  .sidebar {
    background: rgba(5, 5, 5, 0.88);
    border-radius: 8px;
  }

  .nav-item,
  .nav-item.is-active,
  .quick-filter-row button,
  .search-field input,
  .filter-toggle,
  .compact-tenant-card,
  .annual-tenant-card {
    border-radius: 8px;
  }

  .nav-item.is-active {
    color: #050505;
    background: #ffffff;
  }

  .compact-tenant-card {
    background: #171719;
  }
}


/* css/mobile-fixes.css */
/* Final iPhone/PWA fixes loaded after the main stylesheet. */
.mobile-more-trigger,
.mobile-page-menu {
  display: none;
}

/* Mobile UX refresh, loaded last so the app keeps one coherent surface. */
:root {
  --bg: #0f1311;
  --bg-soft: #121816;
  --panel: #171d1b;
  --panel-solid: #171d1b;
  --field: #101512;
  --border: rgba(232, 238, 231, 0.12);
  --border-strong: rgba(232, 238, 231, 0.2);
  --text: #f3f7f2;
  --muted: rgba(243, 247, 242, 0.66);
  --muted-2: rgba(243, 247, 242, 0.42);
  --accent: #38d39f;
  --accent-2: #f2c66d;
  --green: #38d39f;
  --red: #ff7b86;
  --blue: #79b7ff;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
  --radius: 8px;
}

html[data-theme="light"] {
  --bg: #f7f7f2;
  --bg-soft: #eef2ec;
  --panel: #ffffff;
  --panel-solid: #ffffff;
  --field: #f4f6f1;
  --border: rgba(29, 42, 36, 0.12);
  --border-strong: rgba(29, 42, 36, 0.2);
  --text: #16211c;
  --muted: rgba(22, 33, 28, 0.64);
  --muted-2: rgba(22, 33, 28, 0.42);
  --shadow: 0 12px 28px rgba(24, 44, 36, 0.1);
}

* {
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  background: var(--bg);
  color: var(--text);
}

body {
  background:
    linear-gradient(180deg, rgba(56, 211, 159, 0.08), transparent 280px),
    var(--bg);
}

.app-shell {
  min-height: 100dvh;
  background: transparent;
}

.sidebar {
  background: color-mix(in srgb, var(--panel-solid) 88%, #000000 12%);
  border-right: 1px solid var(--border);
}

.brand-mark {
  color: #0b1410;
  background: linear-gradient(135deg, var(--accent), #d9f99d);
}

.brand span,
.eyebrow {
  color: var(--accent);
}

.nav-list {
  gap: 6px;
}

.nav-item {
  gap: 10px;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
}

.nav-icon {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.nav-item.is-active {
  color: #07130e;
  background: var(--accent);
  border-color: transparent;
}

.nav-item.is-active .nav-icon {
  color: #07130e;
  background: rgba(7, 19, 14, 0.08);
}

.main-content {
  max-width: 1440px;
}

.topbar {
  align-items: center;
}

.topbar h1 {
  letter-spacing: 0;
}

.topbar-actions {
  gap: 8px;
}

.theme-toggle {
  font-size: 0;
}

.theme-toggle::before {
  content: "◐";
  font-size: 1rem;
}

.panel,
.stat-card,
.tenant-controls,
.tenant-card,
.archive-card,
.contract-card,
.payment-group,
.payment-card,
.auth-card,
dialog,
.compact-item,
.summary-card,
.mini-stats-grid div,
.insight-list div,
.toggle-line,
.payment-calc-summary,
.ai-import-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel-header,
.panel-header.with-actions {
  align-items: center;
  gap: 12px;
}

.panel-header p,
.tenant-screen-head p,
.desktop-tenant-title p {
  color: var(--muted);
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.mini-button,
.round-add-button,
.filter-toggle,
.quick-filter-row button,
.segmented-control,
.segmented-control button,
.tenant-action-picker select,
input,
select,
textarea,
.soft-input {
  border-radius: var(--radius);
}

.primary-button,
.round-add-button {
  color: #07130e;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(56, 211, 159, 0.18);
}

.primary-button:hover,
.round-add-button:hover {
  filter: brightness(1.04);
}

.secondary-button,
.icon-button,
.mini-button,
.filter-toggle,
.tenant-action-picker select {
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  border-color: var(--border);
}

input,
select,
textarea,
.soft-input {
  min-height: 44px;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--border);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.segmented-control {
  background: var(--field);
  border: 1px solid var(--border);
}

.segmented-control button.is-active,
.quick-filter-row button.is-active {
  color: #07130e;
  background: var(--accent);
  border-color: var(--accent);
}

.stat-card {
  position: relative;
  min-height: 118px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent), var(--panel);
}

.stat-card::after {
  width: 5px;
  inset: 14px auto 14px 14px;
  border-radius: 99px;
  background: var(--accent);
  opacity: 1;
}

.stat-card.expense::after {
  background: var(--red);
}

.stat-card.net::after {
  background: var(--blue);
}

.stat-card span {
  color: var(--muted);
}

.stat-card strong {
  letter-spacing: 0;
}

.tenant-controls {
  padding: 14px;
}

.search-field span {
  color: var(--accent);
}

.quick-filter-row {
  scrollbar-width: none;
}

.quick-filter-row::-webkit-scrollbar {
  display: none;
}

.quick-filter-row button {
  border-color: var(--border);
  color: var(--muted);
  background: var(--field);
}

.quick-filter-row button span {
  margin-left: 6px;
  color: var(--accent-2);
}

.tenant-card-grid {
  gap: 10px;
}

.compact-tenant-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto 42px;
  gap: 12px;
  align-items: center;
  min-height: 96px;
  padding: 12px;
  cursor: pointer;
}

.tenant-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  color: #07130e;
  background: var(--accent);
}

.tenant-icon.late {
  background: var(--red);
}

.tenant-icon.paid {
  background: var(--accent);
}

.tenant-main,
.tenant-money {
  min-width: 0;
}

.tenant-main strong,
.tenant-main span,
.tenant-main small,
.tenant-money strong,
.tenant-money span,
.tenant-money small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tenant-main strong,
.payment-card strong,
.payment-group-head strong {
  color: var(--text);
}

.tenant-main span,
.tenant-main small,
.tenant-money span,
.payment-card span,
.payment-card small,
.payment-group-head span {
  color: var(--muted);
}

.tenant-money {
  text-align: right;
}

.status-text.paid {
  color: var(--green);
}

.status-text.late {
  color: var(--red);
}

.tenant-action-picker,
.tenant-action-picker select {
  width: 38px;
  min-width: 38px;
  height: 38px;
}

.tenant-action-picker select {
  text-align: center;
}

.payment-group {
  padding: 12px;
}

.payment-group-head,
.payment-card {
  gap: 12px;
}

.compact-list-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
  padding: 12px;
  box-shadow: none;
}

.payment-group-actions {
  gap: 8px;
}

.mini-button {
  min-height: 40px;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

th {
  color: var(--muted);
  background: var(--field);
}

td {
  color: var(--text);
}

.network-status {
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  color: color-mix(in srgb, var(--accent) 88%, white);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.server-error,
.warning {
  border-radius: var(--radius);
}

@media (min-width: 721px) {
  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .tenant-card-grid {
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  }
}

@media (max-width: 720px) {
  body {
    background: var(--bg);
  }

  .sidebar {
    display: none;
  }

  .main-content {
    height: 100dvh;
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(96px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overflow-x: hidden;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    grid-template-columns: minmax(0, 1fr) auto;
    margin: calc(-10px - env(safe-area-inset-top)) -10px 10px;
    padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(18px);
  }

  .topbar h1 {
    font-size: 1.45rem;
    line-height: 1.05;
  }

  .eyebrow {
    margin-bottom: 3px;
    font-size: 0.66rem;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions .icon-button {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
  }

  #quickExportJson {
    display: none;
  }

  .page.is-visible {
    gap: 10px;
  }

  .dashboard-actions {
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .dashboard-actions .panel-header.with-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .dashboard-actions .add-button {
    min-height: 46px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat-card {
    min-height: 96px;
    padding: 12px 12px 12px 24px;
  }

  .stat-card strong {
    font-size: 1rem;
    line-height: 1.15;
  }

  .stat-card span {
    font-size: 0.72rem;
    line-height: 1.2;
  }

  .dashboard-grid,
  .two-columns,
  .form-grid,
  .filters-grid,
  .contract-form,
  .mini-stats-grid,
  .dialog-grid {
    grid-template-columns: 1fr;
  }

  .panel,
  .tenant-controls,
  .payment-group {
    padding: 12px;
  }

  .panel-header,
  .panel-header.with-actions {
    display: grid;
    grid-template-columns: 1fr;
    margin-bottom: 10px;
  }

  .form-panel .panel-header.with-actions,
  .inline-expand-panel .panel-header.with-actions {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .form-panel .panel-header.with-actions > .icon-button,
  .inline-expand-panel .panel-header.with-actions > .secondary-button {
    grid-column: 2;
    grid-row: 1;
  }

  .panel-header h2,
  .tenant-screen-head h2 {
    font-size: 1.12rem;
    line-height: 1.1;
  }

  .panel-header p,
  .tenant-screen-head p {
    font-size: 0.78rem;
  }

  .segmented-control {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 3px;
  }

  .segmented-control button {
    min-height: 36px;
    padding: 0 4px;
    font-size: 0.72rem;
  }

  .tenant-screen-head {
    position: sticky;
    top: calc(61px + env(safe-area-inset-top));
    z-index: 30;
    margin: 0 -10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    backdrop-filter: blur(18px);
  }

  .tenant-screen-head .round-add-button {
    width: 44px;
    height: 44px;
  }

  .tenant-controls .filters-grid {
    grid-template-columns: minmax(0, 1fr) 46px;
    gap: 8px;
  }

  .search-field input,
  .filter-toggle {
    min-height: 48px;
  }

  #page-tenants:not(.filters-open) #tenantTypeFilter,
  #page-tenants:not(.filters-open) #tenantStatusFilter,
  #page-tenants:not(.filters-open) .filters-grid > label:not(.search-field) {
    display: none;
  }

  #page-tenants.filters-open .filters-grid {
    grid-template-columns: minmax(0, 1fr) 46px;
  }

  #page-tenants.filters-open .filters-grid > label:not(.search-field) {
    grid-column: 1 / -1;
  }

  .quick-filter-row {
    display: flex;
    gap: 7px;
    margin: 10px -12px 0;
    padding: 0 12px 2px;
    overflow-x: auto;
  }

  .quick-filter-row button {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 0 11px;
    font-size: 0.78rem;
  }

  .compact-tenant-card {
    grid-template-columns: 42px minmax(0, 1fr) 38px;
    grid-template-areas:
      "icon main actions"
      "icon money actions";
    gap: 7px 10px;
    min-height: 92px;
  }

  .tenant-icon {
    grid-area: icon;
    width: 42px;
    height: 42px;
  }

  .tenant-main {
    grid-area: main;
  }

  .tenant-money {
    grid-area: money;
    text-align: left;
  }

  .tenant-action-picker {
    grid-area: actions;
  }

  .tenant-main span,
  .tenant-main small,
  .tenant-money span {
    font-size: 0.72rem;
  }

  .status-text {
    display: inline-block;
    max-width: 100%;
  }

  .inline-expand-panel,
  .form-panel:not(.hidden) {
    position: fixed;
    z-index: 120;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 86dvh;
    padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    overflow-y: auto;
    box-shadow: 0 -18px 42px rgba(0, 0, 0, 0.42);
  }

  .inline-expand-panel:not(.is-open) {
    display: none;
  }

  .sheet-close-button {
    top: 10px;
    right: 10px;
  }

  input,
  select,
  textarea,
  .soft-input {
    min-height: 46px;
    font-size: 16px;
  }

  .form-actions {
    grid-template-columns: 1fr;
  }

  .payment-group-head {
    grid-template-columns: 1fr;
  }

  .payment-group-head > div:last-child {
    text-align: left;
  }

  .payment-group-actions {
    grid-template-columns: 1fr 1fr;
  }

  .mobile-bottom-nav {
    left: 10px;
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 80;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    min-height: 64px;
    padding: 6px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--panel-solid) 88%, transparent);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(22px);
  }

  .mobile-bottom-nav button {
    min-width: 0;
    border-radius: var(--radius);
    color: var(--muted);
    background: transparent;
  }

  .mobile-bottom-nav button span {
    font-size: 1.03rem;
  }

  .mobile-bottom-nav button strong {
    font-size: 0.58rem;
    font-weight: 760;
    letter-spacing: 0;
  }

  .mobile-bottom-nav button.is-active {
    color: #07130e;
    background: var(--accent);
  }

  .global-fab {
    right: 18px;
    bottom: calc(84px + env(safe-area-inset-bottom));
    z-index: 78;
    width: 52px;
    height: 52px;
    border-radius: var(--radius);
    color: #07130e;
    background: var(--accent);
    box-shadow: 0 14px 28px rgba(56, 211, 159, 0.26);
  }

  body.sheet-open .global-fab {
    display: none;
  }

  .mobile-page-menu-sheet {
    left: 10px;
    right: 10px;
    bottom: calc(82px + env(safe-area-inset-bottom));
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--panel-solid) 92%, transparent);
  }

  .mobile-page-menu-head button,
  .mobile-page-menu-grid button,
  .mobile-page-menu-grid button span {
    border-radius: var(--radius);
  }

  .mobile-page-menu-grid button span {
    color: #07130e;
    background: var(--accent);
  }

  .toast-host {
    bottom: calc(84px + env(safe-area-inset-bottom));
  }

  .auth-card {
    border-radius: var(--radius);
  }
}

@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .mobile-bottom-nav button strong {
    display: none;
  }
}

body.document-viewer-open .mobile-more-trigger,
body.document-viewer-open .mobile-bottom-nav,
body.document-viewer-open .global-fab,
body.mobile-menu-open .global-fab {
  display: none !important;
}

@media (max-width: 430px) {
  .mobile-more-trigger {
    display: inline-grid;
  }

  body.auth-required .mobile-more-trigger {
    display: none !important;
  }

  .mobile-page-menu {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: block;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 220ms ease, visibility 220ms ease;
  }

  .mobile-page-menu.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .mobile-page-menu-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(8px);
  }

  .mobile-page-menu-sheet {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: calc(86px + env(safe-area-inset-bottom));
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: rgba(18, 18, 20, 0.94);
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.52);
    backdrop-filter: blur(28px);
    transform: translateY(16px) scale(0.98);
    transition: transform 240ms ease;
  }

  .mobile-page-menu.is-open .mobile-page-menu-sheet {
    transform: translateY(0) scale(1);
  }

  html[data-theme="light"] .mobile-page-menu-sheet {
    background: rgba(255, 255, 255, 0.94);
  }

  .mobile-page-menu-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 40px;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
  }

  .mobile-page-menu-head strong,
  .mobile-page-menu-head span {
    display: block;
  }

  .mobile-page-menu-head span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.78rem;
  }

  .mobile-page-menu-head button {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
    font: inherit;
    font-size: 1.2rem;
  }

  .mobile-page-menu-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-page-menu-grid button {
    min-height: 58px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: 9px;
    border: 1px solid var(--border);
    border-radius: 18px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    text-align: left;
    font: inherit;
    padding: 0 12px;
  }

  .mobile-page-menu-grid button span {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: #0b0b0c;
    background: #ffffff;
    font-size: 1rem;
  }

  html[data-theme="light"] .mobile-page-menu-grid button span {
    color: #ffffff;
    background: #101012;
  }

  .mobile-page-menu-grid button strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.86rem;
  }
}

/* Apple-style app navigation refresh. */
:root {
  --ios-blue: #0a84ff;
  --ios-blue-soft: rgba(10, 132, 255, 0.16);
  --ios-material: rgba(28, 28, 30, 0.74);
  --ios-material-strong: rgba(36, 36, 38, 0.86);
  --ios-separator: rgba(255, 255, 255, 0.14);
}

html[data-theme="light"] {
  --ios-blue: #007aff;
  --ios-blue-soft: rgba(0, 122, 255, 0.12);
  --ios-material: rgba(248, 248, 248, 0.76);
  --ios-material-strong: rgba(255, 255, 255, 0.9);
  --ios-separator: rgba(60, 60, 67, 0.18);
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.nav-icon svg,
.tab-icon svg,
.page-menu-icon svg,
.mobile-more-trigger svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-icon {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.045);
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.nav-item.is-active {
  color: var(--text);
  background: rgba(10, 132, 255, 0.14);
  border-color: rgba(10, 132, 255, 0.24);
}

.nav-item.is-active .nav-icon {
  color: var(--ios-blue);
  background: var(--ios-blue-soft);
}

.mobile-more-trigger svg {
  width: 21px;
  height: 21px;
}

@media (max-width: 720px) {
  .mobile-bottom-nav {
    left: 0;
    right: 0;
    bottom: 0;
    min-height: calc(64px + env(safe-area-inset-bottom));
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-color: var(--ios-separator);
    border-radius: 0;
    background: var(--ios-material);
    box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(30px) saturate(1.8);
  }

  .mobile-bottom-nav button {
    min-height: 50px;
    display: grid;
    grid-template-rows: 29px 15px;
    align-content: center;
    justify-items: center;
    gap: 1px;
    padding: 4px 0 2px;
    border: 0;
    border-radius: 12px;
    color: rgba(235, 235, 245, 0.58);
    background: transparent;
  }

  html[data-theme="light"] .mobile-bottom-nav button {
    color: rgba(60, 60, 67, 0.62);
  }

  .mobile-bottom-nav button.is-active {
    color: var(--ios-blue);
    background: transparent;
  }

  .tab-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    transition: color 180ms ease, background 180ms ease, transform 180ms ease;
  }

  .tab-icon svg {
    width: 23px;
    height: 23px;
    stroke-width: 1.85;
  }

  .mobile-bottom-nav button.is-active .tab-icon {
    background: var(--ios-blue-soft);
    transform: translateY(-1px);
  }

  .mobile-bottom-nav button strong {
    max-width: 100%;
    color: currentColor;
    font-size: 0.62rem;
    font-weight: 650;
    line-height: 1;
    letter-spacing: 0;
  }

  .global-fab {
    bottom: calc(82px + env(safe-area-inset-bottom));
    border-radius: 18px;
    color: #ffffff;
    background: var(--ios-blue);
    box-shadow: 0 12px 26px rgba(10, 132, 255, 0.34);
  }

  .mobile-page-menu-backdrop {
    background: rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(10px);
  }

  .mobile-page-menu-sheet {
    left: 12px;
    right: 12px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    padding: 14px;
    border: 1px solid var(--ios-separator);
    border-radius: 28px;
    background: var(--ios-material-strong);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
    backdrop-filter: blur(34px) saturate(1.8);
  }

  .mobile-page-menu-head button {
    border-radius: 50%;
    color: var(--text);
    background: rgba(120, 120, 128, 0.18);
    border-color: transparent;
  }

  .mobile-page-menu-grid {
    gap: 10px;
  }

  .mobile-page-menu-grid button {
    min-height: 64px;
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
    border: 0;
    border-radius: 18px;
    color: var(--text);
    background: rgba(120, 120, 128, 0.13);
    padding: 0 12px;
  }

  .mobile-page-menu-grid button.is-active {
    background: var(--ios-blue-soft);
  }

  .page-menu-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    color: var(--ios-blue);
    background: rgba(10, 132, 255, 0.14);
  }

  .page-menu-icon svg {
    width: 22px;
    height: 22px;
  }

  .mobile-page-menu-grid button.is-active .page-menu-icon {
    color: #ffffff;
    background: var(--ios-blue);
  }

  .mobile-page-menu-grid button strong {
    font-size: 0.9rem;
    font-weight: 650;
  }

  .topbar-actions .icon-button {
    color: var(--text);
    background: rgba(120, 120, 128, 0.18);
    border-color: transparent;
    backdrop-filter: blur(18px);
  }
}

@media (max-width: 380px) {
  .mobile-bottom-nav button strong {
    display: block;
    font-size: 0.55rem;
  }
}

@media (max-width: 720px) {
  .mobile-page-menu-grid button .page-menu-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    color: var(--ios-blue);
    background: var(--ios-blue-soft);
    font-size: 1rem;
  }

  .mobile-page-menu-grid button .page-menu-icon svg {
    width: 22px;
    height: 22px;
  }

  .mobile-page-menu-grid button.is-active .page-menu-icon {
    color: #ffffff;
    background: var(--ios-blue);
  }
}

/* Keep Arabic names and Latin amounts from reordering each other. */
.money-value,
.metric-money {
  direction: ltr;
  unicode-bidi: isolate;
  white-space: nowrap;
}

.metric-line {
  display: grid;
  max-width: 100%;
  gap: 2px;
  direction: ltr;
  unicode-bidi: isolate;
}

.insight-list strong .metric-line,
.insight-list strong .metric-name,
.insight-list strong .metric-money {
  color: inherit;
  font: inherit;
}

.insight-list strong .metric-name {
  display: inline;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: auto;
  unicode-bidi: isolate;
}

.insight-list strong .metric-money {
  display: block;
}

.compact-item bdi {
  direction: auto;
  unicode-bidi: isolate;
}

.compact-item .compact-subtitle,
.compact-item .money-value {
  direction: ltr;
  unicode-bidi: isolate;
}

/* Navigation ownership: desktop/tablet uses the sidebar, mobile uses the bottom bar. */
@media (min-width: 721px) {
  .app-shell {
    display: grid;
    grid-template-columns: 270px minmax(0, 1fr);
    min-height: 100dvh;
    overflow-x: hidden;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    width: 270px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 28px;
    overflow: hidden;
    padding: 22px 18px;
    border-right: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 0;
  }

  .sidebar .brand {
    display: flex;
  }

  .nav-list {
    width: 100%;
    display: grid;
    grid-auto-flow: row;
    grid-template-columns: 1fr;
    grid-auto-columns: auto;
    gap: 8px;
    overflow: visible;
  }

  .nav-item {
    width: 100%;
    min-width: 0;
    justify-content: flex-start;
    padding: 0 14px;
  }

  .sidebar-footer {
    display: grid;
    margin-top: auto;
  }

  .mobile-bottom-nav,
  .mobile-more-trigger,
  .mobile-page-menu,
  #mobileMoreTab {
    display: none !important;
  }
}

@media (max-width: 720px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    overscroll-behavior-y: auto;
  }

  .sidebar {
    display: none !important;
  }

  .mobile-more-trigger {
    display: none !important;
  }

  .mobile-bottom-nav {
    display: grid !important;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .main-content {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(88px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: static;
    z-index: auto;
    margin: 0 0 12px;
    padding: 0;
    border-bottom: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .tenant-screen-head {
    position: static;
    z-index: auto;
    margin: 0;
    padding: 0;
    border-bottom: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .payment-screen-head {
    align-items: center;
  }

  .round-add-button {
    width: 46px;
    height: 46px;
    min-width: 46px;
    min-height: 46px;
    border-radius: 16px;
    font-size: 1.65rem;
    line-height: 1;
  }

  .dashboard-actions .add-button {
    min-height: 48px;
    justify-content: center;
    font-size: 1rem;
    border-radius: 16px;
  }

  .global-fab {
    display: none !important;
  }

  #mobileMoreTab {
    color: rgba(235, 235, 245, 0.58);
  }

  html[data-theme="light"] #mobileMoreTab {
    color: rgba(60, 60, 67, 0.62);
  }

  body.mobile-menu-open #mobileMoreTab,
  #mobileMoreTab.is-active {
    color: var(--ios-blue);
  }

  body.mobile-menu-open #mobileMoreTab .tab-icon {
    background: var(--ios-blue-soft);
  }
}


/* css/red-invoice-theme.css */
/* RED Invoice direction: professional light dashboard, black sidebar, compact mobile nav. */
:root,
html[data-theme="dark"],
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --bg-soft: #eceff3;
  --panel: #ffffff;
  --panel-solid: #ffffff;
  --field: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --accent: #111827;
  --accent-2: #374151;
  --green: #16a34a;
  --red: #dc2626;
  --blue: #2563eb;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
  --radius: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
  background: var(--bg) !important;
  color: var(--text);
}

body {
  background: var(--bg) !important;
}

.app-shell {
  background: var(--bg);
}

.sidebar {
  color: #f9fafb;
  background: #0b0d10 !important;
  border-right: 0 !important;
  box-shadow: none !important;
}

.brand {
  padding: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: #111827;
  background: #ffffff !important;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: none !important;
}

.brand strong {
  color: #ffffff;
}

.brand span,
.sidebar-footer span {
  color: rgba(255, 255, 255, 0.56) !important;
}

.nav-list {
  gap: 6px;
}

.nav-item {
  min-height: 42px;
  gap: 10px;
  color: rgba(255, 255, 255, 0.66) !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: 10px !important;
  box-shadow: none !important;
}

.nav-item:hover {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.08) !important;
}

.nav-item.is-active {
  color: #111827 !important;
  background: #ffffff !important;
  font-weight: 800;
}

.nav-icon {
  width: 28px;
  height: 28px;
  color: currentColor !important;
  background: rgba(255, 255, 255, 0.08) !important;
  border-radius: 9px;
}

.nav-item.is-active .nav-icon {
  color: #111827 !important;
  background: #f3f4f6 !important;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.12) !important;
  background: transparent !important;
  box-shadow: none !important;
}

.sidebar-footer strong {
  color: #ffffff !important;
}

.main-content {
  max-width: 1500px;
  padding: 28px;
}

.page,
.page.is-visible {
  animation: none !important;
  transform: none !important;
}

.topbar {
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--muted) !important;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1 {
  color: var(--text);
  font-size: clamp(2rem, 4vw, 3.4rem);
  font-weight: 800;
  letter-spacing: 0;
}

h2 {
  color: var(--text);
  font-weight: 800;
}

.panel,
.stat-card,
.tenant-controls,
.tenant-card,
.archive-card,
.contract-card,
.payment-group,
.payment-card,
.auth-card,
.summary-card,
.compact-item,
.insight-list div,
.mini-stats-grid div,
.table-wrap,
dialog {
  color: var(--text);
  background: #ffffff !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
}

.panel {
  padding: 18px;
}

.panel-header,
.panel-header.with-actions {
  gap: 12px;
}

.panel-header p,
.tenant-screen-head p,
.compact-item span,
.payment-card span,
.payment-card small,
.payment-group-head span,
.insight-list span,
.summary-card span,
.stat-card span {
  color: var(--muted) !important;
}

.stat-card {
  min-height: 108px;
  padding: 16px 16px 16px 22px;
  background: #ffffff !important;
}

.stat-card::after {
  width: 4px;
  inset: 16px auto 16px 12px;
  border-radius: 999px;
  background: #111827 !important;
  opacity: 1;
}

.stat-card.income::after {
  background: var(--green) !important;
}

.stat-card.expense::after {
  background: #f87171 !important;
}

.stat-card.net::after {
  background: var(--blue) !important;
}

.stat-card strong,
.compact-item strong,
.payment-card strong,
.payment-group-head strong,
.insight-list strong,
.summary-card strong {
  color: var(--text) !important;
}

.stat-card.income strong {
  color: var(--green) !important;
}

.stat-card.expense strong {
  color: var(--red) !important;
}

.stat-card.net strong {
  color: var(--blue) !important;
}

.primary-button,
.round-add-button,
.add-button {
  color: #ffffff !important;
  background: #111827 !important;
  border: 1px solid #111827 !important;
  border-radius: 10px !important;
  box-shadow: none !important;
  font-weight: 800;
}

.secondary-button,
.icon-button,
.mini-button,
.filter-toggle,
.tenant-action-picker select {
  color: #111827 !important;
  background: #ffffff !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: 10px !important;
  box-shadow: none !important;
}

.danger-button,
.mini-button.danger {
  color: #991b1b !important;
  background: #fef2f2 !important;
  border-color: #fecaca !important;
}

input,
select,
textarea,
.soft-input {
  color: var(--text) !important;
  background: #ffffff !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: 10px !important;
  box-shadow: none !important;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #111827 !important;
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.12) !important;
}

.segmented-control,
.quick-filter-row button {
  background: #f3f4f6 !important;
  border: 1px solid var(--border) !important;
  border-radius: 999px !important;
}

.segmented-control button,
.quick-filter-row button {
  color: var(--muted) !important;
}

.segmented-control button.is-active,
.quick-filter-row button.is-active {
  color: #ffffff !important;
  background: #111827 !important;
  border-color: #111827 !important;
}

.network-status {
  width: fit-content;
  color: #166534 !important;
  background: #f0fdf4 !important;
  border: 1px solid #bbf7d0 !important;
  border-radius: 999px !important;
  box-shadow: none !important;
}

.server-error,
.warning {
  color: #991b1b !important;
  background: #fef2f2 !important;
  border: 1px solid #fecaca !important;
}

.tenant-icon {
  color: #111827 !important;
  background: #f3f4f6 !important;
  border: 1px solid var(--border) !important;
}

.status-text.paid {
  color: var(--green) !important;
}

.status-text.late {
  color: var(--red) !important;
}

.table-wrap {
  overflow: hidden;
}

th {
  color: #4b5563 !important;
  background: #f9fafb !important;
}

td {
  color: var(--text) !important;
}

.toast {
  color: #ffffff;
  background: #111827;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(17, 24, 39, 0.18);
}

.toast.error {
  background: #b91c1c;
}

.app-loader {
  background: #f4f5f7 !important;
}

.loader-card {
  color: #111827;
}

.mobile-top-nav {
  display: none;
}

.mobile-bottom-nav,
.mobile-page-menu,
.mobile-more-trigger,
.global-fab {
  display: none !important;
}

#paymentFormPanel:not(.is-open) {
  display: none !important;
}

#tenantFormPanel.hidden {
  display: none !important;
}

#tenantFormPanel:not(.hidden),
#paymentFormPanel.is-open {
  position: fixed;
  z-index: 10010 !important;
  left: 50%;
  top: 50%;
  width: min(760px, calc(100vw - 48px));
  max-height: min(82dvh, 760px);
  overflow-y: auto;
  transform: translate(-50%, -50%) !important;
  padding: 22px;
  background: #ffffff !important;
  box-shadow: 0 28px 90px rgba(17, 24, 39, 0.28) !important;
  pointer-events: auto !important;
}

body.sheet-open {
  overflow: hidden !important;
}

body.sheet-open::before {
  content: none !important;
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(17, 24, 39, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.modal-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.sheet-close-button {
  color: #111827;
  background: #f3f4f6;
  border: 1px solid var(--border);
}

#paymentForm .panel-header.with-actions,
#tenantForm .panel-header.with-actions {
  padding-right: 52px;
}

@media (min-width: 721px) {
  .app-shell {
    grid-template-columns: 270px minmax(0, 1fr) !important;
  }

  .sidebar {
    position: sticky !important;
    top: 0 !important;
    height: 100dvh !important;
    display: flex !important;
  }

  .mobile-top-nav {
    display: none !important;
  }
}

@media (max-width: 720px) {
  html,
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app-shell {
    display: block !important;
    min-height: 100dvh;
    overflow: visible !important;
  }

  .main-content {
    padding: 18px 14px 28px;
    overflow: visible !important;
  }

  .sidebar,
  .mobile-bottom-nav,
  .mobile-page-menu,
  .global-fab {
    display: none !important;
  }

  .topbar {
    position: static !important;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    margin: 0 0 12px;
    padding: 0;
    border: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .topbar h1 {
    font-size: 1.65rem;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions .icon-button {
    width: 40px;
    height: 40px;
  }

  #quickExportJson {
    display: none !important;
  }

  .mobile-top-nav {
    display: flex;
    gap: 8px;
    margin: 0 -14px 14px;
    padding: 0 14px 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .mobile-top-nav::-webkit-scrollbar {
    display: none;
  }

  .mobile-top-nav button {
    flex: 0 0 auto;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: #4b5563;
    background: #ffffff;
    font: inherit;
    font-weight: 750;
    box-shadow: 0 3px 10px rgba(17, 24, 39, 0.04);
  }

  .mobile-top-nav button.is-active {
    color: #ffffff;
    background: #111827;
    border-color: #111827;
  }

  .mobile-top-nav .tab-icon {
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: transparent;
  }

  .mobile-top-nav .tab-icon svg {
    width: 18px;
    height: 18px;
  }

  .mobile-top-nav strong {
    font-size: 0.84rem;
    line-height: 1;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .panel,
  .stat-card,
  .tenant-controls,
  .tenant-card,
  .payment-group,
  .payment-card {
    border-radius: 14px !important;
  }

  .tenant-screen-head {
    position: static !important;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .round-add-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px !important;
  }

  .dashboard-actions {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .dashboard-actions .panel-header.with-actions {
    grid-template-columns: 1fr;
  }

  .dashboard-actions .add-button {
    width: 100%;
    min-height: 46px;
  }

  #tenantFormPanel:not(.hidden),
  #paymentFormPanel.is-open {
    inset: 12px !important;
    left: 12px !important;
    right: 12px !important;
    bottom: 12px !important;
    top: 12px !important;
    width: auto !important;
    max-height: none !important;
    height: auto !important;
    transform: none !important;
    border-radius: 20px !important;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 24px 70px rgba(17, 24, 39, 0.28) !important;
    -webkit-overflow-scrolling: touch;
  }

  #paymentForm .panel-header.with-actions,
  #tenantForm .panel-header.with-actions {
    grid-template-columns: 1fr;
    padding-right: 48px;
  }

  #resetPaymentForm {
    display: none !important;
  }
}

@media (max-width: 390px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* iPhone safe-area correction after the SPA refactor.
   This block intentionally lives last because older mobile layers are concatenated above. */
@supports (padding-top: env(safe-area-inset-top)) {
  :root {
    --iphone-safe-top: env(safe-area-inset-top, 0px);
    --iphone-safe-bottom: env(safe-area-inset-bottom, 0px);
  }
}

@media (max-width: 720px) {
  html {
    min-height: 100%;
    background: var(--bg);
  }

  body {
    min-height: 100dvh;
    padding-top: 0;
    background: var(--bg);
    overflow-x: hidden;
  }

  .app-shell {
    min-height: 100dvh;
    padding-top: 0 !important;
  }

  .main-content {
    min-height: 100dvh;
    padding: calc(18px + env(safe-area-inset-top, 0px)) 14px calc(30px + env(safe-area-inset-bottom, 0px)) !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }

  .topbar {
    position: relative !important;
    display: grid !important;
    top: auto !important;
    z-index: 20;
    margin: 0 0 14px !important;
    padding: 0 !important;
  }

  body[data-page="tenants"] .topbar,
  body[data-page="payments"] .topbar,
  body[data-page="settings"] .topbar {
    margin-top: 0 !important;
  }

  #page-tenants,
  #page-payments,
  #page-settings,
  #page-dashboard {
    scroll-margin-top: calc(18px + env(safe-area-inset-top, 0px));
  }

  .tenant-screen-head {
    position: relative !important;
    top: auto !important;
    z-index: 10;
    margin: 0 0 12px !important;
    padding: 0 !important;
  }

  body:not(.auth-required) .mobile-bottom-nav,
  body:not(.auth-required) .global-fab,
  body.auth-required .mobile-bottom-nav,
  body.auth-required .global-fab {
    display: none !important;
  }

  #tenantFormPanel:not(.hidden),
  #paymentFormPanel.is-open,
  .form-panel:not(.hidden),
  .inline-expand-panel.is-open {
    top: calc(14px + env(safe-area-inset-top, 0px)) !important;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    max-height: calc(100dvh - 28px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
  }

  .auth-gate {
    padding: calc(18px + env(safe-area-inset-top, 0px)) 14px calc(18px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

.rent-increase-fields {
  display: grid;
  grid-template-columns: 1fr minmax(120px, 180px);
  gap: 10px 12px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.rent-increase-fields legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.rent-increase-fields .rent-increase-toggle,
.rent-increase-fields p {
  grid-column: 1 / -1;
}

.rent-increase-fields p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.rent-increase-fields.is-enabled {
  border-color: rgba(10, 132, 255, 0.35);
  background: rgba(10, 132, 255, 0.08);
}

.account-form {
  margin-top: 10px;
  grid-template-columns: minmax(160px, 240px) minmax(180px, 260px) auto;
  align-items: end;
  gap: 10px;
}

.account-form + .account-form {
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

#accountSettingsPanel {
  padding: 16px;
}

#accountSettingsPanel .panel-header {
  margin-bottom: 8px;
}

#accountSettingsPanel .panel-header h2 {
  font-size: 1rem;
}

#accountSettingsPanel .panel-header p {
  font-size: 0.82rem;
}

#accountSettingsPanel input {
  min-height: 40px;
  padding: 8px 12px;
}

#accountSettingsPanel .form-actions {
  width: auto;
  display: flex;
  align-items: end;
  gap: 8px;
  grid-column: auto;
}

#accountSettingsPanel button {
  min-height: 40px;
  white-space: nowrap;
}

.auth-recovery-panel {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.auth-recovery-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 800;
}

.auth-recovery-panel .auth-form {
  margin-top: 12px;
}

#accountMessage[data-type="success"] {
  color: #15803d !important;
  border-color: rgba(34, 197, 94, 0.4) !important;
  background: rgba(34, 197, 94, 0.12) !important;
}

#accountMessage[data-type="error"] {
  color: #991b1b !important;
  border-color: rgba(239, 68, 68, 0.4) !important;
  background: rgba(239, 68, 68, 0.12) !important;
}

@media (max-width: 720px) {
  .rent-increase-fields {
    grid-template-columns: 1fr;
  }

  .account-form {
    grid-template-columns: 1fr;
  }

  #accountSettingsPanel .form-actions {
    width: 100%;
    grid-column: 1;
  }
}

.ai-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.ai-tabs button {
  border: 0;
  border-radius: 11px;
  padding: 9px 13px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  white-space: nowrap;
}

.ai-tabs button.is-active {
  color: var(--button-text);
  background: var(--text);
}

.ai-tab-page {
  display: none;
}

.ai-tab-page.is-visible {
  display: block;
}

.ai-upload-box {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.ai-upload-box span,
.ai-history-card small {
  color: var(--muted);
  font-weight: 700;
}

.ai-message {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 12px;
  font-weight: 800;
}

.ai-message[data-type="success"],
.ai-check.is-ok {
  color: #15803d;
  border: 1px solid rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.12);
}

.ai-message[data-type="error"],
.ai-check.is-warning {
  color: #991b1b;
  border: 1px solid rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.12);
}

.ai-message[data-type="info"] {
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--panel-soft);
}

.ai-check {
  padding: 11px 13px;
  border-radius: 12px;
  font-weight: 800;
}

.ai-history-list {
  display: grid;
  gap: 10px;
}

.ai-history-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-soft);
}

.ai-history-card div {
  display: grid;
  gap: 4px;
}

.ai-history-card div span {
  color: var(--muted);
}

.ai-history-card small {
  grid-column: 1 / -1;
}

.ai-history-card .ai-history-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.ai-table-wrap input,
.ai-table-wrap select {
  min-width: 120px;
}

.ai-bank-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.ai-bank-summary .wide {
  grid-column: span 3;
}

.ai-insight-panel {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-soft);
}

.ai-insight-panel p {
  margin: 0;
  white-space: pre-wrap;
}

.ai-insight-panel ul {
  margin: 0;
  padding-left: 18px;
}

.ai-assistant-panel {
  display: grid;
  gap: 14px;
}

.ai-chat-messages {
  display: grid;
  gap: 10px;
}

.ai-chat-message {
  max-width: 860px;
  display: grid;
  gap: 5px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-soft);
}

.ai-chat-message.is-user {
  justify-self: end;
  background: rgba(255, 255, 255, 0.08);
}

.ai-chat-message strong {
  font-size: 0.78rem;
  color: var(--muted);
}

.ai-chat-message p {
  margin: 0;
  white-space: pre-wrap;
}

.ai-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.ai-chat-form label {
  display: grid;
  gap: 8px;
}

@media (max-width: 720px) {
  .ai-hero-panel .panel-header.with-actions {
    align-items: stretch;
  }

  .ai-tabs {
    width: 100%;
  }

  .ai-tabs button {
    flex: 0 0 auto;
  }

  .ai-history-card {
    grid-template-columns: 1fr;
  }

  .ai-bank-summary {
    grid-template-columns: 1fr;
  }

  .ai-bank-summary .wide {
    grid-column: auto;
  }

  .ai-chat-form {
    grid-template-columns: 1fr;
  }
}

/* v27 theme and contrast guardrails */
:root {
  --button-text: #08090b;
  --field-bg: #111216;
  --field-text: #f7f7f5;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0c;
  --bg-soft: #111216;
  --panel: #171719;
  --panel-solid: #171719;
  --panel-soft: #202024;
  --border: rgba(255, 255, 255, 0.12);
  --text: #f7f7f5;
  --muted: rgba(247, 247, 245, 0.68);
  --muted-2: rgba(247, 247, 245, 0.48);
  --field-bg: #0f1014;
  --field-text: #f7f7f5;
  --button-text: #09090b;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --bg-soft: #e9edf2;
  --panel: #ffffff;
  --panel-solid: #ffffff;
  --panel-soft: #f7f9fc;
  --border: rgba(17, 24, 39, 0.14);
  --text: #101828;
  --muted: #667085;
  --muted-2: #8a94a6;
  --field-bg: #ffffff;
  --field-text: #101828;
  --button-text: #ffffff;
}

html[data-theme="dark"] body,
html[data-theme="light"] body {
  color: var(--text);
  background: var(--bg);
}

html[data-theme="light"] body {
  background: linear-gradient(180deg, #f7f9fc 0%, #edf1f6 100%);
}

html[data-theme="dark"] body {
  background: linear-gradient(180deg, #0b0b0c 0%, #111216 52%, #0b0b0c 100%);
}

.app-version-label {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
}

.topbar-version {
  margin: 3px 0 0;
}

html[data-theme="light"] .sidebar {
  color: #f8fafc;
  background: #08090b;
}

html[data-theme="light"] .sidebar .brand strong,
html[data-theme="light"] .sidebar .brand span,
html[data-theme="light"] .sidebar .app-version-label {
  color: #f8fafc;
}

html[data-theme="light"] .sidebar .nav-item {
  color: rgba(248, 250, 252, 0.72);
}

html[data-theme="light"] .sidebar .nav-item:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

html[data-theme="light"] .sidebar .nav-item.is-active {
  color: #08090b;
  background: #ffffff;
}

html[data-theme="dark"] .panel,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .tenant-card,
html[data-theme="dark"] .tenant-controls,
html[data-theme="dark"] .payment-card,
html[data-theme="dark"] .payment-group,
html[data-theme="dark"] .contract-card,
html[data-theme="dark"] .archive-card,
html[data-theme="dark"] .auth-card,
html[data-theme="dark"] dialog,
html[data-theme="light"] .panel,
html[data-theme="light"] .stat-card,
html[data-theme="light"] .tenant-card,
html[data-theme="light"] .tenant-controls,
html[data-theme="light"] .payment-card,
html[data-theme="light"] .payment-group,
html[data-theme="light"] .contract-card,
html[data-theme="light"] .archive-card,
html[data-theme="light"] .auth-card,
html[data-theme="light"] dialog {
  color: var(--text) !important;
  background: var(--panel) !important;
  border-color: var(--border) !important;
}

html[data-theme] input,
html[data-theme] select,
html[data-theme] textarea,
html[data-theme] .soft-input,
html[data-theme] .summary-card,
html[data-theme] .compact-item,
html[data-theme] .toggle-line,
html[data-theme] .payment-calc-summary,
html[data-theme] .mini-stats-grid div,
html[data-theme] .tenant-icon,
html[data-theme] .ai-insight-panel,
html[data-theme] .ai-chat-message,
html[data-theme] .ai-history-card {
  color: var(--field-text) !important;
  background: var(--field-bg) !important;
  border-color: var(--border) !important;
}

html[data-theme] h1,
html[data-theme] h2,
html[data-theme] h3,
html[data-theme] h4,
html[data-theme] label,
html[data-theme] th,
html[data-theme] td,
html[data-theme] .panel-header,
html[data-theme] .tenant-card strong,
html[data-theme] .payment-card strong,
html[data-theme] .contract-card strong,
html[data-theme] .summary-card strong,
html[data-theme] .stat-card strong,
html[data-theme] .money-value {
  color: var(--text) !important;
}

html[data-theme] p,
html[data-theme] small,
html[data-theme] .panel-header p,
html[data-theme] .tenant-card span,
html[data-theme] .payment-card span,
html[data-theme] .contract-card span,
html[data-theme] .summary-card span {
  color: var(--muted) !important;
}

html[data-theme] .primary-button,
html[data-theme] .round-add-button,
html[data-theme] .segmented-control button.is-active,
html[data-theme] .quick-filter-row button.is-active,
html[data-theme] .ai-tabs button.is-active {
  color: var(--button-text) !important;
  background: var(--text) !important;
}

html[data-theme="light"] .primary-button,
html[data-theme="light"] .round-add-button,
html[data-theme="light"] .segmented-control button.is-active,
html[data-theme="light"] .quick-filter-row button.is-active,
html[data-theme="light"] .ai-tabs button.is-active {
  color: #ffffff !important;
  background: #111827 !important;
}

html[data-theme] .secondary-button,
html[data-theme] .icon-button,
html[data-theme] .mini-button,
html[data-theme] .filter-toggle,
html[data-theme] .tenant-action-picker select,
html[data-theme] .theme-toggle {
  color: var(--text) !important;
  background: var(--panel-soft) !important;
  border-color: var(--border) !important;
}

html[data-theme] ::placeholder {
  color: var(--muted-2) !important;
}

/* v28 hard UI fixes requested from screenshots */
html[data-theme="light"] {
  --bg: #f1f3f6;
  --panel: #ffffff;
  --panel-solid: #ffffff;
  --panel-soft: #f6f8fb;
  --field-bg: #ffffff;
  --text: #111827;
  --field-text: #111827;
  --muted: #5b6575;
  --muted-2: #8a94a6;
  --border: rgba(17, 24, 39, 0.14);
}

html[data-theme="dark"] {
  --bg: #08090b;
  --panel: #15171b;
  --panel-solid: #15171b;
  --panel-soft: #1e2229;
  --field-bg: #0f1116;
  --text: #f8fafc;
  --field-text: #f8fafc;
  --muted: #cbd5e1;
  --muted-2: #94a3b8;
  --border: rgba(255, 255, 255, 0.14);
}

#page-year .annual-desktop-table,
#page-year .annual-grid-wrap,
#page-year .annual-table,
#page-year .annual-table tbody,
#page-year .annual-table tr,
#page-year .annual-table td,
#page-year .annual-table th {
  color: var(--text) !important;
  background: var(--panel) !important;
}

#page-year .annual-table td:first-child,
#page-year .annual-table th:first-child {
  min-width: 260px;
  color: var(--text) !important;
  background: var(--panel-soft) !important;
}

#page-year .annual-table td:first-child strong {
  display: block;
  color: var(--text) !important;
  font-weight: 900;
}

#page-year .annual-table td:first-child span {
  display: block;
  color: var(--muted) !important;
  margin-top: 4px;
}

#page-dashboard .chart-panel canvas {
  display: none !important;
}

#page-dashboard .chart-panel {
  min-height: auto !important;
}

.finance-evolution-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.finance-evolution-row {
  display: grid;
  grid-template-columns: 42px minmax(120px, 1fr) minmax(120px, auto) minmax(120px, auto);
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.finance-evolution-row:last-child {
  border-bottom: 0;
}

.finance-evolution-row strong,
.finance-evolution-row span {
  color: var(--text) !important;
}

.finance-evolution-row small {
  grid-column: 2 / -1;
  color: var(--muted) !important;
  font-weight: 800;
}

.finance-bars {
  display: grid;
  gap: 5px;
}

.finance-bar {
  width: var(--w);
  min-width: 14px;
  height: 8px;
  border-radius: 999px;
}

.finance-bar.is-empty {
  min-width: 0;
  opacity: 0;
}

.finance-bar.income {
  background: #16a34a;
}

.finance-bar.expected {
  background: #111827;
  opacity: 0.62;
}

.finance-bar.expense {
  background: #ef4444;
}

.finance-bar.bank-revenue {
  background: #3b82f6;
  opacity: 0.45;
}

#financeEvolutionList::before {
  content: "Priorité: appeler ou envoyer un rappel aux locataires ci-dessous";
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.86rem;
}

#incomeExpenseChart.is-hidden {
  display: none !important;
}

.rent-summary-row {
  grid-template-columns: 42px minmax(150px, 1fr) minmax(150px, auto) minmax(150px, auto);
}

html[data-theme="dark"] .finance-bar.expected {
  background: #e5e7eb;
}

#page-dashboard.simple-rent-dashboard .segmented-control,
#page-dashboard.simple-rent-dashboard #dashboardYearFilter {
  display: none !important;
}

#page-dashboard.simple-rent-dashboard .dashboard-actions .panel-header.with-actions {
  grid-template-columns: minmax(0, 1fr) auto;
}

#page-dashboard.simple-rent-dashboard .stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

#page-dashboard.simple-rent-dashboard .stats-grid .stat-card:nth-child(n + 5) {
  display: none;
}

#page-dashboard.simple-rent-dashboard .dashboard-grid {
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  align-items: start;
}

#page-dashboard.simple-rent-dashboard .chart-panel .panel-header,
#page-dashboard.simple-rent-dashboard .insights-panel .panel-header {
  margin-bottom: 14px;
}

#page-dashboard.simple-rent-dashboard .chart-panel .panel-header p,
#page-dashboard.simple-rent-dashboard .insights-panel .panel-header p {
  max-width: 620px;
}

#page-dashboard.simple-rent-dashboard .finance-evolution-list.simple-rent-actions {
  gap: 12px;
}

#page-dashboard.simple-rent-dashboard .finance-evolution-list.simple-rent-actions::before {
  content: "Priorité: relancer ces locataires";
}

.simple-rent-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-soft);
}

.simple-rent-action strong,
.simple-rent-action b {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.25;
}

.simple-rent-action span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 800;
}

.simple-rent-action b {
  white-space: nowrap;
}

.simple-rent-empty {
  display: grid;
  gap: 6px;
  padding: 18px;
  border: 1px solid rgba(22, 163, 74, 0.35);
  border-radius: 12px;
  background: rgba(22, 163, 74, 0.1);
}

.simple-rent-empty strong {
  color: var(--text);
  font-size: 1.05rem;
}

.simple-rent-empty span {
  color: var(--muted);
  font-weight: 800;
}

#page-dashboard.simple-rent-dashboard .insight-list strong {
  font-size: 1.02rem;
  line-height: 1.35;
}

@media (max-width: 980px) {
  #page-dashboard.simple-rent-dashboard .stats-grid,
  #page-dashboard.simple-rent-dashboard .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  #page-dashboard.simple-rent-dashboard .stats-grid {
    gap: 10px;
  }

  #page-dashboard.simple-rent-dashboard .stat-card strong {
    font-size: clamp(1.75rem, 10vw, 2.35rem);
  }

  .simple-rent-action {
    grid-template-columns: 1fr;
  }

  .simple-rent-action b {
    font-size: 1.25rem;
  }
}

#page-expenses .two-columns {
  grid-template-columns: 1fr !important;
}

#page-expenses .two-columns > .panel {
  min-width: 0;
}

#page-expenses .table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
}

#page-expenses table {
  width: 100%;
  min-width: 880px;
  table-layout: fixed;
}

#page-expenses th,
#page-expenses td {
  color: var(--text) !important;
  background: var(--panel) !important;
  vertical-align: middle;
}

#page-expenses th:nth-child(1),
#page-expenses td:nth-child(1) {
  width: 54px;
}

#page-expenses th:nth-child(2),
#page-expenses td:nth-child(2) {
  width: 105px;
}

#page-expenses th:nth-child(3),
#page-expenses td:nth-child(3) {
  width: auto;
  white-space: normal;
}

#page-expenses th:nth-child(4),
#page-expenses td:nth-child(4) {
  width: 145px;
}

#page-expenses th:nth-child(5),
#page-expenses td:nth-child(5) {
  width: 140px;
  text-align: right;
}

#page-expenses th:nth-child(6),
#page-expenses td:nth-child(6) {
  width: 120px;
}

#page-expenses td[data-label="Montant"] strong {
  display: inline-block;
  color: var(--text) !important;
  white-space: nowrap;
  direction: ltr;
}

#page-expenses .tenant-action-picker select {
  min-width: 96px;
}

#page-tenants .quick-filter-row,
#tenantQuickFilters,
#tenantFilterToggle {
  display: none !important;
}

#page-tenants .tenant-controls {
  padding-bottom: 16px;
}

#page-tenants .tenant-controls .filters-grid {
  grid-template-columns: minmax(260px, 1fr) minmax(160px, 240px) minmax(160px, 240px) !important;
  align-items: end;
}

html[data-theme] .theme-toggle {
  min-width: 104px !important;
  color: var(--text) !important;
  background: var(--panel) !important;
  border: 1px solid var(--border) !important;
}

html[data-theme] .theme-toggle::before {
  color: var(--text) !important;
}

html[data-theme] .theme-toggle,
html[data-theme] .theme-toggle * {
  opacity: 1 !important;
}

html[data-theme="light"] .main-content,
html[data-theme="light"] .topbar,
html[data-theme="light"] .network-status,
html[data-theme="light"] .mobile-top-nav {
  color: var(--text) !important;
}

html[data-theme="dark"] .main-content,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .network-status,
html[data-theme="dark"] .mobile-top-nav {
  color: var(--text) !important;
}

@media (max-width: 720px) {
  .finance-evolution-row {
    grid-template-columns: 34px 1fr;
  }

  .finance-evolution-row > span {
    font-size: 0.84rem;
  }

  #page-tenants .tenant-controls .filters-grid {
    grid-template-columns: 1fr !important;
  }
}

/* v30 - dark mode readability: forms, modals and dashboard cards */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08090b;
  --bg-soft: #0d1117;
  --panel: #15171d;
  --panel-solid: #15171d;
  --panel-soft: #1e222b;
  --field-bg: #0f1218;
  --field-text: #f8fafc;
  --text: #f8fafc;
  --muted: #cbd5e1;
  --muted-2: #94a3b8;
  --border: rgba(255, 255, 255, 0.16);
}

html[data-theme="dark"] body,
html[data-theme="dark"] .app-shell,
html[data-theme="dark"] .main-content,
html[data-theme="dark"] .page,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .mobile-top-nav,
html[data-theme="dark"] .network-status {
  color: var(--text) !important;
  background: var(--bg) !important;
}

html[data-theme="dark"] .panel,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .tenant-card,
html[data-theme="dark"] .tenant-controls,
html[data-theme="dark"] .payment-card,
html[data-theme="dark"] .payment-group,
html[data-theme="dark"] .contract-card,
html[data-theme="dark"] .archive-card,
html[data-theme="dark"] .auth-card,
html[data-theme="dark"] .summary-card,
html[data-theme="dark"] .compact-item,
html[data-theme="dark"] .ai-chat-message,
html[data-theme="dark"] .ai-history-card,
html[data-theme="dark"] dialog,
html[data-theme="dark"] .dialog-card,
html[data-theme="dark"] .document-viewer-bar {
  color: var(--text) !important;
  background: var(--panel) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] #paymentFormPanel,
html[data-theme="dark"] #paymentFormPanel.is-open,
html[data-theme="dark"] #paymentFormPanel:not(.hidden),
html[data-theme="dark"] .form-panel,
html[data-theme="dark"] .form-panel:not(.hidden),
html[data-theme="dark"] .inline-expand-panel,
html[data-theme="dark"] .inline-expand-panel.is-open,
html[data-theme="dark"] .payment-sheet-form,
html[data-theme="dark"] .tenant-form,
html[data-theme="dark"] .contract-form,
html[data-theme="dark"] form.dialog-card {
  color: var(--text) !important;
  background: var(--panel) !important;
  border-color: var(--border) !important;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55) !important;
}

html[data-theme="dark"] .insight-list div,
html[data-theme="dark"] #paymentCalculationSummary,
html[data-theme="dark"] .payment-calc-summary,
html[data-theme="dark"] .panel-soft,
html[data-theme="dark"] .calc-box,
html[data-theme="dark"] .form-note,
html[data-theme="dark"] .quick-summary {
  color: var(--text) !important;
  background: var(--field-bg) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] #paymentFormPanel *,
html[data-theme="dark"] .form-panel *,
html[data-theme="dark"] .dialog-card *,
html[data-theme="dark"] .summary-card *,
html[data-theme="dark"] .insight-list div *,
html[data-theme="dark"] #paymentCalculationSummary *,
html[data-theme="dark"] .payment-calc-summary * {
  color: inherit;
}

html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] label,
html[data-theme="dark"] legend,
html[data-theme="dark"] th,
html[data-theme="dark"] td,
html[data-theme="dark"] .panel-header,
html[data-theme="dark"] .panel-header h2,
html[data-theme="dark"] .payment-sheet-form label,
html[data-theme="dark"] .form-grid label,
html[data-theme="dark"] .field-label,
html[data-theme="dark"] .insight-list strong,
html[data-theme="dark"] .summary-card strong,
html[data-theme="dark"] .stat-card strong,
html[data-theme="dark"] .metric-name,
html[data-theme="dark"] .metric-money {
  color: var(--text) !important;
  -webkit-text-fill-color: var(--text) !important;
}

html[data-theme="dark"] p,
html[data-theme="dark"] small,
html[data-theme="dark"] .panel-header p,
html[data-theme="dark"] .insight-list span,
html[data-theme="dark"] .summary-card span,
html[data-theme="dark"] .stat-card span,
html[data-theme="dark"] .app-version-label,
html[data-theme="dark"] .muted {
  color: var(--muted) !important;
  -webkit-text-fill-color: var(--muted) !important;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] option,
html[data-theme="dark"] .soft-input {
  color: var(--field-text) !important;
  background-color: var(--field-bg) !important;
  border-color: var(--border) !important;
  caret-color: var(--field-text) !important;
  -webkit-text-fill-color: var(--field-text) !important;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: var(--muted-2) !important;
  -webkit-text-fill-color: var(--muted-2) !important;
}

html[data-theme="dark"] input:-webkit-autofill,
html[data-theme="dark"] textarea:-webkit-autofill,
html[data-theme="dark"] select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--field-bg) inset !important;
  -webkit-text-fill-color: var(--field-text) !important;
}

html[data-theme="dark"] .primary-button {
  color: #08090b !important;
  background: #f8fafc !important;
  border-color: #f8fafc !important;
  -webkit-text-fill-color: #08090b !important;
}

html[data-theme="dark"] .secondary-button,
html[data-theme="dark"] .icon-button,
html[data-theme="dark"] .mini-button,
html[data-theme="dark"] .sheet-close-button,
html[data-theme="dark"] .theme-toggle,
html[data-theme="dark"] .local-button {
  color: var(--text) !important;
  background: var(--panel-soft) !important;
  border-color: var(--border) !important;
  -webkit-text-fill-color: var(--text) !important;
}

html[data-theme="dark"] .danger-button {
  color: #fecaca !important;
  background: rgba(127, 29, 29, 0.28) !important;
  border-color: rgba(248, 113, 113, 0.35) !important;
  -webkit-text-fill-color: #fecaca !important;
}

html[data-theme="dark"] .success,
html[data-theme="dark"] .server-ok,
html[data-theme="dark"] .network-status.is-online {
  color: #bbf7d0 !important;
  background: rgba(22, 101, 52, 0.28) !important;
  border-color: rgba(74, 222, 128, 0.35) !important;
  -webkit-text-fill-color: #bbf7d0 !important;
}

/* v31 - rent core: accounting tools are separated from rent tracking */
.accounting-separate-panel .panel-header.with-actions {
  gap: 18px;
}

.accounting-separate-panel .row-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.separation-note {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--field-bg, rgba(15, 18, 24, 0.06));
  color: var(--text);
}

.separation-note strong {
  color: var(--text);
}

.separation-note span {
  color: var(--muted);
  font-weight: 750;
}

.rent-core-mode #page-dashboard .ai-assistant-panel {
  display: none !important;
}

@media (max-width: 720px) {
  .accounting-separate-panel .panel-header.with-actions {
    align-items: stretch;
  }

  .accounting-separate-panel .row-actions {
    justify-content: stretch;
  }

  .accounting-separate-panel .row-actions > button {
    width: 100%;
  }
}

/* v32 - separate finance dashboard */
.finance-dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.75fr);
  gap: 16px;
  align-items: start;
}

.compact-filters {
  grid-template-columns: minmax(120px, 160px) minmax(120px, 160px);
  gap: 10px;
  margin: 0;
}

.finance-category-stack {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--field-bg, rgba(15, 18, 24, 0.04));
}

.finance-category-stack h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.finance-full-row {
  grid-template-columns: 42px minmax(120px, 1fr) minmax(120px, auto) minmax(120px, auto);
}

.finance-ai-panel .ai-chat-messages {
  min-height: 160px;
}

@media (max-width: 900px) {
  .finance-dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .compact-filters,
  .finance-full-row {
    grid-template-columns: 1fr;
  }
}
