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

:root {
  --green: #2e7d32;
  --green-light: #4caf50;
  --orange: #f57c00;
  --red: #c62828;
  --bg: #f2f4f3;
  --card: #ffffff;
  --text: #1a1a1a;
  --text-sub: #666;
  --border: #e0e0e0;
  --nav-h: 64px;
  --header-h: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Utility ── */
.hidden { display: none !important; }
.mt-8 { margin-top: 8px; }

/* ── Auth screens ── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  z-index: 100;
  padding: 24px;
}

.screen-inner {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.app-logo { margin-bottom: 8px; }

.screen-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--green);
}

.screen-desc {
  font-size: 14px;
  color: var(--text-sub);
  text-align: center;
  margin-bottom: 4px;
}

/* ── Forms ── */
.text-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: #fafafa;
  color: var(--text);
  transition: border-color 0.15s;
}
.text-input:focus { border-color: var(--green); background: white; }

.pin-input {
  text-align: center;
  font-size: 28px;
  letter-spacing: 12px;
}

select.text-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

.error-msg { font-size: 13px; color: var(--red); min-height: 18px; text-align: center; }

/* ── Buttons ── */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--green);
  color: white;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { background: var(--green-light); transform: scale(0.98); }
.btn-primary.full-width { display: block; }

.btn-text {
  background: none;
  border: none;
  color: var(--green);
  font-size: 14px;
  cursor: pointer;
  padding: 8px;
  -webkit-tap-highlight-color: transparent;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  color: var(--text-sub);
  -webkit-tap-highlight-color: transparent;
}

/* ── App layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-h);
  background: var(--green);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}
.header-title { font-size: 17px; font-weight: 700; }
.header-month { font-size: 14px; opacity: 0.85; }

#main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(var(--nav-h) + var(--safe-bottom) + 8px);
}

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  font-size: 11px;
  color: var(--text-sub);
  cursor: pointer;
  padding: 8px 0 4px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}
.nav-btn.active { color: var(--green); }
.nav-btn svg { stroke: currentColor; }

/* ── Cards ── */
.card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Gauge ── */
.gauge-amounts {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.gauge-total { font-size: 32px; font-weight: 700; color: var(--text); }
.gauge-budget { font-size: 14px; color: var(--text-sub); }

.gauge-track {
  width: 100%;
  height: 20px;
  background: #e8f5e9;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
}
.gauge-bar {
  height: 100%;
  border-radius: 10px;
  transition: width 0.6s cubic-bezier(.4,0,.2,1), background-color 0.3s;
  background: var(--green-light);
  min-width: 4px;
}
.gauge-bar.warn { background: var(--orange); }
.gauge-bar.over { background: var(--red); }

.gauge-remaining { font-size: 13px; color: var(--text-sub); }

/* ── Camera button ── */
.camera-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 8px 0 12px;
}

.camera-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 200px;
  height: 200px;
  background: var(--green);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(46,125,50,.35);
  transition: transform 0.1s, box-shadow 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.camera-btn:active { transform: scale(0.96); box-shadow: 0 2px 8px rgba(46,125,50,.3); }
.camera-icon { width: 56px; height: 56px; stroke: white; }

.gallery-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
  width: 220px;
  min-height: 56px;
  background: white;
  color: var(--green);
  border: 2px solid var(--green);
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  padding: 12px 20px;
  box-shadow: 0 2px 8px rgba(46,125,50,.12);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.1s;
  user-select: none;
}
.gallery-btn:active { background: #e8f5e9; transform: scale(0.97); }

/* ── Receipt list (home & history) ── */
.receipt-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.receipt-item:last-child { border-bottom: none; }

.receipt-cat-badge {
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 20px;
  background: #e8f5e9;
  color: var(--green);
  white-space: nowrap;
  flex-shrink: 0;
}
.receipt-cat-badge.daily { background: #e3f2fd; color: #1565c0; }
.receipt-cat-badge.other { background: #f3e5f5; color: #6a1b9a; }

.receipt-info { flex: 1; min-width: 0; }
.receipt-store { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.receipt-date { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

.receipt-amount { font-size: 18px; font-weight: 700; color: var(--text); white-space: nowrap; }

.receipt-actions { display: flex; gap: 4px; flex-shrink: 0; }
.receipt-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-sub);
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
}
.receipt-action-btn:active { background: var(--bg); }
.receipt-action-btn.del { color: #e53935; }

.empty-msg { font-size: 14px; color: var(--text-sub); text-align: center; padding: 16px 0; }

/* ── History ── */
.month-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none;
}
.month-tabs::-webkit-scrollbar { display: none; }

.month-tab {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 20px;
  background: white;
  border: 1.5px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.month-tab.active { background: var(--green); color: white; border-color: var(--green); }

.history-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.history-month-total { font-size: 24px; font-weight: 700; }
.history-count { font-size: 13px; color: var(--text-sub); }

/* ── Settings ── */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.form-row:last-child { margin-bottom: 0; }
.form-label { font-size: 13px; color: var(--text-sub); font-weight: 500; }

.checkbox-group { display: flex; flex-direction: column; gap: 10px; }
.checkbox-label { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--green); }

.token-display-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.token-display { font-size: 16px; font-family: monospace; flex: 1; color: var(--text); word-break: break-all; }
.hint-text { font-size: 12px; color: var(--text-sub); line-height: 1.5; }

.settings-msg { min-height: 24px; text-align: center; font-size: 14px; padding: 8px; }
.settings-msg.ok { color: var(--green); }
.settings-msg.err { color: var(--red); }

/* ── Overlays & modals ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

.overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.overlay-msg { color: white; font-size: 18px; font-weight: 600; }

.modal-box {
  background: white;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-title { font-size: 18px; font-weight: 700; text-align: center; }
.modal-sub { font-size: 14px; color: var(--text-sub); text-align: center; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

.ocr-partial { font-size: 13px; color: var(--text-sub); background: var(--bg); border-radius: 8px; padding: 8px 12px; }

/* ── Spinner ── */
.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 300;
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  transition: opacity 0.3s;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
