:root {
  --bg: #fffafa;
  --surface: #ffffff;
  --soft: #fdebea;
  --soft-2: #f8d6d3;
  --primary: #d98d88;
  --primary-dark: #b96f6a;
  --text: #3b3030;
  --muted: #8d7c7b;
  --line: #f0dedc;
  --danger: #b95454;
  --shadow: 0 12px 32px rgba(99, 67, 64, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.78) 0 28%, transparent 28% 100%),
    linear-gradient(45deg, transparent 0 45%, rgba(240, 222, 220, 0.52) 45% 58%, transparent 58% 100%),
    var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 16px 96px;
}

.route-home .app {
  height: 100svh;
  overflow: hidden;
  padding: 10px 18px 14px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 0 16px;
}

.brand-logo {
  width: 68px;
  height: 68px;
  object-fit: contain;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 14px;
  font-size: 24px;
}

h3 {
  margin: 18px 0 10px;
  font-size: 16px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.screen {
  display: none;
  animation: rise 0.18s ease;
}

.screen.active {
  display: block;
}

.route-home .topbar {
  display: none;
}

.route-home .bottom-nav {
  display: none;
}

.home-hero {
  position: relative;
  display: grid;
  place-items: center;
  height: clamp(170px, 32svh, 250px);
  margin: 0 -4px 8px;
  padding: 8px 0;
}

.home-logo {
  width: min(92%, 390px);
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 18px 24px rgba(99, 67, 64, 0.12));
}

.online-dot {
  position: absolute;
  top: 14px;
  right: 12px;
  width: 13px;
  height: 13px;
  border-radius: 999px;
  background: #35c66b;
  box-shadow: 0 0 0 4px rgba(53, 198, 107, 0.12);
}

.home-actions {
  display: grid;
  gap: 9px;
}

.home-button {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 8px 14px;
  border: 1px solid #f1dfc6;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  text-align: left;
  box-shadow: 0 12px 24px rgba(99, 67, 64, 0.1);
}

.home-button span {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--soft);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 18px;
}

.home-button strong {
  font-size: 16px;
}

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

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

.tabs.soft {
  grid-template-columns: repeat(3, 1fr);
}

#historyTabs {
  grid-template-columns: repeat(2, 1fr);
}

.tabs.scroll {
  display: flex;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--line);
  white-space: nowrap;
}

.tab.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: none;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 21px;
}

.metric.accent {
  background: var(--soft);
}

.metric.full {
  grid-column: 1 / -1;
}

.custom-period {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 12px;
  margin-bottom: 12px;
}

.custom-period label {
  min-width: 0;
}

.custom-period button {
  min-height: 46px;
}

.form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(217, 141, 136, 0.18);
}

.primary,
.secondary,
.danger,
.ghost {
  min-height: 48px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
}

.primary {
  background: var(--primary);
  color: #fff;
}

.secondary {
  background: var(--soft);
  color: var(--primary-dark);
}

.danger {
  background: #fff0f0;
  color: var(--danger);
}

.ghost {
  background: transparent;
  color: var(--muted);
}

.sticky-action {
  width: 100%;
  margin-top: 14px;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.list-item > div:last-child {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.list-item .secondary,
.list-item .danger {
  min-height: 38px;
  padding: 0 10px;
  font-size: 13px;
}

.list-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.list-item strong {
  display: block;
}

.amount.in {
  color: var(--primary-dark);
}

.amount.out {
  color: var(--danger);
}

.search {
  margin-bottom: 12px;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  grid-template-columns: 1fr auto;
}

.switch input {
  width: 22px;
  min-height: 22px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.backup-actions {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.file-button {
  display: grid;
  place-items: center;
  min-height: 48px;
  border-radius: 8px;
  font-weight: 700;
}

.file-button input {
  display: none;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 250, 250, 0.94);
  backdrop-filter: blur(14px);
}

.nav-item {
  display: grid;
  place-items: center;
  gap: 3px;
  min-height: 58px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}

.nav-item span {
  font-size: 20px;
  line-height: 1;
}

.nav-item.active {
  background: var(--soft);
  color: var(--primary-dark);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 92px;
  left: 16px;
  z-index: 40;
  display: none;
  max-width: 488px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

.toast.show {
  display: block;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: rgba(59, 48, 48, 0.28);
}

.modal-card {
  display: grid;
  gap: 10px;
  width: min(100%, 488px);
  padding: 16px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (min-width: 700px) {
  .app {
    padding-top: 28px;
  }
}

@media (max-width: 420px) {
  .custom-period {
    grid-template-columns: 1fr 1fr;
  }

  .custom-period button {
    grid-column: 1 / -1;
  }
}
