:root {
  --pink: #e8a5b0;
  --green: #a3c4a3;
  --morandi: #8f8a80;
  --bg: #faf7f4;
  --card: #ffffff;
  --text: #3a3632;
  --muted: #8a847c;
  --border: #e6e0d8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* 登入畫面 */
#login-box {
  max-width: 360px;
  margin: 80px auto;
  padding: 32px 24px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
}
#login-box h1 { font-size: 20px; text-align: center; margin-bottom: 24px; }
#login-box input {
  width: 100%; padding: 12px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 16px;
}
#login-box button {
  width: 100%; padding: 12px; border: none; border-radius: 8px;
  background: var(--pink); color: white; font-size: 16px; font-weight: bold;
}
#login-error { color: #c0392b; font-size: 13px; margin-top: 8px; text-align: center; }

/* App 主體 */
#app-shell { max-width: 560px; margin: 0 auto; padding-left: 76px; position: relative; }

.top-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.top-bar h1 { font-size: 18px; margin: 0; }
.top-bar button { background: none; border: none; color: var(--muted); font-size: 14px; }

.view { padding: 16px; }

.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar select, .toolbar input[type="text"] {
  flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}

.item-card {
  background: var(--card); border-radius: 12px; padding: 14px; margin-bottom: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04); cursor: pointer;
}
.item-card-type { font-size: 11px; color: var(--pink); font-weight: bold; margin-bottom: 4px; }
.item-card-title { font-size: 16px; font-weight: bold; margin-bottom: 4px; }
.item-card-preview { font-size: 13px; color: var(--muted); }
.item-card-tags { font-size: 12px; color: var(--green); margin-top: 6px; }

.empty-hint { text-align: center; color: var(--muted); padding: 40px 0; }

.fab {
  position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px;
  border-radius: 50%; background: var(--pink); color: white; font-size: 28px;
  border: none; box-shadow: 0 4px 12px rgba(0,0,0,0.2); z-index: 20;
}

.side-nav {
  position: fixed; top: 0; left: 0; bottom: 0; width: 76px; display: flex;
  flex-direction: column; align-items: stretch;
  background: var(--card); border-right: 1px solid var(--border); z-index: 10;
  padding-top: 16px;
}
.nav-btn {
  padding: 16px 0; background: none; border: none; color: var(--muted); font-size: 22px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.nav-btn span { font-size: 12px; }
.nav-btn.active { color: var(--pink); font-weight: bold; }

/* 編輯彈窗 */
.editor-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 30;
  display: flex; align-items: flex-end;
}
.editor-panel {
  background: var(--card); width: 100%; max-height: 90vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 20px;
}
.editor-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.editor-header h2 { font-size: 18px; margin: 0; }
.editor-panel label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.editor-panel input, .editor-panel textarea, .editor-panel select {
  width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px;
}
.editor-panel textarea { min-height: 100px; resize: vertical; }
.editor-actions { display: flex; gap: 8px; margin-top: 20px; }
.editor-actions button {
  flex: 1; padding: 12px; border: none; border-radius: 8px; font-size: 15px;
}
.btn-save { background: var(--pink); color: white; font-weight: bold; }
.btn-delete { background: #f5e6e6; color: #c0392b; }

.attach-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attach-item {
  position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 11px; text-align: center; background: #f5f2ee;
}
.attach-thumb { width: 100%; height: 100%; object-fit: cover; }
.attach-del {
  position: absolute; top: 0; right: 0; background: rgba(0,0,0,0.6); color: white;
  border: none; width: 18px; height: 18px; border-radius: 0 0 0 8px; font-size: 12px; line-height: 1;
}

.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.calendar-header button { background: none; border: none; font-size: 20px; color: var(--muted); }
#google-connect-btn {
  width: 100%; padding: 10px; margin-bottom: 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--card); font-size: 14px;
}

.calendar-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); text-align: center;
  font-size: 12px; color: var(--muted); margin-bottom: 4px;
}
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 1fr;
  gap: 4px; margin-bottom: 16px;
}
.cal-cell {
  aspect-ratio: 1; border-radius: 8px; background: var(--card); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 4px 2px; font-size: 12px; cursor: pointer; position: relative;
}
.cal-cell.other-month { opacity: 0.35; }
.cal-cell.today { border-color: var(--pink); border-width: 2px; }
.cal-cell.selected { background: var(--pink); color: white; }
.cal-cell .cal-day-num { font-weight: bold; }
.cal-cell .cal-dot {
  width: 5px; height: 5px; border-radius: 50%; background: var(--green); margin-top: 2px;
}
.cal-cell.selected .cal-dot { background: white; }

#calendar-day-events { margin-bottom: 16px; }
#calendar-day-events .day-label { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
#calendar-day-events .day-section-label { font-size: 12px; color: var(--pink); font-weight: bold; margin: 10px 0 6px; }

.calendar-layout { display: flex; flex-direction: column; gap: 12px; }
.calendar-main { width: 100%; }
.calendar-side { width: 100%; }

/* 電腦寬螢幕：格子跟當天列表並排 */
@media (min-width: 720px) {
  #app-shell { max-width: 900px; }
  .calendar-layout { flex-direction: row; align-items: flex-start; }
  .calendar-main { flex: 1.3; }
  .calendar-side { flex: 1; position: sticky; top: 80px; max-height: 70vh; overflow-y: auto; }
}

.cal-cell .cal-dot.expense-dot { background: #d9a441; }
.cal-cell .cal-dots { display: flex; gap: 2px; margin-top: 2px; }

/* 記帳 */
.expense-summary {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px;
}
.expense-chip {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; text-align: center;
}
.expense-chip .exp-label { font-size: 12px; color: var(--muted); }
.expense-chip .exp-amount { font-size: 18px; font-weight: bold; margin-top: 2px; }
.expense-chip.total { grid-column: 1 / -1; background: var(--pink); color: white; }
.expense-chip.total .exp-label { color: white; opacity: 0.85; }

.payment-picker { display: flex; flex-direction: column; gap: 4px; }
.pay-group-label { font-size: 11px; color: var(--muted); margin-top: 8px; }
.pay-group-label:first-child { margin-top: 0; }
.pay-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pay-btn {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--card); font-size: 14px;
}
.pay-btn.selected { background: var(--pink); color: white; border-color: var(--pink); }

#expense-amount {
  font-size: 28px; font-weight: bold; text-align: center; padding: 16px;
}
