/* ===================================================
   學群分流選志願系統 — 全域樣式
   =================================================== */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;700;900&display=swap');

/* --- CSS 變數 --- */
:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --accent: #f59e0b;
    --accent-light: #fbbf24;
    --success: #10b981;
    --success-light: #34d399;
    --danger: #ef4444;
    --danger-light: #f87171;
    --warning: #f59e0b;

    --bg-gradient-start: #0f0c29;
    --bg-gradient-mid: #302b63;
    --bg-gradient-end: #24243e;

    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.15);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Noto Sans TC', sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-mid), var(--bg-gradient-end));
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem 1rem;
    overflow-x: hidden;
}

/* 背景動態光圈 */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.12) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(245, 158, 11, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 50% 80%, rgba(16, 185, 129, 0.08) 0%, transparent 50%);
    animation: bgFloat 20s ease-in-out infinite;
    z-index: -1;
}

@keyframes bgFloat {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(2%, -2%) rotate(1deg); }
    66% { transform: translate(-1%, 1%) rotate(-1deg); }
}

/* --- 容器 --- */
.container {
    width: 100%;
    max-width: 480px;
    animation: fadeInUp 0.6s ease-out;
}

.container.admin-container {
    max-width: 900px;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- 毛玻璃卡片 --- */
.card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--glass-shadow);
    transition: var(--transition);
}

.card + .card {
    margin-top: 1.5rem;
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
}

/* --- 標題 --- */
.app-title {
    text-align: center;
    margin-bottom: 2rem;
}

.app-title h1 {
    font-size: 2rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-light), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 2px;
    margin-bottom: 0.5rem;
}

.app-title .subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 300;
}

.phase-badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    margin-top: 0.5rem;
    letter-spacing: 1px;
}

.phase-badge.pre {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(251, 191, 36, 0.2));
    color: var(--accent-light);
    border: 1px solid rgba(245, 158, 11, 0.4);
}

.phase-badge.official {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.3), rgba(52, 211, 153, 0.2));
    color: var(--success-light);
    border: 1px solid rgba(16, 185, 129, 0.4);
}

/* --- 表單 --- */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    letter-spacing: 0.5px;
}

.form-row {
    display: flex;
    gap: 0.75rem;
}

.form-row .form-group {
    flex: 1;
}

input, select {
    width: 100%;
    padding: 0.8rem 1rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}

input::placeholder {
    color: var(--text-muted);
}

input:focus, select:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* --- File input 專屬樣式 --- */
input[type="file"] {
    padding: 0.5rem 0.8rem;
    line-height: normal;
}

input[type="file"]::file-selector-button {
    margin-right: 1rem;
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: var(--radius-xs);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

input[type="file"]::file-selector-button:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --- 按鈕 --- */
.btn {
    width: 100%;
    padding: 0.85rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.5s, height 0.5s;
}

.btn:active::after {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(16, 185, 129, 0.5);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #dc2626);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.3);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    width: auto;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* --- 分隔線 --- */
.separator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.separator::before, .separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--glass-border);
}

/* --- 志願排序列表 --- */
.wish-list {
    list-style: none;
}

.wish-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.2rem;
    margin-bottom: 0.6rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: var(--transition);
    user-select: none;
}

.wish-item:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--primary-light);
    transform: translateX(4px);
}

.wish-item:active {
    cursor: grabbing;
}

.wish-item.sortable-chosen {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--primary);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
    transform: scale(1.02);
}

.wish-item.sortable-ghost {
    opacity: 0.3;
}

.wish-rank {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-weight: 900;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.wish-name {
    flex: 1;
    font-weight: 500;
    font-size: 1rem;
}

.wish-handle {
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: grab;
}

/* --- 訊息提示 --- */
.message {
    padding: 0.8rem 1rem;
    border-radius: var(--radius-xs);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    animation: fadeInUp 0.3s ease-out;
}

.message.error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger-light);
}

.message.success {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success-light);
}

.message.info {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: var(--primary-light);
}

/* --- 完成畫面 --- */
.done-icon {
    font-size: 4rem;
    text-align: center;
    margin-bottom: 1rem;
    animation: bounceIn 0.6s ease-out;
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.done-list {
    list-style: none;
    margin: 1.5rem 0;
}

.done-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-xs);
    margin-bottom: 0.4rem;
    font-size: 0.95rem;
}

.done-list .rank {
    color: var(--accent-light);
    font-weight: 900;
    min-width: 2rem;
}

/* --- 隱藏 / 顯示 --- */
.hidden {
    display: none !important;
}

/* --- 螢幕提示 (系統未開放) --- */
.system-closed-overlay {
    text-align: center;
    padding: 3rem 2rem;
}

.system-closed-overlay .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.system-closed-overlay h2 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

.system-closed-overlay p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ===================================================
   管理員後台樣式
   =================================================== */

/* 分頁導航 */
.admin-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0.35rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
}

.admin-tab {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: calc(var(--radius) - 4px);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.admin-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

.admin-tab.active {
    color: var(--text-primary);
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.2);
}

/* 分頁面板 */
.tab-panel {
    display: none;
    animation: tabFadeIn 0.35s ease-out;
}

.tab-panel.active {
    display: block;
}

@keyframes tabFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 600px) {
    .admin-tabs {
        flex-direction: column;
    }
}

.admin-section {
    margin-bottom: 1.5rem;
}

.admin-section h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.admin-section h2 .icon {
    font-size: 1.2rem;
}

/* 設定表格 */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 600px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

/* 學生列表 */
.student-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 1rem;
}

.student-table th,
.student-table td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.student-table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.student-table tr:hover td {
    background: rgba(255, 255, 255, 0.04);
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-dot.filled {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.status-dot.unfilled {
    background: var(--danger);
    box-shadow: 0 0 6px var(--danger);
}

/* 匯出按鈕區 */
.export-buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.export-buttons .btn {
    flex: 1;
    min-width: 200px;
}

/* 管理員登入表單 */
.admin-login {
    max-width: 420px;
    margin: 0 auto;
}

/* 頂部導覽列 */
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.admin-header h1 {
    font-size: 1.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-light), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* 統計卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 1.2rem;
    text-align: center;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-3px);
    border-color: rgba(255, 255, 255, 0.25);
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-card .stat-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* 載入動畫 */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- 響應式 --- */
@media (max-width: 500px) {
    body {
        padding: 1rem 0.5rem;
    }

    .card {
        padding: 1.5rem;
        border-radius: var(--radius-sm);
    }

    .app-title h1 {
        font-size: 1.5rem;
    }

    .wish-item {
        padding: 0.8rem 1rem;
    }
}
