:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 8px;
  --scrollbar-size: 10px;
  --scrollbar-track: transparent;
  --scrollbar-thumb: #3a4d66;
  --scrollbar-thumb-hover: #4f6785;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
  width: var(--scrollbar-size);
  height: var(--scrollbar-size);
}

*::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

*::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body.app-ready {
  height: 100vh;
  overflow: hidden;
}

#app {
  height: 100%;
}

#main-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.hidden { display: none !important; }

html.auth-booting #login-view,
html.auth-booting #main-view {
  display: none !important;
}

html.auth-booting body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

html.auth-booting #app {
  width: 100%;
}

#boot-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
  margin: 0 auto;
  width: 100%;
  max-width: 400px;
  padding: 2rem 1.5rem;
}

.boot-spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid #2d3a4f;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: boot-spin 0.8s linear infinite;
}

@keyframes boot-spin {
  to { transform: rotate(360deg); }
}

.error { color: var(--danger); font-size: 0.9rem; }
.subtitle { color: var(--muted); margin-top: -0.5rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.login-panel {
  max-width: 400px;
  margin: 10vh auto;
}

.login-panel form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input, select, button {
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  background: var(--surface2);
  color: var(--text);
}

button {
  cursor: pointer;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
button:hover { background: var(--accent-hover); }
button.secondary { background: var(--surface2); border-color: var(--border); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.stats-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: visible;
  z-index: 40;
  flex-shrink: 0;
}
.stats-chips {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
  font-weight: 500;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
button.stat-chip {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
button.stat-chip:hover {
  background: var(--surface2);
  border-color: var(--accent);
}
.stat-chip:hover {
  border-color: var(--accent);
  background: var(--surface2);
}
.stat-chip-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  background: rgba(59, 130, 246, 0.12);
}
.stat-chip strong { color: var(--accent); }
.stats-legend-wrap {
  position: relative;
  flex-shrink: 0;
  margin-left: auto;
}
.stats-legend-toggle {
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.35rem 0.55rem;
  min-width: 2rem;
}
.stats-legend-toggle[aria-expanded="true"] {
  color: var(--accent);
}
.stats-legend-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 200;
  width: min(720px, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  display: block;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
  transition:
    opacity 0.24s ease,
    transform 0.24s cubic-bezier(0.32, 0.72, 0, 1),
    visibility 0.24s ease;
}
.stats-legend-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}
.stats-legend-panel.hidden {
  display: none !important;
}
.stats-legend-title {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 420px;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

.list-panel {
  padding: 1rem 1.5rem 2.75rem;
  overflow-y: auto;
  min-height: 0;
}
.filters-toolbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  margin-bottom: 1rem;
  padding: 4px 0 0.15rem;
}
.filter-control,
.filter-icon-btn,
.view-toggle .view-btn {
  height: 36px;
  box-sizing: border-box;
  font-size: 0.85rem;
}
.filter-control {
  padding: 0 0.65rem;
  min-width: 0;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.filters-toolbar select.filter-control {
  cursor: pointer;
  appearance: none;
  padding-right: 1.75rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b9cb3' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
}
.filters-toolbar select.filter-control:hover,
.filters-toolbar input.filter-control:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background-color: color-mix(in srgb, var(--accent) 7%, var(--surface2));
}
.filters-toolbar select.filter-control:hover {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%233b82f6' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
.filters-toolbar select.filter-control:focus,
.filters-toolbar input.filter-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.filter-search { flex: 1 1 140px; min-width: 120px; }
.filter-account { flex: 0 1 88px; width: 88px; }
.filter-control-group { flex-shrink: 0; }
.filter-icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  padding: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.filters-toolbar .filter-icon-btn:hover {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface2));
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.filters-toolbar .filter-icon-btn:active {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}
.filters-toolbar .filter-icon-btn svg {
  transition: transform 0.15s;
}
.filters-toolbar .filter-icon-btn:hover svg {
  transform: scale(1.06);
}

.filter-toggle {
  position: relative;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  outline: none;
}
.filter-toggle-track {
  display: block;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background 0.2s, box-shadow 0.15s;
}
.filter-toggle:hover .filter-toggle-track {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.filter-toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.2s;
}
#hide-neutral:checked + .filter-toggle-track {
  background: var(--accent);
}
#hide-neutral:checked + .filter-toggle-track::after {
  transform: translateX(16px);
}
.filter-toggle-tooltip {
  display: none;
  position: fixed;
  z-index: 1200;
  white-space: nowrap;
  padding: 0.35rem 0.55rem;
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text);
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.filter-toggle-tooltip.is-visible {
  display: block;
}

.filters-toolbar .view-btn {
  transition: background 0.15s, color 0.15s;
}
.filters-toolbar .view-btn:not(.active):hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface2));
  color: var(--text);
}

.checkbox { flex-direction: row !important; align-items: center; gap: 0.4rem !important; }

.bulk-actions-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: -0.5rem 0 1rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.bulk-actions-bar.hidden { display: none; }
.col-check { width: 2rem; text-align: center; }
.col-check input { cursor: pointer; }
tbody tr.row-check td.col-check { cursor: default; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.selected { background: var(--surface2); }

#transactions-table tbody tr {
  border-left: 3px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
#transactions-table tbody tr:hover {
  background: var(--surface2);
  border-left-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.15);
}
#transactions-table tbody tr.selected {
  background: rgba(59, 130, 246, 0.1);
  border-left-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}
#transactions-table tbody tr.row-unsettled:hover {
  opacity: 0.72;
}
#transactions-table tbody tr.row-conflict:hover {
  background: rgba(234, 179, 8, 0.24);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-unclassified { background: #334155; color: #cbd5e1; }
.badge-requires_manual { background: #78350f; color: #fde68a; }
.badge-manual { background: #14532d; color: #86efac; }
.badge-auto { background: #1e3a5f; color: #93c5fd; }
.badge-ignored { background: #374151; color: #9ca3af; }
.badge-unsettled { background: #1f2937; color: #9ca3af; border: 1px dashed #6b7280; }
.badge-conflict { background: #713f12; color: #fde68a; border: 1px solid #ca8a04; }

tbody tr.row-unsettled { opacity: 0.55; }
tbody tr.row-unsettled td { color: var(--muted); }
tbody tr.row-unsettled .flow-in,
tbody tr.row-unsettled .flow-out { color: var(--muted); font-weight: 500; }
tbody tr.row-unsettled.selected { opacity: 0.75; }

tbody tr.row-conflict { background: rgba(234, 179, 8, 0.18); }
tbody tr.row-conflict.selected { background: rgba(234, 179, 8, 0.28); }
.conflict-hint { color: #fbbf24; }

.stat-chip-conflict { border-color: #ca8a04; color: #fde68a; }
.stat-chip-warn { border-color: #6b7280; color: #d1d5db; }

.detail-panel {
  border-left: 1px solid var(--border);
  background: var(--surface);
  padding: 0;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.detail-read {
  flex: 1 1 50%;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
}

.detail-read .placeholder { color: var(--muted); text-align: center; margin-top: 3rem; }
.detail-panel-loading {
  color: var(--muted);
  text-align: center;
  margin-top: 2rem;
  font-size: 0.9rem;
}

.detail-header { margin-bottom: 1rem; }
.detail-header h2 { margin: 0 0 0.25rem; font-size: 1rem; }
.meta { color: var(--muted); font-size: 0.85rem; }

.entry-lines {
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.entry-line {
  display: grid;
  grid-template-columns: 70px 1fr 90px;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.entry-line.current { background: var(--surface2); }
.entry-line-header { font-weight: 600; background: var(--surface2); }

.alloc-form { margin-top: 1rem; }
.alloc-row {
  display: grid;
  grid-template-columns: 1fr 90px 32px;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  align-items: center;
}
.alloc-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.weight-sum { font-size: 0.85rem; color: var(--muted); margin: 0.5rem 0; }
.weight-sum.invalid { color: var(--danger); }
.weight-sum.valid { color: var(--success); }

.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  justify-content: center;
}

.persons-dialog {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  max-width: 480px;
  width: 90vw;
}
.persons-dialog.users-dialog {
  max-width: min(1120px, 96vw);
  width: 96vw;
  overflow: visible;
}
dialog[open].persons-dialog,
dialog[open].panel {
  overflow: visible;
}
.persons-dialog::backdrop { background: rgba(0,0,0,0.55); }
.dialog-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.dialog-header h2 { margin: 0; font-size: 1.1rem; }
.persons-list { list-style: none; padding: 0; margin: 0 0 1rem; max-height: 200px; overflow: auto; }
.persons-list li {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.4rem;
  display: flex;
  justify-content: space-between;
}
.persons-list .code { color: var(--muted); font-size: 0.85rem; }
.person-form h3 { margin: 0 0 0.75rem; font-size: 0.95rem; }
.person-form-row { display: grid; grid-template-columns: 1fr 2fr; gap: 0.5rem; margin-bottom: 0.75rem; }

.categories-dialog { max-width: 760px; }
.categories-count-meta { margin: 0 0 0.5rem; }
.categories-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
}
.categories-toolbar input[type="search"] { flex: 1 1 200px; min-width: 160px; }
.categories-filter-chips {
  display: inline-flex;
  gap: 0.35rem;
  flex: 0 0 auto;
}
.categories-filter-chip {
  font-size: 0.78rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.categories-filter-chip:hover {
  border-color: var(--accent);
  background: var(--surface2);
}
.categories-filter-chip.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--accent);
}
.categories-list {
  max-height: min(55vh, 520px);
  overflow: auto;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.categories-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.categories-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
}
.categories-table th,
.categories-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.categories-table tr.category-unmapped td:first-child { color: #fbbf24; }
.category-edit-section {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.job-confirm-dialog { max-width: 560px; }
.job-confirm-steps {
  margin: 0.75rem 0 1rem;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.job-confirm-steps li { line-height: 1.45; }
.job-confirm-note {
  padding: 0.65rem 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.45;
}
.job-confirm-note strong { display: block; margin-bottom: 0.25rem; font-size: 0.82rem; color: var(--muted); }
.job-confirm-warning {
  margin: 0.75rem 0 0;
  color: #fde68a;
}
.job-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}
.tx-card-wide { grid-column: 1 / -1; }

.label-main { font-weight: 500; }
.label-sub { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.label-empty { color: var(--muted); font-style: italic; }

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  height: 36px;
}
.view-btn {
  border: none;
  border-radius: 0;
  background: var(--surface2);
  padding: 0 0.75rem;
  font-size: 0.85rem;
  height: 100%;
}
.view-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.flow-in { color: var(--success); font-weight: 600; font-size: 1.1rem; line-height: 1; }
.flow-out { color: var(--danger); font-weight: 600; font-size: 1.1rem; line-height: 1; }
.flow-neutral { color: var(--muted); }
.col-flow { width: 2rem; text-align: center; }
.col-amount { white-space: nowrap; font-variant-numeric: tabular-nums; width: 7rem; }
.col-alloc { min-width: 6rem; }
.col-title { max-width: 0; width: 35%; }
.tx-title-cell { overflow: hidden; }
.tx-title-cell .label-main {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tx-line-count {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.7rem;
  vertical-align: middle;
}
.alloc-pills {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}
.alloc-meta-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.alloc-display {
  margin: 0.15rem 0 0.65rem;
}
.tx-card .value .alloc-pills {
  justify-content: flex-start;
}
.categories-table .col-alloc {
  min-width: 8rem;
}
.alloc-pill {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  background: color-mix(in srgb, var(--pill-color) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--pill-color) 55%, transparent);
  color: var(--pill-color);
}
.person-color-field { flex: 0 0 auto; }
.person-color-field input[type="color"] {
  width: 2.5rem;
  height: 2rem;
  padding: 0.15rem;
  cursor: pointer;
}
.persons-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.persons-list .person-color-input {
  width: 2rem;
  height: 1.75rem;
  padding: 0.1rem;
  flex-shrink: 0;
  cursor: pointer;
}
.persons-list .person-info { flex: 1; min-width: 0; }

.transaction-dialog {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0;
  width: min(960px, 96vw);
  max-height: 92vh;
}
.transaction-dialog::backdrop { background: rgba(0,0,0,0.6); }
.tx-dialog-body {
  padding: 1rem 1.25rem 1.25rem;
  overflow: auto;
  max-height: calc(92vh - 70px);
}
.tx-summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.tx-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}
.tx-card .label { color: var(--muted); font-size: 0.8rem; }
.tx-card .value { font-size: 1.1rem; font-weight: 600; margin-top: 0.25rem; }
.accounting-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-bottom: 1.25rem; }
.accounting-table th, .accounting-table td {
  text-align: left;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.accounting-table tr.primary-line { background: rgba(59, 130, 246, 0.12); }
.accounting-table tr.clickable { cursor: pointer; }
.accounting-table tr.clickable:hover { background: var(--surface2); }
.tx-classify-section {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.alloc-summary { color: var(--accent); font-weight: 500; font-size: 0.85rem; }

.balance-dock {
  flex: 1 1 50%;
  min-height: 0;
  max-height: 50%;
  display: flex;
  flex-direction: column;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  overflow: hidden;
  transition: flex 0.32s cubic-bezier(0.4, 0, 0.2, 1), max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
.balance-dock.collapsed {
  flex: 0 0 auto;
  min-height: 0;
  max-height: none;
}
.balance-dock-expandable {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 1;
  max-height: 60vh;
  transition:
    max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.24s ease,
    flex 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
.balance-dock.collapsed .balance-dock-expandable {
  max-height: 0;
  opacity: 0;
  flex: 0 0 0;
  pointer-events: none;
}
.balance-dock-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 0 0 auto;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  cursor: default;
}
.balance-dock.collapsed .balance-dock-header {
  border-bottom: none;
}
.balance-dock-header-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
.balance-legend-toggle {
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
}
.balance-legend-panel {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  flex: 0 1 auto;
  min-height: 0;
  max-height: 40vh;
  overflow-y: auto;
}
.balance-legend-cards {
  display: grid;
  gap: 0.65rem;
}
.balance-legend-card {
  margin: 0;
}
.balance-legend-card h4 {
  margin: 0 0 0.25rem;
  font-size: 0.82rem;
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
}
.balance-legend-card p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
}
.balance-hint {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
  margin-left: 0.15rem;
  outline: none;
}
.balance-hint-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.95rem;
  height: 0.95rem;
  font-size: 0.72rem;
  color: var(--accent);
  cursor: help;
  border-radius: 50%;
}
.balance-hint-bubble {
  display: none;
  position: absolute;
  z-index: 1200;
  right: 0;
  bottom: calc(100% + 6px);
  width: min(17rem, calc(100vw - 2.5rem));
  padding: 0.55rem 0.65rem;
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--text);
  font-weight: 400;
  text-align: left;
  pointer-events: none;
}
.balance-hint-bubble.balance-hint-bubble--fixed {
  position: fixed;
  right: auto;
  bottom: auto;
  z-index: 1200;
}
.balance-hint-bubble strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
  color: var(--text);
}
.balance-hint:hover .balance-hint-bubble,
.balance-hint:focus .balance-hint-bubble,
.balance-hint:focus-within .balance-hint-bubble,
.balance-hint.balance-hint--open .balance-hint-bubble {
  display: block;
}
.balance-dock-header h3 { margin: 0; font-size: 0.9rem; }
.balance-dock-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.75rem 0.85rem;
  overflow-y: auto;
  overflow-x: hidden;
}
.balance-person-card {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}
.balance-person-card:last-of-type { border-bottom: none; }
.balance-person-name {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.balance-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.3rem 0;
}
.balance-line-settled {
  padding-top: 0.15rem;
}
.balance-line-cash {
  padding-top: 0.15rem;
}
.balance-line-label {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.1rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.3;
}
.balance-line-settled .balance-line-label {
  font-style: italic;
}
.balance-line-cash .balance-line-label {
  font-style: italic;
}
.balance-line-value {
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.balance-line-value.net-pos { color: var(--success); }
.balance-line-value.net-neg { color: var(--danger); }
.balance-delta-unsettled {
  margin: 0.35rem 0 0;
  color: #9ca3af;
  font-size: 0.72rem;
  font-style: italic;
  overflow-wrap: anywhere;
}
.balance-delta-cash {
  margin: 0.2rem 0 0;
  color: #9ca3af;
  font-size: 0.72rem;
  font-style: italic;
  overflow-wrap: anywhere;
}

.chart-legend-list { margin: 0.75rem 0 0; padding-left: 1.1rem; }
.chart-legend-list li { margin-bottom: 0.35rem; }
.metric-hint { margin-top: 0.75rem; font-style: italic; color: var(--muted); }
.balance-settlement {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.balance-settlement strong { color: var(--text); }
.persons-list li .person-actions { display: flex; gap: 0.35rem; align-items: center; }
.persons-list .delete-person {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 500;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: inherit;
}
.btn-link:hover { background: var(--border); }

.status-legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}
.status-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}
.status-card h4 { margin: 0.4rem 0 0.35rem; font-size: 0.9rem; }
.status-card p { margin: 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.stat-chip-accent strong { color: var(--warning); }

.balance-page {
  padding: 1rem 1.5rem 2rem;
  display: grid;
  gap: 1rem;
}
.balance-controls {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: end;
}
.balance-controls label {
  min-width: 180px;
}
.chart-panel { min-height: 420px; }
.chart-legend h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }

.chart-panel { min-height: 420px; position: relative; }
.chart-panel.loading canvas { opacity: 0.15; }
.chart-loading-overlay {
  position: absolute;
  inset: 1rem;
  z-index: 2;
  pointer-events: none;
}
.chart-legend h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }

/* Dropdown admin menu */
.dropdown { position: relative; }
.dropdown-toggle { white-space: nowrap; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.dropdown-menu:not(.hidden) { display: flex; }
.dropdown-item {
  background: transparent;
  border: none;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-radius: 4px;
  font-weight: 500;
  color: var(--text);
  transition: background 0.12s, color 0.12s;
}
.dropdown-item:hover {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface2));
  color: var(--text);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

/* Progress bar */
.header-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; }
.topbar { position: relative; }
.progress-bar {
  height: 3px;
  background: var(--surface2);
  overflow: hidden;
  border-radius: 2px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease;
}
.progress-bar-indeterminate {
  height: 100%;
  width: 40%;
  background: var(--accent);
  animation: progress-slide 1.2s ease-in-out infinite;
}
@keyframes progress-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
#activity-progress .progress-bar { height: 4px; margin: 0 1rem 0.5rem; border-radius: 2px; }

/* Skeleton loading */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.85; }
}
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.4s ease-in-out infinite;
  border-radius: 4px;
}
.skeleton-cell { height: 1rem; width: 100%; }
.skeleton-text { display: inline-block; height: 0.85rem; width: 5rem; }
.skeleton-chip { min-width: 6rem; }
.skeleton-block { width: 100%; border-radius: var(--radius); }
table.loading tbody { opacity: 0.7; }

/* Bottom sheet activité — overlay, ne réserve plus d'espace dans le flux */
.activity-sheet {
  --activity-panel-max: min(40dvh, 420px);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  pointer-events: none;
}
.activity-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  pointer-events: none;
}
.activity-sheet::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  z-index: 0;
}
.activity-sheet.open {
  pointer-events: auto;
}
.activity-sheet.open::before {
  opacity: 1;
  pointer-events: auto;
}
.activity-tab {
  position: relative;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.35rem 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  pointer-events: auto;
  z-index: 2;
  transition: color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.activity-sheet.open .activity-tab {
  display: none;
}
.activity-panel {
  width: 100%;
  height: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
  transition:
    height 0.32s cubic-bezier(0.32, 0.72, 0, 1),
    max-height 0.32s cubic-bezier(0.32, 0.72, 0, 1),
    opacity 0.24s ease;
}
.activity-sheet.open .activity-panel {
  height: var(--activity-panel-max);
  max-height: var(--activity-panel-max);
  opacity: 1;
  pointer-events: auto;
}
.activity-panel:not(.hidden) { display: flex; }
.activity-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.activity-tabs { display: flex; gap: 0.35rem; }
.activity-tabs button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}
.activity-tabs button.active {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}
.activity-content {
  overflow: auto;
  padding: 0.75rem 1rem 2.5rem;
  flex: 1;
  min-height: 0;
}
.activity-section { margin-bottom: 1rem; }
.activity-section h3 { margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--muted); }
.activity-current-job { font-size: 0.85rem; }
.job-events {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  max-height: 120px;
  overflow-y: auto;
}
.job-event {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.5rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.job-event-time { color: var(--muted); }
.job-event-success .job-event-msg { color: var(--success); }
.job-event-error .job-event-msg { color: var(--danger); }
.job-event-warn .job-event-msg { color: var(--warning); }
.job-current-header { display: flex; gap: 0.5rem; align-items: center; }
.job-history-table { font-size: 0.82rem; }
.job-status-success { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.job-status-error { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.job-status-running, .job-status-pending { background: rgba(59, 130, 246, 0.15); color: var(--accent); }

.activity-feed {
  list-style: none;
  margin: 0;
  padding: 0;
}
.activity-item {
  display: grid;
  grid-template-columns: 4.5rem 1fr 1fr 1.5fr;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  align-items: baseline;
}
.activity-time { color: var(--muted); }
.activity-actor { font-weight: 500; }
.activity-detail { color: var(--muted); }

/* Toast */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast-container-dialog {
  z-index: 2;
  top: 0.75rem;
  right: 0.75rem;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  max-width: 360px;
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--accent); }

/* Users admin */
.users-list-host { margin-bottom: 1rem; }
.users-table { width: 100%; font-size: 0.85rem; table-layout: auto; }
.users-table select { min-width: 9rem; max-width: 100%; }
.users-table .user-scoped-person-select { min-width: 11rem; }
.users-table td:first-child { white-space: normal; word-break: break-word; max-width: 240px; }
.users-table td .user-actions { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.btn-inline {
  background: transparent;
  border: 1px solid var(--border);
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 500;
}
.btn-inline.danger { color: var(--danger); }

.reconcile-score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.score-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}
.score-card strong { display: block; font-size: 1.4rem; margin-top: 0.25rem; }
.score-label { font-size: 0.75rem; color: var(--muted); }
.score-pass { border-color: var(--success); }
.score-warn { border-color: var(--warning); }
.reconcile-table { font-size: 0.85rem; width: 100%; }
.controls-toolbar { margin-bottom: 0.75rem; }

.bucket-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}
.bucket-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
}
.bucket-card h4 { margin: 0 0 0.5rem; font-size: 0.9rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.bucket-values { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; }

@media (prefers-reduced-motion: reduce) {
  .activity-panel,
  .activity-sheet::before,
  .activity-tab,
  .balance-dock,
  .balance-dock-expandable,
  .stats-legend-panel {
    transition: none !important;
  }
  .activity-sheet.open .activity-panel {
    height: var(--activity-panel-max);
    max-height: var(--activity-panel-max);
    opacity: 1;
  }
  .stats-legend-panel.is-open {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 900px) {
  body.app-ready {
    height: auto;
    overflow: visible;
  }
  #main-view {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .layout {
    grid-template-columns: 1fr;
    flex: none;
    min-height: calc(100vh - 120px);
  }
  .detail-panel {
    height: auto;
    min-height: 280px;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .detail-read {
    flex: 1 1 auto;
    min-height: 200px;
  }
  .balance-dock {
    flex: 0 0 auto;
    max-height: min(50vh, 360px);
  }
  .balance-dock.collapsed {
    max-height: none;
  }
}
