/* Tennly v2 app styling from design/app-mockup.css, adapted to the real app's
   markup (ids/classes below). Temporary until Atria's tokens land; selectors
   mirror design/APP-LAYOUT.md so a token swap restyles cleanly. */

/* ---------- Shell ---------- */
/* The hidden attribute must win over display rules below (signed-out view). */
[hidden] { display: none !important; }
.shell { display: flex; min-height: 100vh; }
#sidebar {
  width: var(--tn-sidebar-width); flex: none; background: var(--tn-surface);
  border-right: 1px solid var(--tn-rule);
  display: flex; flex-direction: column; padding: 16px 12px;
  position: sticky; top: 0; height: 100vh;
}
body.side-collapsed #sidebar { width: var(--tn-sidebar-collapsed); }
body.side-collapsed #sidebar .word, body.side-collapsed #sidebar .nav-label,
body.side-collapsed #sidebar .nav-count, body.side-collapsed #planMeter { display: none; }
body.side-collapsed .side-head { flex-direction: column; gap: 12px; padding: 12px 0 16px; }
body.side-collapsed #collapseBtn { width: 44px; flex: none; }
body.side-collapsed #sideNav a { justify-content: center; padding: 0; }
body.side-collapsed #sideNav a svg { width: 20px; height: 20px; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 16px; }
.side-head .wordmark { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.side-head .mark {
  width: 28px; height: 28px; flex: none; background: var(--tn-brand); color: var(--tn-on-brand);
  border-radius: var(--tn-radius); display: grid; place-items: center; font-weight: 600; font-size: 15px;
}
.side-head .word { font-size: 16px; font-weight: 600; color: var(--tn-text); }
#sideNav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
#sideNav a {
  display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 0 10px;
  border-radius: var(--tn-radius); color: var(--tn-text); text-decoration: none;
  font-size: var(--tn-size-ui);
}
#sideNav a:hover { background: var(--tn-surface-raised); }
#sideNav a[aria-current="page"] { background: rgba(31, 78, 121, 0.09); color: var(--tn-brand); font-weight: 600; }
#sideNav a svg { width: 18px; height: 18px; flex: none; color: var(--tn-text-muted); }
#sideNav a[aria-current="page"] svg { color: var(--tn-brand); }
#sideNav .nav-count {
  margin-left: auto; min-width: 22px; text-align: center; font-size: 12px; padding: 1px 6px;
  border: 1px solid var(--tn-rule-strong); border-radius: var(--tn-radius-small);
  color: var(--tn-text-muted); font-variant-numeric: tabular-nums;
}
#sideNav .nav-count.alert { color: var(--tn-overdue); border-color: var(--tn-overdue); background: var(--tn-overdue-fill); }
.side-foot { margin-top: auto; padding: 14px 10px 2px; border-top: 1px solid var(--tn-rule); }
.plan-line { font-size: 13px; color: var(--tn-text-muted); margin: 0; }
.plan-line b { color: var(--tn-text); font-weight: 600; }
.meter { height: 4px; background: var(--tn-rule); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.meter > span, .meter > i { display: block; height: 100%; background: var(--tn-brand); }
.iconbtn {
  min-width: 44px; min-height: 44px; display: inline-grid; place-items: center;
  border-radius: var(--tn-radius); border: 1px solid transparent;
  color: var(--tn-text-muted); background: none; cursor: pointer;
}
.iconbtn:hover { background: var(--tn-surface-raised); color: var(--tn-text); }
.iconbtn svg { width: 17px; height: 17px; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  min-height: var(--tn-topbar-height); background: var(--tn-surface);
  border-bottom: 1px solid var(--tn-rule);
  display: flex; align-items: center; gap: 12px; padding: 6px 20px;
  position: sticky; top: 0; z-index: 20;
}
.crumbs { font-size: 13px; color: var(--tn-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs [aria-current] { color: var(--tn-text); font-weight: 600; }
.searchwrap { position: relative; margin-left: auto; width: min(280px, 40vw); }
.searchbox {
  display: flex; align-items: center; gap: 8px; height: 36px; width: 100%;
  border: 1px solid var(--tn-rule-strong); border-radius: var(--tn-radius);
  padding: 0 10px; background: var(--tn-surface); color: var(--tn-text-muted); font-size: 14px;
}
.searchbox svg { width: 16px; height: 16px; flex: none; }
.searchbox input { border: 0; background: none; outline: none; width: 100%; font: inherit; color: var(--tn-text); }
.searchbox kbd { margin-left: auto; font-family: var(--tn-font-mono); font-size: 12px; border: 1px solid var(--tn-rule-strong); border-radius: var(--tn-radius-small); padding: 0 5px; background: var(--tn-surface-raised); }
.menuwrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 8px); right: 0; width: 252px; z-index: 60;
  background: var(--tn-surface); border: 1px solid var(--tn-rule);
  border-radius: var(--tn-radius-panel); box-shadow: var(--tn-shadow-overlay); padding: 6px;
}
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px;
  padding: 0 10px; border-radius: var(--tn-radius); background: none; border: 0;
  color: var(--tn-text); font-size: 14px; cursor: pointer; text-decoration: none; text-align: left;
}
.menu button:hover, .menu a:hover { background: var(--tn-surface-raised); }
.menu button svg, .menu a svg { width: 16px; height: 16px; color: var(--tn-text-muted); }
.menu button.primary { color: var(--tn-brand); font-weight: 600; }
.menu button.primary svg { color: var(--tn-brand); }
.searchwrap .menu { left: 0; right: auto; width: 100%; max-height: 60vh; overflow-y: auto; }
.search-group { font-size: 12px; font-weight: 600; color: var(--tn-text-muted); padding: 8px 10px 2px; }
.avatar { width: 30px; height: 30px; flex: none; border-radius: 50%; background: var(--tn-surface-raised); border: 1px solid var(--tn-rule-strong); color: var(--tn-text); display: inline-grid; place-items: center; font-size: 12px; font-weight: 600; }
#acctBtn { display: inline-flex; align-items: center; gap: 8px; padding: 0 8px; }
#acctBtn svg { width: 15px; height: 15px; }

#view { padding: 24px 20px; max-width: 1200px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 16px; }
.page-head h1 { font-family: var(--tn-font-display); font-size: 26px; font-weight: 600; margin: 0 0 6px; }
.page-head .actions { display: flex; gap: 10px; flex: none; }
.head-sub { font-size: 14px; color: var(--tn-text-muted); }

/* ---------- Buttons (mockup .btn + legacy .btn.secondary names) ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 20px; border-radius: var(--tn-radius); border: 1px solid transparent; font-family: var(--tn-font); font-size: var(--tn-size-ui); font-weight: 600; white-space: nowrap; cursor: pointer; text-decoration: none; background: var(--tn-brand); color: var(--tn-on-brand); }
.btn:hover { background: var(--tn-brand-strong); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--tn-brand); color: var(--tn-on-brand); }
.btn-primary:hover { background: var(--tn-brand-strong); }
.btn-secondary, .btn.secondary { background: none; color: var(--tn-text); border-color: var(--tn-rule-strong); }
.btn-secondary:hover, .btn.secondary:hover { background: var(--tn-surface-raised); }
.btn-danger, .btn.destructive { background: none; color: var(--tn-overdue); border-color: var(--tn-overdue); }
.btn-danger:hover, .btn.destructive:hover { background: var(--tn-overdue-fill); }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 14px; }
.btn-sm svg { width: 15px; height: 15px; }
.link { color: var(--tn-brand); text-decoration: underline; text-underline-offset: 3px; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; min-height: 44px; }

/* ---------- Panels, KPIs ---------- */
.panel { background: var(--tn-surface); border: 1px solid var(--tn-rule); border-radius: var(--tn-radius-panel); padding: 20px; margin-bottom: 24px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.panel-head h2, .panel-head h3 { font-family: var(--tn-font); font-size: 16px; font-weight: 600; margin: 0; }
.panel-head .sub { font-size: 13px; color: var(--tn-text-muted); }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 24px; margin-bottom: 24px; }
.kpi { background: var(--tn-surface); border: 1px solid var(--tn-rule); border-radius: var(--tn-radius-panel); padding: 18px 20px; display: flex; flex-direction: column; gap: 5px; }
.kpi .kpi-label { font-size: 13px; color: var(--tn-text-muted); }
.kpi .kpi-value { font-family: var(--tn-font-display); font-size: clamp(20px, 1.4vw + 10px, 28px); font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; min-width: 0; }
.kpi .kpi-suffix { font-family: var(--tn-font); font-size: 15px; font-weight: 400; color: var(--tn-text-muted); }
.kpi .money { text-align: left; white-space: normal; }
.kpi { min-width: 0; overflow: hidden; }
.kpi .kpi-value .of { font-family: var(--tn-font); font-size: 15px; font-weight: 400; color: var(--tn-text-muted); }
.kpi .kpi-ctx { font-size: 13px; color: var(--tn-text-muted); }
.kpi .progress { height: 5px; background: var(--tn-rule); border-radius: 3px; margin-top: 7px; overflow: hidden; }
.kpi .progress > span { display: block; height: 100%; background: var(--tn-brand); }
.kpi a.k-link, .kpi .k-link { margin-top: 2px; font-size: 14px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 24px; margin-bottom: 24px; }
.stat { background: var(--tn-surface); border: 1px solid var(--tn-rule); border-radius: var(--tn-radius-panel); padding: 18px 20px; }
.stat .n { font-family: var(--tn-font-display); font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 13px; color: var(--tn-text-muted); }

/* ---------- Chart ---------- */
.chart-key { display: flex; gap: 18px; font-size: 13px; color: var(--tn-text-muted); margin-bottom: 6px; }
.chart-key .swatch { width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; display: inline-block; }
.chart svg { width: 100%; height: auto; display: block; }
.ax { font-size: 12px; fill: var(--tn-text-muted); font-family: var(--tn-font); }
.bv { font-size: 11px; fill: var(--tn-text); font-family: var(--tn-font-mono); }

/* ---------- Tables ---------- */
table.ledger { width: 100%; border-collapse: collapse; font-size: var(--tn-size-table); }
table.ledger caption { text-align: left; font-size: 12px; color: var(--tn-text-muted); padding-bottom: 8px; }
table.ledger th { text-align: left; font-size: 13px; font-weight: 500; color: var(--tn-text-muted); padding: 0 12px 8px; border-bottom: 1px solid var(--tn-rule-strong); white-space: nowrap; }
table.ledger td { padding: 0 12px; height: var(--tn-table-row-height); border-bottom: 1px solid var(--tn-rule); vertical-align: middle; }
table.ledger tbody tr:last-child td { border-bottom: none; }
table.ledger tbody tr:hover td { background: var(--tn-surface-raised); }
table.ledger th.num, table.ledger td.num { text-align: right; }
table.ledger .date, table.ledger .ref { white-space: nowrap; }
table.ledger tr.totals td { border-top: 3px double var(--tn-rule-strong); font-weight: 600; }

/* ---------- Status tags ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 8px; border-radius: var(--tn-radius-small); border: 1px solid; font-weight: 500; white-space: nowrap; }
.status.paid, .status.current { color: var(--tn-paid); border-color: var(--tn-paid); background: var(--tn-paid-fill); }
.status.due { color: var(--tn-due); border-color: var(--tn-due); background: var(--tn-due-fill); }
.status.overdue { color: var(--tn-overdue); border-color: var(--tn-overdue); background: var(--tn-overdue-fill); }
.status.review { color: var(--tn-text-muted); border-color: var(--tn-rule-strong); background: var(--tn-surface-raised); }

/* ---------- Needs attention (lead fix: name+unit owns the row width) ---------- */
.attn, .feed { display: flex; flex-direction: column; list-style: none; margin: 0; padding: 0; }
.attn-item { display: flex; align-items: center; gap: 8px 14px; padding: 14px 0; flex-wrap: wrap; }
.attn-item + .attn-item { border-top: 1px solid var(--tn-rule); }
.attn-main { flex: 1 1 12rem; min-width: 0; }
.attn-name { font-size: 15px; font-weight: 600; }
.attn-sub { font-size: 13px; color: var(--tn-text-muted); }
.attn-side { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.attn-amt { text-align: right; }
.attn-amt .money { font-size: 15px; }
.attn-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.feed-item { display: flex; gap: 12px; padding: 13px 0; }
.feed-item + .feed-item { border-top: 1px solid var(--tn-rule); }
.feed-ico { width: 28px; height: 28px; flex: none; border: 1px solid var(--tn-rule); border-radius: var(--tn-radius-small); display: grid; place-items: center; color: var(--tn-text-muted); background: var(--tn-surface-raised); }
.feed-ico svg { width: 15px; height: 15px; }
.feed-text { font-size: 14px; }
.feed-meta { font-size: 13px; color: var(--tn-text-muted); }

/* ---------- Detail header, tabs, rail ---------- */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.detail-head h1 { font-family: var(--tn-font-display); font-size: 26px; font-weight: 600; margin: 0 0 6px; }
.head-sub { font-size: 14px; color: var(--tn-text-muted); }
.contact-row { display: flex; gap: 18px; margin-top: 12px; font-size: 14px; color: var(--tn-text-muted); flex-wrap: wrap; }
.contact-row span { display: inline-flex; align-items: center; gap: 6px; }
.contact-row svg { width: 15px; height: 15px; }
.head-right { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.balance-label { font-size: 13px; color: var(--tn-text-muted); }
.balance-value { font-family: var(--tn-font-display); font-size: 32px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px 8px; border-bottom: 1px solid var(--tn-rule); margin: 16px 0 24px; }
.tab { min-height: 42px; padding: 0 14px; display: inline-flex; align-items: center; font-size: var(--tn-size-ui); color: var(--tn-text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; background: none; border-top: 0; border-left: 0; border-right: 0; cursor: pointer; }
.tab:hover { color: var(--tn-text); }
.tab[aria-current="page"], .tab.active { color: var(--tn-brand); border-bottom-color: var(--tn-brand); font-weight: 600; }
.brk { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; font-size: 14px; margin: 0; }
.brk dt { color: var(--tn-text-muted); }
.brk dd { margin: 0; text-align: right; }
.brk .brk-row-total { display: contents; }
.brk .brk-row-total dt, .brk .brk-row-total dd { border-top: 3px double var(--tn-rule-strong); padding-top: 10px; font-weight: 600; }
.meta-block { font-size: 14px; }
.meta-block .meta-k { font-size: 13px; color: var(--tn-text-muted); display: block; margin-bottom: 2px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 14px; font-weight: 500; display: flex; flex-direction: column; gap: 6px; }
.drawer-body input:not([type="checkbox"]):not([type="radio"]),
.drawer-body select, .drawer-body textarea {
  min-height: 44px; width: 100%; padding: 10px 12px;
  border-radius: var(--tn-radius); border: 1px solid var(--tn-rule-strong);
  background: var(--tn-surface); color: var(--tn-text);
  font-family: var(--tn-font); font-size: 15px;
}
.drawer-body textarea { min-height: 76px; resize: vertical; line-height: 1.5; }
.drawer-body input:focus, .drawer-body select:focus, .drawer-body textarea:focus {
  outline: var(--tn-focus-width) solid var(--tn-text); outline-offset: var(--tn-focus-offset); border-color: var(--tn-text);
}
.drawer-body input.money-input { text-align: right; font-variant-numeric: tabular-nums; }
.field .hint { font-size: 13px; color: var(--tn-text-muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 10px 16px; font-size: 14px; margin: 0; max-width: 640px; }
.kv .money { text-align: left; }
.kv dt { color: var(--tn-text-muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv dd.link-url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

/* ---------- Checklist ---------- */
.chk-item { display: grid; grid-template-columns: 112px 1fr; gap: 14px; padding: 14px 0; }
.chk-item + .chk-item { border-top: 1px solid var(--tn-rule); }
.chk-name { font-size: 14px; font-weight: 600; }
.chk-rule { font-size: 13px; color: var(--tn-text-muted); margin-top: 3px; }
.chk-rule code { font-family: var(--tn-font-mono); font-size: 12px; background: var(--tn-surface-raised); padding: 0 4px; border-radius: 3px; }
.decision-note { font-size: 13px; color: var(--tn-text-muted); border-top: 1px solid var(--tn-rule); margin-top: 16px; padding-top: 14px; }
.letter-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- Drawer ---------- */
#drawer-root .scrim { position: fixed; inset: 0; background: rgba(16, 24, 40, 0.32); z-index: 50; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; width: min(408px, 100vw); background: var(--tn-surface); border-left: 1px solid var(--tn-rule); box-shadow: var(--tn-shadow-overlay); display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 24px 14px; }
.drawer-head h2 { font-family: var(--tn-font); font-size: 18px; font-weight: 600; margin: 0; }
.drawer-body { padding: 0 24px; overflow-y: auto; }
.drawer-foot { margin-top: auto; padding: 16px 24px 20px; border-top: 1px solid var(--tn-rule); }
.drawer-foot .receipt-note { font-size: 13px; color: var(--tn-text-muted); margin-bottom: 12px; }
.drawer-foot .btn-row { display: flex; gap: 12px; }
.drawer-foot .btn-row .btn { flex: 1; }

/* ---------- Receipt / letter sheets ---------- */
.receipt-sheet { max-width: 30rem; background: var(--tn-surface); border: 1px solid var(--tn-rule); border-radius: var(--tn-radius-panel); padding: 32px; }
.letter-sheet { max-width: 40rem; background: var(--tn-surface); border: 1px solid var(--tn-rule); border-radius: var(--tn-radius-panel); padding: 32px; }
.legal-foot { font-size: 12px; color: var(--tn-text-muted); margin: 24px 0 0; }

#bottomtabs, #fabPay { display: none; }
@media (max-width: 767px) {
  #sidebar { display: none; }
  .searchwrap { width: auto; flex: 1; }
  #newBtn { display: none; }
  #bottomtabs {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--tn-surface); border-top: 1px solid var(--tn-rule);
  }
  #bottomtabs a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 10px 4px 12px; min-height: 62px; color: var(--tn-text-muted);
    font-size: 11px; text-decoration: none;
  }
  #bottomtabs a svg { width: 20px; height: 20px; }
  #bottomtabs a[aria-current="page"] { color: var(--tn-brand); font-weight: 600; }
  #fabPay {
    display: inline-flex; position: fixed; left: 16px; right: 16px; bottom: 76px; z-index: 31;
    box-shadow: var(--tn-shadow-overlay);
  }
  #view { padding-bottom: 190px; }
  .page-head [data-act="pay"] { display: none; }
  .detail-head { flex-direction: column; }
  .head-right { align-items: flex-start; text-align: left; }
  .head-actions { justify-content: flex-start; }
  }

.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px; align-items: start; }
table.ledger { table-layout: fixed; width: 100%; }
table.ledger th:last-child, table.ledger td:last-child { width: 9.5rem; }
@media (max-width: 1500px) {
  .grid-2.detail-split { grid-template-columns: minmax(0, 1fr); }
  .grid-2.detail-split > .rail { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
  .grid-2.detail-split > .rail > section { margin: 0; }
}
@media (max-width: 700px) { .grid-2.detail-split > .rail { grid-template-columns: 1fr; } }
.grid-2 > *, .grid-halves > *, .cols-2 > *, .form-grid > * { min-width: 0; }
.grid-halves { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.cols-detail { display: grid; gap: 24px; align-items: start; grid-template-columns: minmax(0, 1fr); }
.cols-detail > * { min-width: 0; }
@media (min-width: 1200px) { .cols-detail { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); } }
@media (max-width: 900px) { .grid-2, .grid-halves, .cols-2 { grid-template-columns: 1fr; } }

/* ---------- Settings sub-nav: vertical, like the main sidebar ---------- */
.setnav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 76px; align-self: start; }
.setnav button {
  background: none; border: 0; text-align: left; padding: 10px 12px; min-height: 44px;
  border-radius: var(--tn-radius); color: var(--tn-text); font-family: var(--tn-font);
  font-size: var(--tn-size-ui); cursor: pointer;
}
.setnav button:hover { background: var(--tn-surface-raised); }
.setnav button[aria-current="page"] { background: rgba(31, 78, 121, 0.09); color: var(--tn-brand); font-weight: 600; }
