/* ======== common.css 全站共用樣式 ======== */
/* 各頁面專屬的樣式仍寫在該頁的 <style> 中，會覆蓋這裡的設定 */
/* 顏色一律使用下列變數，使用者在「介面設定」換主題時由 theme.js 改寫 */

:root {
    --bg: #050505;              /* 頁面底色 */
    --surface: #0a0a0a;         /* 卡片、側邊欄 */
    --surface-2: #111111;       /* 表頭、區塊標題 */
    --surface-3: #161b22;       /* 滑過、選取 */
    --input-bg: #000000;        /* 輸入框、終端機訊息框 */
    --border: #1f1f1f;
    --border-strong: #30363d;
    --text: #c9d1d9;
    --text-strong: #ffffff;     /* 標題、重點文字 */
    --muted: #8b949e;           /* 次要文字 */
    --muted-2: #6e7681;         /* 更淡的提示文字 */
    --accent: #00ffcc;
    --accent-contrast: #000000; /* 強調色上的文字 */
    --shadow: rgba(0,0,0,0.8);
    --icon-filter: invert(1);   /* 日期選擇器圖示，深色主題需反白 */
    --font-scale: 1;
    --sidebar: var(--surface);
    --menu-hover: var(--surface-3);
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'Consolas', 'Courier New', monospace;
}
body { margin: 0; display: flex; height: calc(100vh / var(--font-scale)); zoom: var(--font-scale); background: var(--bg); color: var(--text); font-family: var(--font-main); overflow: hidden; letter-spacing: 0.5px; }

/* 側邊欄 (由 sidebar.js 產生) */
nav { width: 260px; flex-shrink: 0; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; height: 100%; }
nav h2 { color: var(--accent); font-family: var(--font-main); font-size: 1.1rem; margin: 30px 25px; letter-spacing: 2px; font-weight: 600; text-transform: uppercase; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 0 15px 20px 15px; }
.sidebar-bottom { padding: 10px 15px 15px; border-top: 1px solid var(--border); }
.sidebar-user { padding: 8px 20px; color: var(--text-strong); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user small { display: block; color: var(--muted); font-size: 0.75rem; margin-top: 2px; }
.menu-btn { width: 100%; background: none; color: var(--muted); border: none; padding: 14px 20px; margin: 4px 0; text-align: left; font-size: 0.9rem; cursor: pointer; border-radius: 4px; transition: all 0.3s ease; display: flex; justify-content: space-between; align-items: center; font-weight: 500; letter-spacing: 1px; }
/* 換頁的選單項目是連結 (<a>)：滑鼠中鍵、Ctrl+點擊、右鍵都能開新分頁；樣式和下拉選單的按鈕一致 */
.menu-btn { font-family: var(--font-main); }   /* 按鈕預設用系統字型，統一成網頁字型，連結和按鈕才會一樣 */
a.menu-btn { box-sizing: border-box; text-decoration: none; }
.menu-btn:hover { background: var(--menu-hover); color: var(--text-strong); padding-left: 25px; }
.menu-btn.active { border-left: 2px solid var(--accent); color: var(--text-strong); background: var(--menu-hover); }
.submenu { display: none; margin-bottom: 10px; border-left: 1px solid var(--border); margin-left: 20px; }
.submenu.show { display: block; }
.submenu a { display: block; color: var(--muted-2); text-decoration: none; padding: 10px 15px 10px 20px; font-size: 0.85rem; transition: 0.3s; letter-spacing: 0.5px; }
.submenu a:hover { color: var(--accent); }
.submenu a.current { color: var(--text-strong); }
/* 未讀紅點 (待辦與交接)：側邊欄顯示數字，手機版 ☰ 按鈕右上角 */
.nav-badge { min-width: 18px; padding: 0 6px; border-radius: 10px; background: #da3633; color: #fff; font-size: 0.72rem; font-weight: 700; line-height: 18px; text-align: center; letter-spacing: 0; box-sizing: border-box; }
.nav-badge.bump { animation: op-badge 0.5s ease-out; }
@keyframes op-badge { 0% { transform: scale(0.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
.mobile-topbar button { position: relative; }
.nav-badge.dot { position: absolute; top: -6px; right: -6px; }
.dev-tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 9px; border: 1px solid #d29922; color: #d29922; font-size: 0.68rem; letter-spacing: 0; font-weight: 600; vertical-align: middle; }
.submenu a::before { content: "› "; color: var(--border-strong); margin-right: 8px; transition: 0.3s; }
.submenu a:hover::before { color: var(--accent); }

input[type="date"]::-webkit-calendar-picker-indicator { filter: var(--icon-filter); cursor: pointer; }

/* 固定在畫面底部的儲存列 (表格很長時不用捲到最下面)：
   <div class="sticky-actions"><div class="bar-left"><span class="dirty-note">…</span><span class="save-status"></span></div> 按鈕…</div>
   save-status 顯示儲存中 / 已儲存 / 失敗 (加 .ok / .err)
   加上 .dirty 時顯示「有尚未儲存的修改」並變成黃色提醒
   bottom 抵銷捲動區 main 的內距 (預設 40px；main 沒有內距的頁面設 --main-pad: 0px)，才會貼齊畫面最底部 */
.sticky-actions { position: sticky; bottom: calc(-1 * var(--main-pad, 40px)); z-index: 20; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 16px; margin: 16px -16px 0; background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -8px 18px var(--shadow); }
.sticky-actions > button { margin: 0 !important; }
.sticky-actions .bar-left { margin-right: auto; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-family: var(--font-mono); font-size: 0.85rem; }
.sticky-actions .dirty-note { display: none; color: #d29922; font-weight: 600; }
.sticky-actions .save-status { color: var(--muted); }
.sticky-actions .save-status.ok { color: #3fb950; }
.sticky-actions .save-status.err { color: #da3633; }
.sticky-actions button:disabled { opacity: 0.5; cursor: wait; }
.sticky-actions.dirty { border-top: 2px solid #d29922; }
.sticky-actions.dirty .dirty-note { display: inline; }

/* hidden 屬性一律隱藏 (避免被 display: inline-block 等樣式蓋掉) */
[hidden] { display: none !important; }

/* ======== 動態效果 (質感) ======== */
/* 動畫都很短 (0.15–0.3 秒)、不擋操作；系統設定「減少動態效果」時全部關閉 (最下方) */
@keyframes op-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes op-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes op-drop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes op-pop { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes op-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(218,54,51,0.55); } 50% { box-shadow: 0 0 0 5px rgba(218,54,51,0); } }

/* 換頁時內容輕輕浮上來 */
main { animation: op-rise 0.3s ease-out; }

/* 按鈕：滑過、按下有回饋 */
button { transition: background-color 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.1s; }
button:active:not(:disabled) { transform: scale(0.97); }

/* 輸入框取得焦點時，外圈淡淡的強調色光暈 */
input, select, textarea { transition: border-color 0.2s, box-shadow 0.2s; }
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):focus, select:focus, textarea:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

/* 展開的選單、區塊往下滑出 */
.submenu.show, .section-body.show { animation: op-drop 0.2s ease-out; }

/* 表格滑過的底色漸變 */
td { transition: background-color 0.15s; }

/* 交接卡片滑過微微浮起；「新」標籤閃兩下提醒 */
.ho-card:hover { transform: translateY(-1px); box-shadow: 0 6px 16px var(--shadow); }
.ho-new { animation: op-pulse 1.4s ease-out 2; }
/* 第一次載入時卡片依序浮現 (handover.js 加上 ho-intro) */
.ho-intro .ho-card { animation: op-rise 0.3s ease-out backwards; }
.ho-intro .ho-card:nth-child(2) { animation-delay: 0.04s; }
.ho-intro .ho-card:nth-child(3) { animation-delay: 0.08s; }
.ho-intro .ho-card:nth-child(4) { animation-delay: 0.12s; }
.ho-intro .ho-card:nth-child(n+5) { animation-delay: 0.16s; }

/* 對話框、設定面板、拖曳上傳遮罩、更新提示 */
.modal-bg, #drop-overlay { animation: op-fade 0.18s ease-out; }
.modal, #theme-panel:not([hidden]) { animation: op-pop 0.22s ease-out; }
#update-banner { animation: op-banner 0.35s ease-out; }
@keyframes op-banner { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* 捲軸改細，顏色跟著主題 */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--muted-2); }

/* ======== 質感：圓角、層次、柔和的光 ======== */
/* 選擇器前面加 body 提高優先順序，蓋過各頁 <style> 裡的同名樣式 (各頁不用改)
   報表圖片 (html2canvas) 讀不懂 color-mix：表格內 (th / td) 不要用 color-mix */
body { background: radial-gradient(900px 420px at 75% -120px, color-mix(in srgb, var(--accent) 7%, transparent), transparent 70%) var(--bg); }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--text-strong); }

/* 側邊欄：品牌字漸層、選單圓角、目前頁面的強調色底與左側亮條 */
nav { background: linear-gradient(180deg, var(--sidebar), color-mix(in srgb, var(--sidebar) 92%, var(--accent))); }
nav h2 { background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 45%, var(--text-strong))); -webkit-background-clip: text; background-clip: text; color: transparent; }
body .menu-btn { border-radius: 8px; position: relative; }
body .menu-btn.active { border-left: none; background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--text-strong); }
body .menu-btn.active::before { content: ""; position: absolute; left: 0; top: 22%; bottom: 22%; width: 3px; border-radius: 3px; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
body .submenu a { border-radius: 6px; }
body .submenu a:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
body .submenu a.current { color: var(--accent); }
body .submenu a.current::before { color: var(--accent); }

/* 卡片：圓角、上緣一道淡淡的強調色光、柔和陰影 */
body .content-card, body .attendance-card { border-radius: 14px; position: relative; border-color: color-mix(in srgb, var(--border) 70%, var(--border-strong)); box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 18px 40px -18px var(--shadow); }
body .content-card::before, body .attendance-card::before { content: ""; position: absolute; top: -1px; left: 24px; right: 24px; height: 1px; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 60%, transparent), transparent); pointer-events: none; }

/* 卡片內的小區塊 (交接、待辦、設定規則、可展開的區塊)：同一套圓角 */
body .ho-card, body .todo-item, body .item-card, body .section-wrapper { border-radius: 10px; }
body .ho-btn, body .calc-btn { border-radius: 8px; }

/* 按鈕：圓角、滑過時發光 */
body .primary-btn, body .ghost-btn, body .del-btn, body .save-btn, body .view-btn { border-radius: 8px; }
body .primary-btn:hover:not(:disabled) { box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--accent) 70%, transparent); }
body .ghost-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--text) 5%, transparent); }
body .del-btn:hover:not(:disabled) { box-shadow: 0 6px 16px -6px rgba(218,54,51,0.7); }

/* 輸入框、訊息框、上傳區、表格外框：一致的圓角 */
main input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), main select, main textarea { border-radius: 8px; }
body .terminal-box { border-radius: 10px; }
body .table-wrap, body .table-container { border-radius: 10px; }
body .upload-area { border-radius: 12px; }
body .upload-area:hover, body .upload-area.dragover { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 10%, transparent) inset; }

/* 對話框：背景模糊、較大的圓角 */
body .modal-bg { backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
body .modal { border-radius: 14px; box-shadow: 0 30px 60px -20px var(--shadow); }

/* 底部儲存列：毛玻璃 */
body .sticky-actions { background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ======== 手機版 (寬度 768px 以下) ======== */
/* 側邊欄改成從左側滑出的選單，上方加一條標題列；各頁的內距與表格改為適合小螢幕 */
.mobile-topbar, .nav-backdrop { display: none; }

@media (max-width: 768px) {
    body { flex-direction: column; }

    .mobile-topbar { display: flex; align-items: center; gap: 12px; flex-shrink: 0; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 800; }
    .mobile-topbar button { flex-shrink: 0; width: 40px; height: 40px; background: none; border: 1px solid var(--border-strong); border-radius: 6px; color: var(--text-strong); font-size: 1.2rem; cursor: pointer; }
    .mobile-topbar .title { color: var(--accent); font-weight: 600; letter-spacing: 2px; font-size: 0.9rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

    nav { position: fixed; top: 0; bottom: 0; left: 0; height: auto; width: 82vw; max-width: 300px; z-index: 950; transform: translateX(-100%); transition: transform 0.25s ease; }
    body.nav-open nav { transform: none; box-shadow: 0 0 40px var(--shadow); }
    body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,0.45); }
    nav h2 { margin: 20px 20px; }
    .menu-btn { padding: 12px 16px; }
    .menu-btn:hover { padding-left: 16px; }

    main { width: 100%; min-width: 0; min-height: 0; box-sizing: border-box; padding: 12px !important; }
    .content-card, .attendance-card { padding: 18px 14px !important; margin-bottom: 16px !important; min-height: 0 !important; }
    h1 { font-size: 1.15rem !important; letter-spacing: 1px !important; margin-bottom: 14px !important; }
    .terminal-box { padding: 12px !important; font-size: 0.78rem !important; margin-bottom: 16px !important; overflow-wrap: anywhere; }

    /* 表格不再擠壓，改為可左右滑動 */
    table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    th, td { padding: 8px 10px !important; }
    th { white-space: nowrap; }
    td { min-width: 4em; }

    /* 按鈕、輸入列改為上下排列 */
    .search-bar, .btn-group, .action-bar, .toolbar { flex-wrap: wrap; gap: 10px !important; }
    .search-bar > *, .btn-group > * { flex: 1 1 100%; box-sizing: border-box; }
    .input-grid { grid-template-columns: 1fr !important; }
    .upload-area { padding: 28px 12px !important; }
    .section-header { padding: 14px 16px !important; }
    .section-body { padding: 16px 12px !important; }
    .sticky-actions { bottom: -12px; }   /* 手機版 main 內距 12px */
}

/* 更新公告 (sidebar.js NOTICES)：更新後第一次打開網站跳出一次 */
.op-notice-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; animation: op-drop 0.2s ease-out; }
.op-notice { background: var(--surface); border: 1px solid var(--border-strong); border-top: 3px solid var(--accent); border-radius: 10px; width: 100%; max-width: 460px; padding: 26px 28px 22px; box-shadow: 0 20px 60px var(--shadow); }
.op-notice-tag { display: inline-block; font-size: 0.72rem; color: var(--accent); border: 1px solid var(--accent); border-radius: 10px; padding: 1px 9px; margin-bottom: 10px; letter-spacing: 1px; }
.op-notice h3 { margin: 0 0 14px; color: var(--text-strong); font-weight: 500; font-size: 1.15rem; }
.op-notice-body { color: var(--text); font-size: 0.92rem; line-height: 1.75; }
.op-notice-body b { color: var(--text-strong); }
.op-notice-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.op-notice-actions button { background: transparent; border: 1px solid var(--border-strong); color: var(--muted); padding: 8px 18px; border-radius: 6px; cursor: pointer; font-size: 0.88rem; font-family: var(--font-main); }
.op-notice-actions button:hover { color: var(--text-strong); border-color: var(--muted); }
.op-notice-actions .op-notice-ok { border-color: var(--accent); color: var(--accent); }
.op-notice-actions .op-notice-ok:hover { background: var(--accent); color: var(--accent-contrast); }
