:root {
  color-scheme: light;
  --md-sys-color-primary: #6f3fc4;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #eadcff;
  --md-sys-color-on-primary-container: #3b1a75;
  --md-sys-color-secondary: #6c5b8f;
  --md-sys-color-secondary-container: #e7ddf7;
  --md-sys-color-tertiary: #7d4f9f;
  --md-sys-color-tertiary-container: #f0dbff;
  --md-sys-color-error: #b3261e;
  --md-sys-color-surface: #faf7ff;
  --md-sys-color-surface-container: #f0e9fb;
  --md-sys-color-on-surface: #201c2b;
  --md-sys-color-outline: #7f7593;
  --md-sys-color-outline-variant: #cdc2dc;
  --app-bg-start: #fbf8ff;
  --app-bg-end: #f2ecfb;
  --app-bubble-a: #eadcff;
  --app-bubble-b: #e5dcff;
  --hero-start: #f6efff;
  --hero-end: #ebdfff;
  --card-bg: #ffffff;
  --chart-initial: #7d4fdb;
  --chart-additional: #9e6cf2;
  --chart-interest: #b388ff;
  --chart-total-line: #4c2b8f;
  --chart-grid: #dfd2f0;
  --chart-axis: #5f5178;
  --row-even: #f8f4ff;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --md-sys-color-primary: #d3baff;
  --md-sys-color-on-primary: #2f0f65;
  --md-sys-color-primary-container: #4b2988;
  --md-sys-color-on-primary-container: #eadcff;
  --md-sys-color-secondary: #d3c3ef;
  --md-sys-color-secondary-container: #4d3b6b;
  --md-sys-color-tertiary: #e0baf9;
  --md-sys-color-tertiary-container: #5a3a78;
  --md-sys-color-error: #ffb4ab;
  --md-sys-color-surface: #17131f;
  --md-sys-color-surface-container: #231b30;
  --md-sys-color-on-surface: #f0e9ff;
  --md-sys-color-outline: #9c90b4;
  --md-sys-color-outline-variant: #473b59;
  --app-bg-start: #140f1c;
  --app-bg-end: #1f162b;
  --app-bubble-a: #2a1a40;
  --app-bubble-b: #2d1e4a;
  --hero-start: #2a1b42;
  --hero-end: #221733;
  --card-bg: #211a2c;
  --chart-initial: #c6a8ff;
  --chart-additional: #b68cff;
  --chart-interest: #e2c8ff;
  --chart-total-line: #f0e2ff;
  --chart-grid: #4a3f5a;
  --chart-axis: #d7caec;
  --row-even: #261f33;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", sans-serif;
  color: var(--md-sys-color-on-surface);
  background:
    radial-gradient(circle at 14% 10%, var(--app-bubble-a) 0, transparent 28%),
    radial-gradient(circle at 90% 4%, var(--app-bubble-b) 0, transparent 30%),
    linear-gradient(160deg, var(--app-bg-start) 0%, var(--app-bg-end) 100%);
}

.app-shell {
  width: min(1200px, 94vw);
  margin: 2rem auto 3rem;
  display: grid;
  gap: 1rem;
}

.card {
  border-radius: 24px;
  background: color-mix(in srgb, var(--md-sys-color-surface) 74%, var(--card-bg) 26%);
  border: 1px solid var(--md-sys-color-outline-variant);
  padding: 1.25rem;
  box-shadow: 0 10px 30px color-mix(in srgb, #000000 10%, transparent 90%);
}

.hero {
  background: linear-gradient(145deg, var(--hero-start) 0%, var(--hero-end) 100%);
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.6vw, 2.3rem);
}

.hero p {
  margin: 0.65rem 0 0;
  max-width: 72ch;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
  color: var(--md-sys-color-primary);
}

.md-icon-button {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 999px;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
}

.md-icon-button:hover {
  filter: brightness(1.06);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.8rem;
}

.section-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.material-symbols-outlined {
  font-size: 1.35rem;
}

.fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

.md-field {
  display: grid;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 0.92rem;
}

.md-field input,
.md-field select {
  width: 100%;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 14px;
  padding: 0.72rem 0.82rem;
  background: var(--card-bg);
  color: var(--md-sys-color-on-surface);
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.md-field input:focus,
.md-field select:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--md-sys-color-primary) 24%, transparent 76%);
}

.actions {
  margin-top: 0.95rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.md-button {
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.05rem;
  font: inherit;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.md-button .material-symbols-outlined {
  flex-shrink: 0;
}

.md-button.filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.md-button.tonal {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-surface);
}

.md-button:hover {
  filter: brightness(0.96);
}

.form-error {
  min-height: 1.1rem;
  margin: 0.6rem 0 0;
  color: var(--md-sys-color-error);
  font-weight: 700;
}

.metrics,
.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.print-params {
  display: none;
}

.print-params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.65rem;
}

.print-param-item {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  padding: 0.6rem 0.7rem;
  display: grid;
  gap: 0.2rem;
  background: var(--card-bg);
}

.print-param-item span {
  font-size: 0.8rem;
  font-weight: 700;
}

.print-param-item strong {
  font-size: 0.95rem;
}

.metric-card {
  border-radius: 20px;
  padding: 0.95rem;
  background: var(--card-bg);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.metric-card .label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
  font-size: 0.9rem;
}

.metric-card .value {
  margin-top: 0.35rem;
  font-size: 1.22rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.metric-card.highlight {
  background: var(--md-sys-color-primary-container);
}

#stacked-chart {
  width: 100%;
  height: auto;
  border-radius: 16px;
  background: var(--card-bg);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.legend {
  margin-top: 0.65rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  font-size: 0.9rem;
  font-weight: 700;
}

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

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

thead {
  background: var(--md-sys-color-surface-container);
}

th,
td {
  text-align: left;
  padding: 0.7rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

tbody tr:nth-child(even) {
  background: var(--row-even);
}

.shortcuts {
  border-radius: 20px;
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container);
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.82rem;
}

.shortcuts-block {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
}

.shortcuts-block + .shortcuts-block {
  margin-top: 8px;
  padding-top: 8px;
}

.footer-card {
  text-align: center;
}

.footer-note,
.footer-time {
  margin: 0;
  width: 100%;
  text-align: center;
  line-height: 1.35;
}

.footer-stack {
  font-weight: 700;
}

.footer-note a {
  color: var(--md-sys-color-primary);
  font-weight: 700;
  text-decoration: underline;
}

.footer-note a:hover {
  color: var(--md-sys-color-tertiary);
}

.footer-time {
  margin-top: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}

@media (max-width: 760px) {
  .app-shell {
    width: min(680px, 94vw);
    margin-top: 1rem;
  }

  .card {
    border-radius: 18px;
    padding: 1rem;
  }

  .hero-top {
    align-items: center;
  }

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

  .metrics,
  .compare-grid,
  .print-params-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-wrap {
    margin-inline: -1rem;
    padding-inline: 1rem;
  }

  table {
    min-width: 620px;
  }
}

@media (max-width: 560px) {
  body {
    padding: 0.75rem 0;
  }

  .app-shell {
    width: min(100% - 0.75rem, 100vw - 0.75rem);
    margin: 0.5rem auto 1.5rem;
    gap: 0.75rem;
  }

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

  .hero-top {
    flex-direction: column;
    align-items: stretch;
    gap: 0.8rem;
  }

  .md-icon-button {
    align-self: flex-end;
    width: 46px;
    height: 46px;
  }

  .hero h1 {
    font-size: 1.45rem;
  }

  .hero p {
    font-size: 0.94rem;
  }

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

  .section-head h2 {
    font-size: 1.02rem;
  }

  .md-field span {
    font-size: 0.88rem;
  }

  .md-field input,
  .md-field select {
    min-height: 46px;
    padding: 0.8rem 0.85rem;
    font-size: 0.98rem;
  }

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

  .md-button {
    width: 100%;
    min-height: 46px;
    justify-content: center;
    padding: 0.82rem 1rem;
  }

  .metrics,
  .compare-grid,
  .print-params-grid {
    grid-template-columns: 1fr;
  }

  .metric-card,
  .print-param-item {
    padding: 0.85rem;
  }

  .metric-card .label {
    font-size: 0.86rem;
  }

  .metric-card .value {
    font-size: 1.08rem;
  }

  .legend {
    gap: 0.55rem;
  }

  .legend-item {
    font-size: 0.82rem;
  }

  .table-wrap {
    margin-inline: 0;
    padding-inline: 0;
    overflow: visible;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 0.75rem;
  }

  tbody tr {
    display: grid;
    gap: 0.45rem;
    padding: 0.85rem;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 14px;
    background: color-mix(in srgb, var(--card-bg) 84%, var(--md-sys-color-surface-container) 16%);
  }

  tbody tr:nth-child(even) {
    background: color-mix(in srgb, var(--card-bg) 84%, var(--md-sys-color-surface-container) 16%);
  }

  td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0;
    border-bottom: 0;
    font-size: 0.86rem;
  }

  td::before {
    content: attr(data-label);
    flex: 0 0 44%;
    font-weight: 800;
    color: var(--md-sys-color-primary);
  }

  .shortcuts {
    font-size: 0.77rem;
    padding: 0.85rem;
  }

  .shortcuts-block {
    justify-content: flex-start;
    gap: 0.45rem 0.8rem;
  }

  .footer-card,
  .footer-note,
  .footer-time {
    text-align: left;
  }
}

@media (max-width: 380px) {
  .app-shell {
    width: calc(100vw - 0.5rem);
  }

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

  .eyebrow {
    font-size: 0.74rem;
  }

  .hero h1 {
    font-size: 1.3rem;
  }

  .hero p,
  .md-button,
  .md-field input,
  .md-field select {
    font-size: 0.92rem;
  }

  .metric-card .value {
    font-size: 1rem;
  }

  .legend-item {
    font-size: 0.78rem;
  }

  tbody tr {
    padding: 0.75rem;
    gap: 0.4rem;
  }

  td {
    font-size: 0.82rem;
    gap: 0.5rem;
  }

  td::before {
    flex-basis: 42%;
    font-size: 0.78rem;
  }
}

@media print {
  body {
    background: #ffffff;
    color: #000000;
  }

  .hero .md-icon-button,
  .shortcuts {
    display: none;
  }

  .print-params {
    display: block;
  }

  .app-shell {
    width: 100%;
    margin: 0;
    gap: 0.5rem;
  }

  .card,
  .metric-card {
    box-shadow: none;
    border-color: #c4c4c4;
    background: #ffffff;
    break-inside: avoid;
  }

  #stacked-chart {
    border-color: #c4c4c4;
  }
}
