:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #172026;
  --muted: #66737d;
  --line: #d9ddd9;
  --green: #147a5c;
  --green-soft: #e7f4ee;
  --red: #b3443a;
  --red-soft: #f8e7e4;
  --blue: #2d5f88;
  --gold: #c28a2e;
  --shadow: 0 14px 35px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(45, 95, 136, 0.08), transparent 320px),
    var(--bg);
  color: var(--ink);
  font-family: Tahoma, Arial, sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 0.86rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 760px;
  margin-bottom: 0;
  font-size: clamp(1.7rem, 4vw, 3rem);
  line-height: 1.15;
}

h2 {
  margin-bottom: 6px;
  font-size: 1.08rem;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.icon-button,
.swap-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.icon-button:hover,
.swap-button:hover {
  border-color: var(--blue);
}

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

.summary-band {
  display: grid;
  grid-template-columns: 1.35fr repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.summary-band article,
.settings-grid,
.entry-form,
.quick-notes,
.table-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.summary-band article {
  padding: 18px;
  min-height: 116px;
}

.summary-band span,
.summary-band small {
  display: block;
  color: var(--muted);
}

.summary-band strong {
  display: block;
  margin: 8px 0 2px;
  font-size: clamp(1.25rem, 2.4vw, 2.1rem);
  line-height: 1.1;
}

.capital-panel {
  background: linear-gradient(135deg, #ffffff, #edf6f1);
  border-color: rgba(20, 122, 92, 0.26) !important;
}

.settings-grid {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 16px;
  padding: 18px;
  margin-bottom: 16px;
}

.field-group {
  display: grid;
  gap: 7px;
}

.field-group.full {
  grid-column: 1 / -1;
}

label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45, 95, 136, 0.16);
}

.inline-input,
.dual-money,
.money-entry {
  display: grid;
  align-items: end;
  gap: 10px;
}

.inline-input {
  grid-template-columns: auto minmax(120px, 1fr) auto;
}

.inline-input span {
  color: var(--muted);
  white-space: nowrap;
}

.dual-money {
  grid-template-columns: 1fr 1fr;
}

.entry-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  margin-bottom: 16px;
}

.entry-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.form-head {
  grid-column: 1 / -1;
}

.form-head p,
.quick-notes li,
.table-toolbar p,
.empty-state {
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  align-self: end;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1f3f0;
}

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

.segmented label {
  min-height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--ink);
  transition: 0.16s ease;
}

.segmented input:checked + label {
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(23, 32, 38, 0.08);
}

#typeIncome:checked + label {
  color: var(--green);
}

#typeExpense:checked + label {
  color: var(--red);
}

.money-entry {
  grid-column: 1 / -1;
  grid-template-columns: 1fr auto 1fr;
}

.primary-action {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 700;
}

.primary-action:hover {
  background: #0f684e;
}

.form-error {
  min-height: 24px;
  margin: 0;
  color: var(--red);
  font-size: 0.9rem;
}

.quick-notes {
  padding: 18px;
}

.quick-notes ul {
  margin: 12px 0 0;
  padding: 0 20px 0 0;
}

.quick-notes li + li {
  margin-top: 10px;
}

.table-section {
  padding: 18px;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.table-toolbar p {
  margin-bottom: 0;
}

.table-toolbar input {
  max-width: 280px;
}

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

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

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

th {
  color: var(--muted);
  font-size: 0.82rem;
}

tbody tr:hover {
  background: #fafbf8;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.82rem;
}

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

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

.delete-row {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--red);
}

.delete-row:hover {
  border-color: var(--red);
}

.empty-state {
  padding: 28px 10px;
  text-align: center;
}

.calculator-fab {
  position: fixed;
  left: 22px;
  bottom: 22px;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border: 1px solid rgba(45, 95, 136, 0.2);
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  padding: 0 16px;
  box-shadow: 0 16px 34px rgba(23, 32, 38, 0.24);
}

.calculator-fab span:first-child {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.side-calculator {
  position: fixed;
  left: 22px;
  bottom: 84px;
  z-index: 40;
  width: min(340px, calc(100vw - 28px));
  border: 1px solid rgba(217, 221, 217, 0.78);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 26px 60px rgba(23, 32, 38, 0.24);
  padding: 14px;
  transform: translateY(14px) scale(0.98);
  transform-origin: bottom left;
  opacity: 0;
  pointer-events: none;
  transition: 0.18s ease;
}

.side-calculator.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.calculator-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.calculator-head p {
  margin-bottom: 2px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 700;
}

.calculator-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.calculator-screen {
  display: grid;
  gap: 4px;
  min-height: 92px;
  border: 1px solid rgba(23, 32, 38, 0.08);
  border-radius: 8px;
  background: linear-gradient(135deg, #172026, #263138);
  color: #fff;
  padding: 14px;
  text-align: left;
  direction: ltr;
}

.calculator-screen small {
  min-height: 18px;
  color: rgba(255, 255, 255, 0.66);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calculator-screen strong {
  align-self: end;
  font-size: clamp(1.7rem, 7vw, 2.35rem);
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calculator-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.calculator-keys button,
.calculator-send button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8f5;
  color: var(--ink);
  font-weight: 700;
}

.calculator-keys button:hover,
.calculator-send button:hover,
.calculator-close:hover {
  border-color: var(--blue);
}

.calculator-keys [data-calc-operator],
.calculator-keys [data-calc-action="percent"] {
  background: #eef3f5;
  color: var(--blue);
}

.calculator-keys .equals {
  background: var(--green);
  color: #fff;
}

.calculator-keys .wide {
  grid-column: span 2;
}

.calculator-send {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.calculator-send button {
  background: var(--green-soft);
  color: var(--green);
}

@media (max-width: 900px) {
  .summary-band,
  .settings-grid,
  .entry-layout,
  .entry-form {
    grid-template-columns: 1fr;
  }

  .quick-notes {
    display: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .top-bar,
  .table-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .dual-money,
  .money-entry {
    grid-template-columns: 1fr;
  }

  .swap-button {
    width: 100%;
  }

  .table-toolbar input {
    max-width: none;
  }

  .calculator-fab {
    left: 14px;
    bottom: 14px;
  }

  .side-calculator {
    left: 10px;
    right: 10px;
    bottom: 72px;
    width: auto;
    transform-origin: bottom center;
  }
}
