:root {
  --ink: #1a2942;
  --lake: #3a6da9;
  --mist: #7a9bc5;
  --cream: #fbf7f1;
  --champagne: #d4b87a;
  --text: #2a2f3a;
  --text-soft: #5b6478;
  --card: rgba(255, 255, 255, 0.72);
  --shadow: 0 8px 32px rgba(26, 41, 66, 0.08);
  --shadow-lg: 0 16px 48px rgba(26, 41, 66, 0.12);
  --line: rgba(26, 41, 66, 0.1);
  --danger: #c97b6b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Serif TC", "PingFang TC", "Songti TC", serif;
  color: var(--text);
  line-height: 1.7;
  background:
    radial-gradient(ellipse at top left, #e8eef7 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, #f0e8d8 0%, transparent 50%),
    linear-gradient(180deg, #fbf7f1 0%, #f0eadd 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

.container { max-width: 960px; margin: 0 auto; padding: 24px; }

h1, h2, h3 { font-weight: 500; color: var(--ink); letter-spacing: 0.02em; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 24px;
  padding: 48px 40px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card .mark { font-size: 13px; letter-spacing: 0.4em; color: var(--mist); margin-bottom: 18px; }
.login-card h1 { font-size: 26px; margin-bottom: 28px; }
.login-card input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  background: rgba(255,255,255,0.8);
  outline: none;
  margin-bottom: 16px;
}
.login-card input:focus { border-color: var(--lake); background: white; }
.login-card button {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--ink), var(--lake));
  color: white;
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: transform 0.2s;
}
.login-card button:hover { transform: translateY(-1px); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(16px);
  background: rgba(251,247,241,0.8);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}
.topbar .container { padding-top: 0; padding-bottom: 0; }
.topbar-inner { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; row-gap: 7px; }
.topbar h1 { font-size: 17px; }
.nav-tabs { display: flex; gap: 6px; flex-wrap: nowrap; order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tabs button {
  padding: 6px 13px; border-radius: 18px; border: 1px solid var(--line);
  background: rgba(255,255,255,0.6); font-family: inherit; font-size: 13px; white-space: nowrap; flex: 0 0 auto;
  color: var(--text-soft); cursor: pointer; transition: all 0.2s;
}
.nav-tabs button.active { background: var(--ink); color: white; border-color: var(--ink); }
.logout-btn { background: none; border: none; color: var(--text-soft); font-size: 13px; cursor: pointer; text-decoration: underline; }

@media (min-width: 641px) {
  .nav-tabs { order: 0; width: auto; overflow: visible; }
}

.view { display: none; padding: 28px 0; }
.view.active { display: block; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.6); border-radius: 20px;
  padding: 24px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-dark {
  background: linear-gradient(135deg, rgba(26,41,66,0.95), rgba(58,109,169,0.88));
  color: white; border-radius: 20px; padding: 24px; box-shadow: var(--shadow-lg);
}

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; align-items: stretch; }
.summary-stat { display: flex; flex-direction: column; justify-content: center; min-height: 108px; margin-bottom: 0; box-sizing: border-box; }
.summary-stat .label { font-size: 12px; letter-spacing: 0.15em; opacity: 0.75; margin-bottom: 8px; }
.summary-stat .value { font-size: 28px; font-weight: 500; }
@media (max-width: 640px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-grid .summary-stat:first-child { grid-column: 1 / -1; }
}

/* ---------- Charts (純 SVG，不用套件) ---------- */
.chart-wrap h3 { margin-bottom: 18px; }
.chart-wrap svg { width: 100%; height: auto; min-height: 240px; display: block; }
.chart-empty { text-align: center; color: var(--text-soft); padding: 30px 0; font-size: 14px; }
.chart-axis-label { font-size: 15px; fill: var(--text-soft); font-weight: 500; }
.chart-value-label { font-size: 16px; fill: var(--ink); font-weight: 600; }
.chart-legend { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; margin-bottom: 2px; color: var(--text-soft); font-size: 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.single-chart-point {
  min-height: 230px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(58,109,169,0.1), rgba(255,255,255,0.35));
  border: 1px solid rgba(58,109,169,0.12);
}
.single-chart-value { color: var(--lake); font-size: 42px; line-height: 1.2; font-weight: 600; }
.single-chart-label { color: var(--ink); font-size: 18px; margin-top: 12px; }
.single-chart-date { color: var(--text-soft); font-size: 15px; margin-top: 6px; }
@media (max-width: 640px) {
  .chart-wrap svg { min-height: 270px; }
  .chart-axis-label { font-size: 18px; }
  .chart-value-label { font-size: 19px; }
  .single-chart-point { min-height: 250px; }
  .single-chart-value { font-size: 46px; }
}

/* ---------- 套組次數統計 ---------- */
.package-chart { display: flex; flex-direction: column; gap: 18px; margin-top: 18px; }
.package-chart-row { min-width: 0; }
.package-chart-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 7px; }
.package-chart-head span { color: var(--text); font-size: 14px; overflow-wrap: anywhere; word-break: break-word; }
.package-chart-head strong { color: var(--lake); font-size: 15px; font-weight: 600; white-space: nowrap; }
.package-chart-track { height: 16px; overflow: hidden; border-radius: 999px; background: rgba(58,109,169,0.1); }
.package-chart-bar { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--ink), var(--lake)); }

/* ---------- 魔法商品數量統計 ---------- */
.magic-count-summary { margin-top: 16px; }
.magic-count-total {
  display: flex; align-items: baseline; justify-content: center; gap: 8px;
  padding: 18px; border-radius: 16px; color: white;
  background: linear-gradient(135deg, var(--ink), var(--lake));
}
.magic-count-total span { font-size: 14px; opacity: 0.82; }
.magic-count-total strong { font-size: 42px; line-height: 1; font-weight: 600; }
.magic-count-categories { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.magic-count-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px;
  background: rgba(255,255,255,0.58); color: var(--text-soft);
}
.magic-count-item > span { font-size: 13px; }
.magic-count-item strong { color: var(--ink); font-size: 24px; white-space: nowrap; }
.magic-count-item small { color: var(--text-soft); font-size: 12px; font-weight: 400; }

/* ---------- 互動月曆 ---------- */
.calendar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.calendar-head .cal-title { font-size: 15px; color: var(--ink); font-weight: 500; }
.calendar-head button {
  border: 1px solid var(--line); background: rgba(255,255,255,0.6); border-radius: 10px;
  width: 30px; height: 30px; cursor: pointer; font-family: inherit; color: var(--text);
}
.calendar-legend { display: flex; gap: 18px; font-size: 13px; margin-bottom: 16px; flex-wrap: wrap; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; max-width: 480px; margin: 0 auto; }
.cal-dow { text-align: center; font-size: 12px; color: var(--text-soft); padding-bottom: 6px; }
.cal-cell {
  aspect-ratio: 1; border-radius: 12px; background: rgba(255,255,255,0.5);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text); gap: 4px; position: relative; border: 1px solid transparent;
  font: inherit; padding: 0; cursor: pointer;
}
.cal-cell.empty { background: transparent; }
.cal-cell:not(.empty):hover { background: rgba(58,109,169,0.08); }
.cal-cell.today { border-color: var(--lake); }
.cal-cell.selected { background: var(--ink); border-color: var(--ink); color: white; box-shadow: 0 6px 16px rgba(26,41,66,0.18); }
.cal-cell .cal-daynum { font-size: 13px; }
.cal-cell.today .cal-daynum { font-weight: 700; color: var(--lake); }
.cal-cell.selected .cal-daynum { color: white; }
.cal-cell .icons { display: flex; gap: 3px; align-items: center; justify-content: center; min-height: 16px; }
.cal-cell .icons svg { display: block; }
.calendar-detail {
  max-width: 480px; margin: 18px auto 0; padding: 16px 18px;
  border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,0.58);
  overflow-wrap: anywhere; word-break: break-word;
}
.calendar-detail[hidden] { display: none; }
.calendar-detail-date { color: var(--text-soft); font-size: 12px; margin-bottom: 8px; }
.calendar-detail-list { display: flex; flex-direction: column; gap: 6px; color: var(--ink); font-size: 15px; }
.calendar-detail-empty { color: var(--text-soft); font-size: 14px; }
@media (max-width: 480px) {
  .calendar-grid { max-width: 100%; gap: 5px; }
  .cal-cell { border-radius: 9px; gap: 2px; }
  .cal-cell .cal-daynum { font-size: 11px; }
}

/* ---------- Forms ---------- */
.form-row { margin-bottom: 16px; min-width: 0; }
.form-row label { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; max-width: 100%; min-width: 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 14px; background: rgba(255,255,255,0.85); outline: none;
}
.form-row input[type="date"] { display: block; }
.form-row input[type="date"]::-webkit-date-and-time-value { text-align: left; min-width: 0; }
.form-row input, .form-row select { min-height: 48px; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { border-color: var(--lake); background: white; }
.form-row textarea { min-height: 130px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.filter-bar { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.filter-bar .form-row { margin-bottom: 0; min-width: 130px; flex: 1; }
.filter-bar .btn { text-decoration: none; white-space: nowrap; text-align: center; }
.tag-filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 18px; }
.tag-filter-bar button {
  border: 1px solid var(--line); border-radius: 18px; padding: 7px 14px;
  background: rgba(255,255,255,0.65); color: var(--text-soft); font: inherit; font-size: 13px; cursor: pointer;
}
.tag-filter-bar button.active { background: var(--ink); border-color: var(--ink); color: white; }

#rRawPaste { min-height: 240px; }
#pBurnReading { min-height: 180px; }
.parse-hint { font-size: 12px; color: var(--text-soft); margin-top: 6px; min-height: 16px; }

.section-row {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(360px, 1.5fr);
  gap: 12px;
  margin-bottom: 14px;
  padding: 48px 14px 14px;
  align-items: start;
  background: rgba(255,255,255,0.45);
  border: 1px solid var(--line);
  border-radius: 14px;
  position: relative;
}
.section-row input { min-width: 0; min-height: 48px; }
.section-row textarea { min-width: 0; min-height: 170px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.section-row .sec-label { min-height: 110px; }
.section-row .row-remove {
  position: absolute; top: 10px; left: 10px; width: 28px; height: 28px;
  display: grid; place-items: center; padding: 0; border-radius: 50%;
  border: 1px solid rgba(201,123,107,0.45); background: rgba(201,123,107,0.11);
  color: var(--danger); font: 600 20px/1 sans-serif; cursor: pointer;
}
.section-row .row-remove:hover { color: white; background: var(--danger); }

@media (max-width: 640px) {
  .card { padding: 20px 16px; }
  .section-row {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 50px 12px 14px;
    margin-bottom: 18px;
  }
  .form-row input, .form-row select, .form-row textarea { font-size: 16px; }
  .login-card input { font-size: 16px; }
  .section-row input { min-height: 52px; font-size: 16px; }
  .section-row textarea { min-height: 190px; font-size: 16px; line-height: 1.7; }
  .section-row .sec-label { min-height: 120px; }
  .section-row .row-remove { width: 30px; height: 30px; }
  #rRawPaste { min-height: 280px; font-size: 16px; }
  #pBurnReading { min-height: 220px; font-size: 16px; }
}

.btn { padding: 10px 20px; border-radius: 10px; border: 0; font-family: inherit; font-size: 14px; cursor: pointer; }
.btn-primary { background: linear-gradient(135deg, var(--ink), var(--lake)); color: white; }
.btn-ghost { background: rgba(255,255,255,0.6); border: 1px solid var(--line); color: var(--text); }
.btn-danger { background: rgba(201,123,107,0.12); color: var(--danger); border: 1px solid rgba(201,123,107,0.3); }
.btn-small { padding: 6px 12px; font-size: 12px; }

/* ---------- 紀錄卡片（各自獨立、左對齊） ---------- */
.record-list { display: flex; flex-direction: column; gap: 14px; }
.record-card {
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  text-align: left;
}
.record-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.record-title { font-size: 16px; color: var(--ink); font-weight: 500; text-align: left; overflow-wrap: anywhere; word-break: break-word; min-width: 0; }
.record-price { font-family: inherit; font-size: 17px; color: var(--lake); font-weight: 500; white-space: nowrap; }
.record-card-sub { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; gap: 10px; }
.record-meta { font-size: 12px; color: var(--text-soft); text-align: left; }
.record-delete {
  background: none; border: none; color: var(--text-soft); cursor: pointer;
  font-size: 12px; padding: 4px 8px; border-radius: 8px; transition: all 0.15s; flex-shrink: 0;
}
.record-delete:hover { background: rgba(201,123,107,0.12); color: var(--danger); }
.record-body { margin-top: 12px; font-size: 14px; color: var(--text); text-align: left; overflow-wrap: anywhere; word-break: break-word; }
.record-body .sec { margin-bottom: 6px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.record-body .sec b { color: var(--ink); }
.tag { display: inline-block; padding: 2px 10px; border-radius: 20px; background: rgba(58,109,169,0.1); color: var(--lake); font-size: 11px; margin-left: 6px; }
.tag.candle { background: rgba(212,184,122,0.18); color: #a07a30; }
.tag.topic { background: rgba(58,109,169,0.1); color: var(--lake); white-space: nowrap; }

.empty-hint { text-align: center; color: var(--text-soft); padding: 40px 0; font-size: 14px; }
.site-footer { text-align: center; color: var(--text-soft); font-size: 12px; letter-spacing: 0.08em; padding: 18px 0 30px; opacity: 0.72; }
