:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --accent-2: color-mix(in srgb, var(--button) 60%, #7c5cff 40%);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

.hidden { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { padding: 14px 14px 100px; }

.view.hidden { display: none; }

.home-header {
  font-size: 22px;
  font-weight: 700;
  margin: 8px 0 18px;
}

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.home-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  border: none;
  border-radius: 18px;
  background: var(--secondary-bg);
  padding: 20px 16px;
  min-height: 110px;
  text-align: left;
  transition: transform 0.1s ease;
}

.home-card:active { transform: scale(0.96); }

.home-card-icon { font-size: 28px; }

.home-card-label {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

.home-card-soon { opacity: 0.55; }

.home-card-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  background: color-mix(in srgb, var(--hint) 30%, transparent);
  padding: 3px 7px;
  border-radius: 8px;
}

.back-btn { font-size: 18px; }

.summary-cards {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.loans-summary-card {
  background: var(--secondary-bg);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.loans-summary-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
}

.loans-summary-title span {
  font-weight: 500;
  color: var(--hint);
  font-size: 12px;
}

.loans-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.loans-summary-item { flex: 1; text-align: center; }

.loans-summary-label {
  font-size: 11px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.loans-summary-value {
  font-size: 15px;
  font-weight: 700;
}

.loans-summary-value.overdue { color: #ff6b6b; }

.summary-card {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--secondary-bg);
  border-radius: 16px;
  padding: 14px;
}

.summary-icon {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
}

.summary-card.income .summary-icon { background: color-mix(in srgb, #2ecc71 22%, transparent); color: #2ecc71; }
.summary-card.expense .summary-icon { background: color-mix(in srgb, #ff6b6b 22%, transparent); color: #ff6b6b; }

.summary-info { min-width: 0; }
.summary-label { font-size: 12px; color: var(--hint); font-weight: 600; }
.summary-amount { font-size: 18px; font-weight: 800; margin-top: 2px; }
.summary-card.income .summary-amount { color: #2ecc71; }
.summary-card.expense .summary-amount { color: #ff6b6b; }
.summary-count { font-size: 11px; color: var(--hint); margin-top: 2px; }

.ratio-bar-track {
  position: relative;
  height: 26px;
  border-radius: 13px;
  background: color-mix(in srgb, #2ecc71 25%, var(--secondary-bg));
  overflow: hidden;
  margin-bottom: 14px;
}

.ratio-bar-fill {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(90deg, color-mix(in srgb, #ff6b6b 60%, transparent), #ff6b6b);
  border-radius: 13px;
  transition: width 0.3s ease;
}

.ratio-bar-label {
  position: absolute;
  top: 0;
  right: 12px;
  height: 100%;
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.ratio-bar-label.positive { color: #1a7a41; }
.ratio-bar-label.negative { color: #fff; }

.segmented {
  display: flex;
  background: var(--secondary-bg);
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 12px;
}

.segmented-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 10px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented-btn.active {
  background: var(--button);
  color: var(--button-text);
}

.category-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--secondary-bg);
  border-radius: 14px;
  padding: 12px 14px;
}

.category-icon {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.category-info { flex: 1; min-width: 0; }
.category-name { font-size: 14px; font-weight: 600; }
.category-count { font-size: 12px; color: var(--hint); margin-top: 1px; }

.tx-item-amount.income { color: #2ecc71; }
.tx-item-amount.expense { color: #ff6b6b; }

.tx-item-amount { text-align: right; }

.tx-item-sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--hint);
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--hint) 25%, transparent);
  overflow: hidden;
  margin: 8px 0;
}

.progress-fill {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--button), var(--accent-2));
}

.progress-fill.done { background: #2ecc71; }

.goal-card .goal-sub {
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 4px;
}

.goal-card .goal-sub.overdue {
  color: #ff6b6b;
  font-weight: 600;
}

.goal-card .goal-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.goal-card .goal-actions button {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
}

.goal-card .action-primary {
  background: var(--button);
  color: var(--button-text);
}

.goal-card .action-danger {
  background: color-mix(in srgb, #e05353 20%, var(--secondary-bg));
  color: #e05353;
}

.goal-card .action-secondary {
  background: color-mix(in srgb, var(--link) 18%, var(--secondary-bg));
  color: var(--link);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.month-label {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.nav-btn {
  background: var(--secondary-bg);
  border: none;
  color: var(--text);
  font-size: 20px;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  transition: transform 0.12s ease, background 0.15s ease;
}

.nav-btn:active { transform: scale(0.9); background: color-mix(in srgb, var(--secondary-bg) 70%, var(--button) 30%); }

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar-btn {
  flex: 1;
  border: none;
  background: var(--secondary-bg);
  color: var(--text);
  padding: 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.1s ease;
}

.toolbar-btn:active { transform: scale(0.96); }

.goal-list, .stats-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }

.goal-card, .stats-card {
  background: var(--secondary-bg);
  border-radius: 14px;
  padding: 12px 14px;
}

.goal-card .goal-label, .stats-card .stats-label {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stats-card .stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--hint);
}

.stats-card .stats-percent {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.stats-card .stats-streak {
  font-size: 13px;
  font-weight: 600;
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--hint);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day-cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--secondary-bg);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.day-cell:not(.empty):active { transform: scale(0.92); }

.day-cell.empty { background: transparent; cursor: default; }

.day-cell.today {
  background: var(--button);
  color: var(--button-text);
  font-weight: 700;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--button) 50%, transparent);
}

.day-cell.has-tasks:not(.today) {
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--link) 45%, transparent);
}

.day-cell .dots {
  position: absolute;
  bottom: 6px;
  display: flex;
  gap: 3px;
}

.day-cell .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 28px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--button), var(--accent-2));
  color: var(--button-text);
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--button) 55%, transparent);
  transition: transform 0.12s ease;
}

.fab:active { transform: scale(0.9) rotate(90deg); }

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sheet.hidden { display: none; }
.sheet.open { opacity: 1; }

.sheet-content {
  background: var(--bg);
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px 22px;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2);
  transform: translateY(24px);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.sheet.open .sheet-content { transform: translateY(0); }

.sheet-content::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 4px;
  background: var(--hint);
  opacity: 0.4;
  margin: 0 auto 12px;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 14px;
}

.close-btn {
  background: var(--secondary-bg);
  border: none;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  transition: transform 0.12s ease;
}

.close-btn:active { transform: scale(0.85); }

.task-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.task-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--secondary-bg);
  padding: 12px 14px;
  border-radius: 14px;
  gap: 10px;
}

.task-item .task-info { display: flex; flex-direction: column; gap: 2px; }
.task-item .task-time { font-size: 12px; color: var(--hint); }

.task-item .del-btn {
  background: none;
  border: none;
  color: #e05353;
  font-size: 17px;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}

.task-item .del-btn:active { transform: scale(0.85); }

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 14px 0 8px;
}

.step:first-child .field-label { margin-top: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.vertical { flex-direction: column; }

.new-item-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.new-item-row.hidden { display: none; }
.new-item-row input { flex: 1; }
.new-item-row button { flex-shrink: 0; }

.chip.chip-add {
  border-style: dashed;
  color: var(--link);
}

.chip {
  border: 1.5px solid color-mix(in srgb, var(--hint) 40%, transparent);
  background: var(--secondary-bg);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.chip:active { transform: scale(0.95); }

.chip.selected {
  background: var(--button);
  color: var(--button-text);
  border-color: var(--button);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--button) 40%, transparent);
}

input[type="text"], input[type="date"], input[type="time"], input[type="number"], select {
  width: 100%;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1.5px solid color-mix(in srgb, var(--hint) 35%, transparent);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.15s ease;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--button);
}

.interval-row { display: flex; gap: 8px; }
.interval-row input { flex: 1; }
.interval-row select { flex: 1; }

.primary-btn {
  width: 100%;
  padding: 13px;
  margin-top: 18px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--button), var(--accent-2));
  color: var(--button-text);
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--button) 40%, transparent);
  transition: transform 0.1s ease;
}

.primary-btn:active { transform: scale(0.98); }

.step { animation: fadeIn 0.2s ease; }
.step.hidden { display: none; }

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

.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--secondary-bg);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 20;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.hidden { display: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
