* { box-sizing: border-box; }

:root {
    /* 品牌色：取自雷諾瓦LOGO的金黃色與墨灰色 */
    --color-brand-gold: #ecc742;
    --color-brand-gold-soft: #f6dd85;
    --color-brand-dark: #4b4948;

    --color-primary: #8c5d06;
    --color-primary-dark: #6e4805;
    --color-primary-tint: #fbf1dc;
    --color-text: #292522;
    --color-text-muted: #6b6560;
    --color-border: #e7e0d3;
    --color-bg: #faf7f0;
    --color-surface: #fff;
    --color-success: #1e8449;
    --color-success-tint: #e9f8ee;
    --color-error: #c0392b;
    --color-error-tint: #fdecea;
    --color-warning: #b8710b;
    --color-warning-tint: #fff3dc;
    --shadow-card: 0 1px 2px rgba(75, 73, 72, 0.05), 0 4px 16px rgba(75, 73, 72, 0.06);
    --radius-card: 14px;
}

body {
    font-family: "Microsoft JhengHei", "Segoe UI", sans-serif;
    background:
        radial-gradient(1200px 480px at 50% -120px, rgba(236, 199, 66, 0.16), transparent 65%),
        var(--color-bg);
    color: var(--color-text);
    margin: 0;
    padding: 28px 24px 48px;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.page {
    max-width: 720px;
    margin: 0 auto;
}

.top-nav {
    max-width: 720px;
    margin: 0 auto 24px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 10px 18px;
    box-shadow: var(--shadow-card);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--color-brand-dark);
}

.nav-logo {
    height: 30px;
    width: auto;
    display: block;
}

.nav-user {
    margin-left: auto;
    color: var(--color-text-muted);
    font-size: 13px;
    white-space: nowrap;
}

.section-divider {
    font-size: 19px;
    font-weight: 700;
    color: var(--color-brand-dark);
    margin: 40px 0 4px;
    padding-top: 22px;
    border-top: 2px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-divider::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--color-brand-gold);
    transform: rotate(45deg);
}

.nav-user a {
    color: var(--color-primary);
    margin-left: 8px;
    font-weight: 600;
}

.top-nav a {
    color: var(--color-text-muted);
    text-decoration: none;
    padding: 10px 4px;
    margin-right: 20px;
    border-bottom: 2px solid transparent;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.top-nav a:hover {
    color: var(--color-primary);
    text-decoration: none;
}

.top-nav a.active {
    color: var(--color-primary);
    font-weight: 600;
    border-bottom-color: var(--color-primary);
}

h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--color-brand-dark);
    margin: 0 0 6px;
    letter-spacing: 0.2px;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 24px 26px;
    margin-bottom: 20px;
}

.card h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-brand-dark);
    margin-top: 0;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card h2::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 18px;
    border-radius: 3px;
    background: var(--color-brand-gold);
    flex-shrink: 0;
}

.subsection-title {
    font-size: 15px;
    font-weight: 700;
    margin: 22px 0 10px;
    color: var(--color-brand-dark);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--color-text-muted);
}

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

.legend-swatch {
    display: inline-block;
    width: 13px;
    height: 13px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.field-row {
    margin-bottom: 16px;
}

.field-row label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.field-row input[type="text"] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #ccd1db;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.15s ease;
}

.field-row input[type="text"]:focus {
    outline: none;
    border-color: var(--color-primary);
}

.field-row select {
    padding: 8px 10px;
    border: 1px solid #ccd1db;
    border-radius: 6px;
    font-size: 14px;
    background: var(--color-surface);
}

.radio-group label {
    display: inline-block;
    margin-right: 16px;
    font-size: 14px;
    color: var(--color-text);
}

.store-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 14px;
    max-height: 280px;
    overflow-y: auto;
    background: #fafbfd;
}

.store-picker .region-title {
    grid-column: 1 / -1;
    font-weight: 700;
    font-size: 13px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-top: 10px;
}

.store-picker .region-title:first-child {
    margin-top: 0;
}

.store-picker label {
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.12s ease;
}

.store-picker label:hover {
    background: var(--color-primary-tint);
}

.store-picker label:has(input:checked) {
    background: var(--color-primary-tint);
    color: var(--color-primary-dark);
    font-weight: 600;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(140, 93, 6, 0.3);
    transition: background 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover {
    background: var(--color-primary-dark);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-secondary {
    background: #fff;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
    border-radius: 6px;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 8px;
    transition: background 0.15s ease;
}

.btn-secondary:hover {
    background: var(--color-primary-tint);
}

.msg {
    font-size: 14px;
    margin-top: 10px;
}

.msg.error { color: var(--color-error); }
.msg.success { color: var(--color-success); }

.warnings {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 6px;
    background: var(--color-warning-tint);
    border: 1px solid #f2e0a8;
    font-size: 14px;
    color: var(--color-warning);
}

.leave-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 14px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow: hidden;
}

.leave-table th {
    background: #f6f7fa;
    font-weight: 700;
    color: var(--color-text-muted);
}

.leave-table th, .leave-table td {
    border: 1px solid var(--color-border);
    padding: 8px 10px;
    font-size: 14px;
    text-align: left;
}

.leave-table select {
    width: 100%;
    padding: 5px;
    font-size: 14px;
    border: 1px solid #ccd1db;
    border-radius: 4px;
}

.leave-table tr.weekend td {
    background: #fafafa;
}

.leave-table td.colleague-taken {
    color: var(--color-warning);
    font-weight: 600;
}

/* 表單底部的按鈕列。
 * 用容器包起來而不是讓按鈕裸放，是因為 .hint 帶了 margin-top:-8px(讓它緊貼標題用的)，
 * 直接接在按鈕後面時那個負值會把說明文字往上拉進按鈕裡造成重疊。 */
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.form-actions .btn-secondary {
    margin-left: 0;  /* 間距改由容器的 gap 統一控制，避免多疊一層邊距 */
}

/* .hint 的負上邊距只適用於「緊接在標題後面」的情況；接在其他區塊之後、
 * 或本身就是彈性容器裡的一個項目時，那個負值會造成錯位甚至重疊，要歸零 */
.form-actions + .hint,
.toolbar-row + .hint {
    margin-top: 0;
}

.form-actions .hint,
.toolbar-row .hint {
    margin-top: 0;
    margin-bottom: 0;
}

/* 排班表上方的工具列(復原按鈕等) */
.toolbar-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

/* ===================== 頁首標題列 + 使用說明按鈕 + 彈出視窗 ===================== */

.page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.help-label {
    background: linear-gradient(135deg, var(--color-brand-gold-soft), var(--color-brand-gold));
    border: none;
    color: var(--color-brand-dark);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 9px 18px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(75, 73, 72, 0.25);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.help-label:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(75, 73, 72, 0.3);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(41, 37, 34, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 100;
}

.modal-box {
    background: var(--color-surface);
    border-radius: var(--radius-card);
    box-shadow: 0 12px 40px rgba(75, 73, 72, 0.3);
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 24px;
    background: linear-gradient(135deg, var(--color-brand-gold-soft), var(--color-brand-gold));
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 17px;
    color: var(--color-brand-dark);
}

.modal-close {
    background: rgba(75, 73, 72, 0.12);
    border: none;
    color: var(--color-brand-dark);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.modal-close:hover {
    background: rgba(75, 73, 72, 0.24);
}

.modal-body {
    padding: 22px 26px 28px;
    overflow-y: auto;
}

.modal-body h3 {
    font-size: 15px;
    color: var(--color-brand-dark);
    margin: 22px 0 8px;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p, .modal-body li {
    font-size: 14px;
    line-height: 1.7;
    color: var(--color-text);
}

.modal-body ul {
    margin: 0;
    padding-left: 20px;
}

.modal-body li {
    margin-bottom: 6px;
}

.modal-body li:last-child {
    margin-bottom: 0;
}

.modal-body .hint {
    background: var(--color-primary-tint);
    border: 1px solid var(--color-brand-gold-soft);
    border-radius: 8px;
    padding: 12px 14px;
    margin: 0 0 4px;
    color: var(--color-text);
}

.page-footer {
    text-align: center;
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: 32px;
    padding: 18px 0 4px;
    border-top: 1px solid var(--color-border);
}

/* ===================== 行動裝置適配 =====================
 * 門市人員填休假最自然的裝置就是手機，但原本整份CSS沒有任何斷點，
 * 而且門市核取方塊只有13x13px(業界建議的觸控目標是44x44以上)，27家排在一起
 * 很難點中正確的那一家。這一段專門處理窄螢幕下的可操作性。
 */

/* 觸控裝置(不分螢幕寬度)：把所有勾選/選項的觸控目標放大到手指點得準的尺寸 */
@media (hover: none) and (pointer: coarse) {
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }

    .store-picker label,
    .radio-group label {
        min-height: 44px;          /* 觸控目標高度下限 */
        display: flex;
        align-items: center;
        gap: 10px;
    }

    /* iOS Safari 會在聚焦到 font-size < 16px 的輸入框時自動放大整個頁面，
       之後又不會縮回去，體感非常糟。把表單元件字級拉到16px就不會觸發。 */
    input[type="text"],
    input[type="password"],
    input[type="month"],
    select,
    .field-row input[type="text"],
    .field-row select,
    .leave-table select {
        font-size: 16px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 16px 12px 32px;
    }

    .top-nav {
        margin-bottom: 16px;
        padding: 8px 12px;
    }

    .card {
        padding: 16px 14px;
    }

    /* 標題與「系統操作說明」按鈕改成上下排，避免標題被擠成一行一個字 */
    .page-header-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .help-label {
        width: 100%;
        padding: 12px 18px;
    }

    /* 按鈕在窄螢幕改成整行，比並排的小按鈕好按得多 */
    .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: 13px 20px;
        margin: 0 0 8px;
    }

    .toolbar-row {
        flex-direction: column;
        align-items: stretch;
    }

    /* 門市選擇：單欄排列，並放寬高度上限——巢狀捲動區在手機上很難操作，
       讓它盡量跟著頁面一起捲 */
    .store-picker {
        grid-template-columns: 1fr;
        max-height: 60vh;
        padding: 10px;
    }

    /* 休假表格：拿掉左右內距讓四欄塞得下，並允許整張表在自己的容器裡橫向捲動 */
    .leave-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .leave-table th,
    .leave-table td {
        padding: 10px 6px;
    }

    .leave-table select {
        min-width: 96px;
    }

    /* 說明視窗在手機上改成幾乎滿版，內容才看得完整 */
    .modal-box {
        max-width: 100%;
        max-height: 92vh;
        border-radius: 10px;
    }
}

/* 很窄的螢幕(小尺寸手機)：再進一步壓縮非必要的留白 */
@media (max-width: 400px) {
    body {
        padding: 12px 8px 24px;
    }

    .card {
        padding: 14px 10px;
    }

    .leave-table th,
    .leave-table td {
        padding: 9px 4px;
        font-size: 13px;
    }
}

/* 全域錯誤橫幅：API 失敗(尤其是登入逾時)時固定在畫面最上方，
 * 確保錯誤一定會被使用者看到，不會被當成成功靜靜略過 */
.global-error-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--color-error);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    padding: 12px 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
