/* ==========================================================================

/* ---------------------------------------------------------------------------
   The hidden attribute must actually hide

   `[hidden] { display: none }` is a user-agent rule, so any author rule that
   sets `display` on the same element beats it. `.alert` and `.field` both use
   `display: flex`, which meant every `<div class="alert" hidden>` in the
   codebase rendered anyway — the JavaScript set the attribute correctly and
   nothing happened.

   Found in Phase 13 on the expense form, where a warning about recharging to
   tenants stayed on screen after the choice moved to the landlord. There was
   already a one-off fix for `.tab-panel[hidden]`, which was the same bug
   patched in one place rather than solved.

   !important is warranted here: `hidden` is not a style, it is a statement
   that the element is not currently relevant, and nothing should override it.
   -------------------------------------------------------------------------- */
[hidden] { display: none !important; }

   Nyumba PMS — Application styles
   Base, shell, navigation, cards, forms, tables.
   Interactive layers (modals, toasts, palette) live in components.css.
   ========================================================================== */

/* --- Reset ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  color-scheme: light;
}
[data-mode='dark'] html, html[data-mode='dark'] { color-scheme: dark; }

body {
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  font-feature-settings: 'cv05' 1, 'ss01' 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }

/* Focus is always visible, and always the accent. Never removed. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }

/* Scrollbars: present but quiet. */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--ink-4); background-clip: content-box; }

/* --- Typography helpers ------------------------------------------------ */
h1, h2, h3, h4 { font-weight: 600; line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); }

.display   { font-family: var(--font-display); font-weight: 600; letter-spacing: var(--tracking-tight); }
.page-title{ font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 620; letter-spacing: -.028em; }
.section-title { font-size: var(--text-lg); font-weight: 620; letter-spacing: -.015em; }

/* Money and reference numbers. Tabular so columns of figures align. */
.mono, .figure { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.figure { font-weight: 500; }
.figure--lg { font-size: var(--text-3xl); font-weight: 500; letter-spacing: -.03em; }
.figure--pos { color: var(--pos); } .figure--neg { color: var(--neg); }
/* Used across the reports for figures that want attention without alarm —
   arrears inside their grace period, a partial month, a warning threshold.
   It was referenced in eight views and defined in none, so every one of them
   rendered as ordinary body text. */
.figure--warn { color: var(--warn); }

.eyebrow {
  font-family: var(--font-mono); font-size: var(--text-2xs); font-weight: 600;
  letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--ink-3);
}
.muted     { color: var(--ink-3); }
.muted-more{ color: var(--ink-4); }
.text-sm   { font-size: var(--text-sm); }
.text-xs   { font-size: var(--text-xs); }
.truncate  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2   { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Screen-reader only, but focusable for skip links. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; top: -100px; left: var(--space-4); z-index: 999;
  background: var(--brand); color: var(--brand-contrast);
  padding: var(--space-3) var(--space-5); border-radius: var(--radius-sm); font-weight: 600;
}
.skip-link:focus { top: var(--space-4); }

/* ==========================================================================
   Application shell
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--duration) var(--ease);
}
.app[data-sidebar='collapsed'] { grid-template-columns: var(--sidebar-collapsed) 1fr; }

/* --- Sidebar ----------------------------------------------------------- */
.sidebar {
  background: var(--brand);
  color: color-mix(in srgb, var(--brand-contrast) 82%, transparent);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow: hidden;
  z-index: var(--z-sticky);
}
[data-mode='dark'] .sidebar { background: var(--surface); border-right: 1px solid var(--line); }

.sidebar-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-4);
  min-height: var(--topbar-height); flex: none;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: var(--radius-sm); flex: none;
  background: var(--accent-strong); color: var(--accent-contrast);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 15px; letter-spacing: -.03em;
  overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-text { min-width: 0; overflow: hidden; }
.brand-name {
  font-family: var(--font-display); font-weight: 600; font-size: var(--text-md);
  color: var(--brand-contrast); letter-spacing: -.02em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.brand-sub { font-size: var(--text-2xs); opacity: .8; white-space: nowrap; }

.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: var(--space-2) var(--space-3) var(--space-4); }
.nav-group + .nav-group { margin-top: var(--space-5); }
.nav-group-label {
  font-family: var(--font-mono); font-size: var(--text-2xs); font-weight: 600;
  letter-spacing: var(--tracking-caps); text-transform: uppercase;
  opacity: .45; padding: 0 var(--space-3) var(--space-2); white-space: nowrap;
}

.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-base); font-weight: 500;
  position: relative; white-space: nowrap;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.nav-item + .nav-item { margin-top: 1px; }
.nav-item:hover { background: rgba(255,255,255,.08); color: var(--brand-contrast); }
[data-mode='dark'] .nav-item:hover { background: var(--surface-2); }
.nav-item[aria-current='page'] { background: rgba(255,255,255,.13); color: var(--brand-contrast); font-weight: 600; }
[data-mode='dark'] .nav-item[aria-current='page'] { background: var(--surface-3); }

/* The active marker is a brass rule at the leading edge — the one place
   the accent appears in the navigation, so it reads as "you are here". */
.nav-item[aria-current='page']::before {
  content: ''; position: absolute; left: calc(var(--space-3) * -1 + 2px);
  top: 20%; bottom: 20%; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-icon { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item[aria-current='page'] .nav-icon { opacity: 1; }
.nav-label { overflow: hidden; text-overflow: ellipsis; }
.nav-count {
  margin-left: auto; font-family: var(--font-mono); font-size: var(--text-2xs); font-weight: 600;
  background: rgba(255,255,255,.16); padding: 2px 6px; border-radius: var(--radius-full);
}
.nav-count[data-tone='neg'] { background: var(--neg); color: #fff; }

.sidebar-foot { flex: none; padding: var(--space-3); border-top: 1px solid rgba(255,255,255,.1); }
[data-mode='dark'] .sidebar-foot { border-color: var(--line); }

/* Collapsed rail: labels vanish, icons centre, tooltips take over. */
.app[data-sidebar='collapsed'] .brand-text,
.app[data-sidebar='collapsed'] .nav-label,
.app[data-sidebar='collapsed'] .nav-group-label,
.app[data-sidebar='collapsed'] .nav-count { display: none; }
.app[data-sidebar='collapsed'] .nav-item { justify-content: center; padding-inline: 0; }
.app[data-sidebar='collapsed'] .sidebar-head { justify-content: center; padding-inline: 0; }
.app[data-sidebar='collapsed'] .nav-group + .nav-group {
  margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid rgba(255,255,255,.1);
}

/* --- Topbar ------------------------------------------------------------ */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--space-3);
  height: var(--topbar-height); flex: none;
  padding: 0 var(--space-5);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-2); cursor: pointer;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn--badged { position: relative; }
.icon-btn--badged[data-count]:not([data-count='0'])::after {
  content: attr(data-count);
  position: absolute; top: 1px; right: 1px; min-width: 15px; height: 15px;
  padding: 0 3px; border-radius: var(--radius-full);
  background: var(--neg); color: #fff;
  font-family: var(--font-mono); font-size: 9px; font-weight: 600; line-height: 15px;
  text-align: center; border: 2px solid var(--paper);
}

/* Search opens the command palette rather than being a second search box. */
.topbar-search {
  flex: 1; max-width: 380px;
  display: flex; align-items: center; gap: var(--space-2);
  height: 34px; padding: 0 var(--space-3);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--ink-3);
  font-size: var(--text-sm); cursor: pointer; text-align: left;
  transition: border-color var(--duration-fast) var(--ease);
}
.topbar-search:hover { border-color: var(--line-2); }
.topbar-search svg { width: 15px; height: 15px; flex: none; }
.topbar-search span { flex: 1; }
kbd {
  font-family: var(--font-mono); font-size: var(--text-2xs); font-weight: 500;
  padding: 2px 5px; border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: var(--radius-xs); background: var(--surface-2); color: var(--ink-3);
}
.topbar-spacer { flex: 1; }

.avatar {
  width: 32px; height: 32px; border-radius: var(--radius-full); flex: none;
  display: grid; place-items: center; overflow: hidden;
  background: var(--brand); color: var(--brand-contrast);
  font-size: var(--text-xs); font-weight: 650; letter-spacing: .02em;
}
.avatar--sm { width: 24px; height: 24px; font-size: 10px; }
.avatar--lg { width: 44px; height: 44px; font-size: var(--text-base); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* --- Content ----------------------------------------------------------- */
.content { flex: 1; padding: var(--space-6) var(--space-5) var(--space-16); width: 100%; }
.content-inner { max-width: var(--content-max); margin: 0 auto; }

.page-head {
  display: flex; align-items: flex-start; gap: var(--space-4);
  flex-wrap: wrap; margin-bottom: var(--space-6);
}
.page-head-main { flex: 1; min-width: min(100%, 260px); }
.page-head-actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.page-subtitle { color: var(--ink-3); font-size: var(--text-md); margin-top: var(--space-1); }

.breadcrumb { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--ink-3); margin-bottom: var(--space-2); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb svg { width: 12px; height: 12px; opacity: .5; }

/* --- Grid utilities ---------------------------------------------------- */
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
/* Five across, for the arrears ageing buckets. Collapses to three then two
   rather than shrinking below a readable money figure. */
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px)  { .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 460px)  { .grid-5 { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row-flex { display: flex; align-items: center; gap: var(--space-3); }
.row-flex--wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card--flush { border-radius: 0; border-inline: 0; }
.card-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line);
}
.card-title { font-size: var(--text-base); font-weight: 620; letter-spacing: -.012em; }
.card-body { padding: var(--space-5); }
.card-body--tight { padding: var(--space-4); }
.card-foot {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--line); background: var(--surface-2);
  display: flex; align-items: center; gap: var(--space-3);
}

/* --- KPI tile ---------------------------------------------------------
   Every tile is a link to the list behind the number. A figure you cannot
   drill into is decoration. */
.kpi {
  display: block; position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5);
  transition: border-color var(--duration) var(--ease), transform var(--duration) var(--ease);
}
a.kpi:hover { border-color: var(--line-2); transform: translateY(-2px); }
a.kpi:hover .kpi-go { opacity: 1; transform: translateX(0); }
.kpi-label {
  display: flex; font-size: var(--text-xs); font-weight: 600; color: var(--ink-3);
  letter-spacing: .015em; display: flex; align-items: center; gap: var(--space-2);
}
.kpi-label svg { width: 14px; height: 14px; opacity: .7; }
.kpi-value {
  display: block;
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: var(--text-3xl); font-weight: 500; letter-spacing: -.035em;
  line-height: 1.1; margin-top: var(--space-2);
}
.kpi-value--sm { font-size: var(--text-2xl); }
.kpi-meta {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
  font-size: var(--text-xs); color: var(--ink-3); margin-top: var(--space-2);
}
.kpi-go {
  position: absolute; top: var(--space-4); right: var(--space-4);
  width: 16px; height: 16px; color: var(--accent);
  opacity: 0; transform: translateX(-4px);
  transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease);
}
.kpi[data-tone='pos'] .kpi-value { color: var(--pos); }
.kpi[data-tone='neg'] .kpi-value { color: var(--neg); }
.kpi[data-tone='warn'] .kpi-value { color: var(--warn); }

.delta { display: inline-flex; align-items: center; gap: 3px; font-size: var(--text-xs); font-weight: 600; font-family: var(--font-mono); }
.delta--up { color: var(--pos); } .delta--down { color: var(--neg); } .delta--flat { color: var(--ink-4); }
.delta svg { width: 12px; height: 12px; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0 var(--space-4); height: 36px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-size: var(--text-base); font-weight: 600; letter-spacing: -.008em;
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              transform var(--duration-fast) var(--ease),
              box-shadow var(--duration-fast) var(--ease);
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled='true'] { opacity: .5; cursor: not-allowed; transform: none; }

.btn--primary { background: var(--brand); color: var(--brand-contrast); }
.btn--primary:hover:not([disabled]) { background: var(--brand-hover); box-shadow: var(--shadow-sm); }

.btn--accent { background: var(--accent-strong); color: var(--accent-contrast); }
.btn--accent:hover:not([disabled]) { background: var(--accent-hover); }

.btn--ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink); }
.btn--ghost:hover:not([disabled]) { border-color: var(--ink-4); background: var(--surface-2); }

.btn--quiet { background: transparent; color: var(--ink-2); }
.btn--quiet:hover:not([disabled]) { background: var(--surface-2); color: var(--ink); }

.btn--danger { background: var(--neg); color: var(--danger-contrast); }
.btn--danger:hover:not([disabled]) { filter: brightness(.93); }

.btn--sm { height: 30px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn--sm svg { width: 14px; height: 14px; }
.btn--lg { height: 42px; padding: 0 var(--space-5); font-size: var(--text-md); }
.btn--block { width: 100%; }
.btn--icon { width: 36px; padding: 0; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ==========================================================================
   Badges, pills, status
   ========================================================================== */

.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 3px var(--space-2); border-radius: var(--radius-xs);
  font-size: var(--text-2xs); font-weight: 650; letter-spacing: .02em;
  background: var(--neutral-soft); color: var(--ink-2); white-space: nowrap;
}
.badge--pos  { background: var(--pos-soft);  color: var(--pos-ink); }
.badge--neg  { background: var(--neg-soft);  color: var(--neg-ink); }
.badge--warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge--info { background: var(--info-soft); color: var(--info-ink); }
.badge--brand{ background: var(--brand-soft); color: var(--brand); }
.badge--accent{ background: var(--accent-soft); color: var(--accent-ink); }
[data-mode='dark'] .badge--brand { color: var(--ink); }
.badge--outline { background: transparent; border: 1px solid var(--line-2); color: var(--ink-3); }

/* A dot carries status where a full badge would be noise. */
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--neutral); }
.dot--pos { background: var(--pos); } .dot--neg { background: var(--neg); }
.dot--warn{ background: var(--warn); } .dot--info{ background: var(--info); }
.dot--pulse { box-shadow: 0 0 0 0 currentColor; animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ==========================================================================
   Forms
   ========================================================================== */

.field { margin-bottom: var(--space-4); }
.field--inline { display: flex; align-items: center; gap: var(--space-3); }

.label { display: block; font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-2); }
.label .optional { font-weight: 400; color: var(--ink-4); font-size: var(--text-xs); }
.label .required { color: var(--neg); margin-left: 2px; }

.input, .select, .textarea {
  width: 100%; padding: var(--space-2) var(--space-3); min-height: 36px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--shadow-focus);
}
.input[aria-invalid='true'], .select[aria-invalid='true'], .textarea[aria-invalid='true'] { border-color: var(--neg); }
.input[aria-invalid='true']:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--neg) 22%, transparent); }
.input[readonly], .input[disabled] { background: var(--surface-2); color: var(--ink-3); cursor: not-allowed; }
.textarea { min-height: 88px; resize: vertical; line-height: var(--leading-normal); }

.select {
  appearance: none; padding-right: var(--space-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236C7C72' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--space-3) center; background-size: 15px;
}
[data-mode='dark'] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238FA095' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

/* Money fields: mono, right-aligned, with the currency fixed to the left. */
.input--money { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-prefix {
  display: grid; place-items: center; padding: 0 var(--space-3);
  background: var(--surface-2); border: 1px solid var(--line-2); border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-3); white-space: nowrap;
}

.hint { font-size: var(--text-xs); color: var(--ink-3); margin-top: var(--space-2); line-height: var(--leading-snug); }
.error-text { font-size: var(--text-xs); color: var(--neg); font-weight: 550; margin-top: var(--space-2); display: flex; gap: 4px; align-items: flex-start; }
.error-text svg { width: 13px; height: 13px; flex: none; margin-top: 1px; }

/* Checkbox and radio: the whole row is the target, not just the box. */
.choice {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3); border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.choice:hover { border-color: var(--line-2); background: var(--surface-2); }
.choice input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--brand); flex: none; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice-label { font-size: var(--text-sm); font-weight: 600; }
.choice-hint { font-size: var(--text-xs); color: var(--ink-3); margin-top: 2px; line-height: var(--leading-snug); }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  position: absolute; inset: 0; background: var(--line-2); border-radius: var(--radius-full);
  transition: background var(--duration) var(--ease); pointer-events: none;
}
.switch-track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; box-shadow: var(--shadow-sm);
  transition: transform var(--duration) var(--ease-spring);
}
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--shadow-focus); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 0 var(--space-4); }
.form-section + .form-section { margin-top: var(--space-6); padding-top: var(--space-6); border-top: 1px solid var(--line); }
.form-section-title { font-size: var(--text-sm); font-weight: 650; margin-bottom: var(--space-1); }
.form-section-hint { font-size: var(--text-xs); color: var(--ink-3); margin-bottom: var(--space-4); }

/* ==========================================================================
   Tables
   On mobile these become cards — a horizontally scrolling table is a
   dead end on a phone, and caretakers work on phones.
   ========================================================================== */

.table-wrap { width: 100%; overflow-x: auto; }
.table { font-size: var(--text-sm); }

.table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  padding: var(--space-3) var(--space-4);
  text-align: left; font-size: var(--text-xs); font-weight: 650;
  color: var(--ink-3); letter-spacing: .02em; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.table thead th.is-numeric { text-align: right; }

.table th a.sort {
  display: inline-flex; align-items: center; gap: 4px; color: inherit;
}
.table th a.sort:hover { color: var(--ink); }
.table th a.sort svg { width: 12px; height: 12px; opacity: .35; }
.table th a.sort[data-active] { color: var(--ink); }
.table th a.sort[data-active] svg { opacity: 1; color: var(--accent); }

.table tbody td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background var(--duration-fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.is-numeric { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.table td.is-actions { text-align: right; white-space: nowrap; width: 1%; }
.table .cell-primary { font-weight: 600; color: var(--ink); }
.table .cell-sub { font-size: var(--text-xs); color: var(--ink-3); margin-top: 1px; }
.table tr[data-href] { cursor: pointer; }

/* Row accent for rows needing attention — a hairline, not a wash. */
.table tr[data-flag='neg']  td:first-child { box-shadow: inset 3px 0 0 var(--neg); }
.table tr[data-flag='warn'] td:first-child { box-shadow: inset 3px 0 0 var(--warn); }

.table-toolbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); flex-wrap: wrap;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.search-input { position: relative; flex: 1; min-width: 180px; max-width: 320px; }
.search-input svg {
  position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--ink-4); pointer-events: none;
}
.search-input .input { padding-left: var(--space-8); }

/* Pagination */
.pagination { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.pagination-info { font-size: var(--text-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.page-link {
  min-width: 30px; height: 30px; padding: 0 var(--space-2);
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-variant-numeric: tabular-nums; color: var(--ink-2);
  transition: border-color var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.page-link:hover { border-color: var(--line-2); background: var(--surface-2); }
.page-link[aria-current='page'] { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); font-weight: 600; }
.page-link[aria-disabled='true'] { opacity: .4; pointer-events: none; }

/* ==========================================================================
   Empty states — every list gets one that says what to do next
   ========================================================================== */

.empty { padding: var(--space-12) var(--space-5); text-align: center; }
.empty-art {
  width: 56px; height: 56px; margin: 0 auto var(--space-4);
  display: grid; place-items: center; border-radius: var(--radius-lg);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-4);
}
.empty-art svg { width: 26px; height: 26px; }
.empty-title { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 600; letter-spacing: -.015em; }
.empty-text { color: var(--ink-3); font-size: var(--text-base); max-width: 42ch; margin: var(--space-2) auto var(--space-5); line-height: var(--leading-normal); }

/* An empty state that fills a whole screen rather than sitting inside a list:
   no buildings assigned, nothing to reconcile, a portal with no lease yet. */
.empty--page { padding: var(--space-16) var(--space-5); }
.empty--page .empty-art { width: 72px; height: 72px; border-radius: var(--radius-xl); }
.empty--page .empty-art svg { width: 32px; height: 32px; }
.empty--page .empty-title { font-size: var(--text-xl); }

/* A short line under the message for the practical next step — who to ask,
   what it will look like once it is working. */
.empty-aside {
  max-width: 46ch; margin: 0 auto; padding-top: var(--space-4);
  border-top: 1px solid var(--line);
  font-size: var(--text-sm); color: var(--ink-4); line-height: var(--leading-normal);
}
.empty-aside strong { color: var(--ink-2); font-weight: 600; }

/* The small tinted glyph on a KPI tile. Referenced by the dashboard and the
   health screen and never defined, so the icon inherited body colour and full
   size. */
.kpi-icon {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center; border-radius: var(--radius-md);
  background: var(--surface-2); color: var(--ink-4);
}
.kpi-icon svg { width: 16px; height: 16px; }
.kpi--pos .kpi-icon { background: var(--pos-soft); color: var(--pos); }
.kpi--neg .kpi-icon { background: var(--neg-soft); color: var(--neg); }
.kpi--warn .kpi-icon { background: var(--warn-soft); color: var(--warn); }

/* ==========================================================================
   Skeletons — a shape while data loads, never a bare spinner
   ========================================================================== */

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-xs);
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-line { height: 11px; margin-bottom: var(--space-2); }
.skeleton-line:last-child { width: 60%; margin-bottom: 0; }

/* ==========================================================================
   Motion — entrances are quiet and staggered, never bouncy
   ========================================================================== */

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.rise { animation: rise var(--duration-slow) var(--ease) both; }
.stagger > * { animation: rise var(--duration-slow) var(--ease) both; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 40ms; }
.stagger > *:nth-child(3) { animation-delay: 80ms; }
.stagger > *:nth-child(4) { animation-delay: 120ms; }
.stagger > *:nth-child(5) { animation-delay: 160ms; }
.stagger > *:nth-child(6) { animation-delay: 200ms; }
.stagger > *:nth-child(n+7) { animation-delay: 240ms; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1024px) {
  .app { grid-template-columns: var(--sidebar-collapsed) 1fr; }
  .app[data-sidebar='expanded'] { grid-template-columns: var(--sidebar-collapsed) 1fr; }
}

@media (max-width: 768px) {
  .app, .app[data-sidebar='collapsed'], .app[data-sidebar='expanded'] { grid-template-columns: 1fr; }

  /* Sidebar becomes an off-canvas drawer. */
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, var(--sidebar-width));
    transform: translateX(-100%);
    transition: transform var(--duration-slow) var(--ease);
    z-index: var(--z-drawer); box-shadow: var(--shadow-lg);
  }
  .app[data-mobile-nav='open'] .sidebar { transform: none; }
  .app[data-mobile-nav='open'] .nav-label,
  .app[data-mobile-nav='open'] .nav-group-label,
  .app[data-mobile-nav='open'] .brand-text,
  .app[data-mobile-nav='open'] .nav-count { display: block; }
  .app[data-mobile-nav='open'] .nav-item { justify-content: flex-start; padding-inline: var(--space-3); }
  .app[data-mobile-nav='open'] .sidebar-head { justify-content: flex-start; padding-inline: var(--space-4); }
  .nav-count { display: block; }

  .content { padding: var(--space-4) var(--space-4) var(--space-16); }
  .topbar { padding: 0 var(--space-3); }
  .topbar-search { max-width: none; }
  .topbar-search span, .topbar-search kbd { display: none; }
  .topbar-search { flex: none; width: 34px; justify-content: center; }
  .page-title { font-size: var(--text-xl); }
  .kpi-value { font-size: var(--text-2xl); }

  /* Tables become cards. Each cell carries its own label. */
  .table--responsive thead { display: none; }
  .table--responsive tbody tr {
    display: block; padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--line);
  }
  .table--responsive tbody tr:hover { background: transparent; }
  .table--responsive tbody td {
    display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4);
    padding: 3px 0; border: 0; text-align: right;
  }
  .table--responsive tbody td::before {
    content: attr(data-label);
    font-size: var(--text-xs); font-weight: 600; color: var(--ink-3);
    text-align: left; flex: none;
  }
  .table--responsive tbody td:first-child {
    padding-bottom: var(--space-2); margin-bottom: var(--space-2);
    border-bottom: 1px dashed var(--line); box-shadow: none !important;
  }
  .table--responsive tbody td:first-child::before { display: none; }
  .table--responsive tbody td:first-child { justify-content: flex-start; text-align: left; }
  .table--responsive tbody td.is-actions { justify-content: flex-end; padding-top: var(--space-3); }
  .table--responsive tbody td.is-actions::before { display: none; }
}

/* ==========================================================================
   Reduced motion — honoured everywhere, not selectively
   ========================================================================== */

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