/* ============================================================
   LINE共有家計簿 — Clean White Design System
   Inspired by MUJI × Notion × Premium Japanese Lifestyle Apps
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,400;0,500;0,600;0,700;0,800;0,900;1,400&family=M+PLUS+Rounded+1c:wght@300;400;500;700;800&display=swap');

/* ── Design Tokens ───────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg:        #F7F5F2;
  --bg-white:  #FFFFFF;
  --bg-soft:   #F2F0ED;
  --bg-input:  #FAFAF8;

  /* Borders */
  --border:       #E8E5E1;
  --border-light: #F0EDE9;
  --border-focus: #1C1C1E;

  /* Text */
  --text-1: #1C1C1E;
  --text-2: #636366;
  --text-3: #AEAEB2;
  --text-4: #C7C7CC;

  /* Accent — Sage Green */
  --accent:       #5C8A6B;
  --accent-light: #EAF1EC;
  --accent-mid:   #D1E4D6;

  /* Semantic */
  --success: #5C8A6B;
  --pay:     #C0392B;
  --receive: #5C8A6B;
  --warn:    #C47E3A;

  /* Shadows — warm, subtle */
  --shadow-xs: 0 1px 3px rgba(28,28,30,0.06);
  --shadow-sm: 0 2px 8px rgba(28,28,30,0.07);
  --shadow-md: 0 4px 16px rgba(28,28,30,0.09);
  --shadow-lg: 0 8px 32px rgba(28,28,30,0.11);

  /* Radius */
  --r-sm:  12px;
  --r-md:  18px;
  --r-lg:  22px;
  --r-xl:  26px;
  --r-2xl: 34px;

  /* Bottom nav */
  --nav-h: 64px;

  /* Fonts */
  --font-display: 'Nunito', 'M PLUS Rounded 1c', sans-serif;
  --font-body:    'M PLUS Rounded 1c', 'Nunito', sans-serif;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App Layout ──────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: var(--nav-h);
}

.page-content {
  flex: 1;
  padding: 16px 16px 8px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* ── Top Bar ─────────────────────────────────────────────── */
.top-bar {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-light);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  background: var(--text-1);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.2px;
  color: var(--text-1);
}

.top-bar-actions {
  display: flex;
  gap: 4px;
}

/* ── Bottom Navigation ───────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 100;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 500;
  transition: color 0.2s;
  padding: 8px 4px;
  border-radius: var(--r-sm);
  letter-spacing: 0.3px;
}

.nav-btn i {
  font-size: 19px;
  transition: transform 0.2s;
}

.nav-btn.active {
  color: var(--text-1);
  font-weight: 600;
}

.nav-btn.active i {
  transform: translateY(-1px);
}

.nav-btn:hover:not(.active) { color: var(--text-2); }

/* ── FAB ─────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--text-1);
  border: none;
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 90;
  transition: transform 0.2s, box-shadow 0.2s;
}

.fab:hover { transform: scale(1.06); box-shadow: 0 12px 32px rgba(28,28,30,0.2); }
.fab:active { transform: scale(0.97); }

/* ── Tab Panes ───────────────────────────────────────────── */
.tab-pane { display: none; }
.tab-pane.active {
  display: block;
  animation: fadeUp 0.25s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Hero Card ───────────────────────────────────────────── */
.hero-card {
  background: var(--text-1);
  border-radius: var(--r-xl);
  padding: 24px 22px;
  margin-bottom: 14px;
  color: #fff;
  position: relative;
  overflow: hidden;
}

/* settled variant */
.hero-card.settled {
  background: var(--bg-white);
  color: var(--text-1);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* needs payment */
.hero-card.needs-pay {
  background: var(--text-1);
}

.hero-card-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  opacity: 0.6;
  margin-bottom: 8px;
}

.hero-card.settled .hero-card-label { opacity: 1; color: var(--accent); }

.hero-big-amount {
  font-family: var(--font-display);
  font-size: 50px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1;
  margin-bottom: 6px;
}

.hero-card.settled .hero-big-amount { color: var(--text-1); }

.hero-subtitle {
  font-size: 14px;
  font-weight: 400;
  opacity: 0.75;
  margin-bottom: 18px;
}

.hero-card.settled .hero-subtitle { opacity: 1; color: var(--text-2); }

.hero-transfer-box {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--r-md);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
}

.hero-settled-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-light);
  border: 1px solid var(--accent-mid);
  border-radius: var(--r-md);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

/* ── Stats Row ───────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:active { transform: scale(0.98); }

.stat-icon-wrap {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  margin-bottom: 12px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.stat-val {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  color: var(--text-1);
  letter-spacing: -0.2px;
}

.stat-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
}

/* ── Section Label ───────────────────────────────────────── */
.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.5px;
  margin: 18px 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

/* ── Goals ───────────────────────────────────────────────── */
.goal-item { margin-bottom: 18px; }
.goal-item:last-child { margin-bottom: 0; }

.goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 9px;
}

.goal-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.goal-pct {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 800;
  color: var(--accent);
}

.progress-track {
  height: 6px;
  background: var(--bg-soft);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 7px;
}

.progress-fill {
  height: 100%;
  background: var(--text-1);
  border-radius: 99px;
  transition: width 0.9s cubic-bezier(0.4, 0, 0.2, 1);
}

.goal-amounts {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-3);
}

.goal-amounts .spent { color: var(--text-2); font-weight: 500; }

/* ── Member Settlement ───────────────────────────────────── */
.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border-light);
}

.member-row:last-child { border-bottom: none; }

.member-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-1);
  flex-shrink: 0;
  font-family: var(--font-display);
}

.member-info { flex: 1; }
.member-name { font-size: 14px; font-weight: 600; color: var(--text-1); }
.member-paid { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.settle-badge {
  padding: 5px 11px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge-receive { background: var(--accent-light); color: var(--accent); }
.badge-pay     { background: #FBE9E7; color: var(--pay); }
.badge-even    { background: var(--bg-soft); color: var(--text-3); }

/* ── Category Chart ──────────────────────────────────────── */
.chart-wrapper {
  display: flex;
  align-items: center;
  gap: 20px;
}

.chart-canvas-wrap { width: 120px; height: 120px; flex-shrink: 0; }

.legend { flex: 1; display: flex; flex-direction: column; gap: 9px; }

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.legend-left { display: flex; align-items: center; gap: 8px; color: var(--text-2); }

.legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-amount { font-weight: 600; font-size: 12px; color: var(--text-1); }

/* ── Expense Items ───────────────────────────────────────── */
.expense-list { display: flex; flex-direction: column; }

.expense-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border-light);
}

.expense-item:last-child { border-bottom: none; }

.expense-cat-icon {
  width: 38px; height: 38px;
  border-radius: var(--r-sm);
  background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.expense-info { flex: 1; min-width: 0; }

.expense-item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
  display: flex;
  gap: 7px;
  align-items: center;
}

.expense-right { text-align: right; flex-shrink: 0; }

.expense-amount {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
}

.expense-member {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}

.btn-delete {
  background: none; border: none;
  color: var(--text-4); cursor: pointer;
  font-size: 14px; padding: 4px;
  transition: color 0.2s;
}

.btn-delete:hover { color: var(--pay); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-cat  { background: var(--bg-soft); color: var(--text-2); border: 1px solid var(--border); }
.badge-goal { background: var(--accent-light); color: var(--accent); }

/* ── Filter Row ──────────────────────────────────────────── */
.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-row select { flex: 1; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-1);
  font-family: var(--font-body);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-control:focus {
  border-color: var(--text-1);
  box-shadow: 0 0 0 3px rgba(28,28,30,0.08);
  background: var(--bg-white);
}

.form-control::placeholder { color: var(--text-4); }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23AEAEB2'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
  padding-right: 36px;
}

.input-row { display: flex; gap: 8px; }
.input-row .form-control { flex: 1; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.18s;
  text-decoration: none;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--text-1);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover { background: #333; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: scale(0.98); }

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover { background: #4a7459; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-1);
}

.btn-outline:hover { background: var(--bg-soft); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}

.btn-ghost:hover { background: var(--bg-soft); color: var(--text-1); }

.btn-danger {
  background: #FBE9E7;
  color: var(--pay);
  border: 1px solid #F5C6C1;
}

.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-xs { padding: 5px 10px; font-size: 12px; }
.btn-icon { width: 38px; height: 38px; padding: 0; border-radius: var(--r-sm); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28,28,30,0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

.modal-backdrop.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-sheet {
  width: 100%;
  max-width: 600px;
  background: var(--bg-white);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  animation: slideUp 0.3s cubic-bezier(0.34, 1.4, 0.64, 1);
  max-height: 92vh;
  overflow-y: auto;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 99px;
  margin: 0 auto 20px;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  color: var(--text-1);
  margin-bottom: 22px;
  letter-spacing: 0.1px;
}

.modal-footer-btns {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-footer-btns .btn { flex: 1; }

/* ── LINE Bot Chat ───────────────────────────────────────── */
.chat-frame {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  height: 380px;
  display: flex;
  flex-direction: column;
}

.chat-header {
  background: var(--bg-soft);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.chat-header-icon {
  width: 34px; height: 34px;
  background: #06C755;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: #fff;
}

.chat-header-info .title { font-size: 14px; font-weight: 600; color: var(--text-1); }
.chat-header-info .sub   { font-size: 11px; color: #06C755; }

.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}

.msg-row { display: flex; gap: 8px; }
.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}

.msg-avatar.bot { background: #06C755; color: #fff; }
.msg-avatar.user-av { background: var(--text-1); color: #fff; }

.msg-bubble {
  max-width: 78%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.msg-row.bot  .msg-bubble {
  background: var(--bg-white);
  color: var(--text-1);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}

.msg-row.user .msg-bubble {
  background: var(--text-1);
  color: #fff;
  border-top-right-radius: 4px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
}

.chat-sender-select { width: 90px; flex-shrink: 0; font-size: 13px; padding: 8px 10px; }
.chat-text-input { flex: 1; font-size: 14px; padding: 9px 13px; }
.chat-send-btn { width: 38px; height: 38px; padding: 0; border-radius: 50%; }

/* ── Settings Lists ──────────────────────────────────────── */
.setting-list { display: flex; flex-direction: column; gap: 8px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border-light);
  border-radius: var(--r-md);
}

.setting-row-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-1);
}

.setting-row-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

/* ── Dividers & Utilities ────────────────────────────────── */
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text-muted { color: var(--text-3); }
.text-sm    { font-size: 13px; }
.mb-12      { margin-bottom: 12px; }
.mb-16      { margin-bottom: 16px; }
.gap-8      { gap: 8px; }

/* ── Step Guide ──────────────────────────────────────────── */
.step-guide { display: flex; flex-direction: column; gap: 16px; }

.step { display: flex; gap: 14px; }

.step-num {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--text-1);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.step-body { flex: 1; }
.step-title { font-size: 14px; font-weight: 600; color: var(--text-1); margin-bottom: 4px; }
.step-desc  { font-size: 13px; color: var(--text-2); line-height: 1.6; }

.code-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  margin-top: 8px;
  font-family: monospace;
  font-size: 12px;
  color: var(--accent);
}

/* ── LIFF Promo Card ─────────────────────────────────────── */
.liff-promo {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  margin-bottom: 12px;
}

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

/* ── Responsive ──────────────────────────────────────────── */
@media (min-width: 640px) {
  .page-content  { padding: 24px 24px 10px; }
  .stats-row     { grid-template-columns: repeat(4, 1fr); }
  .hero-big-amount { font-size: 60px; }
}
