/* tokens */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #d8dce1;
  --ink: #1c2733;
  --ink-soft: #5b6774;
  --brand: #1f4e79;
  --brand-ink: #163a5b;
  --good: #217a4b;
  --warn: #b8860b;
  --bad: #b03a2e;
  --muted: #8a94a0;
  --good-bg: rgba(33, 122, 75, 0.1);
  --warn-bg: rgba(184, 134, 11, 0.1);
  --bad-bg: rgba(176, 58, 46, 0.1);
  --muted-bg: rgba(138, 148, 160, 0.1);
  --brand-bg: rgba(31, 78, 121, 0.1);
  --radius: 6px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --sidebar-width: 220px;
  color-scheme: light;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

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

a {
  color: var(--brand);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--brand-ink);
}

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

h1 {
  margin-bottom: var(--space-4);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
}

h2 {
  margin-bottom: var(--space-3);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
}

h3 {
  margin-bottom: var(--space-2);
  font-size: 15px;
  font-weight: 600;
}

ul,
ol {
  margin-top: 0;
  padding-left: var(--space-5);
}

li + li {
  margin-top: var(--space-1);
}

pre {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

summary {
  cursor: pointer;
  font-weight: 600;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: var(--space-2);
  left: var(--space-2);
  padding: var(--space-2) var(--space-3);
  transform: translateY(-160%);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--brand);
}

.skip-link:focus {
  transform: translateY(0);
}

.muted,
.text-muted {
  color: var(--ink-soft);
}

.text-good {
  color: var(--good);
}

.text-warn {
  color: var(--warn);
}

.text-bad,
.negative {
  color: var(--bad);
}

.money,
.date,
.numeric,
time,
td,
.metric-value,
.plan-price,
.portal-balance-value,
.unit-debt {
  font-variant-numeric: tabular-nums;
}

.money,
th.money,
td.money,
.numeric-right {
  text-align: right;
  white-space: nowrap;
}

.inline {
  display: inline;
}

.inline-area-form {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  margin: 0;
}

.inline-area-form input {
  width: 92px;
  text-align: right;
}

.break-word {
  overflow-wrap: anywhere;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* layout */
.app-layout {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  z-index: 20;
  inset: 0 auto 0 0;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  overflow-y: auto;
  background: var(--ink);
  color: #ffffff;
}

.sidebar-brand {
  display: block;
  min-height: 64px;
  padding: 19px var(--space-5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 19px;
  font-weight: 700;
  line-height: 26px;
  text-decoration: none;
}

.sidebar-brand:hover {
  color: #ffffff;
}

.sidebar-nav {
  padding: var(--space-3) 0 var(--space-5);
}

.sidebar-label {
  margin: var(--space-4) var(--space-4) var(--space-1);
  color: #aeb8c3;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar-nav a,
.sidebar-logout {
  display: block;
  width: 100%;
  min-height: 36px;
  padding: 7px var(--space-4) 7px 20px;
  border: 0;
  border-left: 4px solid transparent;
  border-radius: 0;
  background: transparent;
  color: #dce2e8;
  font: inherit;
  text-align: left;
  text-decoration: none;
}

.sidebar-nav a:hover,
.sidebar-nav a:focus-visible,
.sidebar-logout:hover,
.sidebar-logout:focus-visible,
.sidebar-nav a[aria-current="page"] {
  border-left-color: var(--brand);
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--space-3) 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-footer form {
  margin: 0;
}

.app-main {
  min-width: 0;
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}

.workspace-bar {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.workspace-account {
  min-width: 0;
}

.workspace-switcher {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-2);
}

.workspace-switcher select {
  width: auto;
  max-width: 280px;
}

.workspace-account strong,
.workspace-account span,
.workspace-user strong,
.workspace-user span {
  display: block;
}

.workspace-account strong,
.workspace-user strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-account span,
.workspace-user span {
  color: var(--ink-soft);
  font-size: 12px;
}

.workspace-user {
  text-align: right;
}

.content {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-5);
}

.auth-layout {
  min-height: 100vh;
}

.auth-header {
  min-height: 64px;
  padding: 18px var(--space-5);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.auth-header .brand {
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  text-decoration: none;
}

.auth-content {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

.nav-toggle,
.nav-toggle-button {
  display: none;
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.page-heading h1,
.page-heading p {
  margin-bottom: var(--space-1);
}

.page-heading > .actions {
  margin-top: 0;
}

.section-stack > * + * {
  margin-top: var(--space-4);
}

.split-layout,
.payment-columns,
.document-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.document-layout {
  grid-template-columns: minmax(280px, 1fr) minmax(420px, 2fr);
}

/* components */
.card,
.panel {
  margin: 0 0 var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.card > :last-child,
.panel > :last-child {
  margin-bottom: 0;
}

.form-card {
  max-width: 680px;
}

.narrow {
  max-width: 430px;
  margin: var(--space-6) auto;
}

.actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.actions form,
.button-row form {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
}

.button,
button,
input[type="submit"] {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 7px var(--space-3);
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  text-decoration: none;
}

.button:hover,
button:hover,
input[type="submit"]:hover {
  border-color: var(--brand-ink);
  background: var(--brand-ink);
  color: #ffffff;
}

.button.secondary,
button.secondary,
.button-secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button.secondary:hover,
button.secondary:hover,
.button-secondary:hover {
  border-color: var(--muted);
  background: var(--bg);
  color: var(--ink);
}

.button.danger,
button.danger,
.button-danger {
  border-color: var(--bad);
  background: var(--bad);
  color: #ffffff;
}

.button.danger:hover,
button.danger:hover,
.button-danger:hover {
  border-color: #8f2f25;
  background: #8f2f25;
}

.button-sm,
.button.tiny {
  min-height: 30px;
  padding: 4px var(--space-2);
  font-size: 13px;
  line-height: 20px;
}

.button-block {
  width: 100%;
  min-height: 44px;
}

.link-button {
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 400;
  text-decoration: underline;
}

.link-button:hover {
  border: 0;
  background: transparent;
  color: var(--brand-ink);
}

button:disabled,
input[type="submit"]:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

form p,
.form-group {
  margin: 0 0 var(--space-4);
}

label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  padding: 6px var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
}

input[readonly] {
  background: var(--bg);
  color: var(--ink-soft);
}

.check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: 14px;
  font-weight: 400;
}

.check input,
.compact-check,
input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  min-height: 16px;
  accent-color: var(--brand);
}

.helptext,
form small {
  display: block;
  margin-top: var(--space-1);
  color: var(--ink-soft);
  font-size: 12px;
}

.errorlist,
.field-error,
.cell-error {
  margin: var(--space-1) 0 0;
  padding: 0;
  color: var(--bad);
  font-size: 13px;
  list-style: none;
}

.table-wrap,
.table-responsive,
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

th,
td {
  min-height: 40px;
  padding: 9px var(--space-2);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody tr:hover {
  background: var(--brand-bg);
}

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

.status,
.badge {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  line-height: 18px;
  white-space: nowrap;
}

.status-rented,
.status-active,
.status-processed,
.status-confirmed,
.status-closed,
.status-resolved,
.status-auto_matched,
.status-manual,
.status-imported,
.status-issued,
.status-success,
.badge-success,
.badge.success {
  background: var(--good-bg);
  color: var(--good);
}

.status-reserved,
.status-open,
.status-uploaded,
.status-with_errors,
.status-needs_review,
.status-new,
.status-acknowledged,
.status-warning,
.badge-warning,
.badge.warning {
  background: var(--warn-bg);
  color: var(--warn);
}

.status-debt,
.status-overdue,
.status-failed,
.status-unmatched,
.status-error,
.badge-danger,
.badge.danger {
  background: var(--bad-bg);
  color: var(--bad);
}

.status-vacant,
.status-draft,
.status-rolled_back,
.status-terminated,
.status-dismissed,
.status-muted,
.badge-muted {
  background: var(--muted-bg);
  color: var(--ink-soft);
}

.flash,
.message,
.notice,
.warning,
.known-format {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.flash,
.message,
.notice-good,
.known-format {
  border-color: rgba(33, 122, 75, 0.3);
  background: var(--good-bg);
  color: var(--good);
}

.warning,
.notice-warn {
  border-color: rgba(184, 134, 11, 0.3);
  background: var(--warn-bg);
  color: var(--ink);
}

.notice-bad,
.message.error {
  border-color: rgba(176, 58, 46, 0.3);
  background: var(--bad-bg);
  color: var(--bad);
}

.notice-info {
  border-color: rgba(31, 78, 121, 0.3);
  background: var(--brand-bg);
  color: var(--brand-ink);
}

.empty-state {
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.empty-state p {
  margin-bottom: var(--space-3);
  color: var(--ink-soft);
}

.empty-state .button {
  margin: 0 auto;
}

.metric-grid,
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.metric-card,
.stats > .card {
  min-width: 0;
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-value,
.stats > .card > strong:first-child {
  display: block;
  overflow: hidden;
  margin-bottom: var(--space-1);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
}

.metric-label,
.stats > .card > span {
  display: block;
  color: var(--ink-soft);
  font-size: 13px;
}

.metric-card-negative .metric-value,
.metric-card-negative > strong:first-child {
  color: var(--bad);
}

.metric-card-positive .metric-value {
  color: var(--good);
}

.metric-card-accent {
  padding: var(--space-4);
  border: 2px solid var(--brand);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-card-accent .metric-value,
.metric-card-accent h2 {
  color: var(--brand);
}

.checklist {
  padding-left: 0;
  list-style: none;
}

.checklist li {
  position: relative;
  min-height: 24px;
  padding-left: var(--space-5);
}

.checklist li::before {
  position: absolute;
  top: 3px;
  left: 0;
  width: 16px;
  height: 16px;
  border: 1px solid var(--bad);
  border-radius: 4px;
  color: var(--bad);
  content: "";
}

.checklist li.done::before {
  border-color: var(--good);
  background: var(--good-bg);
}

.checklist li.done::after {
  position: absolute;
  top: 4px;
  left: 5px;
  color: var(--good);
  content: "\2713";
  font-size: 12px;
  font-weight: 700;
}

.period-card,
.item-heading,
.header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.details-card summary {
  margin: calc(var(--space-4) * -1);
  padding: var(--space-4);
}

.details-card[open] summary {
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--line);
}

.danger-confirm {
  margin-top: var(--space-5);
  border-color: rgba(176, 58, 46, 0.3);
}

.danger-confirm summary {
  color: var(--bad);
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.segmented label {
  min-height: 32px;
  margin: 0;
  padding: 6px var(--space-3);
  border-radius: 4px;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 13px;
  line-height: 20px;
}

.dropdown-menu {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(28, 39, 51, 0.12);
}

/* pages */
.dashboard-section {
  margin-top: var(--space-5);
}

.dashboard-section > h2 {
  margin-bottom: var(--space-3);
}

.insight-widget {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.insight-widget p {
  margin-bottom: 0;
}

.chessboard-card {
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.chessboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.chessboard-toolbar h2 {
  margin: 0;
}

.chessboard-mode:focus-visible + label {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

#chess-status:checked ~ .chessboard-toolbar label[for="chess-status"],
#chess-debt:checked ~ .chessboard-toolbar label[for="chess-debt"],
#chess-term:checked ~ .chessboard-toolbar label[for="chess-term"] {
  background: var(--brand);
  color: #ffffff;
}

.chess-property + .chess-property {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.chess-property-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.chess-property-heading h3,
.chess-property-heading p {
  margin: 0;
}

.chess-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--space-2);
}

.unit-tile {
  display: flex;
  min-height: 96px;
  flex-direction: column;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
}

.unit-tile:hover {
  border-color: var(--brand);
  color: var(--ink);
}

.unit-tile.status-rented {
  background: var(--good-bg);
}

.unit-tile.status-reserved {
  background: var(--warn-bg);
}

.unit-tile.status-vacant {
  background: var(--muted-bg);
}

.unit-name {
  font-weight: 600;
}

.unit-area,
.unit-term {
  color: var(--ink-soft);
  font-size: 12px;
}

.unit-debt {
  margin-top: auto;
  color: var(--bad);
  font-size: 13px;
  font-weight: 600;
}

.unit-debt-clear {
  color: var(--good);
  font-weight: 600;
}

#chess-debt:checked ~ .chessboard-groups .unit-tile {
  background: var(--muted-bg);
}

#chess-debt:checked ~ .chessboard-groups .unit-tile.debt-clear {
  background: var(--good-bg);
}

#chess-debt:checked ~ .chessboard-groups .unit-tile.debt-due,
#chess-debt:checked ~ .chessboard-groups .unit-tile.debt-overdue {
  background: var(--bad-bg);
}

#chess-term:checked ~ .chessboard-groups .unit-tile {
  background: var(--muted-bg);
}

#chess-term:checked ~ .chessboard-groups .unit-tile.term-stable {
  background: var(--good-bg);
}

#chess-term:checked ~ .chessboard-groups .unit-tile.term-soon {
  background: var(--warn-bg);
}

#chess-term:checked ~ .chessboard-groups .unit-tile.term-expired {
  background: var(--bad-bg);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
  color: var(--ink-soft);
  font-size: 12px;
}

.legend-item::before {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: var(--space-1);
  border-radius: 2px;
  background: var(--muted-bg);
  content: "";
}

.legend-good::before {
  background: var(--good-bg);
  border: 1px solid var(--good);
}

.legend-warn::before {
  background: var(--warn-bg);
  border: 1px solid var(--warn);
}

.legend-bad::before {
  background: var(--bad-bg);
  border: 1px solid var(--bad);
}

.legend-muted::before {
  background: var(--muted-bg);
  border: 1px solid var(--muted);
}

.billing-stats .metric-value,
.billing-stats > .card > strong:first-child {
  font-size: 22px;
}

.review-card h2 {
  margin-bottom: var(--space-1);
}

.review-card label {
  margin-bottom: var(--space-2);
}

.subpanel {
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}

.inline-filter,
.filter-bar,
.filters-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2);
}

.inline-filter input,
.inline-filter select {
  width: auto;
}

.filter-field {
  min-width: 160px;
  flex: 1;
}

.import-review {
  min-width: 1100px;
}

.import-review td {
  min-width: 145px;
  vertical-align: top;
}

.import-review td:first-child,
.import-review td:nth-child(2) {
  min-width: 75px;
}

.import-review input {
  min-width: 130px;
}

.confidence-high {
  background: var(--good-bg);
}

.confidence-medium {
  background: var(--warn-bg);
}

.confidence-low {
  background: var(--bad-bg);
}

.control-totals {
  margin-top: var(--space-4);
}

.finding-actions {
  display: flex;
  min-width: 190px;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.finding-actions form {
  margin: 0;
}

.dismiss-form {
  display: grid;
  width: 100%;
  grid-template-columns: 1fr auto;
  gap: var(--space-1);
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

.plan-card {
  display: flex;
  flex-direction: column;
  margin: 0;
}

.plan-card.current-plan {
  border: 2px solid var(--good);
}

.plan-price {
  font-size: 18px;
}

.plan-card form,
.plan-card .plan-action {
  margin-top: auto;
}

.status-code {
  color: var(--warn);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.grace-banner {
  margin-bottom: var(--space-4);
}

.document-preview {
  width: 100%;
  min-height: 500px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.document-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.form-fieldset {
  margin: 0 0 var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.form-fieldset legend {
  padding: 0 var(--space-1);
  font-size: 13px;
  font-weight: 600;
}

.date-range {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.definition-list {
  margin: 0 0 var(--space-4);
}

.definition-list > div {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(0, 2fr);
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line);
}

.definition-list dt {
  color: var(--ink-soft);
  font-size: 13px;
}

.definition-list dd {
  margin: 0;
}

.document-public-link {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.portal-shell {
  min-height: 100vh;
  background: var(--bg);
}

.portal-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.portal-header-inner {
  display: flex;
  min-height: 64px;
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.portal-brand {
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
}

.portal-contract {
  color: var(--ink-soft);
  font-size: 13px;
  text-align: right;
}

.portal-container {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-4);
}

.portal-object {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.portal-object h1 {
  margin-bottom: var(--space-1);
  font-size: 17px;
}

.portal-object p {
  margin: 0;
}

.portal-nav {
  display: flex;
  gap: 0;
  margin-bottom: var(--space-4);
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}

.portal-nav a {
  min-height: 44px;
  padding: var(--space-3);
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.portal-nav a:hover,
.portal-nav a.active,
.portal-nav a[aria-current="page"] {
  border-bottom-color: var(--brand);
  color: var(--brand);
}

.portal-balance {
  padding: var(--space-5) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.portal-balance-value {
  display: block;
  color: var(--good);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

.portal-balance-value.has-debt {
  color: var(--bad);
}

.portal-balance-label {
  display: block;
  margin-top: var(--space-1);
  color: var(--ink-soft);
  font-size: 13px;
}

.portal-paid-through {
  margin: var(--space-3) 0 0;
  font-weight: 600;
}

.portal-metrics {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.portal-card-list {
  display: grid;
  gap: var(--space-2);
}

.portal-document {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.portal-document-button {
  display: flex;
  width: 100%;
  min-height: 60px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
}

.portal-document-button:hover {
  border-color: var(--brand);
  background: var(--brand-bg);
  color: var(--ink);
}

.portal-document-button > span:first-child,
.portal-document-button strong,
.portal-document-button .portal-document-meta {
  display: block;
}

.portal-document-action {
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.portal-document p {
  margin: 0;
}

.portal-document-meta {
  color: var(--ink-soft);
  font-size: 13px;
}

.portal-accrual {
  margin-bottom: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.portal-accrual-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.portal-accrual-heading h3,
.portal-accrual-heading p {
  margin: 0;
}

.portal-reading-value {
  min-height: 52px;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

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

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

@media (max-width: 780px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 120ms ease-out;
  }

  .app-main {
    margin-left: 0;
  }

  .nav-toggle-button {
    display: inline-flex;
    width: 36px;
    min-width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
  }

  .nav-toggle-button svg {
    width: 16px;
    height: 16px;
  }

  .nav-toggle:checked ~ .sidebar {
    transform: translateX(0);
  }

  .nav-toggle:checked ~ .app-main .nav-toggle-button {
    border-color: var(--brand);
    color: var(--brand);
  }

  .workspace-bar {
    padding: var(--space-3) var(--space-4);
  }

  .workspace-account {
    margin-right: auto;
  }

  .workspace-user span {
    display: none;
  }

  .content {
    padding: var(--space-4);
  }

  .split-layout,
  .payment-columns,
  .document-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .page-heading,
  .period-card,
  .item-heading,
  .header-actions,
  .insight-widget,
  .chessboard-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .page-heading .button,
  .page-heading button {
    width: 100%;
    min-height: 44px;
  }

  .metric-grid,
  .stats,
  .portal-metrics {
    grid-template-columns: 1fr;
  }

  .actions > .button,
  .actions > button,
  .button-row > .button,
  .button-row > button {
    flex: 1 1 100%;
    min-height: 44px;
  }

  .portal-container {
    padding: var(--space-3);
  }

  .portal-header-inner {
    padding: var(--space-3);
  }

  .portal-object {
    align-items: flex-start;
    flex-direction: column;
  }

  .portal-document {
    grid-template-columns: 1fr;
  }

  .portal-document-button {
    min-height: 72px;
    align-items: stretch;
    flex-direction: column;
  }

  .portal-document-action {
    display: flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--brand);
    border-radius: var(--radius);
    background: var(--brand);
    color: #ffffff;
  }

  .portal-document .button {
    width: 100%;
    min-height: 44px;
  }

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

  .segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .segmented label {
    text-align: center;
  }

  .chess-grid {
    grid-template-columns: repeat(2, minmax(96px, 1fr));
  }
}

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

/* Floorplan Chessboard Styles */
.unit-polygon {
  fill: var(--muted-bg);
  fill-opacity: 0.7;
  stroke: var(--line);
  stroke-width: 2;
  cursor: pointer;
  transition: fill 0.2s, stroke 0.2s, fill-opacity 0.2s;
}

.unit-polygon:hover {
  stroke: var(--brand);
  stroke-width: 3.5;
  fill-opacity: 0.9;
}

.unit-polygon.status-rented { fill: var(--good-bg); stroke: var(--good); }
.unit-polygon.status-reserved { fill: var(--warn-bg); stroke: var(--warn); }
.unit-polygon.status-vacant { fill: var(--muted-bg); stroke: var(--line); }

#chess-debt:checked ~ .chessboard-groups .unit-polygon { fill: var(--muted-bg); stroke: var(--line); }
#chess-debt:checked ~ .chessboard-groups .unit-polygon.debt-clear { fill: var(--good-bg); stroke: var(--good); }
#chess-debt:checked ~ .chessboard-groups .unit-polygon.debt-due,
#chess-debt:checked ~ .chessboard-groups .unit-polygon.debt-overdue { fill: var(--bad-bg); stroke: var(--bad); }

#chess-term:checked ~ .chessboard-groups .unit-polygon { fill: var(--muted-bg); stroke: var(--line); }
#chess-term:checked ~ .chessboard-groups .unit-polygon.term-stable { fill: var(--good-bg); stroke: var(--good); }
#chess-term:checked ~ .chessboard-groups .unit-polygon.term-soon { fill: var(--warn-bg); stroke: var(--warn); }
#chess-term:checked ~ .chessboard-groups .unit-polygon.term-expired { fill: var(--bad-bg); stroke: var(--bad); }

.unit-polygon-label {
  fill: #ffffff;
  font-size: 24px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #000000;
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.view-btn {
  background: transparent;
  border: none;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius);
}

.view-btn.active {
  background: var(--brand);
  color: #ffffff;
}

.unit-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  border: 1px solid var(--line);
  color: var(--ink);
}

.unit-chip.status-rented { background: var(--good-bg); }
.unit-chip.status-reserved { background: var(--warn-bg); }
.unit-chip.status-vacant { background: var(--muted-bg); }

#chess-debt:checked ~ .chessboard-groups .unit-chip { background: var(--muted-bg); }
#chess-debt:checked ~ .chessboard-groups .unit-chip.debt-clear { background: var(--good-bg); }
#chess-debt:checked ~ .chessboard-groups .unit-chip.debt-due,
#chess-debt:checked ~ .chessboard-groups .unit-chip.debt-overdue { background: var(--bad-bg); }

#chess-term:checked ~ .chessboard-groups .unit-chip { background: var(--muted-bg); }
#chess-term:checked ~ .chessboard-groups .unit-chip.term-stable { background: var(--good-bg); }
#chess-term:checked ~ .chessboard-groups .unit-chip.term-soon { background: var(--warn-bg); }
#chess-term:checked ~ .chessboard-groups .unit-chip.term-expired { background: var(--bad-bg); }
