:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-muted: #eef3ef;
  --line: #d9dfd8;
  --text: #17211b;
  --muted: #637065;
  --accent: #1f7a5a;
  --accent-strong: #145f46;
  --danger: #b64135;
  --shadow: 0 12px 34px rgba(23, 33, 27, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

h1,
h2,
h3,
p,
span,
strong,
button,
label,
td,
th {
  overflow-wrap: anywhere;
}

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

button {
  align-items: center;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  line-height: 1.15;
  min-height: 40px;
  padding: 0 14px;
  text-align: center;
  white-space: normal;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.secondary {
  background: #e7eee9;
  color: var(--text);
}

.secondary:hover {
  background: #d7e3dc;
}

.danger {
  background: #f4e5e3;
  color: var(--danger);
}

.danger:hover {
  background: #ecd1cd;
}

.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.85rem;
}

.text-button {
  min-height: auto;
  padding: 0;
  background: transparent;
  color: var(--accent);
}

.text-button:hover {
  background: transparent;
  color: var(--accent-strong);
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  background: #edf1ed;
  color: var(--text);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(18px);
}

.brand-row {
  align-items: center;
  display: flex;
  gap: 14px;
  min-width: 0;
}

.menu-button {
  display: none;
}

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

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.85rem, 2.7vw, 2.7rem);
  line-height: 1.05;
}

.backend-badge::after {
  content: attr(data-status);
  display: inline-flex;
  margin-top: 10px;
  border-radius: 999px;
  background: #e7eee9;
  color: var(--muted);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.2;
  max-width: 100%;
  text-align: center;
}

.backend-badge:not([data-status])::after {
  content: "Local browser storage";
}

body[data-backend="supabase"] .backend-badge::after {
  background: #dff1ea;
  color: var(--accent-strong);
}

h2 {
  font-size: 1rem;
}

.header-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.app-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  align-self: start;
  border-right: 1px solid var(--line);
  min-height: calc(100vh - 97px);
  padding: 20px;
  position: sticky;
  top: 97px;
}

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

.nav-item {
  align-items: center;
  background: transparent;
  color: var(--text);
  display: flex;
  justify-content: flex-start;
  min-height: 44px;
  padding: 0 12px;
  text-align: left;
  width: 100%;
}

.nav-item:hover,
.nav-item.active {
  background: #dff1ea;
  color: var(--accent-strong);
}

.app-shell {
  min-width: 0;
  padding: 24px clamp(18px, 4vw, 48px) 48px;
}

.page-view {
  display: grid;
  gap: 20px;
  margin: 0 auto;
  max-width: 1280px;
  width: 100%;
}

.page-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.page-heading h2 {
  font-size: 1.4rem;
}

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}

.summary-card,
.filters-panel,
.category-panel,
.table-panel,
dialog {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.summary-card {
  align-content: center;
  display: grid;
  gap: 12px;
  justify-items: center;
  min-height: 126px;
  padding: 20px 22px;
  border-radius: 8px;
  text-align: center;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.25;
}

.summary-card strong {
  display: block;
  font-size: clamp(1.45rem, 1.35vw, 2rem);
  line-height: 1.08;
  max-width: 100%;
  overflow-wrap: normal;
  word-break: normal;
}

.summary-card:nth-child(6) strong {
  font-size: clamp(1.3rem, 1.15vw, 1.75rem);
  line-height: 1.12;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 20px;
}

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

.filters-panel,
.category-panel,
.chart-panel,
.table-panel {
  border-radius: 8px;
  min-width: 0;
  overflow: hidden;
}

.chart-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.chart-body {
  min-height: 300px;
  overflow-x: auto;
  padding: 18px;
}

.pie-chart-wrap {
  align-items: center;
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(0, 1fr);
  gap: 16px;
}

.pie-chart {
  display: block;
  height: auto;
  max-width: 220px;
  width: 100%;
}

.chart-total-label {
  fill: var(--muted);
  font-size: 0.56rem;
  font-weight: 800;
  text-transform: uppercase;
}

.chart-total-value {
  fill: var(--text);
  font-size: 0.68rem;
  font-weight: 800;
}

.chart-legend {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  min-width: 0;
  padding: 0;
}

.chart-legend li {
  align-items: center;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 9px;
  color: var(--muted);
  font-size: 0.78rem;
  min-width: 0;
}

.chart-legend strong {
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.legend-dot {
  border-radius: 50%;
  display: inline-block;
  height: 11px;
  width: 11px;
}

.bar-chart {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(6, minmax(70px, 1fr));
  min-height: 260px;
}

.bar-column {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-rows: auto 1fr auto;
  height: 250px;
  min-width: 0;
  text-align: center;
}

.bar-value {
  color: var(--muted);
  font-size: clamp(0.62rem, 0.78vw, 0.72rem);
  font-weight: 800;
  line-height: 1.1;
  min-height: 24px;
  white-space: nowrap;
}

.bar-track {
  align-items: end;
  background: var(--surface-muted);
  border-radius: 999px;
  display: flex;
  height: 180px;
  justify-content: center;
  overflow: hidden;
  width: 100%;
}

.bar-track span {
  background: var(--accent);
  border-radius: inherit;
  display: block;
  width: 100%;
}

.bar-column strong {
  color: var(--muted);
  font-size: 0.76rem;
}

.empty-chart {
  color: var(--muted);
  margin: 0;
}

.filters-panel {
  align-self: start;
  display: grid;
  gap: 14px;
  padding: 18px;
  position: sticky;
  top: 118px;
}

.content-stack {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading p,
.panel-heading span {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd8d1;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 40px;
  padding: 9px 11px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(31, 122, 90, 0.16);
}

.two-col,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.category-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  padding: 18px;
}

.category-row {
  display: grid;
  gap: 10px;
}

.category-row div:first-child {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 10px;
}

.category-row strong {
  font-size: 0.92rem;
}

.category-row span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 250px);
  max-width: 100%;
  min-width: 0;
  width: 100%;
}

.expense-card-list,
.property-card-list {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  table-layout: auto;
}

[data-view="expenses"] table {
  min-width: 1500px;
}

[data-view="properties"] table {
  min-width: 820px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
  overflow-wrap: normal;
  word-break: normal;
}

th {
  background: #f9fbf9;
  color: var(--muted);
  font-size: 0.76rem;
  position: sticky;
  top: 0;
  z-index: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.receipt-status {
  align-items: center;
  background: #eef3ef;
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 800;
  justify-content: center;
  line-height: 1;
  min-height: 30px;
  padding: 0 12px;
  white-space: nowrap;
}

.receipt-upload input[type="file"] {
  min-height: auto;
  padding: 10px;
}

.receipt-upload input[type="file"]::file-selector-button {
  border: 0;
  border-radius: 6px;
  background: #e7eee9;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  margin-right: 12px;
  min-height: 36px;
  padding: 0 12px;
}

.receipt-link {
  max-width: 100%;
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-align: left;
}

.receipt-help {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
  margin: -6px 18px 0;
  overflow-wrap: anywhere;
}

.amount {
  font-weight: 800;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 8px;
  min-width: 152px;
}

.row-actions button {
  white-space: nowrap;
}

.expense-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(23, 33, 27, 0.08);
  display: grid;
  gap: 14px;
  padding: 14px;
}

.property-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(23, 33, 27, 0.08);
  display: grid;
  gap: 14px;
  padding: 14px;
}

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

.property-card-header span {
  color: var(--muted);
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.property-card-header strong {
  display: block;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

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

.expense-card-header span {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
}

.expense-card-header strong {
  display: block;
  font-size: 1rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.expense-card-amount {
  color: var(--accent-strong);
  text-align: right;
  white-space: nowrap;
}

.expense-card-details {
  display: grid;
  gap: 10px;
  margin: 0;
}

.expense-card-details div {
  display: grid;
  grid-template-columns: minmax(92px, 32%) minmax(0, 1fr);
  gap: 10px;
}

.expense-card-details dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.expense-card-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop {
  background: rgba(23, 33, 27, 0.42);
}

.modal-heading,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
}

.modal-heading {
  border-bottom: 1px solid var(--line);
}

.modal-actions {
  border-top: 1px solid var(--line);
}

.form-grid {
  padding: 18px;
}

.full {
  grid-column: 1 / -1;
}

.is-busy {
  cursor: wait;
}

.load-error {
  max-width: 720px;
  margin: 12vh auto;
  padding: 24px;
}

[hidden] {
  display: none !important;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #f6f7f4 0%, #e8f1eb 100%);
}

.auth-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-card h1 {
  margin-bottom: 10px;
}

.auth-copy,
.users-copy p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

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

.auth-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 18px;
}

.form-message {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--danger);
  font-weight: 700;
}

.form-message.success {
  color: var(--accent-strong);
}

.user-pill {
  align-items: center;
  align-self: center;
  border-radius: 999px;
  background: #edf4ef;
  color: var(--accent-strong);
  display: inline-flex;
  font-size: 0.84rem;
  font-weight: 800;
  min-height: 40px;
  line-height: 1.2;
  max-width: min(100%, 560px);
  padding: 0 12px;
  text-align: center;
}

.users-panel {
  width: min(820px, calc(100vw - 28px));
}

.users-copy {
  padding: 18px 18px 0;
}

.users-table-wrap {
  max-height: min(620px, calc(100vh - 240px));
}

.role-select,
.status-select {
  min-width: 120px;
}

.property-form {
  border-bottom: 1px solid var(--line);
}

.settings-grid {
  display: grid;
  gap: 16px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
  padding: 18px;
}

.settings-card h3 {
  margin: 0 0 8px;
}

.settings-card p {
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 14px;
}

.tenant-info {
  display: grid;
  gap: 10px;
}

.tenant-info p {
  margin: 0;
}

.document-list {
  display: grid;
  gap: 12px;
}

.document-form {
  border-bottom: 1px solid var(--line);
  margin: -18px -18px 18px;
  padding: 18px;
}

.document-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.document-link {
  justify-content: flex-start;
  text-align: left;
}

.checkbox-label {
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 10px;
}

.checkbox-label input {
  min-height: auto;
  width: auto;
}

.document-item p {
  margin: 6px 0 0;
}

.inline-form {
  align-items: end;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 1180px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .filters-panel {
    position: static;
  }
}

@media (max-width: 980px) {
  body {
    background: var(--surface);
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
    position: sticky;
  }

  .header-actions,
  .header-actions button {
    width: 100%;
  }

  .user-pill {
    justify-content: center;
    width: 100%;
  }

  .brand-row {
    align-items: flex-start;
    width: 100%;
  }

  .brand-row > div {
    min-width: 0;
  }

  h1 {
    font-size: clamp(1.9rem, 11vw, 2.55rem);
  }

  .menu-button {
    display: inline-flex;
  }

  .app-layout {
    display: block;
  }

  .sidebar {
    background: var(--surface);
    box-shadow: var(--shadow);
    height: 100vh;
    left: 0;
    min-height: 0;
    padding: 18px;
    position: fixed;
    top: 0;
    transform: translateX(-105%);
    transition: transform 160ms ease;
    width: min(280px, 82vw);
    z-index: 20;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .nav-overlay {
    background: rgba(23, 33, 27, 0.34);
    inset: 0;
    position: fixed;
    z-index: 19;
  }

  .app-shell {
    padding: 16px 12px 32px;
  }

  .page-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-actions,
  .page-actions button {
    width: 100%;
  }

  .summary-grid,
  .two-col,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    gap: 10px;
  }

  .summary-card {
    min-height: auto;
    padding: 16px;
    text-align: center;
  }

  .summary-card strong {
    font-size: clamp(1.45rem, 8vw, 1.9rem);
  }

  .summary-card:nth-child(6) strong {
    font-size: clamp(1.3rem, 7vw, 1.7rem);
  }

  .chart-body {
    min-height: auto;
    padding: 14px;
  }

  .pie-chart-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .chart-legend {
    width: 100%;
  }

  .bar-chart {
    gap: 8px;
    grid-template-columns: repeat(6, minmax(76px, 1fr));
    min-width: 510px;
    min-height: 220px;
  }

  .bar-column {
    height: 210px;
  }

  .bar-track {
    height: 135px;
  }

  .bar-value {
    font-size: 0.62rem;
  }

  .category-row div:first-child {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .category-row span {
    text-align: left;
    white-space: normal;
  }

  .filters-panel,
  .category-panel,
  .chart-panel,
  .table-panel {
    border-radius: 0;
    box-shadow: none;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .filters-panel,
  .category-list {
    padding: 14px;
  }

  [data-view="expenses"] .table-wrap {
    display: none;
  }

  [data-view="expenses"] .expense-card-list {
    display: grid;
    gap: 14px;
    padding: 14px;
  }

  [data-view="properties"] .table-wrap {
    display: none;
  }

  [data-view="properties"] .property-card-list {
    display: grid;
    gap: 14px;
    padding: 14px;
  }

  .amount {
    white-space: normal;
  }

  .row-actions {
    justify-content: flex-end;
    min-width: 0;
  }

  .row-actions button {
    flex: 1;
    white-space: normal;
  }

  dialog {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    overflow: auto;
  }

  .modal-heading,
  .modal-actions,
  .form-grid {
    padding: 14px;
  }

  .receipt-upload input[type="file"] {
    display: grid;
    gap: 8px;
    width: 100%;
  }

  .receipt-upload input[type="file"]::file-selector-button {
    display: block;
    margin: 0 0 8px;
    width: 100%;
  }

  .receipt-help {
    margin: -6px 14px 0;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions button {
    width: 100%;
  }

  .auth-card {
    padding: 20px;
  }

  .auth-links {
    display: grid;
  }

  .users-panel {
    width: calc(100vw - 16px);
  }

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