:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --surface-3: #f8fafc;
  --field: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --primary: #2f80ed;
  --primary-strong: #1d63c7;
  --primary-soft: rgba(47, 128, 237, 0.12);
  --success: #219653;
  --danger: #eb5757;
  --warning: #f2994a;
  --purple: #9b51e0;
  --teal: #00a896;
  --sidebar-bg: #101827;
  --sidebar-hover: #243143;
  --sidebar-text: #f9fafb;
  --sidebar-muted: #aeb8c8;
  --card-hover: #f8fbff;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.08);
  --shadow-hover: 0 24px 55px rgba(23, 32, 51, 0.13);
  --login-glow-a: rgba(47, 128, 237, 0.28);
  --login-glow-b: rgba(0, 168, 150, 0.2);
  --radius: 8px;
  --sidebar: 280px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1020;
  --surface: #121a2b;
  --surface-2: #1a2538;
  --surface-3: #151f31;
  --field: #0f1728;
  --ink: #edf3ff;
  --muted: #99a7bd;
  --line: #27354c;
  --primary: #69a7ff;
  --primary-strong: #8fbdff;
  --primary-soft: rgba(105, 167, 255, 0.15);
  --success: #5dd18a;
  --danger: #ff7b7b;
  --warning: #ffc46b;
  --purple: #b88cff;
  --teal: #47d6c7;
  --sidebar-bg: #070b14;
  --sidebar-hover: #172235;
  --sidebar-text: #f8fbff;
  --sidebar-muted: #94a3b8;
  --card-hover: #172235;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.26);
  --shadow-hover: 0 24px 60px rgba(0, 0, 0, 0.38);
  --login-glow-a: rgba(105, 167, 255, 0.24);
  --login-glow-b: rgba(71, 214, 199, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

body::selection {
  background: rgba(47, 128, 237, 0.2);
}

body:not(.login-page) {
  background:
    radial-gradient(circle at top left, rgba(47, 128, 237, 0.10), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(0, 168, 150, 0.08), transparent 30rem),
    var(--bg);
}

.login-page {
  position: relative;
  display: grid;
  min-height: 100vh;
  overflow: hidden;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 20%, var(--login-glow-a), transparent 22rem),
    radial-gradient(circle at 82% 70%, var(--login-glow-b), transparent 24rem),
    linear-gradient(135deg, var(--bg), var(--surface-2));
}

.login-page::before,
.login-page::after {
  position: absolute;
  width: 360px;
  height: 360px;
  content: "";
  border: 1px solid rgba(47, 128, 237, 0.16);
  border-radius: 44% 56% 62% 38%;
  filter: blur(0.2px);
  opacity: 0.75;
  animation: login-float 14s ease-in-out infinite alternate;
}

.login-page::before {
  top: -120px;
  right: 8%;
  background: rgba(47, 128, 237, 0.08);
}

.login-page::after {
  bottom: -150px;
  left: 8%;
  background: rgba(0, 168, 150, 0.08);
  animation-duration: 18s;
  animation-delay: -5s;
}

.login-card {
  position: relative;
  display: grid;
  width: min(420px, 100%);
  gap: 18px;
  padding: 26px;
  border: 1px solid color-mix(in srgb, var(--line), transparent 8%);
  border-radius: 18px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface), transparent 6%);
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.16);
  backdrop-filter: blur(18px);
  animation: login-enter 520ms ease-out both;
  z-index: 1;
}

.login-card::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,255,255,0.22), transparent 36%, rgba(47,128,237,0.08));
  opacity: 0.75;
}

.theme-toggle {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--field);
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.theme-toggle:hover {
  transform: translateY(-1px) rotate(8deg);
  border-color: rgba(47, 128, 237, 0.45);
}

.login-theme-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
}

.login-brand {
  margin-bottom: 0;
}

.login-card .status-line {
  min-height: 20px;
}

.login-message.is-error {
  color: var(--danger);
  font-weight: 800;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.svg-sprite,
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.15;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 22px 18px;
  background: var(--sidebar-bg);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--sidebar-bg), #ffffff 4%), var(--sidebar-bg)),
    var(--sidebar-bg);
  color: var(--sidebar-text);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 28px;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 17px;
}

.brand span {
  color: var(--sidebar-muted);
  font-size: 13px;
}

.brand-mark,
.metric-icon,
.category-symbol {
  display: grid;
  place-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary), var(--teal));
  color: #fff;
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(47, 128, 237, 0.25);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.nav-tabs {
  display: grid;
  gap: 6px;
}

.nav-tab,
.ghost-button,
.primary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  text-decoration: none;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.ghost-button:hover,
.primary-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.nav-tab {
  --nav-icon: var(--primary);
  justify-content: flex-start;
  width: 100%;
  padding: 11px 12px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

.nav-tab > .icon {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  padding: 5px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--nav-icon), transparent 84%);
  color: var(--nav-icon);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--nav-icon), transparent 78%);
  transition: transform 160ms ease, background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.nav-tabs .nav-tab:nth-child(1) { --nav-icon: #60a5fa; }
.nav-tabs .nav-tab:nth-child(2) { --nav-icon: #22c55e; }
.nav-tabs .nav-tab:nth-child(3) { --nav-icon: #f97316; }
.nav-tabs .nav-tab:nth-child(4) { --nav-icon: #38bdf8; }
.nav-tabs .nav-tab:nth-child(5) { --nav-icon: #a78bfa; }
.nav-tabs .nav-tab:nth-child(6) { --nav-icon: #2dd4bf; }
.nav-tabs .nav-tab:nth-child(7) { --nav-icon: #fb7185; }
.nav-tabs .nav-tab:nth-child(8) { --nav-icon: #facc15; }
.nav-tabs .nav-tab:nth-child(9) { --nav-icon: #c084fc; }
.nav-tabs .nav-tab:nth-child(10) { --nav-icon: #94a3b8; }
.nav-tabs .nav-tab:nth-child(11) { --nav-icon: #34d399; }

.nav-tab:hover,
.nav-tab.is-active {
  background: var(--sidebar-hover);
  color: #fff;
  transform: translateX(2px);
}

.nav-tab:hover > .icon,
.nav-tab.is-active > .icon {
  background: color-mix(in srgb, var(--nav-icon), transparent 76%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--nav-icon), transparent 62%), 0 8px 18px rgba(0, 0, 0, 0.18);
  transform: scale(1.05);
}

.sidebar-footer {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.main-panel {
  min-width: 0;
  overflow-x: hidden;
  padding: 24px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar > div:first-child {
  min-width: 0;
  flex: 1 1 280px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  color: var(--ink);
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

.month-control,
.period-control {
  display: inline-grid;
  grid-template-columns: 40px minmax(150px, 180px) 40px;
  align-items: center;
  gap: 8px;
}

.period-control {
  display: flex;
  flex: 0 1 620px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 100%;
}

.period-control .icon-button {
  flex: 0 0 40px;
}

.period-control select {
  flex: 0 1 120px;
  min-width: 96px;
}

.period-control > input,
.period-control > .custom-period {
  flex: 1 1 190px;
  min-width: 0;
}

.custom-period {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.month-control input,
input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--ink);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input,
select {
  min-height: 40px;
  padding: 8px 10px;
}

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  padding: 0;
}

textarea {
  min-height: 120px;
  resize: vertical;
  padding: 10px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.14);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
}

.app-message {
  display: none;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.app-message.success,
.app-message.error {
  display: block;
}

.app-message.success {
  border-color: rgba(33, 150, 83, 0.25);
  background: rgba(33, 150, 83, 0.08);
  color: #176f3d;
}

.app-message.error {
  border-color: rgba(235, 87, 87, 0.25);
  background: rgba(235, 87, 87, 0.08);
  color: #b42318;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, background 180ms ease;
}

.metric-card:hover,
.panel:hover {
  border-color: color-mix(in srgb, var(--primary), var(--line) 62%);
  box-shadow: var(--shadow-hover);
}

.metric-card:hover {
  transform: translateY(-2px);
}

.metric-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 112px;
  padding: 18px;
}

.metric-card small,
.balance-strip span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.metric-card strong {
  grid-column: 1 / -1;
  display: block;
  margin-top: 4px;
  font-size: clamp(20px, 1.4vw, 25px);
  line-height: 1.1;
  white-space: nowrap;
  word-break: normal;
}

.metric-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
}

.metric-card.income .metric-icon {
  background: color-mix(in srgb, var(--success), transparent 85%);
  color: var(--success);
}

.metric-card.expense .metric-icon {
  background: color-mix(in srgb, var(--danger), transparent 85%);
  color: var(--danger);
}

.metric-card.invest .metric-icon {
  background: color-mix(in srgb, var(--teal), transparent 85%);
  color: var(--teal);
}

.metric-card.balance .metric-icon {
  background: var(--primary-soft);
  color: var(--primary);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.85fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-heading > span {
  color: var(--muted);
  font-weight: 700;
}

.result-count {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.chart-wrap {
  display: grid;
  grid-template-columns: minmax(220px, 330px) minmax(0, 1fr);
  align-items: center;
  gap: 16px;
}

.donut-box {
  position: relative;
  display: grid;
  place-items: center;
}

canvas {
  width: 100%;
  max-width: 340px;
  height: auto;
}

.donut-center {
  position: absolute;
  display: grid;
  place-items: center;
  text-align: center;
}

.donut-center strong {
  color: var(--ink);
  font-size: 20px;
}

.donut-center span {
  color: var(--muted);
  font-weight: 800;
}

.legend-list,
.method-list,
.mini-list,
.fixed-list,
.category-grid,
.forecast-grid {
  display: grid;
  gap: 10px;
}

.legend-row,
.method-row,
.mini-row,
.fixed-row,
.category-item,
.forecast-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.legend-row:hover,
.method-row:hover,
.mini-row:hover,
.fixed-row:hover,
.category-item:hover,
.forecast-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--primary), var(--line) 60%);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

.legend-row {
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
}

.legend-button,
.detail-row {
  width: 100%;
  border: 1px solid var(--line);
  text-align: left;
}

.legend-button:hover,
.legend-button.is-active,
.detail-row:hover {
  border-color: rgba(47, 128, 237, 0.35);
  background: var(--card-hover);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.legend-row strong,
.method-row strong,
.mini-row strong,
.fixed-row strong,
.category-item strong,
.forecast-card strong {
  color: var(--ink);
}

.legend-row span,
.method-row span,
.mini-row span,
.fixed-row span,
.category-item span,
.forecast-card span,
.status-line,
.transaction-meta {
  color: var(--muted);
}

.method-row {
  grid-template-columns: 1fr auto;
}

.fixed-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.fixed-row > div,
.fixed-row-side {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.fixed-row-side {
  justify-items: end;
}

.method-button {
  width: 100%;
  border: 1px solid var(--line);
  text-align: left;
}

.method-button:hover,
.method-button.is-active {
  border-color: rgba(47, 128, 237, 0.4);
  background: var(--card-hover);
}

.category-detail {
  margin-top: 16px;
}

.category-detail:empty {
  display: none;
}

.detail-heading,
.detail-row {
  display: grid;
  align-items: center;
  gap: 10px;
}

.detail-heading {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 10px;
}

.detail-heading span {
  color: var(--muted);
  font-weight: 700;
}

.detail-list {
  display: grid;
  gap: 8px;
}

.detail-row {
  grid-template-columns: 92px minmax(0, 1fr) minmax(120px, 0.5fr) auto;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--field);
}

.detail-row strong,
.detail-row span {
  min-width: 0;
}

.detail-row strong {
  overflow-wrap: anywhere;
}

.detail-row span {
  color: var(--muted);
}

.progress-track {
  grid-column: 1 / -1;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
}

.forecast-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.forecast-card {
  min-height: 114px;
}

.forecast-value {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.forecast-card strong {
  font-size: 18px;
}

.forecast-card.is-negative {
  border-color: rgba(235, 87, 87, 0.35);
}

.forecast-delta {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.forecast-delta.is-up {
  background: rgba(235, 87, 87, 0.12);
  color: var(--danger);
}

.forecast-delta.is-down {
  background: rgba(33, 150, 83, 0.12);
  color: var(--success);
}

.forecast-delta.is-neutral {
  background: var(--surface-2);
  color: var(--muted);
}

.yearly-timeline-panel {
  overflow: hidden;
}

.year-timeline {
  overflow-x: auto;
  padding: 2px 0 4px;
}

.timeline-chart {
  display: block;
  width: 100%;
  min-width: 720px;
  height: auto;
  color: var(--muted);
}

.timeline-grid line {
  stroke: var(--line);
  stroke-width: 1;
  opacity: 0.72;
}

.timeline-grid text,
.timeline-axis text,
.timeline-legend text {
  color: var(--muted);
  fill: currentColor;
  font-size: 12px;
  font-weight: 700;
}

.timeline-axis text {
  cursor: pointer;
  text-anchor: end;
}

.timeline-hit rect {
  fill: transparent;
  cursor: pointer;
}

.timeline-area {
  fill: color-mix(in srgb, var(--warning), transparent 88%);
}

.timeline-line {
  fill: none;
  stroke: var(--warning);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
  filter: drop-shadow(0 8px 12px color-mix(in srgb, var(--warning), transparent 76%));
}

.timeline-points circle {
  fill: var(--surface);
  stroke: var(--warning);
  stroke-width: 3;
}

.timeline-points circle.is-current {
  fill: var(--warning);
  stroke: var(--surface);
}

.timeline-value-label {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 900;
  text-anchor: middle;
}

.timeline-legend line {
  stroke: var(--warning);
  stroke-width: 4;
  stroke-linecap: round;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(320px, 0.78fr) minmax(0, 1.22fr);
  gap: 16px;
}

.stacked-form,
.filter-row,
.field-row,
.button-row,
.form-actions {
  display: grid;
  gap: 12px;
}

.field-row,
.filter-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.button-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 12px 0;
}

.bulk-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.8fr) minmax(160px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.duplicate-alerts {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid rgba(242, 153, 74, 0.4);
  border-radius: var(--radius);
  background: rgba(242, 153, 74, 0.1);
}

.duplicate-alerts > strong {
  color: var(--ink);
}

.duplicate-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
}

.duplicate-alert small {
  color: var(--muted);
  text-align: right;
}

.tax-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.tax-fields {
  display: grid;
  gap: 10px;
}

.check-line {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 800;
}

.check-line input {
  width: 16px;
  min-height: 16px;
}

.invoice-meta,
.invoice-due {
  margin-bottom: 12px;
}

.form-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.primary-button {
  min-width: 0;
  padding: 0 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(47, 128, 237, 0.22);
}

.primary-button:hover {
  background: linear-gradient(135deg, var(--primary-strong), var(--primary));
}

.primary-button:disabled {
  cursor: not-allowed;
  background: #b9cbe6;
}

.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  font-weight: 800;
}

.ghost-button:hover,
.icon-button:hover {
  background: var(--surface-2);
  border-color: color-mix(in srgb, var(--primary), var(--line) 60%);
}

.full-width {
  width: 100%;
}

.import-label {
  position: relative;
  overflow: hidden;
}

.upload-zone {
  position: relative;
  display: grid;
  min-height: 170px;
  place-items: center;
  border: 1px dashed #b7c2d2;
  border-radius: var(--radius);
  background: var(--surface-3);
  text-align: center;
}

.upload-zone .icon {
  width: 34px;
  height: 34px;
  color: var(--primary);
}

.upload-zone input {
  position: absolute;
  inset: 0;
  cursor: pointer;
  opacity: 0;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: var(--field);
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  color: var(--ink);
}

tbody tr:last-child td {
  border-bottom: 0;
}

td select,
td input {
  min-height: 34px;
  padding: 6px 8px;
}

.amount-cell {
  text-align: right;
  font-weight: 800;
  white-space: nowrap;
}

.negative-amount {
  color: #ef4444;
}

tr.invoice-row-blocked td {
  background: rgba(239, 68, 68, 0.06);
}

.invoice-warning {
  margin-top: 4px;
  color: #ef4444;
  font-size: 12px;
  font-weight: 800;
}

.control-legend,
.alert-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.control-legend span,
.alert-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  font-weight: 800;
}

.alert-item {
  border-color: rgba(242, 153, 74, 0.35);
  background: rgba(242, 153, 74, 0.1);
}

.alert-item span {
  color: var(--muted);
}

.control-add-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 0.7fr) auto;
  gap: 10px;
  align-items: end;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.status-dot.paid,
.bill-cell.paid {
  background: #12d82f;
}

.status-dot.open,
.bill-cell.open {
  background: var(--field);
}

.status-dot.partial,
.bill-cell.partial {
  background: #ff9800;
}

.status-dot.renegotiate,
.bill-cell.renegotiate {
  background: #fff200;
}

.control-table {
  min-width: 1260px;
}

.control-table-wrap {
  max-height: calc(100vh - 260px);
}

.control-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 1px 0 var(--line);
}

.control-table th:first-child {
  min-width: 260px;
}

.control-table th,
.control-table td {
  border: 1px solid var(--line);
  text-align: center;
}

.control-table tbody th {
  background: var(--field);
  color: var(--ink);
  text-align: left;
  text-transform: none;
}

.due-day {
  background: var(--sidebar-bg);
  color: #fff;
  font-weight: 900;
}

.bill-cell {
  min-width: 130px;
}

.bill-cell.is-empty {
  background: var(--surface-2);
}

.bill-cell strong {
  display: block;
  margin-bottom: 6px;
  white-space: nowrap;
}

.paid-diff {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.bill-cell select {
  min-height: 30px;
  padding: 4px 6px;
  font-size: 12px;
}

.bill-cell-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.bill-edit-button {
  width: auto;
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.paid-edit {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto;
  gap: 6px;
  margin-top: 6px;
}

.paid-edit input {
  min-height: 30px;
  padding: 4px 6px;
  font-size: 12px;
}

.tag,
.pill,
.source-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.tag {
  color: #fff;
}

.account-badge,
.bank-chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid color-mix(in srgb, var(--account-color, var(--bank-color, var(--primary))), transparent 55%);
  border-radius: 999px;
  background: color-mix(in srgb, var(--account-color, var(--bank-color, var(--primary))), transparent 86%);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-badge {
  max-width: 150px;
}

.bank-chip {
  --account-color: var(--bank-color);
}

.invoice-import-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
}

.invoice-import-row div {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.invoice-import-row span:not(.bank-chip) {
  color: var(--muted);
}

.pill.fixed {
  background: rgba(242, 153, 74, 0.14);
  color: #a85c0a;
}

.pill.eventual {
  background: rgba(47, 128, 237, 0.12);
  color: var(--primary);
}

.pill.projected,
.source-pill {
  background: var(--surface-2);
  color: var(--muted);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.row-actions .icon-button,
.icon-button {
  width: 40px;
  min-height: 40px;
}

.icon-button.danger {
  color: var(--danger);
}

.camera-box {
  position: relative;
  display: grid;
  min-height: 330px;
  overflow: hidden;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #111827;
}

.camera-box video,
.camera-box img {
  display: none;
  width: 100%;
  height: 100%;
  max-height: 420px;
  object-fit: contain;
}

.camera-box.has-video video,
.camera-box.has-image img {
  display: block;
}

.camera-box.has-video #cameraPlaceholder,
.camera-box.has-image #cameraPlaceholder {
  display: none;
}

#cameraPlaceholder {
  color: #dbeafe;
}

.text-area-label {
  margin-top: 12px;
}

.balance-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(47, 128, 237, 0.25);
  border-radius: var(--radius);
  background: rgba(47, 128, 237, 0.08);
}

.balance-strip strong {
  font-size: 20px;
}

.category-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.category-item {
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
}

.category-symbol {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  color: #fff;
}

.category-item .keyword-text {
  grid-column: 2 / -1;
}

.category-item .row-actions {
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: center;
}

.car-layout {
  margin-bottom: 16px;
}

.car-history-panel {
  margin-top: 16px;
}

.car-photo-box {
  display: grid;
  width: min(300px, 100%);
  aspect-ratio: 3 / 2;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--muted);
  font-weight: 800;
}

.car-photo-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.car-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.car-items {
  display: grid;
  gap: 8px;
}

.car-item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 0.35fr) 40px;
  gap: 8px;
  align-items: center;
}

.car-expense-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
}

.car-expense-row > div {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.car-expense-side {
  align-items: end;
  justify-items: end;
}

.car-expense-row span,
.car-expense-row a {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.car-alert.due,
.alert-item.due {
  border-color: rgba(235, 87, 87, 0.35);
  background: rgba(235, 87, 87, 0.1);
}

.car-alert.upcoming,
.alert-item.upcoming {
  border-color: rgba(242, 153, 74, 0.35);
  background: rgba(242, 153, 74, 0.1);
}

.notification-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.notification-card {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.notification-card.email-card {
  grid-column: span 2;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.admin-log-panel {
  grid-column: 1 / -1;
}

.compact-admin-form {
  margin-top: 14px;
}

.admin-list {
  margin-top: 14px;
}

.admin-row,
.notification-log {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  text-align: left;
}

.admin-row span,
.notification-log div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.admin-row small,
.notification-log span,
.notification-log small,
.branding-preview span {
  color: var(--muted);
}

.notification-log {
  grid-template-columns: 180px minmax(0, 1fr);
}

.notification-log.error {
  border-color: rgba(235, 87, 87, 0.35);
  background: rgba(235, 87, 87, 0.06);
}

.notification-log.success {
  border-color: rgba(33, 150, 83, 0.3);
  background: rgba(33, 150, 83, 0.06);
}

.notification-log small {
  overflow-wrap: anywhere;
}

.branding-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.dialog {
  width: min(760px, calc(100% - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.dialog-panel {
  display: grid;
  gap: 14px;
  padding: 20px;
  background: var(--surface);
}

.empty-state,
.empty-table {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state {
  border: 1px dashed #c8d2df;
  border-radius: var(--radius);
}

.screen.is-active {
  animation: screen-enter 220ms ease-out both;
}

.progress-fill {
  animation: progress-enter 520ms ease-out both;
  transform-origin: left center;
}

@keyframes login-enter {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes login-float {
  from {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  to {
    transform: translate3d(22px, 18px, 0) rotate(18deg);
  }
}

@keyframes screen-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes progress-enter {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

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

.install-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.install-panel {
  width: min(620px, 100%);
}

@media (max-width: 1180px) {
  .summary-grid,
  .forecast-grid,
  .notification-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .two-column {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    width: 100%;
    max-width: 100vw;
    height: auto;
    overflow: hidden;
    padding: 14px;
  }

  .brand {
    justify-content: center;
    margin-bottom: 14px;
    text-align: center;
  }

  .brand-mark {
    width: 52px;
    height: 52px;
  }

  .brand strong {
    font-size: 18px;
  }

  .nav-tabs {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
    padding: 0;
  }

  .nav-tab {
    min-width: 0;
    justify-content: center;
    min-height: 58px;
    padding: 8px;
  }

  .nav-tab span {
    display: none;
  }

  .nav-tabs .nav-tab:nth-child(6),
  .nav-tabs .nav-tab:nth-child(7),
  .nav-tabs .nav-tab:nth-child(9),
  .nav-tabs .nav-tab:nth-child(10) {
    display: none;
  }

  .sidebar-footer {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 12px;
  }

  .main-panel {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    padding: 16px;
  }

  .topbar {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
  }

  .topbar > div:first-child {
    flex: 0 1 auto;
    text-align: left;
  }

  .month-control {
    width: 100%;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
  }

  .period-control {
    display: grid;
    width: 100%;
    max-width: 100%;
    grid-template-columns: 40px minmax(72px, 92px) minmax(0, 1fr) 40px;
    gap: 6px;
  }

  .period-control > * {
    min-width: 0;
  }

  .period-control select,
  .period-control > input {
    min-width: 0;
    width: 100%;
  }

  .period-control .icon-button {
    width: 100%;
    padding: 0;
  }

  .period-control > .custom-period {
    grid-column: 3;
    width: 100%;
  }

  .custom-period,
  .control-add-form {
    grid-template-columns: 1fr;
  }

  .summary-grid,
  .filter-row,
  .bulk-form,
  .control-add-form,
  .button-row,
  .form-actions,
  .category-grid,
  .forecast-grid,
  .admin-grid,
  .chart-wrap,
  .notification-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .field-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-log-panel {
    grid-column: auto;
  }

  .notification-card.email-card {
    grid-column: auto;
  }

  .metric-card {
    grid-template-columns: 38px minmax(0, 1fr);
    min-height: 112px;
    gap: 10px;
    padding: 12px;
  }

  .metric-card strong {
    font-size: clamp(18px, 5.2vw, 22px);
    white-space: nowrap;
  }

  .metric-card small {
    min-width: 0;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .metric-icon {
    width: 38px;
    height: 38px;
  }

  .detail-heading {
    grid-template-columns: 1fr;
  }

  .detail-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .detail-row > span:first-child {
    grid-column: 1;
    grid-row: 1;
  }

  .detail-row > strong:first-of-type {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .detail-row > span:nth-of-type(2) {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .detail-row > strong:last-child {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
  }

  .car-item-row,
  .car-expense-row,
  .invoice-import-row,
  .admin-row,
  .notification-log {
    grid-template-columns: 1fr;
  }

  .car-item-row .icon-button {
    width: 100%;
  }

  h1 {
    font-size: 24px;
  }

  .panel {
    padding: 14px;
  }
}

@media (max-width: 560px) {
  .main-panel {
    padding: 12px;
  }

  .nav-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .period-control .icon-button {
    min-width: 0;
  }

  .period-control {
    grid-template-columns: 36px minmax(66px, 82px) minmax(0, 1fr) 36px;
    gap: 6px;
  }

  .period-control select,
  .period-control > input,
  .period-control .icon-button {
    min-height: 44px;
    font-size: 14px;
  }

  .period-control > input[type="month"] {
    padding-right: 8px;
    padding-left: 8px;
  }

  .metric-card {
    grid-template-columns: 34px minmax(0, 1fr);
    min-height: 106px;
    padding: 11px;
  }

  .metric-card strong {
    font-size: clamp(17px, 5vw, 21px);
  }

  .metric-card small {
    font-size: 12px;
  }

  .metric-icon {
    width: 34px;
    height: 34px;
  }

  h1 {
    font-size: clamp(24px, 7vw, 30px);
  }

  .panel,
  .metric-card {
    max-width: 100%;
  }

  .panel-heading,
  .car-items-header {
    align-items: stretch;
    flex-direction: column;
  }

  .donut-box canvas {
    max-width: 280px;
  }

  .method-row {
    grid-template-columns: 1fr;
  }
}
