/* 豆兒香 營運數據儀表板 — 版面樣式
   顏色都集中在最上面的變數區，要改配色改這裡就好。 */

:root {
  --bg: #f1f3f6;
  --card: #ffffff;
  --ink: #1f2328;
  --ink-soft: #5b6470;
  --ink-faint: #8b94a0;
  --line: #e3e7ec;

  --rev: #1a73e8;        /* 營收 — 今年 */
  --rev-prev: #a8c7fa;   /* 營收 — 去年 */
  --ord: #e8710a;        /* 訂單 — 今年 */
  --ord-prev: #fcd0a2;   /* 訂單 — 去年 */


  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 35, 40, .06), 0 4px 14px rgba(31, 35, 40, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
               "Microsoft JhengHei", "PingFang TC", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 頂部 ---------- */

/* ---------- 頂部工具列 ----------
   左：平台篩選　中：標題　右：日期範圍 + 快捷鍵
   整條鎖在畫面頂端，所以底色必須是不透明的，
   不然捲動時圖表會透過來跟文字疊在一起。 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* 左右等寬，標題才會真的在正中間 */
  align-items: center;
  gap: 16px;
}

/* 中間標題 */
.brand {
  text-align: center;
  line-height: 1.3;
}

.brand-1,
.brand-2 {
  display: block;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
}

/* 左邊平台篩選 */
.platforms {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.platforms button {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-faint);
  cursor: pointer;
  white-space: nowrap;
}

.platforms button:hover { background: #f6f8fa; }

.platforms button.on {
  background: #e8f0fe;
  border-color: #c6dafc;
  color: var(--rev);
  font-weight: 600;
}

/* 右邊日期範圍 */
.daterange {
  position: relative;
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.dr-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dr-label {
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.dr-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  white-space: nowrap;
}

.dr-field:hover { background: #f6f8fa; }

.dr-field.open {
  border-color: var(--rev);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, .12);
}

.dr-icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: var(--ink-faint);
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* ---------- 版面 ---------- */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn-apply {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 20px;
  border: 0;
  border-radius: 8px;
  background: var(--rev);
  color: #fff;
  cursor: pointer;
}

.btn-apply:hover { background: #1667d3; }

.presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.presets button {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
}

.presets button:hover { background: #f6f8fa; }

.presets button.active {
  background: #e8f0fe;
  border-color: #c6dafc;
  color: var(--rev);
  font-weight: 600;
}

/* ---------- 雙月份日曆 ---------- */

/* 跟轉圈圈同一個坑：這裡有自訂 display，一定要自己寫 [hidden]，
   否則 hidden 屬性收不起來，日曆會一直卡在畫面上。 */
.cal[hidden] { display: none; }

.cal {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  z-index: 40;
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(31, 35, 40, .12), 0 16px 40px rgba(31, 35, 40, .18);
}

/* 日曆上方的手動輸入格 */
.cal-inputs {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.cal-inputs input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 14px;
  text-align: center;
  color: var(--ink);
  background: var(--card);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.cal-inputs input:focus {
  outline: none;
  border-color: var(--rev);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, .12);
}

.cal-inputs input.bad {
  border-color: #e8918d;
  background: #fdf3f2;
}

.cal-tilde {
  color: var(--ink-faint);
  flex: none;
}

.cal-hint.warn { color: #c5221f; }

.cal-body {
  display: flex;
  gap: 26px;
}

.cal-month { width: 224px; }

.cal-mhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}

.cal-nav {
  border: 0;
  background: none;
  font-family: inherit;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-soft);
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.cal-nav:hover { background: #f0f2f5; color: var(--ink); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.cal-dow {
  font-size: 11px;
  color: var(--ink-faint);
  text-align: center;
  padding: 4px 0 6px;
}

.cal-day {
  border: 0;
  background: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
}

.cal-day:hover { background: #f0f2f5; }

.cal-day.blank { visibility: hidden; pointer-events: none; }

/* 超出可選範圍（例如未來的日期）就變灰且點不動 */
.cal-day.off {
  color: #c3c9d1;
  pointer-events: none;
}

.cal-day.today { box-shadow: inset 0 0 0 1px #c6dafc; }

.cal-day.in {
  background: #e8f0fe;
  border-radius: 0;
  color: var(--rev);
}

.cal-day.edge {
  background: var(--rev);
  color: #fff;
  font-weight: 700;
}

.cal-day.edge.start { border-radius: 8px 0 0 8px; }
.cal-day.edge.end { border-radius: 0 8px 8px 0; }
.cal-day.edge.only { border-radius: 8px; }

.cal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.cal-hint {
  font-size: 12px;
  color: var(--ink-faint);
}

.cal-close {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
}

.cal-close:hover { background: #f6f8fa; color: var(--ink); }

/* ---------- 錯誤訊息 ---------- */

.alert {
  background: #fce8e6;
  border: 1px solid #f5c6c3;
  color: #98342f;
  border-radius: var(--radius);
  padding: 13px 16px;
  font-size: 14px;
}

.alert strong { margin-right: 8px; }

/* ---------- 數字卡 ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.stat {
  padding: 18px 20px;
  border-top: 3px solid var(--line);
}

.stat[data-metric="revenue"] { border-top-color: var(--rev); }
.stat[data-metric="orders"]  { border-top-color: var(--ord); }
.stat[data-metric="ticket"]  { border-top-color: #7b61c9; }

.stat-label {
  font-size: 13px;
  color: var(--ink-soft);
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -.4px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 圖表 ---------- */

.chart-card { padding: 16px 18px 10px; }

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.chart-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
}

.chart-host {
  position: relative;
  width: 100%;
}

.chart-host svg { display: block; }

.chart-empty {
  padding: 60px 0;
  text-align: center;
  color: var(--ink-faint);
  font-size: 14px;
}

/* 滑鼠移上去的資訊卡 */
.tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(31, 35, 40, .12), 0 8px 24px rgba(31, 35, 40, .16);
  padding: 10px 14px;
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .1s;
}

.tooltip.on { opacity: 1; }

.tt-block + .tt-block { margin-top: 8px; }

.tt-date {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 2px;
}

.tt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
}

.tt-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.tt-val {
  margin-left: auto;
  padding-left: 22px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.tt-val.none { color: var(--ink-faint); font-weight: 400; }

/* ---------- 讀取中 ---------- */

/* 這個 display:flex 會蓋過瀏覽器對 hidden 屬性的預設處理，
   所以一定要自己寫一條 [hidden]，不然轉圈圈會永遠蓋在畫面上。 */
.loading[hidden] { display: none; }

.loading {
  position: fixed;
  inset: 0;
  background: rgba(241, 243, 246, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #d4dae2;
  border-top-color: var(--rev);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 手機 ---------- */

@media (max-width: 980px) {
  /* 一排塞不下就改成上下堆疊：標題 → 平台 → 日期 */
  .topbar { position: static; }

  .topbar-inner {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 12px;
  }

  .brand { order: -1; }
  .daterange { justify-self: center; align-items: center; }
  .presets { justify-content: center; }
  .platforms { justify-content: center; }

  /* 日曆改成置中浮動，不然會被擠出畫面右側 */
  .cal {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
    max-height: 88vh;
    overflow: auto;
  }

  .cal-body { flex-direction: column; gap: 14px; }
  .cal-month { width: 260px; }
}

@media (max-width: 760px) {
  .stats { grid-template-columns: 1fr; }
  .stat-value { font-size: 26px; }
}
