:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #059669;
  --danger: #dc2626;
  --code-bg: #1f2937;
}

* { box-sizing: border-box; }

/* HTML5 hidden 屬性需要這條 !important 才不會被自定義 .loading-overlay 等 display 規則蓋掉。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  font-size: 18px;
  letter-spacing: 0.5px;
}

.navlinks { display: flex; align-items: center; gap: 16px; }
.navlinks a { text-decoration: none; color: var(--primary); }
.navlinks .user { color: var(--muted); font-size: 14px; }

.container {
  max-width: 95vw;
  margin: 0 auto;
  padding: 24px 24px 80px;
}

h1 { margin: 0 0 4px; font-size: 24px; }
h2 { margin: 0 0 12px; font-size: 18px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

/* ---- login ---- */
.login-card {
  max-width: 380px;
  margin: 80px auto;
  padding: 32px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card .subtitle { text-align: center; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.login-card button {
  padding: 10px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  margin-top: 8px;
}
.login-card button:hover { background: var(--primary-hover); }

.alert {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

/* ---- dashboard cards ---- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.1s, box-shadow 0.1s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.06); }
.card.disabled { opacity: 0.45; pointer-events: none; }
.card-icon { font-size: 32px; margin-bottom: 8px; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.card-desc { font-size: 13px; color: var(--muted); }

/* ---- daily / weekend report form ---- */
.date-form { margin-bottom: 24px; }
.date-form .row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.date-form .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 200px;            /* 兩個 input 強制等寬 */
}
.date-form .field.field-wide { width: 280px; }  /* 含左右箭頭的日期 field */
.date-form .field label {
  font-size: 14px;
  color: var(--muted);
}
.date-form input[type="date"],
.date-form input[type="text"],
.date-form input[type="email"],
.date-form input[type="number"],
.date-form input[type="password"],
.date-form input[type="search"],
.date-form select,
.date-form select.select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  height: 38px;
  box-sizing: border-box;
  background: #fff;
}

/* 日期 ← → 切換 */
.date-with-arrows {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.date-with-arrows input[type="date"] { flex: 1; }
.date-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  text-decoration: none;
  color: var(--primary);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}
.date-arrow:hover { background: #eff6ff; border-color: var(--primary); }
.date-form button.primary {
  padding: 0 18px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  height: 38px;            /* 與 input 等高 */
}
.date-form button.primary:hover { background: var(--primary-hover); }

/* 全域連結：藍色、無底線，hover 才有底線（覆蓋瀏覽器預設） */
a {
  color: var(--primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* 日期連結 + 表格內所有可點連結：藍色字、無底線，hover 才出底線 */
a.date-link,
a.date-link:visited,
table.db-overview a,
table.db-overview a:visited {
  color: var(--primary);
  text-decoration: none;
  border: 0;
}
a.date-link:hover,
table.db-overview a:hover { text-decoration: underline; }

/* 日期快捷連結：直接列今/昨/前 3 天，緊接查詢按鈕右邊 */
.date-shortcuts {
  font-size: 14px;
  margin-left: 16px;
}
.date-shortcuts a,
.date-shortcuts a:hover,
.date-shortcuts a:visited {
  color: var(--primary);
  text-decoration: none;
}
.form-hints {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 0;
  line-height: 1.5;
}

/* Google 登入按鈕（仿 Google Sign-In button 樣式） */
.login-card a.google-login-btn,
a.google-login-btn,
.google-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  background: #fff;
  color: #1f1f1f !important;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none !important;
  margin-top: 24px;
  width: 100%;
  box-sizing: border-box;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(60,64,67,0.08);
  transition: box-shadow 0.15s, background 0.15s, border-color 0.15s;
}
.google-login-btn:hover {
  background: #f6f9fc;
  border-color: #c4cad2;
  box-shadow: 0 1px 3px rgba(60,64,67,0.16);
}
.google-login-btn:active { background: #eff3f6; }

/* 星期幾 label：日期 input 旁的「(一)」 */
.wd-label {
  font-size: 14px;
  color: var(--muted);
  margin-left: 6px;
  min-width: 28px;
  display: inline-block;
}

/* ---- sync dashboard ---- */
table.db-overview {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 14px;
}
table.db-overview th,
table.db-overview td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
table.db-overview th {
  background: #f3f4f6;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;       /* 表頭單字不要被擠成垂直 */
  padding: 8px 14px;
}
table.db-overview td { padding: 8px 14px; }
table.db-overview td.nowrap,
table.db-overview th.nowrap { white-space: nowrap; }
/* zebra striping：增加可讀性 */
table.db-overview tbody tr:nth-child(odd)  { background: #ffffff; }
table.db-overview tbody tr:nth-child(even) { background: #fafbfc; }
table.db-overview tbody tr:hover           { background: #f0f7ff; }

table.db-overview td.num,
table.db-overview th.num {
  text-align: right;
  font-family: "SF Mono", "Menlo", "Roboto Mono", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

/* 影片每日票房 / 單日排行：固定 col widths 讓多個 table 對齊 */
table.daily-bo                          { table-layout: fixed; }
table.daily-bo th, table.daily-bo td    { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.db-overview code {
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.badge-ok {
  display: inline-block;
  background: #d1fae5;
  color: #047857;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.err { color: var(--danger); font-size: 13px; }
button.primary.secondary {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}
button.primary.secondary:hover { background: #eff6ff; }
button.primary.danger {
  background: #dc2626;
}
button.primary.danger:hover { background: #b91c1c; }

/* ---- new hash display ---- */
.hash-display textarea {
  width: 100%;
  padding: 10px 12px;
  font: 13px/1.4 "SF Mono", Menlo, monospace;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafb;
  resize: vertical;
  word-break: break-all;
}
.hash-display code {
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}

/* ---- account management form ---- */
.account-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.account-form .field { width: 220px; display: flex; flex-direction: column; gap: 4px; }
.account-form .field label { font-size: 14px; color: var(--muted); }
.account-form input[type="password"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  height: 38px;
  box-sizing: border-box;
}
.account-form button.primary {
  padding: 0 18px;
  height: 38px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}
.account-form button.primary:hover { background: var(--primary-hover); }

@media (max-width: 600px) {
  .account-form { flex-direction: column; align-items: stretch; }
  .account-form .field, .account-form button.primary { width: 100%; }
  .account-form button.primary { height: 42px; }
}

.hint {
  margin-top: 24px;
  padding: 12px 14px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e40af;
  font-size: 13px;
}

.status-bar {
  background: #ecfdf5;
  color: var(--success);
  border: 1px solid #a7f3d0;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 24px;
}

.section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 20px;
}
.section textarea {
  width: 100%;
  padding: 12px;
  font: 14px/1.6 -apple-system, "SF Mono", Menlo, monospace;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  background: #fafafb;
}
.section textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; background: #fff; }

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
}
.actions button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
  cursor: pointer;
}
.actions button:hover { background: #f3f4f6; }
.actions form.inline { display: inline; margin: 0; }
.actions .copy-status { color: var(--success); font-size: 13px; }

/* 小型 inline 動作按鈕（編輯／停用／刪除 等）— 統一 button + a 樣式 */
button.copy-btn,
a.copy-btn,
.copy-btn {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  margin: 0 2px;
  background: #fff;
  color: #374151;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  text-decoration: none !important;
  cursor: pointer;
  line-height: 1.5;
  white-space: nowrap;
}
.copy-btn:hover { background: #f3f4f6; border-color: #9ca3af; }
.copy-btn:active { background: #e5e7eb; }

.hint {
  margin-top: 24px;
  padding: 12px 14px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e40af;
  font-size: 13px;
}

/* ---- Loading overlay ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.loading-card {
  background: #fff;
  padding: 28px 36px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  text-align: center;
  min-width: 280px;
}
.loading-text { font-size: 15px; color: var(--text); margin-top: 14px; font-weight: 500; }
.loading-sub  { font-size: 12px; color: var(--muted); margin-top: 4px; }

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 600px) {
  .container { padding: 16px 12px 60px; }
  h1 { font-size: 20px; }
  .section textarea { font-size: 13px; }
  /* 日期欄位手機 stack：每個 field 各佔一行 */
  .date-form .row { flex-direction: column; align-items: stretch; gap: 12px; }
  .date-form .field, .date-form button.primary { width: 100%; }
  .date-form button.primary { height: 42px; }
}

/* ============ Mobile UI 優化（≤ 768px）desktop 完全不變 ============ */
.hamburger-btn { display: none; }
.mobile-tabs { display: none; }

@media (max-width: 768px) {
  /* 1. Hamburger menu */
  .topbar { position: relative; padding: 12px 16px; }
  .hamburger-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    margin-left: auto;
    color: var(--text);
  }
  .navlinks {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 12px;
    left: 12px;
    background: #fff;
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.12);
    gap: 0;
    z-index: 100;
    font-size: 15px;
  }
  .navlinks.open { display: flex; }
  .navlinks a {
    padding: 12px 0;
    width: 100%;
    border-bottom: 1px solid #f3f4f6;
  }
  .navlinks a:last-of-type { border-bottom: 0; }
  .navlinks .user {
    padding: 12px 0 4px;
    width: 100%;
    border-top: 1px solid #e5e7eb;
    margin-top: 4px;
    font-size: 13px;
  }

  /* 2. Dashboard cards：mobile 改 1 欄 */
  .cards { grid-template-columns: 1fr; }

  /* 4. 表格在 mobile：水平 scroll 區域突破 section padding 貼齊視窗邊，
        避免「爆框」感。表格字級稍縮 + cell padding 縮 */
  .section { padding: 14px 16px; border-radius: 10px; }
  .section > div[style*="overflow-x"],
  .section > .table-scroll {
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
    -webkit-overflow-scrolling: touch;
  }
  table.db-overview { font-size: 13px; }
  table.db-overview th,
  table.db-overview td { padding: 6px 8px; }

  /* 「當日總和 / 區間總和」等 summary block：在 mobile 變雙欄 key/value list，
     不再橫向 scroll、不爆框 */
  .summary-block table.db-overview,
  .summary-block table.db-overview tbody,
  .summary-block table.db-overview tr {
    display: block;
  }
  .summary-block table.db-overview tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid #e0f2fe;
  }
  .summary-block table.db-overview tr:last-child { border-bottom: 0; }
  .summary-block table.db-overview th,
  .summary-block table.db-overview td {
    display: block;
    padding: 8px 10px;
    text-align: left !important;
    border: 0;
    font-family: inherit;
  }
  .summary-block table.db-overview th {
    color: var(--muted);
    background: transparent;
    font-weight: 500;
    font-size: 12px;
  }
  .summary-block table.db-overview td {
    font-weight: 600;
    text-align: right !important;
  }
  /* summary-block 還是要突破 padding 但不需要橫向 scroll */
  .summary-block > div[style*="overflow-x"] { margin: 0; padding: 0; }

  /* date-form 內 inline width="280px" 等強制 100% 寬，避免帳號管理表單擠出 */
  .date-form .row { flex-direction: column; align-items: stretch; gap: 12px; }
  .date-form .field {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .date-form button.primary { width: 100%; height: 42px; }

  /* 3. Tabbed textarea：tab nav + 切換 */
  .mobile-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .mobile-tabs button {
    flex-shrink: 0;
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 999px;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
  }
  .mobile-tabs button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
  }
  .tab-content[data-mobile-hidden="true"] { display: none; }
}

/* ---------- 社群管理（beta）表單：對齊全站輸入/按鈕樣式 ---------- */
.social-form .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.social-form .field label { font-size: 14px; color: var(--muted); }
.social-form input[type="text"],
.social-form input[type="password"],
.social-form input[type="url"],
.social-form input[type="date"],
.social-form input[type="email"],
.social-form select,
.social-form textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  box-sizing: border-box;
  background: #fff;
  font-family: inherit;
}
.social-form input, .social-form select { height: 38px; }
.social-form textarea {
  min-height: 150px;
  resize: vertical;
  font: 14px/1.6 -apple-system, "SF Mono", Menlo, monospace;
  background: #fafafb;
}
.social-form input:focus,
.social-form select:focus,
.social-form textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; background: #fff; }
.social-form button.primary {
  padding: 0 18px;
  height: 38px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}
.social-form button.primary:hover { background: var(--primary-hover); }
