/* Ledger: a cash-flow dashboard where each month eases in. Colours and timing come from tokens.css. */

.ledger {
  --chart-gap: 18px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--lg-bg);
  color: var(--lg-ink);
  font-family: var(--lg-font);
  font-size: 14px;
  line-height: 1.45;
  color-scheme: light;
}

.ledger[data-theme="dark"],
[data-theme="dark"] .ledger { color-scheme: dark; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ledger:not([data-theme="light"]) { color-scheme: dark; }
}

.ledger *,
.ledger *::before,
.ledger *::after { box-sizing: border-box; }

.ledger :focus-visible {
  outline: 2px solid var(--lg-focus);
  outline-offset: 2px;
}

.lg-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.lg-skip {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 50;
  padding: 10px 14px;
  border-radius: var(--lg-radius-sm);
  background: var(--lg-ink);
  color: var(--lg-surface);
  font-weight: 600;
  text-decoration: none;
}
.lg-skip:focus { top: 12px; }

.lg-num { font-family: var(--lg-mono); font-variant-numeric: tabular-nums; }

/* Brand mark */
.lg-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
}
.lg-brand__mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--lg-accent);
  color: var(--lg-on-accent);
}

/* Top bar: only under 900 px */
.lg-topbar { display: none; }

/* Sidebar */
.lg-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 22px 16px 16px;
  background: var(--lg-surface);
  border-right: 1px solid var(--lg-line);
  overflow-y: auto;
}
.lg-nav .lg-brand { padding: 0 8px 20px; }

.lg-nav__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: var(--lg-radius-sm);
  color: var(--lg-ink-2);
  text-decoration: none;
}
.lg-nav__link:hover { background: var(--lg-surface-2); color: var(--lg-ink); }
.lg-nav__link[aria-current="page"] {
  background: var(--lg-accent-soft);
  color: var(--lg-accent-text);
  font-weight: 600;
}
.lg-nav__spacer { flex: 1; }

.lg-badge {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--lg-warn-soft);
  color: var(--lg-warn);
  font-size: 11px;
  font-weight: 500;
}
.lg-badge:empty { display: none; }

.lg-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 12px 0 0 4px;
  border-top: 1px solid var(--lg-line);
}
.lg-profile .lg-icon-btn { width: 32px; height: 32px; }
.lg-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--lg-accent-soft);
  color: var(--lg-accent-text);
  font-size: 12px;
  font-weight: 600;
}
.lg-profile__text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lg-profile__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lg-profile__studio { font-size: 12px; color: var(--lg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.lg-icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--lg-line-strong);
  border-radius: var(--lg-radius-sm);
  background: var(--lg-surface);
  color: var(--lg-ink-2);
  cursor: pointer;
}
.lg-icon-btn:hover { color: var(--lg-ink); background: var(--lg-surface-2); }

/* Main */
.lg-main {
  min-width: 0;
  padding: 22px 28px 40px;
}
.lg-main:focus { outline: none; }

.lg-screen { display: flex; flex-direction: column; gap: 18px; max-width: 1280px; }
.lg-screen[hidden] { display: none; }

.lg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.lg-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.lg-title:focus { outline: none; }
.lg-sub { margin: 0; color: var(--lg-muted); }
.lg-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Buttons and fields */
.lg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--lg-line-strong);
  border-radius: var(--lg-radius-sm);
  background: var(--lg-surface);
  color: var(--lg-ink);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.lg-btn:hover { background: var(--lg-surface-2); }
.lg-btn--primary {
  border-color: var(--lg-accent);
  background: var(--lg-accent);
  color: var(--lg-on-accent);
  font-weight: 600;
}
.lg-btn--primary:hover { background: var(--lg-accent); filter: brightness(1.08); }
.lg-btn--small { min-height: 30px; padding: 0 10px; font-size: 13px; }

.lg-select {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.lg-select select {
  appearance: none;
  min-height: 36px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--lg-line-strong);
  border-radius: var(--lg-radius-sm);
  background: var(--lg-surface);
  color: var(--lg-ink);
  font: inherit;
  cursor: pointer;
}
.lg-select svg {
  position: absolute;
  right: 12px;
  pointer-events: none;
  color: var(--lg-ink-2);
}

.lg-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--lg-ink);
}
.lg-input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--lg-line-strong);
  border-radius: var(--lg-radius-sm);
  background: var(--lg-surface);
  color: var(--lg-ink);
  font: inherit;
  font-size: 14px;
  font-weight: 400;
}
.lg-link {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--lg-accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* Cards */
.lg-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
  background: var(--lg-surface);
  border: 1px solid var(--lg-line);
  border-radius: var(--lg-radius);
  min-width: 0;
}
.lg-card__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.lg-card__title { margin: 0; font-size: 15px; font-weight: 600; }
.lg-card__text { margin: 0; color: var(--lg-muted); }

/* KPI row */
.lg-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.lg-kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  background: var(--lg-surface);
  border: 1px solid var(--lg-line);
  border-radius: var(--lg-radius);
  min-width: 0;
}
.lg-kpi__label { color: var(--lg-muted); }
.lg-kpi__value { font-size: 24px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lg-kpi__note { font-size: 12px; color: var(--lg-muted); }
.lg-kpi__note[data-tone="up"] { color: var(--lg-accent-text); }
.lg-kpi__note[data-tone="down"] { color: var(--lg-warn); }
.lg-kpi--kept { background: var(--lg-accent); border-color: var(--lg-accent); color: var(--lg-on-accent); }
.lg-kpi--kept .lg-kpi__label,
.lg-kpi--kept .lg-kpi__note,
.lg-kpi--kept .lg-kpi__note[data-tone] { color: var(--lg-on-accent-muted); }

/* Overview layout */
.lg-overview-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; align-items: stretch; }
.lg-aside { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.lg-legend { display: flex; gap: 14px; font-size: 12px; color: var(--lg-muted); }
.lg-legend span { display: flex; align-items: center; gap: 6px; }
.lg-legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--lg-bar-in); }
.lg-legend i.is-out { background: var(--lg-bar-out); }
.lg-legend i.is-due { background: none; border: 1.5px dashed var(--lg-bar-in); }

/* Lists */
.lg-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.lg-list__row { display: flex; justify-content: space-between; gap: 12px; }
.lg-list__row[data-late] { color: var(--lg-warn); }
.lg-list__empty { color: var(--lg-muted); }
.lg-new-row { animation: lg-row-in var(--lg-duration) var(--lg-ease); }
@keyframes lg-row-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.lg-meter { display: flex; flex-direction: column; gap: 4px; }
.lg-meter__track { height: 6px; border-radius: 3px; background: var(--lg-surface-2); overflow: hidden; }
.lg-meter__fill { height: 100%; border-radius: 3px; background: var(--lg-accent); }
.lg-meter__fill[data-tone="2"] { background: var(--lg-account-2); }
.lg-meter__fill[data-tone="3"] { background: var(--lg-account-3); }

/* Chart */
.lg-chart { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 8px; min-height: 240px; flex: 1; }
.lg-chart--tall { min-height: 380px; }
.lg-chart__axis {
  position: relative;
  margin: 30px 0 22px;
  font-family: var(--lg-mono);
  font-size: 10px;
  color: var(--lg-muted);
  line-height: 1;
}
.lg-chart__axis span { position: absolute; right: 0; transform: translateY(50%); }
.lg-chart__body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lg-chart__area { position: relative; flex: 1; min-height: 0; margin-top: 30px; }
.lg-chart__plot {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  gap: var(--chart-gap);
  border-bottom: 1px solid var(--lg-line-strong);
  background-image: linear-gradient(var(--lg-surface-2) 1px, transparent 1px);
  background-size: 100% 33.333%;
}
.lg-chart__col { flex: 1; height: 100%; display: flex; gap: 4px; }
.lg-chart__slot { position: relative; flex: 1; height: 100%; }
.lg-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  border-radius: 4px 4px 0 0;
  background: var(--lg-bar-in);
  opacity: 0.55;
}
.lg-bar--out { background: var(--lg-bar-out); opacity: 1; }
.lg-bar--due {
  background: none;
  border: 1.5px dashed var(--lg-bar-in);
  border-bottom: 0;
  opacity: 0;
}
.lg-bar--due.has-due { opacity: 0.55; }
.lg-chart__col.is-selected .lg-bar--in,
.lg-chart__col.is-selected .lg-bar--due.has-due { opacity: 1; }

.lg-chart.is-moving .lg-bar {
  transition:
    height var(--lg-duration) var(--lg-ease),
    bottom var(--lg-duration) var(--lg-ease),
    opacity var(--lg-duration) var(--lg-ease);
}
.lg-chart.is-moving .lg-chart__tip {
  transition: left var(--lg-duration) var(--lg-ease), bottom var(--lg-duration) var(--lg-ease), opacity 120ms linear;
}

.lg-chart__hits {
  position: absolute;
  inset: 0;
  display: flex;
  gap: var(--chart-gap);
}
.lg-chart__hit {
  flex: 1;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.lg-chart__hit:hover { background: color-mix(in srgb, var(--lg-surface-2) 55%, transparent); }

.lg-chart__tip {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 2;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--lg-tip-bg);
  color: var(--lg-tip-ink);
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}
.lg-chart__tip[data-edge="start"] { transform: translateX(-18%); }
.lg-chart__tip[data-edge="end"] { transform: translateX(-82%); }

.lg-chart__labels { display: flex; gap: var(--chart-gap); font-size: 11px; line-height: 16px; color: var(--lg-muted); }
.lg-chart__labels span { flex: 1; text-align: center; }
.lg-chart__labels span.is-selected { color: var(--lg-ink); font-weight: 600; }

/* Tables */
.lg-table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.lg-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.lg-table caption { text-align: left; }
.lg-table th,
.lg-table td { padding: 10px 12px; border-bottom: 1px solid var(--lg-line); text-align: left; white-space: nowrap; }
.lg-table td { height: 44px; }
.lg-table th:first-child,
.lg-table td:first-child { padding-left: 0; }
.lg-table th:last-child,
.lg-table td:last-child { padding-right: 0; }
.lg-table th { font-size: 12px; font-weight: 500; color: var(--lg-muted); }
.lg-table .is-num { text-align: right; font-family: var(--lg-mono); }
.lg-table tr.is-selected td { background: var(--lg-accent-soft); }
.lg-table tr.is-selected td:first-child { box-shadow: inset 3px 0 0 var(--lg-accent); padding-left: 10px; }
.lg-table tbody tr:last-child td { border-bottom: 0; }

.lg-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.lg-sort::after { content: ""; width: 8px; font-size: 10px; }
th[aria-sort="ascending"] .lg-sort { color: var(--lg-ink); }
th[aria-sort="descending"] .lg-sort { color: var(--lg-ink); }
th[aria-sort="ascending"] .lg-sort::after { content: "\25B2"; }
th[aria-sort="descending"] .lg-sort::after { content: "\25BC"; }
.lg-table th.is-num .lg-sort { flex-direction: row-reverse; }

.lg-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--lg-surface-2);
  color: var(--lg-ink-2);
}
.lg-chip[data-status="paid"] { background: var(--lg-accent-soft); color: var(--lg-accent-text); }
.lg-chip[data-status="overdue"] { background: var(--lg-warn-soft); color: var(--lg-warn); }
.lg-chip[data-status="draft"] { color: var(--lg-muted); }

.lg-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.lg-filters .lg-field { min-width: 180px; }
.lg-filters .lg-select select { min-height: 40px; width: 100%; }
.lg-count { margin: 0 0 0 auto; font-size: 13px; color: var(--lg-muted); }

.lg-amount-in { color: var(--lg-accent-text); }

/* Accounts and reports */
.lg-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.lg-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.lg-big { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.lg-stats { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; }
.lg-stats dt { color: var(--lg-muted); }
.lg-stats dd { margin: 0; text-align: right; font-family: var(--lg-mono); font-variant-numeric: tabular-nums; }

/* Settings */
.lg-fieldset { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.lg-fieldset legend { padding: 0; margin-bottom: 8px; font-weight: 600; font-size: 15px; }
.lg-choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--lg-line-strong);
  border-radius: var(--lg-radius-sm);
  cursor: pointer;
}
.lg-choice:has(input:checked) { border-color: var(--lg-accent); background: var(--lg-accent-soft); color: var(--lg-accent-text); font-weight: 600; }
.lg-choice input { accent-color: var(--lg-accent); margin: 0; }
.lg-form { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.lg-form__row { display: flex; align-items: center; gap: 12px; }
.lg-status { margin: 0; font-size: 13px; color: var(--lg-accent-text); }

/* Dialog */
.lg-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--lg-line);
  border-radius: var(--lg-radius);
  background: var(--lg-surface);
  color: var(--lg-ink);
  box-shadow: var(--lg-shadow);
  font-family: var(--lg-font);
  font-size: 14px;
}
.lg-dialog::backdrop { background: var(--lg-scrim, rgb(20 32 28 / 0.4)); }
.lg-dialog[open] { animation: lg-dialog-in 240ms var(--lg-ease); }
.lg-dialog[open]::backdrop { animation: lg-fade-in 240ms linear; }
@keyframes lg-dialog-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes lg-fade-in { from { opacity: 0; } to { opacity: 1; } }
.lg-dialog__form { display: flex; flex-direction: column; gap: 14px; padding: 22px; }
.lg-dialog__title { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.lg-dialog__row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lg-dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* Reduced motion: no growing or moving, a short cross-fade instead (done in ledger.js). */
@media (prefers-reduced-motion: reduce) {
  .lg-chart.is-moving .lg-bar,
  .lg-chart.is-moving .lg-chart__tip { transition: none; }
  .lg-new-row { animation: lg-fade-in var(--lg-fade) linear; }
  .lg-dialog[open] { animation: lg-fade-in var(--lg-fade) linear; }
  .lg-dialog[open]::backdrop { animation: lg-fade-in var(--lg-fade) linear; }
}

/* Under 1100 px the side column moves under the chart. */
@media (max-width: 1100px) {
  .lg-overview-grid { grid-template-columns: minmax(0, 1fr); }
  .lg-aside { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Under 900 px the sidebar becomes a top bar with a menu button. */
@media (max-width: 899px) {
  .ledger { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .lg-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 16px;
    background: var(--lg-surface);
    border-bottom: 1px solid var(--lg-line);
  }
  .lg-nav {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 19;
    height: auto;
    max-height: calc(100vh - 56px);
    padding: 12px 16px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--lg-line);
    box-shadow: var(--lg-shadow);
    display: none;
  }
  .ledger[data-nav-open] .lg-nav { display: flex; }
  .lg-nav .lg-brand { display: none; }
  .lg-nav__spacer { display: none; }
  .lg-main { padding: 18px 16px 32px; }
  .lg-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lg-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .lg-grid-2 { grid-template-columns: minmax(0, 1fr); }
  .lg-chart--tall { min-height: 300px; }
}

@media (max-width: 600px) {
  .ledger { --chart-gap: 8px; }
  .lg-aside { grid-template-columns: minmax(0, 1fr); }
  .lg-kpi__value { font-size: 20px; }
  .lg-dialog__row { grid-template-columns: minmax(0, 1fr); }
  .lg-count { margin-left: 0; width: 100%; }
}
