:root {
  --tg-bg: #ffffff;
  --tg-text: #1f2a44;
  --tg-hint: #7a8399;
  --tg-link: #2481cc;
  --tg-button: #2cb67d;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #f0f2f5;

  --border: rgba(0, 0, 0, 0.08);
  --success: #2cb67d;
  --danger: #e74c3c;
  --warn: #f39c12;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  padding-bottom: env(safe-area-inset-bottom, 24px);
  font-size: 15px;
  line-height: 1.4;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

#app-title {
  font-weight: 700;
  font-size: 17px;
}

#user-chip {
  font-size: 12px;
  color: var(--tg-hint);
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--tg-secondary-bg);
}

#tabs {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--tg-bg);
  z-index: 10;
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }

.tab {
  border: 0;
  background: transparent;
  color: var(--tg-hint);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tab[aria-selected="true"] {
  background: var(--tg-button);
  color: var(--tg-button-text);
}

#content {
  padding: 16px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--tg-hint);
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"] { min-height: 44px; }
input[type="file"] {
  padding: 8px;
  background: transparent;
  border: 1px dashed var(--border);
}
textarea {
  min-height: 60px;
  resize: vertical;
}

button.primary {
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: 0;
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
}
button.primary:active { transform: scale(0.98); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.kpi {
  background: var(--tg-secondary-bg);
  border-radius: 10px;
  padding: 14px;
  border-left: 3px solid var(--tg-hint);
}
.kpi.pos { border-left-color: var(--success); }
.kpi.neg { border-left-color: var(--danger); }
.kpi.warn { border-left-color: var(--warn); }
.kpi .label {
  font-size: 11px;
  color: var(--tg-hint);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 700;
}
.kpi .value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.kpi.pos .value { color: var(--success); }
.kpi.neg .value { color: var(--danger); }
.kpi.warn .value { color: var(--warn); }

.history-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.history-item:last-child { border-bottom: none; }
.history-item .info { min-width: 0; }
.history-item .title { font-weight: 600; font-size: 14px; }
.history-item .meta {
  font-size: 12px;
  color: var(--tg-hint);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 65vw;
}
.history-item .amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 15px;
}
.history-item .amount.in { color: var(--success); }
.history-item .amount.out { color: var(--danger); }
.history-item .amount.mid { color: var(--tg-link); }

.hint {
  color: var(--tg-hint);
  font-size: 13px;
  margin-top: 12px;
  line-height: 1.5;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--tg-hint);
  font-size: 14px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 12px 18px;
  border-radius: 20px;
  background: var(--tg-text);
  color: var(--tg-bg);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 100;
  font-size: 14px;
  max-width: 90vw;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); color: #fff; }
