:root {
  --bg: var(--tg-theme-bg-color, #0f1117);
  --card: var(--tg-theme-secondary-bg-color, #181c26);
  --text: var(--tg-theme-text-color, #f1f5f9);
  --muted: var(--tg-theme-hint-color, #94a3b8);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --surface: rgba(128, 128, 128, 0.11);
  --surface-strong: rgba(128, 128, 128, 0.18);
  --border: rgba(128, 128, 128, 0.2);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.16);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.18);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --purple: #8b5cf6;
}

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

body {
  margin: 0;
  padding: 12px 12px calc(84px + env(safe-area-inset-bottom)) 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

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

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-sub {
  font-size: 11px;
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
}

.hero-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.hero-val {
  font-size: 30px;
  font-weight: 800;
  margin: 4px 0 8px;
  letter-spacing: -0.025em;
}

.curr-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chip {
  background: var(--surface);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.metric-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 11px;
}

.metric-box .lbl {
  color: var(--muted);
  font-size: 11px;
}

.metric-box .val {
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
}

.val-green { color: var(--green); }
.val-danger { color: var(--danger); }
.val-muted { color: var(--muted); }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 14px 2px 8px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.btn-sm {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

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

.btn-full {
  width: 100%;
  padding: 11px 12px;
  font-size: 14px;
  border-radius: 12px;
}

.btn-sm:disabled, .btn-ghost:disabled, .btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.progress-track {
  height: 10px;
  background: var(--surface-strong);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 8px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 999px;
  transition: width 0.35s ease;
}

.row-item {
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.row-item:first-child { padding-top: 2px; }
.row-item:last-child { border-bottom: none; padding-bottom: 2px; }

.row-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.row-title {
  font-weight: 700;
  font-size: 14px;
  word-break: break-word;
}

.row-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.row-right {
  text-align: right;
  flex-shrink: 0;
}

.row-amount {
  font-weight: 700;
  font-size: 15px;
}

.row-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
}

.badge-ok { background: var(--green-soft); color: var(--green); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--surface); color: var(--muted); }

.chart-wrap {
  position: relative;
  height: 210px;
  margin-top: 8px;
}

.chart-wrap-sm {
  position: relative;
  height: 185px;
  margin-top: 8px;
}

.filter-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  margin-bottom: 10px;
  outline: none;
}

.cal-month-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.cal-month-title {
  font-size: 15px;
  font-weight: 700;
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.switch-row:last-child { border-bottom: none; }

.switch-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 7px 2px calc(7px + env(safe-area-inset-bottom));
  z-index: 50;
}

.tab {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  padding: 2px 0;
}

.tab .ico { font-size: 18px; line-height: 1.1; }
.tab.active { color: var(--accent); font-weight: 700; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--card);
  width: 100%;
  max-width: 540px;
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  max-height: 88vh;
  overflow-y: auto;
}

.modal h3 {
  margin: 0 0 14px;
  font-size: 17px;
}

.field { margin-bottom: 12px; }

.field label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  font-size: 13px;
}

.field-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.search-results {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  max-height: 190px;
  overflow-y: auto;
}

.search-item {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.search-item:last-child { border-bottom: none; }
.search-item:active { background: var(--surface); }

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn-cancel {
  background: var(--surface);
  color: var(--text);
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #ffffff;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  z-index: 200;
  max-width: 92vw;
  text-align: center;
}

.error-box {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 14px 4px;
  font-size: 13px;
}

.archived-item {
  opacity: 0.62;
}
