:root {
  --bg: #0b0e14;
  --surface: #141925;
  --surface-2: #1b2233;
  --border: #232c42;
  --text: #e8edf7;
  --text-dim: #8a94ab;
  --accent: #4ade80;
  --accent-dim: rgba(74, 222, 128, 0.14);
  --danger: #f87171;
  --radius: 16px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body {
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  position: relative;
  display: flex;
  flex-direction: column;
}

.screen { flex: 1; display: flex; flex-direction: column; padding: max(12px, env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.month-label { font-size: 15px; font-weight: 600; color: var(--text-dim); letter-spacing: 0.02em; }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 38px; height: 38px;
  border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:active { background: var(--surface-2); color: var(--text); }

/* ---------- Hero ---------- */
.hero { text-align: center; margin: 6vh 0 30px; }
.hero-caption {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--text-dim); margin-bottom: 10px;
}
.hero-amount {
  font-size: clamp(56px, 17vw, 84px);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--text);
  transition: color .3s;
}
.hero-amount.warn { color: #fbbf24; }
.hero-amount.over { color: var(--danger); }
.hero-sub { margin-top: 14px; font-size: 14px; color: var(--text-dim); }
.hero-sub b { color: var(--text); font-weight: 600; }

.progress-track {
  height: 6px; border-radius: 3px;
  background: var(--surface-2);
  margin: 22px auto 0;
  width: min(72%, 260px);
  overflow: hidden;
}
.progress-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--accent), #34d399);
  border-radius: 3px;
  transition: width .5s cubic-bezier(.22,1,.36,1), background .3s;
}
.progress-fill.warn { background: #fbbf24; }
.progress-fill.over { background: var(--danger); }

/* ---------- Entry form ---------- */
#entry-form { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }

.combo { position: relative; }
.combo input, .amount-wrap input, .modal input[type="text"], .modal input[type="number"], .modal input[type="date"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 17px;
  padding: 16px 18px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.combo input:focus, .amount-wrap input:focus, .modal input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input::placeholder { color: #556079; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.combo-list {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 30;
  box-shadow: 0 -12px 40px rgba(0,0,0,.5);
  max-height: 240px;
  overflow-y: auto;
}
.combo-item {
  padding: 14px 18px;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.combo-item:last-child { border-bottom: none; }
.combo-item:active, .combo-item.hover { background: var(--surface-2); }
.combo-item.add-new { color: var(--accent); font-weight: 600; }
.combo-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.combo-item.add-new .dot { background: var(--accent); }

.amount-row { display: flex; gap: 10px; }
.amount-wrap { position: relative; flex: 1; }
.amount-wrap .currency {
  position: absolute; left: 18px; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); font-size: 17px; pointer-events: none;
}
.amount-wrap input { padding-left: 36px; font-weight: 600; }
.amount-wrap.big input { font-size: 26px; padding: 18px 18px 18px 40px; text-align: center; }

.submit-btn {
  flex-shrink: 0;
  background: var(--accent);
  color: #06281a;
  border: none; border-radius: var(--radius);
  padding: 0 26px;
  font-size: 16px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer;
  transition: transform .1s, filter .15s;
}
.submit-btn svg { width: 20px; height: 20px; }
.submit-btn:active { transform: scale(0.96); filter: brightness(1.1); }
.submit-btn:disabled { opacity: .4; cursor: default; }

.quick-msg {
  text-align: center; margin-top: 14px;
  font-size: 14px; font-weight: 500; color: var(--accent);
  animation: fadein .25s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; } }

/* ---------- History sheet ---------- */
.sheet {
  position: fixed; inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.32,.72,.28,1);
  will-change: transform;
}
.sheet.open { transform: translateY(0); }

.sheet-header {
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  align-items: center;
  gap: 8px;
}
.history-nav { display: flex; align-items: center; justify-content: center; gap: 4px; }
.history-title { font-size: 16px; font-weight: 700; min-width: 140px; text-align: center; }
.history-total {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 14px; color: var(--text-dim);
  padding-top: 8px;
}
.history-total b { color: var(--text); }

.history-body { flex: 1; overflow-y: auto; padding: 8px 20px calc(30px + env(safe-area-inset-bottom)); }

.day-group { margin-bottom: 8px; }
.day-label {
  font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 16px 4px 8px;
}
.tx-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 8px;
}
.tx-icon {
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 10px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  font-size: 15px; font-weight: 700;
  text-transform: uppercase;
}
.tx-info { flex: 1; min-width: 0; }
.tx-item { font-size: 15.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-time { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.tx-amount { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-actions { display: flex; gap: 6px; }
.tx-actions .icon-btn { width: 34px; height: 34px; border-radius: 10px; }
.tx-actions .icon-btn svg { width: 16px; height: 16px; }
.icon-btn.danger { color: var(--danger); }

.empty-history {
  text-align: center; color: var(--text-dim);
  padding: 80px 20px; font-size: 15px; line-height: 1.6;
}
.empty-history span { font-size: 34px; display: block; margin-bottom: 12px; opacity: .6; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 7, 12, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadein .2s ease;
}
.modal {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 28px 24px calc(28px + env(safe-area-inset-bottom));
  animation: slideup .3s cubic-bezier(.32,.72,.28,1);
}
@keyframes slideup { from { transform: translateY(60%); opacity: .5;} to { transform: translateY(0); opacity: 1;} }

@media (min-width: 520px) {
  .modal-overlay { align-items: center; padding: 20px; }
  .modal { border-radius: 24px; }
}

.modal h2 { font-size: 21px; font-weight: 700; margin-bottom: 6px; }
.modal-sub { font-size: 14px; color: var(--text-dim); margin-bottom: 20px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin: 16px 0 8px; }
.field-label:first-of-type { margin-top: 0; }

.primary-btn {
  width: 100%;
  background: var(--accent);
  color: #06281a;
  border: none; border-radius: 14px;
  padding: 16px;
  font-size: 16px; font-weight: 700;
  margin-top: 22px;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}
.primary-btn:active { transform: scale(.98); filter: brightness(1.08); }

.ghost-btn {
  width: 100%;
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 15px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
}
.ghost-btn.danger { color: var(--danger); }
.ghost-btn:active { color: var(--text); }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 20px;
  font-size: 15px;
  cursor: pointer;
}
.switch-row input { display: none; }
.toggle {
  width: 48px; height: 28px; flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  transition: background .2s;
}
.toggle::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .2s, background .2s;
}
.switch-row input:checked + .toggle { background: var(--accent-dim); border-color: var(--accent); }
.switch-row input:checked + .toggle::after { transform: translateX(20px); background: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(28px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: #e8edf7;
  color: #0b0e14;
  font-size: 14px; font-weight: 600;
  padding: 12px 22px;
  border-radius: 999px;
  z-index: 200;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: fadein .2s ease;
  white-space: nowrap;
}
