:root {
  --bg: #0c0f16;
  --surface: #161b26;
  --surface-2: #1e2533;
  --line: #2a3242;
  --text: #e8ecf3;
  --muted: #93a0b4;
  --accent: #ffb02e;
  --accent-2: #4ea1ff;
  --green: #4cd17e;
  --red: #ff6b6b;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

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

body {
  padding-bottom: calc(96px + var(--safe-bottom));
  min-height: 100vh;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(180deg, #10141c 0%, rgba(16,20,28,0.96) 100%);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  max-width: 760px;
  margin: 0 auto;
}
.app-title { font-size: 18px; font-weight: 700; letter-spacing: 0.2px; }
.app-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.total { font-size: 20px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.stat-card.wide { grid-column: 1 / -1; }
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.breakdown { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.bd-row { display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.bd-bar-wrap { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bd-bar { height: 100%; background: var(--accent-2); border-radius: 99px; }
.bd-val { font-variant-numeric: tabular-nums; color: var(--muted); }

.ppk-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px; }
.ppk { text-align: center; }
.ppk .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ppk .l { font-size: 11px; color: var(--muted); margin-top: 3px; line-height: 1.25; }

/* ---------- Filter ---------- */
.filter-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 6px; -webkit-overflow-scrolling: touch; }
.chip {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 99px;
  font-size: 13px;
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #1a1300; font-weight: 600; }

/* ---------- Entries ---------- */
.entries { display: flex; flex-direction: column; gap: 8px; }
.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
}
.entry:active { background: var(--surface-2); }
.entry-icon {
  width: 40px; height: 40px; flex: 0 0 auto;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 19px;
  background: var(--surface-2);
}
.entry-main { flex: 1; min-width: 0; }
.entry-top { display: flex; justify-content: space-between; gap: 10px; }
.entry-type { font-weight: 600; font-size: 15px; }
.entry-cost { font-weight: 700; font-variant-numeric: tabular-nums; }
.entry-meta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.entry-note { font-style: italic; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- FAB ---------- */
.fab-bar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(14px + var(--safe-bottom));
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 20;
  pointer-events: none;
}
.fab {
  pointer-events: auto;
  border: none;
  border-radius: 99px;
  padding: 15px 24px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.fab-primary { background: var(--accent); color: #1a1300; }
.fab-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }

/* ---------- Modal / Sheet ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--line);
  padding: 18px 18px calc(20px + var(--safe-bottom));
  max-height: 92vh;
  overflow-y: auto;
  animation: slideUp 0.22s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 28px; line-height: 1; cursor: pointer; padding: 0 6px; }

/* Scan box */
.scan-box { background: var(--surface-2); border: 1px dashed var(--line); border-radius: 14px; padding: 14px; margin-bottom: 16px; }
.scan-hint { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.scan-actions { display: flex; gap: 10px; }
.scan-btn {
  flex: 1;
  text-align: center;
  background: var(--accent-2);
  color: #04121f;
  border: none;
  border-radius: 11px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.scan-btn.ghost { background: transparent; color: var(--accent-2); border: 1px solid var(--accent-2); }
.scan-btn:disabled { opacity: 0.45; cursor: default; }
.scan-files { font-size: 12px; color: var(--muted); margin-top: 10px; }
.scan-status { font-size: 13px; margin-top: 10px; min-height: 18px; }
.scan-status.ok { color: var(--green); }
.scan-status.err { color: var(--red); }
.scan-status.loading { color: var(--accent-2); }

/* Form */
.entry-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field > span { font-weight: 500; }
.field input, .field select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 14px;
  color: var(--text);
  font-size: 16px;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent-2); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field.checkbox { flex-direction: row; align-items: center; gap: 10px; align-self: end; padding-bottom: 13px; cursor: pointer; }
.field.checkbox input {
  width: 24px; height: 24px; flex: 0 0 auto;
  -webkit-appearance: auto;
  appearance: auto;
  accent-color: var(--accent);
  padding: 0;
  cursor: pointer;
}
.field.checkbox span { color: var(--text); font-size: 15px; cursor: pointer; }

.form-error { color: var(--red); font-size: 13px; min-height: 16px; }
.form-actions { display: flex; gap: 12px; margin-top: 4px; }
.btn { flex: 1; border: none; border-radius: 12px; padding: 15px; font-size: 15px; font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--accent); color: #1a1300; }
.btn.danger { background: transparent; color: var(--red); border: 1px solid var(--red); flex: 0 0 auto; padding-left: 22px; padding-right: 22px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom));
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast[hidden] { display: none; }
.toast.err { border-color: var(--red); color: var(--red); }

@media (min-width: 620px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stat-card.wide { grid-column: span 2; }
  .modal { align-items: center; }
  .sheet { border-radius: 22px; }
}
