/* ===== emoji 字體（舊版 Windows 缺 emoji 字體時的 fallback）=====
   舊電腦（Windows 7/8 或更老）系統本身沒有彩色 emoji 字型，
   會把 🖨 ✏️ 🗑 等圖示顯示為空白方塊。
   透過 Google Fonts 載入 Noto Color Emoji，讓瀏覽器在系統缺字時能補上圖形。
   這個字體走 unicode-range 子集化，實際流量不大且會被瀏覽器快取。 */
@import url('https://fonts.googleapis.com/css2?family=Noto+Color+Emoji&display=swap');

/* ===== JESCO 統一設計系統 ===== */
:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --success: #34a853;
    --warning: #fbbc04;
    --danger: #d93025;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #202124;
    --text-secondary: #5f6368;
    --border: #dadce0;
    --shadow: 0 2px 8px rgba(60,64,67,0.15);
    --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    /* Arial 放在正黑體前面：西文/數字用 Arial（穩定、各平台一致），
       中文會 fallback 到 Microsoft JhengHei；避免某些舊電腦的正黑體數字偏寬偏淡 */
    font-family: Arial, "Microsoft JhengHei", "Noto Color Emoji", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}
/* button / input / select 預設不繼承 body 的 font-family，補上同樣 fallback */
button, input, select, textarea {
    font-family: inherit;
}

/* ===== 導航列 ===== */
.navbar {
    background: #1a1a2e;
    color: white;
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 65px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar-brand {
    font-size: 1.3rem;
    font-weight: 700;
    color: #ffc107;
    text-decoration: none;
    margin-right: 32px;
    letter-spacing: 1px;
}
.navbar-nav {
    display: flex;
    gap: 4px;
    list-style: none;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
}
.navbar-nav a {
    color: #b0b0b0;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s;
}
.navbar-nav a:hover,
.navbar-nav a.active {
    background: rgba(255,255,255,0.1);
    color: white;
}
.navbar-version {
    font-size: 0.75rem;
    color: #666;
    margin-left: auto;
}

/* ===== Navbar 下拉選單 ===== */
.nav-dropdown { position: relative; display: inline-block; }
.nav-dropdown-toggle {
    color: #b0b0b0;
    background: transparent;
    border: 0;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    display: inline-flex; align-items: center; gap: 4px;
}
.nav-dropdown-toggle:hover,
.nav-dropdown.open .nav-dropdown-toggle,
.nav-dropdown.has-active .nav-dropdown-toggle {
    background: rgba(255,255,255,0.1);
    color: white;
}
.nav-dropdown-menu a.active {
    background: rgba(255,255,255,0.12);
    color: white;
}
.nav-dropdown-toggle .caret {
    font-size: 0.7rem; transition: transform .15s;
}
.nav-dropdown.open .nav-dropdown-toggle .caret { transform: rotate(180deg); }
.nav-dropdown-menu {
    /* position 由 JS 設為 fixed + 動態 top/left，避免被 navbar-nav 的 overflow 截掉 */
    display: none;
    position: fixed;
    min-width: 220px;
    background: #1a1a2e;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
    padding: 6px;
    z-index: 200;
    list-style: none;
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu li { list-style: none; }
.nav-dropdown-menu a {
    display: block;
    color: #b0b0b0;
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: all 0.15s;
}
.nav-dropdown-menu a:hover { background: rgba(255,255,255,0.1); color: white; }

/* ===== 容器 ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.container-narrow { max-width: 900px; margin: 0 auto; padding: 20px; }

/* ===== 卡片 ===== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.card-header {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
    color: var(--text);
}

/* ===== 表單 ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-secondary);
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: border 0.2s, box-shadow 0.2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,115,232,0.15);
}
textarea.form-control { resize: vertical; min-height: 80px; }

/* ===== 按鈕 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
}
.btn:hover { filter: brightness(0.92); transform: translateY(-1px); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: #202124; }
.btn-danger  { background: var(--danger); color: white; }
.btn-secondary { background: #e8eaed; color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
th {
    background: #f8f9fa;
    font-weight: 700;
    padding: 12px 16px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    font-size: 0.9rem;
    color: var(--text-secondary);
}
td {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f3f4;
    font-size: 0.95rem;
}
tr:hover td { background: #f8f9fa; }

/* ===== 標籤頁 ===== */
.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab-btn {
    padding: 10px 20px;
    background: #e8eaed;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.2s;
    font-family: inherit;
}
.tab-btn.active { background: var(--primary); color: white; }

/* ===== 搜尋列 ===== */
.search-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.search-bar input,
.search-bar select { flex: 1; min-width: 150px; }

/* ===== 照片格線 ===== */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 10px;
}
.photo-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: #eee;
}
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item .delete-btn {
    position: absolute; top: 5px; right: 5px;
    background: rgba(217,48,37,0.9);
    color: white; border: none; border-radius: 50%;
    width: 28px; height: 28px; cursor: pointer;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
}
.modal-content {
    background: white;
    max-width: 600px;
    margin: 50px auto;
    padding: 24px;
    border-radius: var(--radius);
    max-height: 90vh;
    overflow-y: auto;
}

/* ===== 載入遮罩 ===== */
.loading-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.9);
    display: none; justify-content: center; align-items: center;
    flex-direction: column; z-index: 9999;
}
.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    width: 40px; height: 40px;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 首頁格線 ===== */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 24px;
}
.module-card {
    background: white;
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--text);
    transition: all 0.3s;
    border-left: 5px solid var(--primary);
}
.module-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(60,64,67,0.2);
}
.module-card .icon { font-size: 2.2rem; margin-bottom: 12px; }
.module-card h3 { font-size: 1.15rem; margin-bottom: 8px; }
.module-card p { font-size: 0.9rem; color: var(--text-secondary); }
.module-card.green  { border-left-color: var(--success); }
.module-card.yellow { border-left-color: var(--warning); }
.module-card.red    { border-left-color: var(--danger); }
.module-card.blue   { border-left-color: var(--primary); }

/* ===== RWD ===== */
@media (max-width: 768px) {
    .navbar { padding: 0 12px; }
    .navbar-nav a { padding: 6px 10px; font-size: 0.85rem; }
    .container, .container-narrow { padding: 12px; }
    .card { padding: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    /* 例外：含 sticky 子元素的 card 不能 overflow，否則 position:sticky 會被困在容器內失效
       （例如排程管理的 .sticky-toolbar / .sticky-head / .sched-wrap）*/
    .card:has(.sticky-toolbar),
    .card:has(.sched-wrap),
    .card:has(.sticky-head) { overflow: visible; }
    .search-bar { flex-direction: column; }
    .search-bar input, .search-bar select { min-width: 100%; }
}

/* 手機（≤480px）：常見兩欄/三欄表單收合單欄、照片格縮小、搜尋列換行 */
@media (max-width: 480px) {
    /* 兩欄/多欄表單 → 單欄 */
    .form-row,
    .measure-item-row,
    .edit-grid { grid-template-columns: 1fr !important; }

    /* 照片瀏覽格縮小門檻，避免 200px 在窄螢幕被 1 列頂出橫向捲動 */
    .photos-view { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important; }

    /* 搜尋列：input/select 換行佔滿一行 */
    .search-bar { flex-wrap: wrap; }
    .search-bar input,
    .search-bar select { min-width: 100% !important; }

    /* 導覽列字級再縮小 */
    .navbar-nav a { padding: 5px 8px; font-size: .8rem; }

    /* tab-bar 按鈕字級縮、padding 緊一點，避免 4-5 顆塞不下 */
    .tab-bar .tab-btn,
    .tabs .tab-btn { font-size: .82rem; padding: 8px 6px; }
}
