@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700;800&family=Source+Sans+3:wght@400;500;600;700&family=JetBrains+Mono:wght@500;700&display=swap");

:root {
  --bg: #f4f6fb;
  --bg-soft: #eef2ff;
  --card: rgba(255, 255, 255, 0.95);
  --text: #172554;
  --muted: #475569;
  --primary: #1d4ed8;
  --primary-strong: #1e3a8a;
  --accent: #d97706;
  --accent-soft: #fff7ed;
  --success: #15803d;
  --danger: #b91c1c;
  --line: #dbe5f4;
  --line-strong: #c7d2fe;
  --shadow-soft: 0 18px 40px rgba(15, 23, 42, 0.08);
  --shadow-hover: 0 24px 46px rgba(29, 78, 216, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 600px at 8% -10%, #dbeafe 0%, transparent 60%),
    radial-gradient(860px 560px at 95% 4%, #ffedd5 0%, transparent 56%),
    var(--bg);
  min-height: 100vh;
  padding: 20px 0 100px;
}

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

.bg-shape {
  position: fixed;
  border-radius: 999px;
  z-index: 0;
  filter: blur(10px);
  pointer-events: none;
}

.shape-1 {
  width: 360px;
  height: 360px;
  left: -140px;
  bottom: 10%;
  background: rgba(37, 99, 235, 0.18);
}

.shape-2 {
  width: 280px;
  height: 280px;
  right: -90px;
  top: 22%;
  background: rgba(217, 119, 6, 0.2);
}

.nav-chip,
.rail-btn,
.dock-btn,
.quick-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font: inherit;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
  color: var(--primary-strong);
  background: #eef2ff;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.nav-chip:hover,
.rail-btn:hover,
.dock-btn:hover,
.quick-btn:hover {
  background: #dbeafe;
  border-color: #bfdbfe;
  transform: translateY(-1px);
}

.nav-chip.is-active,
.rail-btn.is-active,
.dock-btn.is-active {
  background: linear-gradient(110deg, #1d4ed8, #1e3a8a);
  color: #fff;
  border-color: transparent;
}

.app-shell {
  width: min(1280px, 96vw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 20px;
  position: relative;
  z-index: 2;
}

.section-rail {
  position: sticky;
  top: 20px;
  align-self: start;
  border-radius: 18px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-soft);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.rail-btn {
  text-align: left;
}

.app {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.segment-dashboard,
.segment-income,
.segment-expenses,
.segment-investments {
  display: none;
}

body.page-dashboard .segment-dashboard,
body.page-income .segment-income,
body.page-expenses .segment-expenses,
body.page-investments .segment-investments {
  display: block;
}

body.page-dashboard .hero.segment-dashboard {
  display: grid;
}

.card {
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow-soft);
  padding: 20px;
  animation: card-rise 0.45s ease both;
}

.hero {
  display: block;
  padding: 12px;
  background:
    linear-gradient(125deg, rgba(191, 219, 254, 0.72), rgba(255, 237, 213, 0.65)),
    var(--card);
  border-color: #cbd5ff;
}

.quick-actions {
  display: grid;
  gap: 10px;
}

.quick-actions-inline {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
}

.quick-actions-inline .quick-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  justify-content: center;
  text-align: center;
}

.quick-btn {
  background: #fff;
  border-color: #bfdbfe;
  color: var(--primary-strong);
  justify-content: flex-start;
  text-align: left;
}

.quick-btn:first-child {
  background: linear-gradient(112deg, #1d4ed8, #2563eb);
  color: #fff;
  border-color: transparent;
}

.quick-btn:first-child:hover {
  background: linear-gradient(112deg, #1e40af, #1d4ed8);
}

.dashboard-head {
  align-items: flex-start;
}

.dashboard-head h2 {
  margin-bottom: 0;
}

.dashboard-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dashboard-month-block {
  display: grid;
  gap: 5px;
}

.dashboard-month-block .month-badge {
  width: fit-content;
}

.dashboard-compare {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.dashboard-quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.dash-quick-btn {
  padding: 7px 10px;
  font-size: 0.82rem;
  border-radius: 11px;
}

.install-card {
  border: 1px solid rgba(29, 78, 216, 0.25);
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.72), rgba(255, 247, 237, 0.8));
}

.install-btn {
  min-width: 140px;
}

.install-btn[hidden] {
  display: none;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-tag {
  background: var(--accent-soft);
  color: #9a3412;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 5px 10px;
}

.month-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  padding: 5px 10px;
  font-weight: 700;
}

h2 {
  margin: 0 0 14px;
  font-family: "Manrope", "Segoe UI", sans-serif;
  font-size: 1.3rem;
}

h3 {
  margin: 16px 0 10px;
  font-family: "Manrope", "Segoe UI", sans-serif;
  font-size: 1rem;
}

.grid-form,
.mini-form,
.history-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.compact-form {
  margin-bottom: 14px;
}

.mini-form {
  margin-top: 10px;
  margin-bottom: 8px;
}

.history-filters {
  margin-bottom: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}

button:not(.nav-chip):not(.rail-btn):not(.dock-btn):not(.quick-btn):not(.row-btn) {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(110deg, #1d4ed8, #1e3a8a);
  cursor: pointer;
  align-self: end;
  transition: transform 0.18s ease, filter 0.2s ease, box-shadow 0.2s ease;
}

button:not(.nav-chip):not(.rail-btn):not(.dock-btn):not(.quick-btn):not(.row-btn):hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

button:not(.nav-chip):not(.rail-btn):not(.dock-btn):not(.quick-btn):not(.row-btn):active {
  transform: translateY(0);
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  color: var(--text);
  padding-top: 28px;
}

.checkbox-row input {
  width: auto;
}

.input-error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.15);
}

.field-error {
  margin-top: 4px;
  color: var(--danger);
  font-size: 0.82rem;
  line-height: 1.25;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.stats article {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(165deg, #ffffff, #f8fbff);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.stats article::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: #bfdbfe;
}

.stats article[data-stat-tone="positive"]::before {
  background: linear-gradient(90deg, #22c55e, #16a34a);
}

.stats article[data-stat-tone="danger"]::before {
  background: linear-gradient(90deg, #f97316, #ea580c);
}

.stats article[data-stat-tone="accent"]::before {
  background: linear-gradient(90deg, #2563eb, #1d4ed8);
}

.stats article[data-stat-tone="neutral"]::before {
  background: linear-gradient(90deg, #a5b4fc, #818cf8);
}

.stats p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.stats strong {
  font-family: "JetBrains Mono", monospace;
  font-size: 1.1rem;
}

.stat-trend {
  margin: 0;
  min-height: 1.1em;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.stat-trend.is-better {
  color: var(--success);
}

.stat-trend.is-worse {
  color: var(--danger);
}

.stat-trend.is-neutral {
  color: var(--muted);
}

.dashboard-charts {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chart-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(175deg, #ffffff, #f8fbff);
}

.chart-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chart-head h3 {
  margin: 0;
}

.chart-head .hint {
  margin: 0;
}

.trend-chart {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.trend-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.trend-month {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: capitalize;
}

.trend-bars {
  display: grid;
  gap: 6px;
}

.trend-bar {
  position: relative;
  height: 9px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.trend-bar::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--bar-size, 0%);
  border-radius: 999px;
}

.trend-bar-income::after {
  background: linear-gradient(90deg, #22c55e, #16a34a);
}

.trend-bar-expenses::after {
  background: linear-gradient(90deg, #fb923c, #ea580c);
}

.trend-bar-saved::after {
  background: linear-gradient(90deg, #60a5fa, #2563eb);
}

.trend-legend {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.trend-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.legend-income {
  background: #16a34a;
}

.legend-expenses {
  background: #ea580c;
}

.legend-saved {
  background: #2563eb;
}

.category-chart {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.category-chart li {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) minmax(0, 2fr) auto;
  align-items: center;
  gap: 10px;
}

.category-chart-label {
  font-weight: 700;
  color: var(--text);
  font-size: 0.84rem;
}

.category-chart-track {
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.category-chart-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f97316, #ea580c);
}

.category-chart-value {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 700;
}

.single-stat {
  grid-template-columns: minmax(220px, 340px);
}

.budget-track {
  width: 100%;
  height: 18px;
  border-radius: 999px;
  overflow: hidden;
  background: #e2e8f0;
  display: flex;
}

.budget-segment {
  width: 0;
  height: 100%;
  transition: width 0.35s ease;
}

.budget-spent {
  background: linear-gradient(120deg, #ea580c, #f97316);
}

.budget-saved {
  background: linear-gradient(120deg, #16a34a, #22c55e);
}

.budget-legend {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
}

.budget-legend strong {
  color: var(--text);
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.category-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.category-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  background: #fff;
}

.table-wrap,
.projection {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td:last-child,
th:last-child {
  text-align: right;
}

.row-btn {
  background: #fff;
  color: var(--danger);
  border: 1px solid rgba(185, 28, 28, 0.3);
  box-shadow: none;
  border-radius: 10px;
  padding: 7px 10px;
}

.row-btn:hover {
  background: rgba(185, 28, 28, 0.08);
  box-shadow: none;
}

.investment-list {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.investment-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
  min-width: 0;
}

.inv-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.inv-head h3 {
  margin: 0;
  overflow-wrap: anywhere;
}

.inv-meta {
  margin: 8px 0 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.9rem;
}

.inv-meta span,
.inv-meta strong {
  overflow-wrap: anywhere;
}

.projection table {
  min-width: 640px;
}

.empty {
  color: var(--muted);
  margin: 0;
}

.mobile-dock {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 42;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  padding: 8px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
  display: none;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.dock-btn {
  border-radius: 12px;
  font-size: 0.82rem;
  padding: 10px 8px;
  text-align: center;
}

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

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

  .section-rail {
    display: none;
  }
}

@media (max-width: 900px) {
  body {
    padding-top: 16px;
  }

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

  .mobile-dock {
    display: grid;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(1280px, 97vw);
  }

  .card {
    border-radius: 16px;
    padding: 14px;
  }

  .grid-form,
  .mini-form,
  .history-filters {
    grid-template-columns: 1fr;
  }

  .checkbox-row {
    padding-top: 0;
  }

  .single-stat {
    grid-template-columns: 1fr;
  }

  .category-chart li {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .category-chart-track {
    order: 3;
  }

  .dashboard-head-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .dashboard-quick-actions {
    width: 100%;
  }

  .dash-quick-btn {
    flex: 1 1 170px;
    justify-content: center;
    text-align: center;
  }

  .table-wrap thead,
  .projection thead {
    display: none;
  }

  .table-wrap tbody,
  .projection tbody {
    display: grid;
    gap: 10px;
  }

  .table-wrap tr,
  .projection tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    padding: 6px 10px;
  }

  .table-wrap td,
  .projection td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .table-wrap td > *,
  .projection td > * {
    min-width: 0;
  }

  .table-wrap td::before,
  .projection td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
    flex: 0 0 47%;
  }

  .projection table {
    min-width: 0;
  }

  .table-wrap td:last-child,
  .projection td:last-child {
    border-bottom: 0;
  }

  .table-wrap td[data-label=""]::before,
  .projection td[data-label=""]::before {
    content: none;
  }

  .table-wrap td[colspan],
  .projection td[colspan] {
    display: block;
    border-bottom: 0;
  }

  .table-wrap td[colspan]::before,
  .projection td[colspan]::before {
    content: none;
  }
}

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

  .card {
    animation: none;
  }
}
