/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f1a;
  --bg2:       #1a1a2e;
  --bg3:       #22223a;
  --border:    #2e2e4a;
  --accent:    #00d4aa;
  --accent2:   #00a8ff;
  --danger:    #ff5f6d;
  --text:      #e8e8f0;
  --text2:     #8888aa;
  --text3:     #555570;
  --card-r:    16px;
  --font-jp:   'Noto Sans JP', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

html, body {
  height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font-jp);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.hidden-input { position: absolute; opacity: 0; width: 0; height: 0; }

/* ─── Splash ─── */
#splash {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .5s ease;
}
#splash.fade-out { opacity: 0; pointer-events: none; }

.splash-inner { text-align: center; }

.splash-icon {
  width: 80px; height: 80px; margin: 0 auto 20px;
  animation: float 2s ease-in-out infinite;
}
.splash-icon svg { width: 100%; height: 100%; }

@keyframes float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

.splash-title {
  font-size: 22px; font-weight: 700;
  letter-spacing: .1em; color: var(--text);
  margin-bottom: 6px;
}
.splash-sub { font-size: 12px; color: var(--text2); letter-spacing: .15em; margin-bottom: 32px; }

.splash-loader {
  width: 48px; height: 2px; background: var(--border);
  margin: 0 auto; border-radius: 2px; overflow: hidden;
}
.splash-loader > div {
  width: 40%; height: 100%; background: var(--accent);
  border-radius: 2px;
  animation: slide 1s ease-in-out infinite;
}
@keyframes slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* ─── App Shell ─── */
#app {
  display: flex; flex-direction: column;
  height: 100dvh; overflow: hidden;
}

/* ─── Header ─── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative; z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { width: 32px; height: 32px; }
.header-title { font-size: 16px; font-weight: 700; letter-spacing: .05em; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text2); cursor: pointer;
  transition: all .2s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover, .icon-btn:active { background: var(--accent); border-color: var(--accent); color: var(--bg); }

/* ─── Pages ─── */
.pages { flex: 1; overflow: hidden; position: relative; }
.page {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  -webkit-overflow-scrolling: touch;
}
.page.active { transform: translateX(0); }
.page.slide-left { transform: translateX(-30%); }

.page-content { padding: 20px 16px 100px; }

/* ─── Stats Bar ─── */
.stats-bar {
  display: flex; align-items: center;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--card-r);
  padding: 16px; margin-bottom: 20px;
  gap: 0;
}
.stat-item { flex: 1; text-align: center; }
.stat-label { display: block; font-size: 10px; color: var(--text2); letter-spacing: .1em; margin-bottom: 4px; }
.stat-value { font-size: 18px; font-weight: 700; font-family: var(--font-mono); color: var(--text); }
.stat-value.accent { color: var(--accent); }
.stat-divider { width: 1px; height: 36px; background: var(--border); }

/* ─── Camera Card ─── */
.camera-card {
  position: relative; overflow: hidden;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 20px; padding: 36px 24px;
  text-align: center; margin-bottom: 28px;
  cursor: pointer;
  transition: all .25s cubic-bezier(.4,0,.2,1);
}
.camera-card::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: 20px;
  border: 2px solid transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent2)) border-box;
  -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: destination-out;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity .25s;
}
.camera-card:hover::before, .camera-card:active::before { opacity: 1; }
.camera-card:active { transform: scale(.98); }

.camera-card-bg {
  position: absolute; inset: 0; border-radius: 20px;
  background: radial-gradient(ellipse at 50% 0%, rgba(0,212,170,.06) 0%, transparent 70%);
}

.camera-icon-wrap {
  width: 64px; height: 64px; margin: 0 auto 16px;
  background: rgba(0,212,170,.08); border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(0,212,170,.2);
}
.camera-icon-wrap svg { width: 40px; height: 40px; }
.camera-label { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.camera-sub { font-size: 12px; color: var(--text2); }

/* ─── Section Header ─── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.section-title { font-size: 13px; font-weight: 700; letter-spacing: .1em; color: var(--text2); text-transform: uppercase; }
.text-btn { background: none; border: none; color: var(--accent); font-size: 13px; cursor: pointer; font-family: var(--font-jp); padding: 4px 0; }

/* ─── Receipt List ─── */
.receipt-list { display: flex; flex-direction: column; gap: 10px; }
.receipt-list.full { margin-top: 12px; }

.receipt-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--card-r); padding: 14px;
  cursor: pointer; transition: all .2s;
  animation: fadeUp .3s ease both;
}
@keyframes fadeUp {
  from { opacity:0; transform: translateY(10px); }
  to   { opacity:1; transform: translateY(0); }
}
.receipt-card:active { background: var(--bg3); }

.receipt-thumb {
  width: 48px; height: 48px; border-radius: 10px;
  object-fit: cover; flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg3);
}
.receipt-thumb-placeholder {
  width: 48px; height: 48px; border-radius: 10px; flex-shrink: 0;
  background: var(--bg3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}

.receipt-info { flex: 1; min-width: 0; }
.receipt-vendor {
  font-size: 14px; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; margin-bottom: 4px;
}
.receipt-meta { font-size: 11px; color: var(--text2); display: flex; gap: 8px; align-items: center; }
.receipt-cat {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px;
  font-size: 10px; color: var(--text2);
}
.receipt-amount {
  font-family: var(--font-mono);
  font-size: 15px; font-weight: 500;
  color: var(--accent); flex-shrink: 0;
}
.receipt-delete {
  background: none; border: none;
  color: var(--text3); font-size: 18px; cursor: pointer;
  padding: 4px 8px; flex-shrink: 0;
  transition: color .2s;
}
.receipt-delete:hover { color: var(--danger); }

/* ─── Empty State ─── */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text3);
}
.empty-state svg { width: 64px; height: 64px; margin: 0 auto 16px; }
.empty-state p { font-size: 14px; margin-bottom: 6px; }
.empty-sub { font-size: 12px !important; }

/* ─── History Page ─── */
.page-title-bar {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.back-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text2); cursor: pointer;
}
.back-btn svg { width: 20px; height: 20px; }
.page-title-bar h2 { flex: 1; font-size: 18px; font-weight: 700; }

.filter-bar { margin-bottom: 16px; }
.filter-select {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 10px 14px;
  font-size: 13px; font-family: var(--font-jp); width: 100%;
  appearance: none;
}

/* ─── Modals ─── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10,10,20,.85);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 24px; width: 100%; max-width: 420px;
  padding: 28px 24px;
  animation: slideUp .3s cubic-bezier(.4,0,.2,1);
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity:0; }
  to   { transform: translateY(0);    opacity:1; }
}

/* OCR Modal */
.ocr-step {
  text-align: center; padding: 8px 0 20px;
}
.step-icon {
  position: relative; width: 80px; height: 80px;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
}
.step-icon svg { width: 64px; height: 64px; }
.step-icon.scanning .scan-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scanMove 1.5s ease-in-out infinite;
  border-radius: 2px;
}
@keyframes scanMove {
  0%   { top: 10%; }
  50%  { top: 85%; }
  100% { top: 10%; }
}

.progress-bar {
  height: 4px; background: var(--bg3); border-radius: 4px; overflow: hidden; margin-bottom: 12px;
}
.progress-fill {
  height: 100%; width: 0%; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width .3s ease;
}
.progress-label { font-size: 12px; color: var(--text2); text-align: center; }

/* Edit Modal */
.edit-modal {
  max-height: 90vh; overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.close-btn {
  width: 32px; height: 32px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}

.receipt-preview-wrap {
  position: relative; margin-bottom: 20px; border-radius: 12px; overflow: hidden;
}
.receipt-preview {
  width: 100%; height: 160px; object-fit: cover;
  border-radius: 12px; display: block;
  border: 1px solid var(--border);
}
.ocr-badge {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0,212,170,.15); border: 1px solid var(--accent);
  color: var(--accent); font-size: 10px; font-weight: 700;
  letter-spacing: .1em; padding: 3px 8px; border-radius: 20px;
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 11px; color: var(--text2);
  letter-spacing: .1em; text-transform: uppercase; margin-bottom: 6px;
}
.form-group input,
.form-group select {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 12px 14px;
  font-size: 14px; font-family: var(--font-jp);
  transition: border-color .2s;
}
.form-group input:focus,
.form-group select:focus {
  outline: none; border-color: var(--accent);
}
.input-wrap { position: relative; }
.yen-sign {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--accent); font-family: var(--font-mono); font-size: 16px; font-weight: 500;
}
.amount-input input { padding-left: 30px; font-family: var(--font-mono); font-size: 18px; }

.form-actions {
  display: flex; gap: 12px; margin-top: 20px; padding-bottom: 4px;
}
.btn-primary, .btn-secondary {
  flex: 1; padding: 14px;
  border-radius: 12px; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: all .2s; font-family: var(--font-jp);
  border: none;
}
.btn-primary {
  background: var(--accent); color: var(--bg);
}
.btn-primary:active { opacity: .8; transform: scale(.98); }
.btn-secondary {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
}
.btn-secondary:active { opacity: .8; }

/* ─── Toast ─── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 12px; font-size: 13px;
  white-space: nowrap; z-index: 9000;
  opacity: 0; transition: all .3s;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--accent); }
.toast.error { border-color: var(--danger); }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
