:root {
  --bg-top: #f0dbc0;
  --bg-bottom: #e4c195;
  --ink: #1f0d13;
  --ink-soft: rgba(31, 13, 19, 0.7);
  --card: rgba(255, 249, 239, 0.58);
  --line: rgba(31, 13, 19, 0.12);
  --line-strong: rgba(31, 13, 19, 0.2);
  --shadow: 0 24px 60px rgba(31, 13, 19, 0.12);
  --shadow-soft: 0 12px 24px rgba(31, 13, 19, 0.08);
  --success: #15784f;
  --success-bg: rgba(21, 120, 79, 0.12);
  --danger: #8d2232;
  --danger-bg: rgba(141, 34, 50, 0.12);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.45), transparent 34%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--ink);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.65; cursor: wait; }
.hidden { display: none !important; }

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  min-height: 100svh;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
}

.glass {
  background: var(--card);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow);
}

.auth-view, .app-view { min-height: calc(100svh - 38px); }
.auth-view { display: grid; place-items: center; }
.auth-card {
  width: 100%;
  padding: 22px;
  border-radius: 32px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #2f0e19 0%, #1f0d13 100%);
  color: #fff7ef;
  font-weight: 800;
  font-size: 1.4rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.8rem, 7vw, 2.55rem); line-height: 1.03; letter-spacing: -0.04em; }
h2 { font-size: clamp(1.55rem, 6.6vw, 2.2rem); line-height: 1.05; letter-spacing: -0.03em; }
h3 { font-size: clamp(1.2rem, 5vw, 1.75rem); line-height: 1.1; }

.mode-switch,
.top-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px;
  border-radius: 22px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.26);
}

.mode-switch__btn,
.top-tabs__tab {
  min-height: 52px;
  border-radius: 16px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 800;
}

.mode-switch__btn.active,
.top-tabs__tab.active {
  background: var(--ink);
  color: #fff7ef;
  box-shadow: 0 12px 20px rgba(31, 13, 19, 0.16);
}

.auth-form { display: none; gap: 14px; }
.auth-form.active { display: grid; }
label span { display: block; margin-bottom: 8px; font-weight: 800; }
input {
  width: 100%;
  min-height: 58px;
  padding: 0 16px;
  border-radius: 18px;
  border: 1px solid rgba(31, 13, 19, 0.12);
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  outline: none;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

input:focus {
  border-color: rgba(31, 13, 19, 0.34);
  box-shadow: 0 0 0 5px rgba(31, 13, 19, 0.08);
}

.primary-btn,
.secondary-btn,
.enter-btn,
.ghost-btn {
  min-height: 56px;
  border-radius: 18px;
  border: 0;
  font-weight: 800;
}

.primary-btn,
.enter-btn {
  background: linear-gradient(180deg, #290610 0%, #1f0d13 100%);
  color: #fff5ea;
  box-shadow: 0 18px 28px rgba(31, 13, 19, 0.18);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  border: 1px solid var(--line);
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0 16px;
}

.ghost-btn.small {
  min-height: 40px;
  border-radius: 14px;
  padding-inline: 12px;
}

.ghost-btn.danger {
  color: var(--danger);
  border-color: rgba(141, 34, 50, 0.18);
  background: rgba(255, 255, 255, 0.5);
}

.captcha-wrap {
  border-radius: 18px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.46);
  border: 1px dashed rgba(31, 13, 19, 0.18);
  overflow: hidden;
}

.message {
  min-height: 24px;
  margin-top: 10px;
  font-size: 0.92rem;
  color: var(--ink-soft);
}
.message.error { color: var(--danger); }
.message.success { color: var(--success); }

.app-header {
  border-radius: 28px;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.phone-panel { min-height: calc(100svh - 190px); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.ledger-layout {
  display: grid;
  grid-template-rows: 3fr 2fr;
  gap: 14px;
  min-height: calc(100svh - 220px);
}

.ledger-log,
.entry-pad,
#exportTab {
  border-radius: 28px;
  padding: 16px;
}

.ledger-log {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.ledger-log__header,
.entry-pad__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

#balanceText {
  font-size: clamp(2rem, 8vw, 3.4rem);
  letter-spacing: -0.05em;
}

.entries-list {
  flex: 1;
  overflow: auto;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entries-date {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 12px 0 8px;
  background: linear-gradient(180deg, rgba(255, 249, 239, 0.98), rgba(255, 249, 239, 0.92) 75%, rgba(255, 255, 255, 0));
  font-size: 1rem;
  font-weight: 900;
}

.entry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid rgba(31, 13, 19, 0.08);
}

.entry-row.is-editing {
  background: rgba(31, 13, 19, 0.04);
  border-radius: 18px;
  padding-inline: 12px;
  margin-inline: -12px;
}

.entry-row__meta { min-width: 0; }
.entry-row__time {
  display: block;
  font-size: 0.84rem;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.entry-row__desc {
  font-size: 1rem;
  font-weight: 700;
  word-break: break-word;
}

.entry-row__right {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.entry-row__amount {
  flex-shrink: 0;
  font-size: 1.08rem;
}
.entry-row__amount.negative { color: var(--danger); }
.entry-row__amount.positive { color: var(--success); }

.entry-row__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.empty-state {
  margin: auto 0;
  padding: 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.46);
  border: 1px dashed rgba(31, 13, 19, 0.16);
  text-align: center;
  color: var(--ink-soft);
}

.entry-pad {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
}

.entry-pad__top {
  display: grid;
  grid-template-columns: minmax(0, 132px) 1fr;
  gap: 12px;
  align-items: stretch;
}

.type-toggle {
  border: 1px solid transparent;
  border-radius: 24px;
  position: relative;
  min-height: 124px;
  overflow: hidden;
  text-align: left;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff9f1;
  box-shadow: var(--shadow-soft);
}

.type-toggle::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.88;
  z-index: 0;
}

.type-toggle.income::before {
  background: linear-gradient(160deg, #1f5a44 0%, #18895c 70%, #31a66e 100%);
}

.type-toggle.expense::before {
  background: linear-gradient(160deg, #5a1826 0%, #8d2232 72%, #b53a4b 100%);
}

.type-toggle > * { position: relative; z-index: 1; }

.type-toggle__symbol {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  font-size: 1.8rem;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.type-toggle__text strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.type-toggle__text small {
  display: block;
  color: rgba(255, 245, 234, 0.82);
  line-height: 1.35;
}

.amount-field small,
.subtle {
  display: block;
  margin-top: 8px;
  color: var(--ink-soft);
  line-height: 1.45;
}

.enter-btn { width: 100%; }

.export-card {
  display: grid;
  gap: 16px;
}

.range-picker {
  display: grid;
  gap: 12px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.range-chip {
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  font-weight: 800;
}

.range-chip.active {
  background: var(--ink);
  color: #fff8f0;
  border-color: transparent;
  box-shadow: 0 10px 18px rgba(31, 13, 19, 0.14);
}

.date-grid,
.export-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.summary-box {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
}

@media (min-width: 640px) {
  .entry-pad__top {
    grid-template-columns: 172px 1fr;
  }

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