/* ══════════════════════════════════════════
   WAA家記帳小幫手 — 可愛動物插畫風格
══════════════════════════════════════════ */

/* ── 變數 ───────────────────────────────── */
:root {
  --bg:            #FFF8F0;
  --card:          #FFFFFF;
  --primary:       #5CB88A;
  --primary-light: #EAF6F0;
  --primary-dark:  #3A9068;
  --orange:        #FF9A3C;
  --orange-light:  #FFF3E4;
  --pink:          #FF8FAB;
  --pink-light:    #FFF0F5;
  --text:          #3D3D3D;
  --text-light:    #888888;
  --border:        #EDE8E0;
  --shadow:        0 4px 20px rgba(0,0,0,0.07);
  --shadow-lg:     0 8px 32px rgba(0,0,0,0.12);
  --radius:        20px;
  --radius-sm:     12px;
  --font:          'Microsoft JhengHei', Calibri, 'Noto Sans TC', 'PingFang TC', sans-serif;
}

/* ── Reset ──────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: var(--font); }
a { text-decoration: none; }
.hidden { display: none !important; }

/* ══════════════════════════════════════════
   LOGIN PAGE
══════════════════════════════════════════ */
#login-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(145deg, #fff8f0 0%, #ffeef8 40%, #eef8f2 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  overflow: hidden;
}

.login-bg-deco {
  position: absolute; inset: 0; pointer-events: none;
}
.login-bg-deco span {
  position: absolute;
  opacity: 0.12;
  animation: floatPaw 6s ease-in-out infinite;
}
.login-bg-deco span:nth-child(even) { animation-delay: 3s; }

.deco-star {
  position: absolute;
  color: var(--primary);
  font-size: 1.4rem !important;
  opacity: 0.2 !important;
  animation: twinkle 4s ease-in-out infinite !important;
}

.login-card {
  background: var(--card);
  border-radius: 32px;
  padding: 40px 36px 36px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,200,220,0.2);
  text-align: center;
  max-width: 360px;
  width: 100%;
  position: relative;
  z-index: 1;
}

/* 吉祥物 */
.mascot-wrap {
  position: relative;
  width: 160px;
  height: auto;
  margin: 0 auto 16px;
  overflow: visible;
}
.mascot-bunny {
  width: 160px;
  height: auto;
  display: block;
  animation: bunnyBounce 3s ease-in-out infinite;
  filter: drop-shadow(0 6px 16px rgba(100,80,60,0.15));
}
.mascot-float {
  position: absolute;
  font-size: 1.1rem;
  animation: floatStar 3s ease-in-out infinite;
  pointer-events: none;
}
.mascot-float.s1 { top: 10px; right: -5px; animation-delay: 0s; }
.mascot-float.s2 { top: 30px; left: -10px; animation-delay: 1s; }
.mascot-float.s3 { bottom: 20px; right: -8px; animation-delay: 2s; }

.app-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}
.login-subtitle {
  color: var(--text-light);
  font-size: 0.95rem;
  margin-bottom: 28px;
}

.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%;
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: white;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s;
  cursor: pointer;
}
.btn-google:hover {
  background: #f8f8f8;
  border-color: #ccc;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transform: translateY(-1px);
}

.login-error {
  margin-top: 14px;
  padding: 10px 14px;
  background: #fff0f0;
  border-radius: 10px;
  color: #d32f2f;
  font-size: 0.88rem;
}

/* ══════════════════════════════════════════
   MAIN APP
══════════════════════════════════════════ */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Header ─────────────────────────────── */
#app-header {
  background: linear-gradient(135deg, var(--primary) 0%, #4aaa7c 100%);
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 12px rgba(60,144,100,0.25);
  position: sticky; top: 0; z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-bunny { filter: drop-shadow(0 2px 4px rgba(255,150,180,0.3)); }
.header-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: white;
  letter-spacing: 0.3px;
}
.header-right { display: flex; align-items: center; gap: 8px; }
.user-chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 4px 10px 4px 4px;
}
.user-chip img {
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.5);
  object-fit: cover;
}
#user-name {
  color: white;
  font-size: 0.82rem;
  font-weight: 600;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-logout {
  background: rgba(255,255,255,0.22);
  color: white;
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.35); }

/* ── Tab Nav ─────────────────────────────── */
.tab-nav {
  display: flex;
  background: var(--card);
  border-bottom: 1.5px solid var(--border);
  padding: 0 16px;
  gap: 4px;
}
.tab-btn {
  flex: 1;
  padding: 12px 8px 10px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-light);
  border-bottom: 2.5px solid transparent;
  transition: all 0.2s;
  text-align: center;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Main Content ───────────────────────── */
.app-main {
  flex: 1;
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}
.tab-content { animation: fadeIn 0.2s ease; }

/* ══════════════════════════════════════════
   UPLOAD AREA
══════════════════════════════════════════ */
.upload-area {
  background: var(--card);
  border: 2.5px dashed #c8e6d4;
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  transition: all 0.25s;
  cursor: pointer;
  position: relative;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.upload-area.drag-over { border-style: solid; }

.upload-icon-wrap { margin-bottom: 10px; }
.upload-icon {
  font-size: 3rem;
  animation: bounceIcon 2.5s ease-in-out infinite;
}
.upload-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.upload-hint {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-bottom: 20px;
  line-height: 1.5;
}
.upload-buttons {
  display: flex; gap: 10px; justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.btn-upload-action {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(92,184,138,0.4); }
.btn-outline-green {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline-green:hover { background: var(--primary-light); transform: translateY(-1px); }

.upload-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-light); font-size: 0.82rem;
  margin: 4px 40px 12px;
}
.upload-divider::before, .upload-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.btn-manual {
  color: var(--text-light);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  transition: all 0.2s;
}
.btn-manual:hover { color: var(--primary); background: var(--primary-light); }

/* ── AI辨識中 ────────────────────────────── */
.analyzing-overlay {
  background: var(--card);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.analyzing-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.analyzing-emoji { font-size: 3.5rem; animation: bunnyBounce 1s ease-in-out infinite; }
.analyzing-dots { display: flex; gap: 6px; }
.analyzing-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: dotPulse 1.4s ease-in-out infinite;
}
.analyzing-dots span:nth-child(2) { animation-delay: 0.2s; }
.analyzing-dots span:nth-child(3) { animation-delay: 0.4s; }
.analyzing-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.analyzing-sub { font-size: 0.85rem; color: var(--text-light); }

/* ══════════════════════════════════════════
   FORM
══════════════════════════════════════════ */
.form-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.btn-reset {
  font-size: 0.82rem;
  color: var(--text-light);
  padding: 5px 10px;
  border-radius: 8px;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-reset:hover { color: var(--orange); background: var(--orange-light); }

.form-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-row { display: flex; gap: 10px; }
.form-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}
.label-opt {
  font-weight: 400;
  color: var(--text-light);
  font-size: 0.8rem;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text);
  background: #fafafa;
  transition: all 0.2s;
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(92,184,138,0.12);
}
.form-textarea { resize: vertical; min-height: 72px; }
.form-select { 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 fill='%23888' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.btn-submit {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(92,184,138,0.35);
}
.btn-submit:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(92,184,138,0.45);
}
.btn-submit:active { transform: translateY(0); }

/* ══════════════════════════════════════════
   RECORDS LIST
══════════════════════════════════════════ */
.list-controls {
  display: flex; gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.search-wrap {
  flex: 1;
  min-width: 180px;
  position: relative;
}
.search-icon {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--card);
  color: var(--text);
  transition: all 0.2s;
  outline: none;
}
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(92,184,138,0.12); }
.filter-select {
  padding: 10px 30px 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  background: var(--card);
  color: var(--text);
  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 fill='%23888' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
  outline: none;
  transition: all 0.2s;
}
.filter-select:focus { border-color: var(--primary); }

/* 統計列 */
.stats-bar {
  display: flex; align-items: center; gap: 14px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  margin-bottom: 12px;
  border: 1px solid #c8e6d4;
}
.stat-item { display: flex; align-items: center; gap: 5px; }
.stat-label { font-size: 0.82rem; color: var(--primary-dark); font-weight: 600; }
.stat-value { font-size: 1rem; font-weight: 700; color: var(--primary-dark); }
.stat-divider { width: 1px; height: 20px; background: #b2d8c3; }

/* 記錄卡片 */
.records-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.record-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1px solid #f0ece6;
  transition: all 0.2s;
  animation: fadeIn 0.25s ease;
}
.record-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.09);
}

.record-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; margin-bottom: 8px;
}
.record-top-left { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }

.category-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  width: fit-content;
}
.record-store {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.record-items {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-amount-block { text-align: right; flex-shrink: 0; }
.amount-main {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.amount-twd {
  display: block;
  font-size: 0.78rem;
  color: var(--primary-dark);
  font-weight: 600;
}

.record-bottom {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #f4f0ec;
}
.record-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.record-date {
  font-size: 0.78rem;
  color: var(--text-light);
}
.record-creator {
  font-size: 0.78rem;
  color: var(--text-light);
}
.record-actions { display: flex; gap: 4px; }
.btn-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.btn-edit { background: var(--orange-light); }
.btn-edit:hover { background: #ffe0c0; transform: scale(1.1); }
.btn-delete { background: #ffeaea; }
.btn-delete:hover { background: #ffcccc; transform: scale(1.1); }

/* 空狀態 */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-light);
}
.empty-mascot { font-size: 3.5rem; margin-bottom: 14px; }
.empty-state p { font-size: 0.95rem; line-height: 1.8; }

.loading-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}
.loading-bunny {
  font-size: 2.5rem;
  margin-bottom: 10px;
  animation: bunnyBounce 1s ease-in-out infinite;
}

/* ══════════════════════════════════════════
   MODAL
══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease;
}
@media (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 20px; }
}
.modal-card {
  background: var(--card);
  border-radius: 28px 28px 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}
@media (min-width: 600px) {
  .modal-card { border-radius: 28px; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 0;
  position: sticky; top: 0;
  background: var(--card);
  z-index: 1;
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.btn-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #f0f0f0;
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.btn-close:hover { background: #e0e0e0; }

.modal-body {
  padding: 16px 20px 0;
}
.modal-body .form-group { margin-bottom: 12px; }
.modal-footer {
  display: flex; gap: 10px;
  padding: 16px 0 4px;
  position: sticky; bottom: 0;
  background: var(--card);
  padding-bottom: 20px;
}
.btn-cancel {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: #f4f0ec;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-cancel:hover { background: var(--border); }
.btn-submit-sm {
  flex: 2;
  padding: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  transition: all 0.2s;
  box-shadow: 0 3px 10px rgba(92,184,138,0.3);
}
.btn-submit-sm:hover { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(92,184,138,0.4); }

/* ══════════════════════════════════════════
   TOAST
══════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 22px;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 999;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
  animation: slideUpToast 0.3s ease;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast-success { background: var(--primary); color: white; }
.toast-error   { background: #e53935; color: white; }
.toast-info    { background: #3D3D3D; color: white; }

/* ══════════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════════ */
@keyframes bunnyBounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}
@keyframes floatStar {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.8; }
  50%       { transform: translateY(-10px) scale(1.15); opacity: 1; }
}
@keyframes floatPaw {
  0%, 100% { transform: translateY(0) rotate(-20deg); }
  50%       { transform: translateY(-12px) rotate(-15deg); }
}
@keyframes twinkle {
  0%, 100% { opacity: 0.15; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(1.2); }
}
@keyframes dotPulse {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%           { transform: scale(1.1); opacity: 1; }
}
@keyframes bounceIcon {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30%       { transform: translateY(-6px) rotate(-5deg); }
  60%       { transform: translateY(-3px) rotate(3deg); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes slideUpToast {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ══════════════════════════════════════════
   RESPONSIVE — Desktop
══════════════════════════════════════════ */
@media (min-width: 600px) {
  .app-main { padding: 20px; }
  .records-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
  .login-card { padding: 48px 44px 40px; }
}
@media (min-width: 900px) {
  .records-grid { grid-template-columns: repeat(3, 1fr); }
}
