:root {
  color-scheme: light;
  --app-bg: var(--tg-theme-secondary-bg-color, #eef4f2);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-soft: #f7faf9;
  --ink: var(--tg-theme-text-color, #101918);
  --muted: var(--tg-theme-hint-color, #66716f);
  --line: #d2ddda;
  --accent: var(--tg-theme-button-color, #087267);
  --accent-dark: #075d55;
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --amber: #d58400;
  --danger: #b44135;
  --hero-end: #056158;
  --sheet-shadow: 0 -18px 54px rgba(11, 33, 29, 0.18);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--app-bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--app-bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

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

button,
select {
  cursor: pointer;
}

button {
  -webkit-tap-highlight-color: transparent;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

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

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 0 2px 20px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(26px, 7vw, 32px);
  font-weight: 760;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.date-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  margin: 5px 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 680;
}

.date-action svg {
  width: 18px;
  height: 18px;
}

.icon-button {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
}

.icon-button svg {
  width: 23px;
  height: 23px;
}

.hero-summary {
  display: grid;
  min-height: 184px;
  place-content: center;
  padding: 22px 18px;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, var(--accent), var(--hero-end));
  color: var(--accent-text);
  text-align: center;
}

.hero-summary > span {
  font-size: 17px;
  font-weight: 520;
  opacity: 0.86;
}

.hero-amount {
  margin-top: 6px;
  font-size: clamp(45px, 14vw, 68px);
  font-variant-numeric: tabular-nums;
  font-weight: 760;
  letter-spacing: -0.05em;
  line-height: 1.06;
}

.hero-amount .currency-code {
  margin-left: 5px;
  font-size: 0.4em;
  letter-spacing: -0.01em;
}

.hero-secondary {
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.quick-fields {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.field-card {
  position: relative;
  display: grid;
  min-height: 90px;
  align-content: center;
  padding: 15px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  text-align: left;
}

.field-card > span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 560;
}

.field-card input {
  width: 100%;
  min-width: 0;
  margin-top: 3px;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  font-weight: 690;
  letter-spacing: -0.025em;
}

.field-card:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.balance-field {
  padding-right: 132px;
}

.currency-action {
  position: absolute;
  top: 50%;
  right: 12px;
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  gap: 7px;
  transform: translateY(-50%);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--accent);
  font-size: 15px;
  font-weight: 680;
}

.currency-action svg {
  width: 20px;
  height: 20px;
}

.period-field {
  width: 100%;
  border: 1px solid var(--line);
}

.period-field strong {
  margin-top: 3px;
  font-size: 25px;
  font-weight: 690;
  letter-spacing: -0.025em;
}

.period-field svg {
  position: absolute;
  top: 50%;
  right: 20px;
  width: 22px;
  height: 22px;
  transform: translateY(-50%);
}

.metrics-panel {
  margin-top: 16px;
  padding: 7px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.metrics-panel > div {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px dashed var(--line);
}

.metrics-panel > div:last-child {
  border: 0;
}

.metrics-panel span {
  color: var(--muted);
  font-size: 15px;
}

.metrics-panel strong {
  color: var(--accent);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  font-weight: 730;
  text-align: right;
}

.metrics-panel strong.amber {
  color: var(--amber);
}

.warning {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-left: 3px solid var(--amber);
  border-radius: 3px var(--radius-sm) var(--radius-sm) 3px;
  background: color-mix(in srgb, var(--amber) 10%, var(--surface));
  color: var(--ink);
  font-size: 14px;
}

.schedule-section {
  margin-top: 28px;
}

.schedule-section > header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding: 0 3px 13px;
}

.schedule-section h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 760;
  letter-spacing: -0.025em;
}

.schedule-section header p {
  margin: 4px 0 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 590;
}

#saveStatus {
  color: var(--muted);
  font-size: 12px;
  transition: color 160ms ease;
}

#saveStatus.busy {
  color: var(--accent);
}

.schedule-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.schedule-row {
  display: grid;
  grid-template-columns: 36px minmax(76px, 1fr) minmax(108px, auto);
  gap: 10px;
  align-items: center;
  min-height: 76px;
  margin: 0 16px;
  border-bottom: 1px solid var(--line);
}

.schedule-row:last-child {
  border-bottom: 0;
}

.day-number {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent);
  font-size: 15px;
  font-weight: 760;
}

.schedule-date {
  font-size: 16px;
  font-weight: 650;
}

.schedule-money {
  text-align: right;
}

.schedule-money strong {
  display: block;
  color: var(--accent);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.schedule-money span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.more-button,
.outline-button,
.primary-button,
.text-button {
  width: 100%;
  min-height: 50px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
}

.more-button {
  margin-top: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: center;
  background: var(--app-bg);
  text-align: center;
  transition: opacity 180ms ease;
}

.splash-mark {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  margin-bottom: 16px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 26px;
  font-weight: 800;
}

.splash strong {
  font-size: 22px;
}

.splash span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.splash.error .splash-mark {
  background: var(--danger);
}

.splash.error span {
  max-width: 310px;
  color: var(--danger);
}

.sheet {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.sheet::backdrop {
  background: rgba(11, 22, 20, 0.42);
  backdrop-filter: blur(3px);
}

.sheet-card {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  width: min(100%, 680px);
  max-height: calc(100dvh - 34px);
  overflow: auto;
  margin: auto;
  padding: 28px 20px calc(22px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  box-shadow: var(--sheet-shadow);
  animation: sheet-in 220ms cubic-bezier(0.2, 0.85, 0.3, 1);
}

.sheet-handle {
  position: absolute;
  top: 10px;
  left: 50%;
  width: 48px;
  height: 5px;
  transform: translateX(-50%);
  border-radius: 99px;
  background: var(--line);
}

.sheet-close {
  position: absolute;
  top: 22px;
  right: 18px;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-size: 36px;
  font-weight: 300;
  line-height: 1;
}

.sheet-close:focus-visible {
  border-radius: 50%;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sheet h2 {
  max-width: calc(100% - 48px);
  margin: 22px 0 0;
  font-size: 26px;
  font-weight: 760;
  letter-spacing: -0.035em;
}

.sheet-lead {
  margin: 8px 0 20px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.textarea-field textarea {
  width: 100%;
  min-height: 142px;
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.45;
}

.textarea-field textarea:focus,
.sheet-field-grid input:focus,
.settings-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.field-help,
.field-error {
  margin: 8px 1px 0;
  color: var(--muted);
  font-size: 13px;
}

.field-error {
  color: var(--danger);
}

.preview-panel {
  display: grid;
  min-height: 104px;
  align-content: center;
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.preview-panel span {
  color: var(--muted);
  font-size: 14px;
}

.preview-panel strong {
  margin-top: 4px;
  color: var(--accent);
  font-size: 31px;
  font-variant-numeric: tabular-nums;
  font-weight: 730;
}

.primary-button {
  margin-top: 18px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.primary-button:disabled,
.outline-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.text-button {
  margin-top: 4px;
  border: 0;
  background: transparent;
  color: var(--accent);
}

.compact-sheet {
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

.sheet-field-grid {
  display: grid;
  gap: 12px;
}

.sheet-field-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.sheet-field-grid input {
  width: 100%;
  height: 52px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 16px;
}

.settings-card {
  padding-top: 30px;
}

.settings-group {
  display: block;
  margin: 20px 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.settings-group legend,
.settings-group .group-title,
.rates-group h3 {
  display: block;
  margin: 0 0 8px;
  padding: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 590;
}

.settings-group legend {
  transform: translateY(-26px);
}

.settings-group:has(legend) {
  margin-top: 48px;
}

.single-row {
  position: relative;
  margin-top: 42px;
}

.single-row .group-title {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
}

.settings-group select {
  width: 100%;
  height: 56px;
  padding: 0 42px 0 14px;
  border: 0;
  border-radius: var(--radius-sm);
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 17px;
  font-weight: 650;
}

.settings-row {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0 14px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-row select {
  width: auto;
  min-width: 112px;
  margin-left: auto;
  padding-left: 8px;
  text-align: right;
}

.settings-row strong {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.rates-group {
  position: relative;
  margin-top: 48px;
}

.rates-group h3 {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
}

.rate-status {
  min-height: 20px;
  margin: 12px 4px 0;
  color: var(--accent);
  font-size: 13px;
}

.rate-status.error {
  color: var(--danger);
}

.outline-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
}

.outline-button svg {
  width: 21px;
  height: 21px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 18px;
  z-index: 200;
  width: min(calc(100% - 36px), 520px);
  margin: auto;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--surface);
  font-size: 14px;
  text-align: center;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.22);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@keyframes sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

@media (min-width: 620px) {
  .app-shell {
    padding-right: 24px;
    padding-left: 24px;
  }

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

  .balance-field {
    grid-column: span 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-soft: #182321;
  --line: #334440;
  --hero-end: #034c47;
}
