:root {
  --ink: #17211b;
  --muted: #6d776f;
  --line: #dfe7e1;
  --surface: #ffffff;
  --canvas: #f4f7f4;
  --green: #18623c;
  --green-soft: #e5f4eb;
  --red: #a73a3a;
  --red-soft: #fbe9e8;
  --blue-soft: #e5eefc;
  --blue: #2458a6;
  --gold-soft: #fbf1d7;
  --gold: #7c5a0f;
  --shadow: 0 16px 45px rgba(23, 33, 27, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 92% 0%, rgba(116, 184, 142, 0.13), transparent 28rem),
    var(--canvas);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(36, 115, 70, 0.22);
  outline-offset: 2px;
}

.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;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  max-width: 1220px;
  margin: 0 auto;
  padding: 2.4rem 2rem 1.4rem;
}

.topbar h1,
.section-heading h2,
.dialog-heading h2,
.login-card h1 {
  margin: 0;
  letter-spacing: -0.04em;
}

.topbar h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.page-shell {
  display: grid;
  gap: 1.25rem;
  max-width: 1220px;
  margin: 0 auto;
  padding: 0 2rem 4rem;
}

.ledger-section,
.totals-section {
  overflow: hidden;
  border: 1px solid rgba(223, 231, 225, 0.85);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 1.6rem;
  border-bottom: 1px solid var(--line);
}

.section-heading.compact {
  border-bottom: 0;
  padding-bottom: 0.75rem;
}

.section-heading h2 {
  font-size: 1.35rem;
}

.section-heading p:not(.eyebrow) {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.quiet-button,
.secondary-button,
.icon-button,
.delete-button {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.quiet-button {
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.8);
}

.quiet-button:hover,
.secondary-button:hover {
  color: var(--ink);
  background: #eef3ef;
}

.add-button,
.primary-button {
  border: 0;
  border-radius: 14px;
  background: var(--green);
  color: white;
  font-weight: 750;
  box-shadow: 0 8px 20px rgba(24, 98, 60, 0.2);
}

.add-button-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.76rem 1.05rem;
}

.add-button-inline span {
  font-size: 1.3rem;
  line-height: 0.8;
}

.add-button:hover,
.primary-button:hover {
  background: #0f5230;
}

.add-button:disabled,
.primary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.table-shell {
  min-height: 230px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

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

th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  font-size: 0.9rem;
}

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

tbody tr:hover {
  background: #fafcfb;
}

.numeric {
  text-align: right;
}

.date-cell,
.secondary-value {
  color: var(--muted);
}

.amount-cell {
  font-weight: 750;
}

.operation-badge,
.currency-badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.85rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.operation-badge.plus {
  color: var(--green);
  background: var(--green-soft);
}

.operation-badge.minus {
  color: var(--red);
  background: var(--red-soft);
}

.currency-badge.usd {
  color: var(--blue);
  background: var(--blue-soft);
}

.currency-badge.eur {
  color: var(--gold);
  background: var(--gold-soft);
}

.positive-value {
  color: var(--green);
  font-weight: 700;
}

.negative-value {
  color: var(--red);
  font-weight: 700;
}

.action-cell {
  width: 1%;
}

.delete-button {
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  color: var(--red);
  font-size: 0.8rem;
}

.delete-button:hover {
  background: var(--red-soft);
}

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

.empty-state h3 {
  margin: 0.7rem 0 0.35rem;
  color: var(--ink);
}

.empty-state p {
  margin: 0;
}

.empty-icon {
  display: grid;
  width: 3rem;
  height: 3rem;
  margin: 0 auto;
  place-items: center;
  border-radius: 15px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 1.35rem;
  font-weight: 800;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  padding: 1rem 1.6rem 1.6rem;
}

.summary-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.85rem;
  min-height: 145px;
  padding: 1.15rem;
  overflow: hidden;
  border-radius: 18px;
}

.summary-card > b {
  grid-column: 2;
  align-self: end;
  font-size: 0.98rem;
}

.summary-card p {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.summary-card strong {
  display: block;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
}

.summary-card span {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.currency-symbol {
  display: grid;
  width: 2.45rem;
  height: 2.45rem;
  place-items: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 1.2rem;
  font-weight: 850;
}

.usd-card {
  background: var(--blue-soft);
}

.eur-card {
  background: var(--gold-soft);
}

.rub-card {
  align-content: center;
  background: #e5f2e9;
}

.rub-card strong {
  font-size: clamp(1.4rem, 3vw, 1.9rem);
}

.add-button-floating {
  position: fixed;
  right: 1.35rem;
  bottom: 1.35rem;
  z-index: 10;
  display: none;
  width: 3.7rem;
  height: 3.7rem;
  font-size: 2rem;
}

.operation-dialog {
  width: min(520px, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 24px;
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(15, 34, 22, 0.24);
}

.operation-dialog::backdrop {
  background: rgba(13, 26, 18, 0.48);
  backdrop-filter: blur(3px);
}

.operation-dialog form {
  display: grid;
  gap: 1.25rem;
  padding: 1.5rem;
}

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

.dialog-heading h2 {
  font-size: 1.45rem;
}

.icon-button {
  display: grid;
  width: 2.3rem;
  height: 2.3rem;
  place-items: center;
  border-radius: 50%;
  background: #f0f3f0;
  color: var(--ink);
  font-size: 1.35rem;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.input-field > span {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.35rem;
  border-radius: 14px;
  background: #f0f3f0;
}

.segment {
  position: relative;
}

.segment input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segment span {
  display: flex;
  justify-content: center;
  padding: 0.72rem;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
  cursor: pointer;
}

.segment input:checked + span {
  background: white;
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(23, 33, 27, 0.08);
}

.plus-segment input:checked + span {
  color: var(--green);
}

.minus-segment input:checked + span {
  color: var(--red);
}

.input-field {
  display: block;
}

.input-with-suffix {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}

.input-with-suffix:focus-within {
  border-color: #75a88a;
  box-shadow: 0 0 0 3px rgba(24, 98, 60, 0.1);
}

.input-with-suffix input {
  min-width: 0;
  flex: 1;
  padding: 0.85rem 1rem;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 650;
}

.input-with-suffix b {
  padding-right: 1rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.form-error {
  margin: 0;
  padding: 0.75rem 0.9rem;
  border-radius: 11px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 0.84rem;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.primary-button,
.secondary-button {
  min-height: 3rem;
  padding: 0.75rem 1rem;
  border-radius: 13px;
  font-weight: 750;
}

.secondary-button {
  border: 1px solid var(--line);
  background: white;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  z-index: 30;
  max-width: calc(100% - 2rem);
  padding: 0.85rem 1rem;
  transform: translateX(-50%);
  border-radius: 12px;
  background: #17211b;
  color: white;
  box-shadow: var(--shadow);
  font-size: 0.86rem;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-shell {
  width: min(420px, 100%);
}

.login-card {
  padding: clamp(1.6rem, 6vw, 2.4rem);
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 3.2rem;
  height: 3.2rem;
  margin-bottom: 1.4rem;
  place-items: center;
  border-radius: 15px;
  background: var(--green);
  color: white;
  font-size: 1.45rem;
  font-weight: 850;
  box-shadow: 0 10px 22px rgba(24, 98, 60, 0.2);
}

.login-card h1 {
  font-size: 2rem;
}

.login-copy {
  margin: 0.65rem 0 1.6rem;
  color: var(--muted);
  line-height: 1.55;
}

.login-form {
  display: grid;
  gap: 1rem;
}

.login-form label > span {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
}

.login-form input {
  width: 100%;
  min-height: 3rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
}

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

  .rub-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .topbar {
    padding: 1.5rem 1rem 1rem;
  }

  .page-shell {
    padding: 0 1rem 6rem;
  }

  .ledger-section,
  .totals-section {
    border-radius: 20px;
  }

  .section-heading {
    padding: 1.2rem;
  }

  .section-heading > .add-button-inline {
    display: none;
  }

  .add-button-floating {
    display: block;
  }

  .table-shell {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tbody {
    padding: 0.35rem 1rem 1rem;
  }

  tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 1rem;
    margin-top: 0.65rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 16px;
  }

  tbody tr:hover {
    background: white;
  }

  td {
    padding: 0;
    border: 0;
    white-space: normal;
  }

  td::before {
    display: block;
    margin-bottom: 0.28rem;
    color: var(--muted);
    content: attr(data-label);
    font-size: 0.66rem;
    font-weight: 750;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  td.numeric {
    text-align: left;
  }

  .date-cell {
    grid-column: 1 / -1;
  }

  .action-cell {
    grid-column: 1 / -1;
    width: auto;
    padding-top: 0.7rem;
    border-top: 1px solid var(--line);
  }

  .action-cell::before {
    display: none;
  }

  .delete-button {
    width: 100%;
    padding: 0.65rem;
    background: var(--red-soft);
  }

  .summary-grid {
    grid-template-columns: 1fr;
    padding: 0.8rem 1rem 1rem;
  }

  .rub-card {
    grid-column: auto;
  }

  .summary-card {
    min-height: 125px;
  }

  .toast {
    bottom: 5.7rem;
  }
}
