:root {
  --ink: #20242c;
  --muted: #59616e;
  --line: #dde1e7;
  --panel: #ffffff;
  --canvas: #f8f9fb;
  --green: #236c4a;
  --green-2: #dff1e5;
  --rust: #b85b3f;
  --amber: #f2b84b;
  --blue: #3b6f92;
  --violet: #7762a8;
  --shadow: 0 8px 24px rgba(20, 24, 32, 0.10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

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

button {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.74;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #f2b84b;
  outline-offset: 2px;
}

.login-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  padding: 22px;
}

.auth-brand {
  color: var(--ink);
  margin-bottom: 4px;
}

.auth-brand span {
  color: var(--muted);
}

.login-card .primary-button {
  width: 100%;
}

.login-status {
  min-height: 20px;
  margin: 0;
  color: var(--rust);
  font-size: 13px;
}

.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #ffffff;
  color: var(--ink);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--green-2);
  color: var(--green);
  border-radius: 8px;
  font-weight: 800;
  font-size: 24px;
}

.brand span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.sidebar .field span {
  color: var(--muted);
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.field.compact {
  color: var(--ink);
}

.field.compact select {
  background: #f8f9fb;
  color: var(--ink);
  border-color: var(--line);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  min-height: 40px;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.nav {
  display: grid;
  gap: 5px;
}

.nav button {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 7px;
  text-align: left;
}

.nav button.active,
.nav button:hover {
  background: #eaf3ee;
  color: var(--green);
}

.nav .nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 28px clamp(18px, 3vw, 40px) 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1,
.modal-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar > div:first-child {
  min-width: 0;
  max-width: 100%;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.topbar-actions,
.inline-actions,
.table-actions,
.modal-actions,
.filterbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.secondary-button,
.danger-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 7px;
  min-height: 38px;
  padding: 9px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.ghost-button {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.secondary-button {
  background: #eef5ef;
  border-color: #c9dacf;
  color: var(--green);
}

.danger-button {
  background: #fff2ed;
  color: #9b3d25;
  border-color: #f1c9bd;
}

.icon-button {
  width: 36px;
  padding: 0;
  background: #f7f8f5;
  border-color: var(--line);
  color: var(--ink);
  font-size: 22px;
}

.alerts {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

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

.install-panel {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  position: fixed;
  z-index: 2000;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  max-width: 520px;
  margin-inline: auto;
  border: 2px solid #236c4a;
}

#installPwaStatus { margin: 0; }
#installPwaStatus:empty { display: none; }
#biometricOffer { max-width: min(420px, calc(100vw - 32px)); }
#biometricOffer h2 { font-size: 20px; }

.install-panel span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.alert {
  border-left: 4px solid var(--rust);
  background: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border-radius: 6px;
}

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

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

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-height: 112px;
  display: grid;
  align-content: space-between;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 28px;
  letter-spacing: 0;
}

.metric small {
  color: var(--green);
  font-weight: 800;
}

.section {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  overflow: hidden;
}

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

.section-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.section-body {
  padding: 16px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  background: #edf1ee;
  color: #425149;
  white-space: nowrap;
}

.status.paid,
.status.occupied,
.status.closed,
.status.active {
  background: var(--green-2);
  color: var(--green);
}

.status.due,
.status.open {
  background: #fff1cf;
  color: #885d00;
}

.status.overdue,
.status.vacant,
.status.inactive {
  background: #ffe5dc;
  color: #9b3d25;
}

.status.progress {
  background: #e4eef5;
  color: var(--blue);
}

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

.unit-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 11px;
}

.unit-card header {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.unit-card header > div {
  min-width: 0;
}

.unit-card header .status {
  flex-shrink: 0;
}

.unit-card h3 {
  margin: 0;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.premises-units summary {
  cursor: pointer;
  font-weight: 700;
}

.premises-units ul {
  columns: 2;
  margin: 10px 0 0;
  padding-left: 22px;
}

.premises-unit,
.premises-units li {
  overflow-wrap: anywhere;
}

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

.split {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr;
  gap: 18px;
}

.progress-stack {
  display: grid;
  gap: 13px;
}

.progress-row {
  display: grid;
  gap: 7px;
}

.progress-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.bar {
  height: 10px;
  background: #e8ede9;
  border-radius: 999px;
  overflow: hidden;
}

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

.filterbar {
  margin-bottom: 12px;
}

.filterbar input,
.filterbar select {
  width: min(260px, 100%);
}

dialog {
  width: min(680px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

dialog::backdrop {
  background: rgba(16, 24, 20, 0.42);
}

#passkeyForm { padding: 20px; display: grid; gap: 12px; }
#operationStatus:empty { display: none; }
#modalForm {
  margin: 0;
}

.modal-head,
.modal-actions {
  padding: 16px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

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

.modal-fields .wide {
  grid-column: 1 / -1;
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  margin: 0;
}

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

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.mobile-menu { display: none; }
.lucide { width: 18px; height: 18px; flex: 0 0 18px; stroke-width: 1.8; }
.topbar h1 { font-size: 26px; }
.op-workspace { min-width: 0; }
.op-toolbar, .op-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 18px; }
.op-toolbar > p { margin: 0; color: var(--muted); font-size: 14px; }
.op-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.op-filters { display: flex; gap: 12px; border-top: 1px solid var(--line); padding: 16px 0; }
.op-search { position: relative; width: min(380px, 100%); }
.op-search .lucide { position: absolute; top: 12px; left: 12px; color: var(--muted); }
.op-search input { padding-left: 38px; }
.op-filters > label:last-child { width: 170px; }
.op-table-scroll { max-width: 100%; overflow-x: auto; border-bottom: 1px solid var(--line); background: #fff; }
.op-table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; }
.op-table th { background: #f0f2f6; color: #505866; font-weight: 600; font-size: 12px; padding: 13px 14px; white-space: nowrap; }
.op-table td { padding: 15px 14px; border-top: 1px solid #e8ebef; vertical-align: top; min-width: 100px; overflow-wrap: anywhere; max-width: 340px; }
.op-table tbody tr:hover { background: #fbfcfd; }
.op-table td strong { display: block; font-weight: 600; }
.op-table td small { display: block; margin-top: 5px; color: var(--muted); line-height: 1.5; }
.op-table td:last-child { min-width: 160px; }
.op-table td .secondary-button { font-size: 12px; margin: 0 4px 6px 0; min-height: 34px; background: white; border-color: var(--line); color: var(--ink); }
.op-status { display: inline-block; padding: 4px 8px; border-radius: 4px; white-space: nowrap; background: #eef1f5; color: #414b59; font-size: 12px; font-weight: 600; }
.op-status.paid, .op-status.approved, .op-status.sent, .op-status.completed, .op-status.active { background: #e5f3eb; color: #21543b; }
.op-status.pending, .op-status.renewal_due, .op-status.queued, .op-status.partial { background: #fff3d8; color: #785006; }
.op-status.overdue, .op-status.failed, .op-status.rejected { background: #fde9e9; color: #8b3030; }
.op-status.simulated, .op-status.in_progress { background: #e9effb; color: #335494; }
.op-premises { margin-top: 6px; color: var(--muted); font-size: 12px; max-width: 290px; line-height: 1.6; }
.op-premises summary { cursor: pointer; }
.op-metrics { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.op-metric { position: relative; padding: 22px 18px; min-height: 125px; background: #fff; border: 0; border-right: 1px solid var(--line); text-align: left; color: var(--ink); }
.op-metric:last-child { border-right: 0; }
.op-metric span { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.op-metric strong { display: block; margin-top: 16px; font-size: 25px; font-weight: 600; overflow-wrap: anywhere; }
.op-metric > .lucide { position: absolute; right: 12px; top: 12px; color: #7a8390; }
.op-overview { display: grid; grid-template-columns: minmax(0,1.4fr) minmax(0,1fr); gap: 28px; }
.op-overview > section { min-width: 0; }
.op-section-heading h2 { font-size: 16px; margin: 0; }
.op-wide { grid-column: 1 / -1; }
#operationsError { color: #9d3030; padding: 0 16px; }
.op-warning { color: #785006; }
.op-error { padding: 20px; color: #9d3030; }
#opNotice { font-size: 14px; color: #345b45; line-height: 1.6; }

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

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    display: none;
  }
  .sidebar[data-expanded="true"] .nav { display: grid; }
  .mobile-menu { display: inline-flex; }
  .sidebar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .brand, .sidebar .nav { grid-column: 1 / -1; }
  .op-metrics { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .op-overview { grid-template-columns: minmax(0,1fr); }

  .summary-grid,
  .cards-grid,
  .split {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .op-toolbar { align-items: flex-start; flex-direction: column; }
  .op-filters { flex-wrap: wrap; }
  .op-metric { padding: 18px 12px; }
  .op-metric strong { font-size: 21px; }
  .op-metric span { max-width: 90%; line-height: 1.4; }
  .op-table td .secondary-button { min-height: 44px; }
  .workspace {
    padding: 20px 14px 34px;
  }

  .primary-button,
  .ghost-button,
  .secondary-button,
  .danger-button,
  .icon-button,
  input,
  select,
  textarea {
    min-height: 44px;
  }

  .icon-button {
    width: 44px;
  }

  .topbar,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .inline-actions,
  .install-panel,
  .filterbar {
    width: 100%;
  }

  .install-panel {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: auto;
  }
  .install-panel > div, #installPwaStatus { grid-column: 1 / -1; }

  .topbar-actions button,
  .inline-actions button,
  .install-panel button,
  .filterbar input,
  .filterbar select {
    flex: 1;
  }

  .summary-grid,
  .cards-grid,
  .split,
  .modal-fields {
    grid-template-columns: 1fr;
  }

  .premises-units ul {
    columns: 1;
  }

  .data-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

.account-money { white-space: nowrap; }
.email-preview { border-bottom: 1px solid #dce1e0; padding: 16px 0; }
#communicationsPreview { padding: 0 16px; }
#communicationsReview { margin-left: 16px; }
#communicationsNotice { margin: 16px; }
.email-preview h3 { margin: 0; font-size: 16px; }
.email-preview dl { display: grid; grid-template-columns: 65px minmax(0,1fr); gap: 6px; }
.email-preview dd { margin: 0; overflow-wrap: anywhere; }
.email-preview pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; line-height: 1.5; }
.email-confirm { display: flex; gap: 10px; align-items: center; min-height: 44px; margin: 16px; cursor: pointer; }
.email-confirm input { width: 20px; height: 20px; flex: 0 0 20px; }
.expense-period { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; margin-bottom: 16px; }
.expense-period input, .expense-period select { width: 100%; min-width: 0; }
.expense-review { display: grid; grid-template-columns: minmax(80px,1fr) minmax(0,2fr); gap: 8px 16px; }
.expense-review dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) { .expense-period { grid-template-columns: minmax(0,1fr); } }
.op-section-heading { flex-wrap: wrap; }
.account-workspace { margin-bottom: 24px; }
.workspace-tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--border, #dce1e0); margin-bottom: 16px; }
.workspace-tabs button { display: inline-flex; align-items: center; gap: 8px; border: 0; border-bottom: 2px solid transparent; background: transparent; padding: 12px 14px; min-height: 44px; color: #444b48; border-radius: 0; cursor: pointer; }
.workspace-tabs button.selected { color: #106745; border-bottom-color: #106745; font-weight: 700; }
.workspace-tabs svg { width: 18px; height: 18px; flex-shrink: 0; }
.client-toolbar { display: grid; grid-template-columns: minmax(220px, 2fr) repeat(3,minmax(145px,1fr)); gap: 14px; align-items: end; }
.client-toolbar .account-actions, #workspaceNotice { grid-column: 1 / -1; }
.client-toolbar input, .client-toolbar select, .accounting-filters input, .accounting-filters select { width: 100%; min-width: 0; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.account-actions button, .accounting-filters > button { display: inline-flex; gap: 8px; align-items: center; justify-content: center; }
.account-actions svg, .accounting-filters > button svg { width: 18px; height: 18px; flex-shrink: 0; }
.accounting-filters { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; padding-bottom: 20px; margin-bottom: 24px; border-bottom: 1px solid #dce1e0; align-items: end; }
.accounting-more { grid-column: 1 / -1; }
.accounting-more summary, .accounting-details summary { cursor: pointer; padding: 12px 0; min-height: 44px; font-weight: 600; }
.accounting-filter-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; padding-top: 10px; }
.accounting-details { margin: 16px 0; }
.accounting-filters .field, .client-toolbar .field { min-width: 0; }
@media (max-width: 800px) {
  .client-toolbar, .accounting-filters, .accounting-filter-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .client-toolbar > .field:first-child { grid-column: 1 / -1; }
  .client-toolbar > .field:nth-child(2) { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  .op-section-heading h2 { flex-basis: 100%; }
  .accounting-filters, .accounting-filter-grid { grid-template-columns: minmax(0,1fr); }
  .workspace-tabs button { padding: 10px 8px; font-size: 13px; }
  .client-toolbar { gap: 12px; }
  .account-actions button { min-height: 44px; }
}
.shop-choice { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 8px; }
.shop-choice input { width: 20px; height: 20px; flex: 0 0 20px; }
.shop-choice[hidden] { display: none; }
 .category-selector {position:relative;min-width:200px;}
 .category-selector summary {cursor:pointer;padding:10px;border:1px solid #ccd3ce;border-radius:4px;}
 .category-selector fieldset {margin:8px 0;padding:8px;display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:4px;border:1px solid #ccd3ce;max-height:320px;overflow:auto;}
 .category-selector label,.review-confirm {display:flex;align-items:center;gap:10px;min-height:44px;padding:6px;font-size:14px;}
 .category-selector input,.review-confirm input {width:18px;height:18px;flex-shrink:0;}
 .reconcile-upload {display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:16px;margin:16px 0;}
 #statementRows input {min-height:42px;min-width:140px;max-width:250px;border:1px solid #ccd3ce;border-radius:4px;padding:8px;}
 .statement-text {white-space:pre-wrap;overflow-wrap:anywhere;max-height:240px;overflow:auto;}
 #reconcileResults .account-actions {flex-wrap:wrap;margin-bottom:16px;}
 #statementSave {margin:16px 0;}
 .access-permissions { display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px;margin:16px 0; }
 .access-permissions fieldset { border:1px solid #cdd6d2;padding:12px;min-width:0; }
 .access-permissions label { display:flex;align-items:center;gap:8px;margin:4px 0;min-height:40px;cursor:pointer; }
 .access-permissions input { width:18px;height:18px;min-width:0;min-height:0;padding:0;margin:0;flex:0 0 18px; }
 .dashboard-progress {width:100%;height:10px;border:0;appearance:none;overflow:hidden;}
 .dashboard-progress::-webkit-progress-bar {background:#e5e7eb;}
 .dashboard-progress::-webkit-progress-value {background:#147d64;}
 .dashboard-progress::-moz-progress-bar {background:#147d64;}
