:root {
    --primary-color: #0d47a1;
    --accent-color: #2196f3;
    --bg-color: #f0f2f5;
    --text-main: #333;
    --text-light: #666;
    --success: #2e7d32;
    --danger: #d32f2f;
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
}

body {
    font-family: 'Noto Sans TC', sans-serif;
    background-color: var(--bg-color);
    margin: 0;
    padding: 0;
    color: var(--text-main);
    padding-bottom: calc(50px + var(--safe-bottom));
    -webkit-tap-highlight-color: transparent;
}

/* --- Header --- */
header {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: white;
    padding: calc(20px + var(--safe-top)) 16px 50px;
    padding-top: calc(30px + var(--safe-top));
    text-align: center;
    position: relative;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#logout-btn {
    position: absolute;
    top: calc(15px + var(--safe-top));
    right: 15px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    padding: 6px 12px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: all 0.3s;
    z-index: 10;
    min-height: 38px;
    min-width: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
#logout-btn:hover { background: rgba(255, 255, 255, 0.3); }

#refresh-btn {
    position: absolute;
    top: calc(15px + var(--safe-top));
    right: 78px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    border-radius: 15px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: all 0.3s;
    z-index: 10;
    min-height: 38px;
    min-width: 38px;
    padding: 6px 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
#refresh-btn:hover { background: rgba(255, 255, 255, 0.3); }

header h1 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.4;
    padding: 0 50px;
}
header p { margin: 5px 0 0; opacity: 0.9; font-size: 0.9rem; }

nav {
    background: white;
    padding: 10px 12px;
    margin: -40px auto 10px;
    max-width: 800px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    position: relative;
    z-index: 5;
}

.nav-btn {
    background: transparent;
    color: var(--text-light);
    border: none;
    padding: 12px 20px;
    cursor: pointer;
    font-weight: 500;
    font-size: 1rem;
    border-radius: 8px;
    transition: all 0.3s;
    min-height: 44px;
    flex: 1 1 0;
    min-width: 0;
    max-width: 260px;
}
.nav-btn:hover { background-color: #e3f2fd; color: var(--primary-color); }
.nav-btn.active { background-color: var(--primary-color); color: white; }

.container {
    max-width: 800px;
    margin: auto;
    padding: 0 15px;
}
.content-page { display: none; animation: fadeIn 0.5s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

#group-selection-menu h2 { margin-top: 5px; }

.condition-box {
    background-color: #fffde7;
    padding: 12px;
    margin-top: 10px;
    border-radius: 8px;
    border: 1px solid #fff59d;
    color: #555;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* --- Session Card --- */
.session-card {
    background: white; border-radius: 12px; padding: 20px; margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05); border-left: 5px solid var(--accent-color);
    transition: transform 0.2s; cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.session-card:hover { transform: translateY(-3px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); }

.session-info { flex: 1; padding-right: 20px; }
.session-info h4 { margin: 0 0 5px; font-size: 1.2rem; color: #2c3e50; }
.session-info small { color: #7f8c8d; background: #f1f2f6; padding: 2px 8px; border-radius: 4px; font-size: 0.8rem; }

.status-badge { display: inline-block; margin-top: 8px; font-weight: bold; font-size: 0.9rem; }
.status-available { color: var(--success); }
.status-full { color: var(--danger); }

.btn {
    background: var(--accent-color); color: white; border: none; padding: 10px 24px;
    border-radius: 50px; cursor: pointer; font-weight: bold;
    box-shadow: 0 4px 6px rgba(33, 150, 243, 0.3); transition: all 0.2s; white-space: nowrap;
    flex-shrink: 0;
}
.btn:hover { background: var(--primary-color); }
.btn:disabled { background: #bdbdbd; cursor: not-allowed; box-shadow: none; }

.btn-outline { background: transparent; border: 2px solid var(--primary-color); color: var(--primary-color); padding: 8px 20px; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; margin-left: 5px; }
.btn-danger { background: var(--danger); box-shadow: none; }
.btn-warn { background: #ff9800; }

.group-card, .doc-card, .inquiry-card {
    background: white; border-radius: 12px; padding: 20px; margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05); border-left: 5px solid var(--accent-color);
    transition: transform 0.2s; cursor: pointer;
}
.group-card:hover { transform: translateY(-3px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
.group-card.reg-disabled { cursor: not-allowed; opacity: 0.85; }
.group-card.reg-disabled:hover { transform: none; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
.group-card-status {
    margin-top: 10px; padding: 8px 12px; border-radius: 8px; font-weight: bold; text-align: center; font-size: 0.95rem;
}
.group-card-status.status-closed { background: #ffebee; color: #c62828; border: 1px solid #ef9a9a; }
.group-card-status.status-not-yet { background: #fff3e0; color: #e65100; border: 1px solid #ffcc80; }

/* 查詢結果卡片樣式 */
.inquiry-card { border-left-color: var(--success); cursor: default; }
.inquiry-row { display: flex; justify-content: space-between; margin-bottom: 8px; border-bottom: 1px dashed #eee; padding-bottom: 8px; }
.inquiry-row label { margin: 0; color: #888; font-size: 0.9rem; font-weight: normal; }
.inquiry-row span { font-weight: 500; color: #333; text-align: right; word-break: break-all; max-width: 60%; }

input, select {
    width: 100%;
    padding: 12px;
    margin: 8px 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-sizing: border-box;
    background-color: #f9f9f9;
    font-size: 16px;
}

label { font-size: 0.9rem; font-weight: bold; color: #555; margin-top: 10px; display: block; }

table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; }
th { background: #e3f2fd; color: var(--primary-color); padding: 15px; text-align: left; white-space: nowrap; }
td { padding: 15px; border-bottom: 1px solid #eee; min-width: 80px; }

/* Modal Styles */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7); z-index: 9999;
    justify-content: center; align-items: center; backdrop-filter: blur(3px);
}

.modal-content {
    background: white; width: 95%;
    max-width: 600px; /* Default width */
    height: 85vh;
    border-radius: 12px; padding: 25px; display: flex; flex-direction: column;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.modal-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #eee; padding-bottom: 15px; margin-bottom: 15px; }
.modal-body { overflow-y: auto; flex: 1; padding-right: 5px; -webkit-overflow-scrolling: touch; }
.close-modal {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: #666;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: -8px -8px -8px 0;
}

.grid-form { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.grid-form-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

#login-modal .modal-content { max-width: 400px; text-align: center; height: auto; }

/* 大專組樣式 */
.member-block {
    border: 1px solid #e3f2fd;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    position: relative;
}
.member-block h4 {
    margin-top: 0;
    color: var(--primary-color);
    border-bottom: 2px solid #e3f2fd;
    padding-bottom: 5px;
    margin-bottom: 10px;
}

/* 地址組合欄位樣式 */
.address-group { display: flex; flex-direction: column; gap: 5px; }
.address-row-1 { display: flex; gap: 10px; }
.address-row-1 select { flex: 1; }

@media (max-width: 600px) {
    header {
        padding: calc(16px + var(--safe-top)) 12px 45px;
        padding-top: calc(24px + var(--safe-top));
    }
    header h1 {
        font-size: 1.35rem;
        line-height: 1.35;
        padding: 0 10px 0 50px;
    }
    header p { font-size: 0.85rem; }

    #logout-btn {
        top: calc(12px + var(--safe-top));
        right: 10px;
        padding: 6px 10px;
        font-size: 0.8rem;
        min-height: 36px;
        min-width: 36px;
    }
    #refresh-btn {
        top: calc(12px + var(--safe-top));
        right: 66px;
        left: auto;
        padding: 6px 9px;
        font-size: 0.8rem;
        min-height: 36px;
        min-width: 36px;
    }

    nav {
        margin: -35px 12px 12px;
        padding: 10px;
        gap: 6px;
    }
    .nav-btn {
        flex: 1 1 100%;
        max-width: none;
        padding: 14px 12px;
        font-size: 0.95rem;
    }

    .container { padding: 0 12px; }

    .group-card,
    .inquiry-card,
    .session-card {
        padding: 16px;
        margin-bottom: 12px;
    }
    .group-card h3 { font-size: 1.1rem; }
    .condition-box { font-size: 0.9rem; padding: 10px; }

    .session-card {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        text-align: left;
    }
    .session-info { padding-right: 0; }
    .session-card .btn { align-self: flex-end; }

    .modal-overlay { padding: 10px; align-items: flex-start; overflow-y: auto; }
    .modal-content {
        width: 100%;
        max-width: none;
        height: auto;
        max-height: calc(100vh - 20px);
        padding: 20px 16px;
        margin: auto 0;
    }
    #login-modal .modal-content { height: auto; }
    .modal-body { padding-right: 0; }
    .modal-header h3, #reg-session-title { font-size: 1.1rem; }

    .grid-form,
    .grid-form-2 { grid-template-columns: 1fr; gap: 8px; }
    input, select {
        padding: 14px;
        font-size: 16px;
        min-height: 48px;
    }
    .btn {
        padding: 14px 20px;
        min-height: 48px;
        font-size: 1rem;
    }
    .btn-sm { padding: 10px 14px; min-height: 40px; }

    th, td { padding: 12px 10px; font-size: 0.9rem; }
    #page-time table { min-width: 520px; }
    #page-time .container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    .inquiry-row {
        flex-direction: column;
        gap: 2px;
        align-items: flex-start;
    }
    .inquiry-row span { max-width: 100%; text-align: left; }

    #session-container .view-header,
    #session-container div[style*="display:flex"] {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    #session-container h2, #list-title { font-size: 1.2rem; }
    #session-container .btn { align-self: flex-start; }
}
