/* =====================================================================
 * Tokens
 * =================================================================== */
:root {
  color-scheme: light;

  /* Surface */
  --bg:           #f4f6f9;
  --panel:        #ffffff;
  --panel-soft:   #f7f9fc;
  --panel-inset:  #f1f4f9;
  --line:         #e4e8ee;
  --line-soft:    #eef1f5;
  --line-strong:  #d3dae3;   /* hover / emphasis borders */
  --bg-soft:      #f5f8fc;   /* row hover, expanded body fills */

  /* Ink */
  --ink:          #0f1419;
  --ink-2:        #2c333d;
  --ink-muted:    #5d6673;
  --ink-faint:    #8a93a0;

  /* Accent — pine green. Reads as property/land rather than SaaS blue. */
  --accent:       #2f6f57;
  --accent-2:     #3d8b6d;
  --accent-hover: #245845;
  --accent-soft:  #e9f3ee;
  --accent-ring:  rgba(61, 139, 109, .28);
  --on-accent:    #ffffff;
  --link:         #2f6f57;
  --link-hover:   #245845;

  /* Solid ink surfaces (near-black chips / buttons / icons) — tokenized so
     dark mode never paints white text onto a light fill. */
  --solid:        #14181f;
  --solid-hover:  #000000;
  --on-solid:     #ffffff;

  /* Semantic (bg / text / hairline triplets so dark can flip cleanly) */
  --danger:       #b42318;
  --danger-bg:    #fee4e2;
  --danger-line:  #fbcaca;
  --warn:         #92400e;
  --warn-bg:      #fef3c7;
  --warn-line:    #fde68a;
  --ok:           #047857;
  --ok-bg:        #d1fae5;
  --ok-line:      #a7f3d0;
  --info:         #1e40af;
  --info-bg:      #dbeafe;
  --info-line:    #bfdbfe;
  --neutral:      #4b5563;
  --neutral-bg:   #e5e7eb;
  --neutral-line: #d1d5db;

  /* Sidebar (its own palette so light-mode tweaks don't drag the rail) */
  --rail-bg:      #0b100e;
  --rail-bg-2:    #131a17;
  --rail-line:    #212b26;
  --rail-edge:    #000000;
  --rail-ink:     #d8ded9;
  --rail-ink-2:   #9aa69f;
  --rail-active:  #ffffff;
  --rail-hover:   rgba(255, 255, 255, .05);
  --rail-active-bg: rgba(255, 255, 255, .08);

  /* Effect */
  --shadow-xs:    0 1px 2px rgba(15, 23, 42, .05);
  --shadow-sm:    0 1px 3px rgba(15, 23, 42, .07), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md:    0 6px 18px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-lg:    0 16px 40px rgba(15, 23, 42, .12);

  --radius-sm:    7px;
  --radius:       10px;
  --radius-lg:    14px;

  --font-sans:    "Inter var", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
                  Roboto, "Helvetica Neue", system-ui, sans-serif;
  --font-mono:    ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;

  --t-fast:       120ms cubic-bezier(.4, 0, .2, 1);
  --t-base:       180ms cubic-bezier(.4, 0, .2, 1);
}

/* =====================================================================
 * Dark theme — a pure token flip. Applies when the OS prefers dark (and
 * the user hasn't forced light via the toggle) or when data-theme="dark"
 * is set. Every component reads these tokens, so the whole app follows.
 * The declaration list is duplicated across the two selectors on purpose:
 * one can't group a media query with an attribute selector.
 * =================================================================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg:           #0b0e13;
    --panel:        #14181f;
    --panel-soft:   #1a1f28;
    --panel-inset:  #1e242e;
    --line:         #272f3b;
    --line-soft:    #1f262f;
    --line-strong:  #3a4453;
    --bg-soft:      #1a1f28;

    --ink:          #e9edf3;
    --ink-2:        #c4ccd6;
    --ink-muted:    #939cac;
    --ink-faint:    #6c7684;

    --accent:       #2f9770;
    --accent-2:     #45b088;
    --accent-hover: #3aa87b;
    --accent-soft:  #12291f;
    --accent-ring:  rgba(69, 176, 136, .40);
    --on-accent:    #ffffff;
    --link:         #67c9a0;
    --link-hover:   #8ad9b8;

    --solid:        #e9edf3;
    --solid-hover:  #ffffff;
    --on-solid:     #0b0e13;

    --danger:       #f9a8a2;
    --danger-bg:    rgba(239, 68, 68, .16);
    --danger-line:  rgba(239, 68, 68, .34);
    --warn:         #fbcf7a;
    --warn-bg:      rgba(245, 158, 11, .15);
    --warn-line:    rgba(245, 158, 11, .32);
    --ok:           #6ee7b7;
    --ok-bg:        rgba(16, 185, 129, .15);
    --ok-line:      rgba(16, 185, 129, .32);
    --info:         #9cc2ff;
    --info-bg:      rgba(59, 130, 246, .16);
    --info-line:    rgba(59, 130, 246, .34);
    --neutral:      #aab3c0;
    --neutral-bg:   rgba(148, 163, 184, .16);
    --neutral-line: rgba(148, 163, 184, .30);

    --rail-bg:      #0c1210;
    --rail-bg-2:    #101815;
    --rail-line:    #212c27;
    --rail-edge:    #000000;
    --rail-ink:     #d8ded9;
    --rail-ink-2:   #929e97;

    --shadow-xs:    0 1px 2px rgba(0, 0, 0, .3);
    --shadow-sm:    0 1px 3px rgba(0, 0, 0, .4), 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md:    0 8px 24px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
    --shadow-lg:    0 20px 48px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:           #0b0e13;
  --panel:        #14181f;
  --panel-soft:   #1a1f28;
  --panel-inset:  #1e242e;
  --line:         #272f3b;
  --line-soft:    #1f262f;
  --line-strong:  #3a4453;
  --bg-soft:      #1a1f28;

  --ink:          #e9edf3;
  --ink-2:        #c4ccd6;
  --ink-muted:    #939cac;
  --ink-faint:    #6c7684;

  --accent:       #2f9770;
  --accent-2:     #45b088;
  --accent-hover: #3aa87b;
  --accent-soft:  #12291f;
  --accent-ring:  rgba(69, 176, 136, .40);
  --on-accent:    #ffffff;
  --link:         #67c9a0;
  --link-hover:   #8ad9b8;

  --solid:        #e9edf3;
  --solid-hover:  #ffffff;
  --on-solid:     #0b0e13;

  --danger:       #f9a8a2;
  --danger-bg:    rgba(239, 68, 68, .16);
  --danger-line:  rgba(239, 68, 68, .34);
  --warn:         #fbcf7a;
  --warn-bg:      rgba(245, 158, 11, .15);
  --warn-line:    rgba(245, 158, 11, .32);
  --ok:           #6ee7b7;
  --ok-bg:        rgba(16, 185, 129, .15);
  --ok-line:      rgba(16, 185, 129, .32);
  --info:         #9cc2ff;
  --info-bg:      rgba(59, 130, 246, .16);
  --info-line:    rgba(59, 130, 246, .34);
  --neutral:      #aab3c0;
  --neutral-bg:   rgba(148, 163, 184, .16);
  --neutral-line: rgba(148, 163, 184, .30);

  --rail-bg:      #0c1210;
  --rail-bg-2:    #101815;
  --rail-line:    #212c27;
  --rail-edge:    #000000;
  --rail-ink:     #d8ded9;
  --rail-ink-2:   #929e97;

  --shadow-xs:    0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm:    0 1px 3px rgba(0, 0, 0, .4), 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md:    0 8px 24px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
  --shadow-lg:    0 20px 48px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--link); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--link-hover); }

h1 {
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 .5rem;
}
h2 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 1.75rem 0 .6rem;
  color: var(--ink);
}
.muted { color: var(--ink-muted); }
.link-muted { color: var(--ink-muted); text-decoration: underline; text-underline-offset: 2px; }
.mono { font-family: var(--font-mono); font-size: .85em; }

/* =====================================================================
 * Layout
 * =================================================================== */
body.has-nav { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
body.no-nav  { display: block; }

.sidebar {
  background: linear-gradient(180deg, var(--rail-bg) 0%, var(--rail-bg-2) 100%);
  color: var(--rail-ink);
  padding: 1.5rem 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-right: 1px solid var(--rail-edge);
  /* Pin to the viewport so the user email / sign-out / version row
     always stays bottom-left no matter how far we scroll. If the nav
     itself overflows the viewport the sidebar scrolls internally
     instead of pushing the foot off. */
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  font-weight: 650;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  color: #fff;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rail-line);
}
.sidebar nav { display: flex; flex-direction: column; gap: .1rem; }
.sidebar nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: .68rem;
  color: var(--rail-ink-2);
  padding: .5rem .75rem .5rem .85rem;
  border-radius: var(--radius-sm);
  font-size: .92rem;
  font-weight: 500;
  transition: color var(--t-fast), background var(--t-fast);
}
.sidebar nav a:hover { color: var(--rail-active); background: var(--rail-hover); }
.sidebar nav a.active {
  color: var(--rail-active);
  background: var(--rail-active-bg);
}
.sidebar nav a.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 22%;
  bottom: 22%;
  width: 3px;
  background: var(--accent-2);
  border-radius: 0 3px 3px 0;
}
/* Nav icons (inline SVG, stroke = currentColor so they follow the link ink). */
.nav-ico {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  display: inline-flex;
  opacity: .82;
}
.nav-ico svg { width: 100%; height: 100%; display: block; }
.sidebar nav a:hover .nav-ico,
.sidebar nav a.active .nav-ico { opacity: 1; }
.nav-section-label {
  margin-top: 1rem;
  padding: 0 .75rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--rail-ink-2);
  opacity: .7;
}

/* Entity switcher — sits above the nav. One portal, two LLCs; every list
   page reads the same filter, so the control belongs in the rail, not on
   each page. */
.entity-switch { display: flex; flex-direction: column; gap: .15rem; margin: 0; }
.entity-switch-label {
  padding: 0 .75rem .3rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--rail-ink-2);
  opacity: .7;
}
.entity-switch a {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .34rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  color: var(--rail-ink-2);
  transition: color var(--t-fast), background var(--t-fast);
}
.entity-switch a:hover { color: var(--rail-active); background: var(--rail-hover); }
.entity-switch a.active {
  color: var(--rail-active);
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}
.entity-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: .55;
}
.entity-switch a.active .entity-dot { opacity: 1; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--rail-line);
  font-size: .85rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.sidebar-user { color: var(--rail-ink); word-break: break-all; font-size: .82rem; }
.sidebar .link-muted { color: var(--rail-ink-2); font-size: .82rem; }
.sidebar .link-muted:hover { color: #fff; }
.sidebar-version {
  margin-top: .4rem;
  align-self: flex-start;
  color: var(--rail-ink-2);
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--rail-line);
  font-size: .7rem;
  font-family: var(--font-mono);
  padding: .15rem .45rem;
  border-radius: 999px;
}
.sidebar-foot-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }

/* Theme toggle — lives in the sidebar foot. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .7rem;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--rail-line);
  border-radius: 999px;
  color: var(--rail-ink-2);
  font: inherit;
  font-size: .8rem;
  font-weight: 500;
  box-shadow: none;
  cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.theme-toggle:hover { color: #fff; background: rgba(255, 255, 255, .09); border-color: var(--rail-ink-2); box-shadow: none; }
.theme-toggle:active { transform: none; }
.theme-toggle svg { width: 15px; height: 15px; display: block; }
/* The visible glyph reflects the *effective* theme (mirrors the token logic). */
.theme-ico-sun { display: none; }
.theme-ico-moon { display: inline-flex; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-ico-sun { display: inline-flex; }
  :root:not([data-theme="light"]) .theme-ico-moon { display: none; }
}
[data-theme="dark"] .theme-ico-sun { display: inline-flex; }
[data-theme="dark"] .theme-ico-moon { display: none; }
[data-theme="light"] .theme-ico-sun { display: none; }
[data-theme="light"] .theme-ico-moon { display: inline-flex; }

.main {
  padding: 2rem 2.5rem 4rem;
  max-width: 1180px;
}

/* =====================================================================
 * Auth (login / invite acceptance)
 * =================================================================== */
/* Full viewport width (override the base .main max-width) so place-items
   centers the auth card on the whole screen, not within a left-pinned
   1180px box. */
body.no-nav .main { display: grid; place-items: center; min-height: 100vh; padding: 2rem; max-width: none; width: 100%; }
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.25rem 2rem;
  width: 100%;
  max-width: 380px;
}
.auth-card h1 { text-align: center; margin-bottom: 1.5rem; }
.auth-brand {
  text-align: center;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: .35rem;
}
.auth-card-wide { max-width: 540px; }
.auth-card-wide h1 { text-align: left; margin-bottom: .5rem; }
.auth-card-wide .auth-brand { text-align: left; }
.totp-secret-block {
  background: var(--panel-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  margin-top: .5rem;
}
.totp-secret-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-muted); margin-top: .35rem; }
.totp-secret-value { font-size: 1rem; word-break: break-all; }
.totp-secret-value code { font-family: var(--font-mono); font-size: 1.05rem; }
.totp-secret-hint { margin-top: .65rem; font-size: .85rem; }

/* =====================================================================
 * Forms
 * =================================================================== */
form { display: flex; flex-direction: column; gap: 1rem; }
label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .85rem;
  font-weight: 500;
  color: var(--ink-2);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="search"],
input[type="datetime-local"],
textarea,
select {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .58rem .7rem;
  width: 100%;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input[type="search"] { appearance: none; -webkit-appearance: none; }
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
input[type="file"] {
  font: inherit;
  font-size: .9rem;
  color: var(--ink-2);
  background: var(--panel-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: .7rem;
  width: 100%;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
input[disabled], textarea[disabled], select[disabled] {
  background: var(--panel-inset);
  color: var(--ink-muted);
  cursor: not-allowed;
}

/* A form rendered as a panel — the standard edit-page shell. */
.card-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  padding: 1.35rem 1.4rem;
}
.form-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
@media (max-width: 720px) {
  .form-grid, .form-row-2, .form-grid-3 { grid-template-columns: 1fr; }
}

.checkbox-inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: .55rem;
  flex-wrap: wrap;
}
.checkbox-inline input[type="checkbox"],
.checkbox-inline input[type="radio"] { width: auto; margin: 0; }
.checkbox-inline small { flex-basis: 100%; margin-top: .15rem; }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem 1.1rem 1.1rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
legend { font-size: .82rem; font-weight: 600; color: var(--ink-muted); padding: 0 .35rem; }

/* =====================================================================
 * Buttons
 * =================================================================== */
button, .btn {
  font: inherit;
  font-weight: 550;
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid transparent;
  padding: .55rem 1.05rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  box-shadow: var(--shadow-xs);
  transition: background var(--t-fast), box-shadow var(--t-fast),
              transform var(--t-fast), border-color var(--t-fast);
}
button:hover, .btn:hover {
  background: var(--accent-hover);
  color: var(--on-accent);
  box-shadow: var(--shadow-sm);
}
button:active, .btn:active { transform: translateY(1px); box-shadow: var(--shadow-xs); }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.btn-secondary {
  background: var(--panel);
  color: var(--ink-2);
  border-color: var(--line);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--panel-soft); color: var(--ink); border-color: var(--line-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #921a14; color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border: 0;
  box-shadow: none;
  padding: .35rem .65rem;
}
.btn-ghost:hover { background: var(--panel-soft); color: var(--ink); box-shadow: none; }
.btn-small { padding: .25rem .65rem; font-size: .78rem; }

button[disabled], .btn[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* =====================================================================
 * Alerts
 * =================================================================== */
.alert {
  padding: .7rem .9rem;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 500;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.alert-ok    { background: var(--ok-bg);     color: var(--ok);     border-color: var(--ok-line); }
.alert-warn  { background: var(--warn-bg);   color: var(--warn);   border-color: var(--warn-line); }
.alert-info  { background: var(--info-bg);   color: var(--info);   border-color: var(--info-line); }
.alert a { color: inherit; text-decoration: underline; }

/* =====================================================================
 * Cards (dashboard tiles)
 * =================================================================== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-top: 1.25rem; }
/* Full-row spacer used to break a KPI strip onto a new line. */
.cards .kpi-break { grid-column: 1 / -1; height: 0; margin: 0; padding: 0; border: 0; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  box-shadow: var(--shadow-xs);
  display: block;
  transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-base);
}
.card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.card-static:hover { transform: none; box-shadow: var(--shadow-xs); border-color: var(--line); }
.card-num { font-size: 2.1rem; font-weight: 650; color: var(--ink); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.card-label { color: var(--ink-muted); font-size: .85rem; font-weight: 500; }
.card-sub { color: var(--ink-faint); font-size: .78rem; margin-top: .2rem; }
.card-num.is-neg { color: var(--danger); }
.card-num.is-pos { color: var(--ok); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  padding: 1.1rem 1.25rem;
}

/* =====================================================================
 * Tables
 * =================================================================== */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  /* auto (not hidden) so a table wider than the viewport scrolls
     horizontally instead of being clipped — important on mobile. */
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-xs);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: .8rem 1rem; text-align: left; vertical-align: middle; }
thead { background: var(--panel-soft); }
th {
  font-size: .72rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: .055em;
  border-bottom: 1px solid var(--line);
}
tbody tr { border-top: 1px solid var(--line-soft); transition: background var(--t-fast); }
tbody tr:first-child { border-top: 0; }
tbody tr:hover { background: var(--panel-soft); }
td { color: var(--ink-2); }

/* Right-align numeric columns app-wide. */
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt-neg { color: var(--danger); }
.amt-pos { color: var(--ok); }

/* Roll-up table totals row. */
tfoot .row-total th,
tfoot .row-total td {
  border-top: 2px solid var(--line);
  font-weight: 650;
  color: var(--ink);
  background: var(--panel-soft);
}

/* Sortable column headers (table.sortable — see assets/app.js). */
.th-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.th-sortable:hover { color: var(--ink); }
.th-sortable.sort-asc::after  { content: " \25B2"; font-size: .8em; }
.th-sortable.sort-desc::after { content: " \25BC"; font-size: .8em; }

/* Truncated cell with hover-to-see-full (uses native title=""). */
.cell-notes {
  max-width: 22rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink-muted);
  cursor: help;
}
.has-tip { cursor: help; border-bottom: 1px dotted var(--ink-faint); }
.empty-state { color: var(--ink-muted); padding: 1.5rem 0; }

/* =====================================================================
 * Toolbar / actions
 * =================================================================== */
.toolbar {
  display: flex;
  gap: .75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.toolbar h1 { margin: 0; }
.toolbar-actions { display: flex; gap: .5rem; }

.actions-cell { display: flex; gap: .4rem; }
.actions-cell a, .actions-cell button { padding: .3rem .65rem; font-size: .82rem; font-weight: 500; }
.inline-form { display: inline; }

.section-heading {
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 1.6rem 0 .6rem;
}

/* =====================================================================
 * Filter chips + list filter row
 * =================================================================== */
.filter-row { display: flex; gap: .4rem; align-items: center; margin-bottom: 1.25rem; flex-wrap: wrap; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  padding: .3rem .8rem;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 500;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink-muted);
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.filter-chip:hover { color: var(--ink); border-color: var(--line-strong); }
.filter-chip.active { background: var(--solid); color: var(--on-solid); border-color: var(--solid); }
.filter-chip.active:hover { color: var(--on-solid); }

/* Generic list-page filter row — search box + selects + apply/reset. */
.list-filters {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: .5rem;
  flex-wrap: wrap;
  margin: 0 0 1.25rem;
}
.list-filters .list-filters-search,
.list-filters .list-filters-select,
.list-filters input[type="date"] {
  width: auto;
  padding: .42rem .7rem;
  font-size: .9rem;
}
.list-filters .btn { padding: .42rem .85rem; font-size: .88rem; }
.list-filters-search { flex: 1 1 260px; max-width: 360px; }
.list-filters-select { flex: 0 1 240px; }
.list-filters .btn-ghost { color: var(--ink-muted); }
.list-filters label { flex-direction: row; align-items: center; gap: .4rem; color: var(--ink-muted); font-size: .82rem; }

/* =====================================================================
 * Status pills — lease / maintenance / transaction states
 * =================================================================== */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: .15rem .6rem;
  border-radius: 999px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .055em;
  font-weight: 650;
  border: 1px solid transparent;
  white-space: nowrap;
}
.status-active        { background: var(--ok-bg);      color: var(--ok);      border-color: var(--ok-line); }
.status-month_to_month{ background: var(--info-bg);    color: var(--info);    border-color: var(--info-line); }
.status-draft         { background: var(--neutral-bg); color: var(--neutral); border-color: var(--neutral-line); }
.status-ended         { background: var(--neutral-bg); color: var(--neutral); border-color: var(--neutral-line); }
.status-terminated    { background: var(--danger-bg);  color: var(--danger);  border-color: var(--danger-line); }
.status-inactive      { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-line); }
.status-archived      { background: var(--neutral-bg); color: var(--neutral); border-color: var(--neutral-line); }
.status-open          { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-line); }
.status-scheduled     { background: var(--info-bg);    color: var(--info);    border-color: var(--info-line); }
.status-in_progress   { background: var(--info-bg);    color: var(--info);    border-color: var(--info-line); }
.status-done          { background: var(--ok-bg);      color: var(--ok);      border-color: var(--ok-line); }
.status-cancelled     { background: var(--neutral-bg); color: var(--neutral); border-color: var(--neutral-line); }
.status-paid          { background: var(--ok-bg);      color: var(--ok);      border-color: var(--ok-line); }
.status-overdue       { background: var(--danger-bg);  color: var(--danger);  border-color: var(--danger-line); }
.status-partial       { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-line); }
.status-uncategorized { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-line); }
.status-duplicate     { background: var(--neutral-bg); color: var(--neutral); border-color: var(--neutral-line); }
.status-new           { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }

/* Category / entity tag — lower-key than a status pill. */
.tag {
  display: inline-flex;
  align-items: center;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .03em;
  padding: .12rem .45rem;
  border-radius: 4px;
  background: var(--neutral-bg);
  color: var(--neutral);
  white-space: nowrap;
}
.tag-income   { background: var(--ok-bg);      color: var(--ok); }
.tag-expense  { background: var(--danger-bg);  color: var(--danger); }
.tag-transfer { background: var(--info-bg);    color: var(--info); }
.tag-capital  { background: var(--accent-soft); color: var(--accent); }
.tag-owner    { background: var(--warn-bg);    color: var(--warn); }

/* =====================================================================
 * Expandable-row tables. A real <table> so columns line up across every
 * row; clicking a row toggles a hidden body row underneath it. Scrolls
 * horizontally inside .table-wrap on narrow screens.
 * =================================================================== */
.exp-table { width: 100%; }
.exp-table th { font-weight: 600; text-transform: uppercase; font-size: .72rem; letter-spacing: .04em; color: var(--ink-muted); }
.exp-table td, .exp-table th { padding: .55rem .75rem; vertical-align: middle; }
.exp-table .exp-chev-col { width: 24px; padding-right: 0; }
.exp-table .exp-chev { width: 24px; padding-right: 0; color: var(--ink-faint); }
.exp-table .exp-chev-mark { display: inline-block; transition: transform var(--t-fast); font-size: .8rem; }
.exp-table .exp-row { cursor: pointer; }
.exp-table .exp-row:hover { background: var(--bg-soft); }
.exp-table .exp-row.open { background: var(--bg-soft); }
.exp-table .exp-row.open .exp-chev-mark { transform: rotate(90deg); }
.exp-table .row-title { font-weight: 600; color: var(--ink); }
.exp-table .exp-body > td {
  background: var(--bg-soft);
  border-top: none;
  padding: .65rem 1rem .85rem;
}
.exp-body-actions {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin-bottom: .55rem;
  flex-wrap: wrap;
}
.exp-body-actions .inline-form { display: inline-flex; }
.exp-body-text {
  color: var(--ink-2);
  font-size: .92rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  padding: .25rem 0 .35rem;
}
.exp-body-meta { font-size: .88rem; margin: .15rem 0; }
.exp-body-meta strong { color: var(--ink); margin-right: .35rem; }
.exp-body-footer { font-size: .78rem; }

/* =====================================================================
 * Drag-and-drop file picker (CSV import, document upload)
 * =================================================================== */
.dropzone {
  position: relative;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
  background: var(--panel);
}
.dropzone:hover { border-color: var(--line-strong); }
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-label { display: block; font-weight: 500; color: var(--ink-2); }
.dropzone-hint { display: block; margin-top: .35rem; font-size: .85rem; color: var(--ink-muted); }
.dropzone-preview {
  list-style: none;
  padding: 0;
  margin: .55rem 0 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  font-size: .85rem;
  color: var(--ink-2);
}
.dropzone-preview[hidden] { display: none; }

/* =====================================================================
 * Definition list — used on detail panes (property, lease, transaction)
 * =================================================================== */
.detail-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .4rem 1.1rem;
  font-size: .9rem;
  margin: 0;
}
.detail-grid dt { color: var(--ink-muted); font-weight: 500; }
.detail-grid dd { margin: 0; color: var(--ink-2); }

/* =====================================================================
 * Mobile nav + polish. Desktop is untouched: the sidebar stays a fixed
 * grid column. On phones the sidebar becomes an off-canvas drawer
 * opened by the hamburger in a sticky top bar. The toggle is a hidden
 * checkbox so it needs no JS.
 * =================================================================== */
.mobile-topbar,
.nav-scrim { display: none; }   /* desktop: hidden */
/* Visually hidden (not display:none) so the <label for> reliably toggles
   it across browsers; position:absolute keeps it out of layout flow. */
.nav-toggle-cb {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 720px) {
  /* Drop the 2-column grid so the sidebar can float above content. */
  body.has-nav { display: block; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: .6rem;
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--rail-bg);
    padding: .5rem .85rem;
    border-bottom: 1px solid #000;
  }
  .mobile-topbar-brand { color: #fff; font-weight: 650; font-size: 1rem; }
  .mobile-topbar-entity {
    margin-left: auto;
    color: var(--rail-ink-2);
    font-size: .74rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 45%;
  }
  .nav-toggle-btn {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    padding: 9px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex: 0 0 auto;
  }
  .nav-toggle-bar { display: block; height: 2px; background: #fff; border-radius: 2px; }

  /* Off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 250px;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform var(--t-base);
  }
  .nav-toggle-cb:checked ~ .sidebar { transform: translateX(0); }

  /* Dim + tap-to-close backdrop (the label closes the checkbox). */
  .nav-scrim {
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, .5);
  }
  .nav-toggle-cb:checked ~ .nav-scrim { display: block; }

  /* General polish — tighten spacing for small screens. */
  .main { padding: 1.1rem 1rem 3rem; }
  h1 { font-size: 1.4rem; }
  .cards { grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: 1rem; }
  .card { padding: .9rem 1rem; }
  .card-num { font-size: 1.6rem; }
  .toolbar { flex-wrap: wrap; }
  .toolbar-actions { flex-wrap: wrap; }
  .list-filters .list-filters-search,
  .list-filters .list-filters-select { flex: 1 1 100%; max-width: none; }
  th, td { padding: .55rem .6rem; }
  .detail-grid { grid-template-columns: 1fr; gap: .1rem .5rem; }
  .detail-grid dd { margin-bottom: .5rem; }
}

@media print {
  .sidebar, .mobile-topbar, .nav-scrim, .toolbar-actions, .list-filters, .filter-row { display: none !important; }
  body.has-nav { display: block; }
  .main { max-width: none; padding: 0; }
  .table-wrap { border: 0; box-shadow: none; overflow: visible; }
}
