/* Expense Tracker — light/dark financial dashboard */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.06);
  --sidebar-w: 280px;
  --green: #15803d;
  --green-bg: #dcfce7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --amber: #b45309;
}

[data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --sidebar-bg: #111827;
  --sidebar-text: #f9fafb;
  --sidebar-muted: #9ca3af;
  --nav-hover: rgba(255, 255, 255, 0.08);
  --nav-active: rgba(255, 255, 255, 0.14);
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #1a1d24;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: #2d333b;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --sidebar-bg: #0a0c10;
  --sidebar-text: #f9fafb;
  --sidebar-muted: #9ca3af;
  --nav-hover: rgba(255, 255, 255, 0.06);
  --nav-active: rgba(255, 255, 255, 0.12);
  --green-bg: rgba(21, 128, 61, 0.25);
  --red-bg: rgba(185, 28, 28, 0.25);
}

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

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.boot-error {
  margin: 1rem;
  padding: 1rem 1.25rem;
  background: var(--red-bg);
  color: var(--red);
  border-radius: var(--radius);
  font-weight: 600;
}

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

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

.mobile-nav-bar {
  display: none;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 20;
}

.sidebar-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0 0.25rem;
}

.brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.25rem;
}

.brand-title {
  margin: 0;
  font-weight: 700;
  font-size: 1rem;
}

.brand-sub {
  margin: 0;
  font-size: 0.75rem;
  color: var(--sidebar-muted);
}

.toast-root {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  pointer-events: none;
  max-width: min(22rem, calc(100vw - 2rem));
}

.toast {
  pointer-events: auto;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: 0.875rem;
  line-height: 1.4;
  animation: toast-in 0.2s ease;
}

.toast.is-leaving {
  animation: toast-out 0.2s ease forwards;
}

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

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

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.9375rem;
}

.nav-item:hover {
  background: var(--nav-hover);
}

.nav-item.is-active {
  background: var(--nav-active);
  font-weight: 600;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.unsaved-warning {
  margin: 0;
  font-size: 0.75rem;
  color: #fbbf24;
  padding: 0.5rem;
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: 6px;
}

.main {
  padding: 1.25rem 1.75rem 2.5rem;
  min-width: 0;
  width: 100%;
}

.top-bar-card {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
}

.top-bar-leading {
  flex: 1;
  min-width: 14rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.top-bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.field-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.file-context-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.3;
}

.file-context-dates {
  font-size: 0.8125rem;
  color: var(--muted);
}

.top-bar-meta {
  display: flex;
  flex-direction: column;
  font-size: 0.8125rem;
  color: var(--muted);
}

.select,
input[type="text"],
input[type="search"],
input[type="date"],
input[type="url"],
input[type="number"],
textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.select {
  max-width: 100%;
}

.page-title {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.view {
  display: none;
}

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
  width: 100%;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow-md);
  min-width: 0;
}

@media (max-width: 720px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }
}

.summary-card .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 0.35rem;
}

.summary-card .value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.summary-card.positive .value {
  color: var(--green);
}

.summary-card.negative .value {
  color: var(--red);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 1rem;
}

.card-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.budget-bar-wrap {
  margin-top: 0.5rem;
}

.budget-bar {
  height: 12px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  width: 0;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.budget-bar.over .budget-bar-fill {
  background: var(--red);
}

.budget-bar-label {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.category-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.875rem;
}

.category-row .bar-mini {
  grid-column: 1 / -1;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.category-row .bar-mini span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.table-wrap {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.data-table th,
table.data-table td {
  padding: 0.6rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.data-table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.data-table tr:hover td {
  background: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] table.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.table-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn-danger {
  background: var(--red);
  color: #fff;
}

.btn-danger:hover {
  filter: brightness(1.05);
}

.btn-icon {
  padding: 0.4rem;
  min-width: 2.25rem;
  min-height: 2.25rem;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.btn-close::before {
  content: "×";
  font-size: 1.25rem;
  line-height: 1;
}

.file-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  min-height: 2.5rem;
}

.file-btn input {
  display: none;
}

.file-btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
  border: none;
  min-height: 2.5rem;
}

.btn-accent:hover {
  filter: brightness(1.05);
}

.btn-block {
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--sidebar-muted);
  border: 1px solid transparent;
  font-size: 0.8125rem;
  padding: 0.4rem 0.5rem;
}

.btn-ghost:hover {
  color: var(--sidebar-text);
  background: rgba(255, 255, 255, 0.06);
}

.panel-inset {
  padding: 0.85rem;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.data-help {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--sidebar-muted);
}

.data-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.sidebar-actions.compact {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.sidebar .btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-text);
  border-color: rgba(255, 255, 255, 0.2);
}

.sidebar .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.16);
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  min-width: 0;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.muted {
  color: var(--muted);
}

.muted.small {
  font-size: 0.8125rem;
}

.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

.expenses-table-wrap {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.pagination-info {
  font-size: 0.875rem;
  color: var(--muted);
}

.periods-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.period-card {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.period-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.period-card .meta {
  font-size: 0.8125rem;
  color: var(--muted);
}

.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 28rem;
  width: calc(100% - 2rem);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.modal-wide {
  max-width: 40rem;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.125rem;
}

.modal-body {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8125rem;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.form-error {
  color: var(--red);
  font-size: 0.875rem;
  margin: 0;
}

.req {
  color: var(--red);
}

.import-mode {
  border: none;
  margin: 0 0 0.5rem;
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.875rem;
}

.import-preview-table {
  font-size: 0.8125rem;
  width: 100%;
}

.validation-errors {
  background: var(--red-bg);
  color: var(--red);
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.875rem;
}

.validation-errors ul {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  max-width: 20rem;
}

.print-report h2 {
  margin-top: 0;
}

.print-report .report-meta {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.report-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.app[data-mode="viewer"] .edit-unlocked-only,
.app[data-mode="viewer"] .edit-toggle-only {
  display: none !important;
}

.app[data-editing="false"] .edit-unlocked-only {
  display: none !important;
}

.app[data-mode="editor"] .viewer-only {
  display: none !important;
}

.sidebar-section-title {
  margin: 0 0 0.35rem;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  font-weight: 600;
}

.sidebar-data {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: auto;
}

.active-source {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--sidebar-text);
  word-break: break-word;
}

.history-sections {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.history-section-title {
  margin: 0 0 0.65rem;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.history-section .history-page-list {
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.history-page-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.history-page-item {
  font-size: 0.9375rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  line-height: 1.4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.history-page-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.history-page-item.history-page-empty {
  justify-content: center;
  color: var(--muted);
  background: transparent;
  border-style: dashed;
}

.import-history-main {
  flex: 1;
  min-width: 12rem;
}

.history-page-item .name {
  font-weight: 600;
  display: block;
  margin-bottom: 0.2rem;
}

.history-page-item .meta {
  color: var(--muted);
  font-size: 0.8125rem;
}

.history-page-item .badge-active {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.btn-history-delete {
  flex-shrink: 0;
}

.btn-toggle-active {
  background: var(--amber);
  color: #fff;
  border-color: transparent;
}

.viewer-dataset {
  font-weight: 600;
  color: var(--text);
}

.sidebar-backdrop {
  display: none;
}

.icon-menu {
  display: block;
  width: 1.25rem;
  height: 2px;
  background: currentColor;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .mobile-nav-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: sticky;
    top: 0;
    z-index: 25;
  }

  .mobile-title {
    font-weight: 700;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: min(var(--sidebar-w), 85vw);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop.is-visible {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 15;
  }

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

  .main {
    padding: 1rem;
  }
}

@media print {
  body {
    background: #fff;
    color: #000;
  }

  .sidebar,
  .mobile-nav-bar,
  .top-bar,
  .sidebar-backdrop,
  .filters,
  .nav-list,
  .sidebar-actions,
  .unsaved-warning,
  .toast-root,
  .view:not(#view-report),
  .page-title,
  .modal,
  .btn,
  .edit-unlocked-only,
  .edit-toggle-only {
    display: none !important;
  }

  .app {
    display: block;
  }

  .main {
    padding: 0;
  }

  #view-report {
    display: block !important;
  }

  .card {
    border: none;
    box-shadow: none;
    padding: 0;
  }

  table.data-table {
    font-size: 10pt;
  }

  table.data-table th,
  table.data-table td {
    border-color: #ccc;
  }

  .print-report {
    page-break-inside: avoid;
  }

  @page {
    size: A4;
    margin: 1.5cm;
  }
}
