/* 共用頁首、手機選單、撥號按鈕與聯絡視窗；各公開頁在內嵌樣式之後載入，桌機頁首排版仍由各頁內嵌樣式決定。 */

/* ==================== 撥號圖示 ==================== */
.has-phone-icon::before {
    content: ''; display: inline-block; flex-shrink: 0; width: 1.1em; height: 1.1em; background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ==================== 選單按鈕（桌機隱藏） ==================== */
.menu-icon {
    display: none; align-items: center; justify-content: center; flex-shrink: 0;
    width: 44px; height: 44px; margin-right: -6px; padding: 0;
    background: none; border: 0; border-radius: 10px; color: var(--primary-color);
    cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color 0.2s;
}
.menu-icon svg { width: 28px; height: 28px; fill: currentColor; }
.menu-icon .icon-close,
.menu-icon[aria-expanded="true"] .icon-menu { display: none; }
.menu-icon[aria-expanded="true"] .icon-close { display: block; }
#main-nav .nav-call-item { display: none; }
.nav-backdrop { display: none; }

/* ==================== 手機頁首與下拉選單 ==================== */
@media (max-width: 768px) {
    header { padding: 8px 16px; z-index: 1001; }
    header .header-logo { height: 40px; }
    header .logo-link { gap: 10px; }

    .menu-icon { display: inline-flex; }
    .menu-icon[aria-expanded="true"] { background: #EEF4FB; }
    .menu-icon:focus-visible { outline: 3px solid rgba(21, 101, 192, 0.35); outline-offset: 0; }

    #main-nav ul {
        position: absolute; top: 100%; left: 0; right: 0; width: auto; box-sizing: border-box;
        display: grid; grid-template-columns: 1fr 1fr; gap: 0; align-items: stretch;
        margin: 0; padding: 6px 0 16px; list-style: none;
        background: #fff; border-top: 1px solid #E8EDF3; border-radius: 0 0 16px 16px;
        box-shadow: 0 16px 32px rgba(15, 35, 70, 0.18);
        max-height: calc(100vh - 60px); max-height: calc(100dvh - 60px);
        overflow-y: auto; overscroll-behavior: contain;
        opacity: 0; visibility: hidden; transform: translateY(-8px);
        transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
    }
    #main-nav ul.open { opacity: 1; visibility: visible; transform: none; transition: opacity 0.2s ease, transform 0.2s ease; }
    #main-nav li { grid-column: 1 / -1; width: auto; }
    /* 各頁內嵌的 transition: 0.3s 會連 visibility 一起過場，導致選單剛展開時連結無法取得焦點。 */
    #main-nav li > * { transition: color 0.2s, background-color 0.2s, border-color 0.2s; }

    #main-nav a.nav-item {
        display: flex; align-items: center; width: 100%; min-height: 52px; box-sizing: border-box;
        padding: 0 20px; border-bottom: 1px solid #F0F3F7; border-left: 0;
        font-size: 1.05rem; color: var(--text-color);
    }
    #main-nav a.nav-item::after { display: none; }
    #main-nav a.nav-item.active { color: var(--primary-color); background: #EEF4FB; box-shadow: inset 4px 0 0 var(--accent-color); }
    #main-nav a:focus-visible,
    #main-nav button:focus-visible { outline: 3px solid rgba(21, 101, 192, 0.35); outline-offset: -3px; }

    #main-nav .nav-call-item,
    #main-nav .nav-cta-item { grid-column: auto; }
    #main-nav .nav-call-item { display: block; padding: 16px 6px 0 16px; }
    #main-nav .nav-cta-item { padding: 16px 16px 0 6px; }
    #main-nav .nav-call,
    #main-nav .btn-cta {
        display: flex; align-items: center; justify-content: center; gap: 6px;
        width: 100%; min-height: 48px; margin: 0; padding: 0 10px; box-sizing: border-box;
        border-radius: 10px; font-family: inherit; font-size: 1rem; font-weight: bold;
        line-height: 1.2; text-align: center; white-space: nowrap; transform: none;
    }
    #main-nav .nav-call { color: var(--primary-color); background: #fff; border: 2px solid var(--primary-color); }
    #main-nav .nav-call:active { background: #EEF4FB; }
    #main-nav .btn-cta { border: 2px solid var(--accent-color); }

    .nav-backdrop {
        display: block; position: fixed; inset: 0; z-index: 1000;
        background: rgba(15, 23, 42, 0.45); opacity: 0; visibility: hidden;
        transition: opacity 0.2s ease, visibility 0s linear 0.2s;
    }
    .nav-backdrop.show { opacity: 1; visibility: visible; transition: opacity 0.2s ease; }

    .footer-contact-list { font-size: 0.98em; }
    .footer-contact-list li { word-break: keep-all; overflow-wrap: anywhere; }
    .footer-contact-list a[href^="tel:"] { color: var(--primary-color); font-weight: bold; text-decoration: underline; text-underline-offset: 3px; }
}

/* ==================== 聯絡方式視窗 ==================== */
.modal-overlay {
    display: flex; visibility: hidden; opacity: 0; pointer-events: none;
    position: fixed; inset: 0; z-index: 2000; justify-content: center; align-items: center;
    background-color: rgba(0, 0, 0, 0.6); transition: opacity 0.3s, visibility 0.3s;
}
.modal-overlay.show { visibility: visible; opacity: 1; pointer-events: auto; }
.modal-content {
    position: relative; box-sizing: border-box; width: calc(100% - 32px); max-width: 900px;
    max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain;
    padding: 40px; background: #fff; border-radius: 15px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transform: translateY(-20px); transition: transform 0.3s;
}
.modal-overlay.show .modal-content { transform: translateY(0); }
.modal-close {
    position: absolute; top: 15px; right: 20px; display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border: none; border-radius: 50%; background: #f4f4f4;
    font-size: 28px; font-weight: bold; line-height: 1; color: #aaa; cursor: pointer; transition: 0.3s;
}
.modal-close:hover { color: #333; background: #e0e0e0; }

.modal-header-text { text-align: center; margin-bottom: 30px; }
.modal-header-text h2 { font-size: 2.2em; color: #333; margin: 0 0 10px 0; }
.modal-header-text p { color: #666; font-size: 1.1em; margin: 0; }
.modal-cards { display: flex; gap: 20px; }
.modal-card {
    flex: 1; display: flex; flex-direction: column; min-width: 0;
    padding: 30px 20px; border: 2px solid transparent; border-radius: 10px; text-align: center; transition: 0.3s;
}
.card-line { background-color: #FFFBF0; border-color: #FFE6A8; }
.card-line:hover { box-shadow: 0 5px 15px rgba(255, 179, 0, 0.2); transform: translateY(-5px); }
.card-line .card-icon { background: #fff; color: var(--accent-color); }
.card-line .modal-btn { background: var(--accent-color); color: #333; }
.card-line .modal-btn:hover { background: #FF8F00; color: #333; }
.card-call { background-color: #fff; border-color: #D4E4F7; }
.card-call:hover { box-shadow: 0 5px 15px rgba(21, 101, 192, 0.15); transform: translateY(-5px); }
.card-call .card-icon { background: #EEF4FB; color: var(--primary-color); }
.card-call .modal-btn { padding: 8px; background: #fff; color: var(--primary-color); border: 2px solid var(--primary-color); }
.card-call .modal-btn:hover { background: var(--primary-color); color: #fff; }
.card-form { background-color: #F4F8FC; border-color: #D4E4F7; }
.card-form:hover { box-shadow: 0 5px 15px rgba(21, 101, 192, 0.15); transform: translateY(-5px); }
.card-form .card-icon { background: #fff; color: var(--primary-color); }
.card-form .modal-btn { background: var(--primary-color); color: #fff; }
.card-form .modal-btn:hover { background: #0D47A1; }
.modal-card h3 { margin: 15px 0 10px; font-size: 1.4em; color: #333; }
.modal-card p { flex: 1; margin: 0 0 25px; color: #666; font-size: 0.95em; line-height: 1.6; }
.card-icon { width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); }
.card-icon svg { width: 30px; height: 30px; fill: currentColor; }
.modal-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px; box-sizing: border-box;
    width: 90%; min-height: 48px; margin: 0 auto; padding: 10px 8px; border-radius: 5px; white-space: nowrap;
    font-weight: bold; font-size: 1.1em; text-decoration: none; cursor: pointer; transition: 0.3s;
}
/* 桌機三張卡片的按鈕對齊底部，假日電話顯示在按鈕上方；手機版恢復原本順序。 */
.card-call .modal-btn { order: 1; }
.modal-card p.modal-call-alt { flex: none; margin: -12px 0 18px; font-size: 0.9em; }
.modal-call-alt a { color: var(--primary-color); font-weight: bold; text-decoration: underline; text-underline-offset: 3px; }
.modal-footer-text { text-align: center; font-size: 0.85em; color: #666; margin-top: 30px; }

@media (max-width: 768px) {
    .modal-overlay { align-items: flex-end; }
    .modal-content {
        width: 100%; max-height: 92vh; max-height: 92dvh;
        padding: 22px 16px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom));
        border-radius: 20px 20px 0 0; transform: translateY(40px);
    }
    .modal-close { top: 12px; right: 12px; width: 36px; height: 36px; font-size: 24px; }
    .modal-header-text { margin: 0 44px 16px; }
    .modal-header-text h2 { font-size: 1.45em; margin-bottom: 4px; }
    .modal-header-text p { font-size: 0.92em; }
    .modal-cards { flex-direction: column; gap: 10px; }
    .modal-card {
        display: grid; grid-template-columns: 44px minmax(0, 1fr); column-gap: 12px; align-items: center;
        padding: 14px; text-align: left;
    }
    .modal-card:hover { transform: none; box-shadow: none; }
    .modal-card .card-icon { grid-row: 1 / span 2; width: 44px; height: 44px; align-self: start; }
    .modal-card .card-icon svg { width: 22px; height: 22px; }
    .modal-card h3 { margin: 0; font-size: 1.1em; }
    .modal-card p { margin: 2px 0 0; font-size: 0.88em; line-height: 1.5; }
    .modal-card .modal-btn { grid-column: 1 / -1; width: 100%; margin-top: 12px; font-size: 1.02em; border-radius: 8px; }
    .card-call .modal-btn { order: 0; }
    .modal-card p.modal-call-alt { grid-column: 1 / -1; margin: 8px 0 0; text-align: center; }
    .modal-footer-text { margin-top: 14px; font-size: 0.8em; }
}

@media (prefers-reduced-motion: reduce) {
    #main-nav ul, .nav-backdrop, .modal-overlay, .modal-content { transition: none; }
}
