/* ── 리셋 & 기본 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:           #f0f2f5;
    --sidebar-bg:   #ffffff;
    --card-bg:      #ffffff;
    --accent:       #2563eb;
    --accent-light: #eff6ff;
    --accent-dark:  #1d4ed8;
    --text:         #111827;
    --text-sub:     #6b7280;
    --border:       #e5e7eb;
    --border-focus: #93c5fd;
    --error:        #dc2626;
    --radius:       12px;
    --radius-sm:    8px;
    --shadow-sm:    0 1px 3px rgba(0,0,0,.07);
    --shadow:       0 4px 16px rgba(0,0,0,.08);
    --shadow-md:    0 8px 32px rgba(0,0,0,.14);
    --t:            .18s ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:           #0f172a;
        --sidebar-bg:   #1e293b;
        --card-bg:      #1e293b;
        --accent:       #3b82f6;
        --accent-light: #1e3a5f;
        --accent-dark:  #2563eb;
        --text:         #f1f5f9;
        --text-sub:     #94a3b8;
        --border:       #334155;
        --border-focus: #60a5fa;
        --shadow-sm:    0 1px 3px rgba(0,0,0,.3);
        --shadow:       0 4px 16px rgba(0,0,0,.3);
        --shadow-md:    0 8px 32px rgba(0,0,0,.5);
    }
}

body {
    font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── 스플릿 레이아웃 ── */
.layout { display: flex; height: 100vh; overflow: hidden; }

/* 왼쪽 사이드바 */
.sidebar {
    width: 300px; min-width: 260px;
    display: flex; flex-direction: column;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.sidebar-logo {
    display: flex; flex-direction: column; align-items: center;
    gap: 8px; padding: 24px 20px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--sidebar-bg);
}
.sidebar-logo-img { width: 72px; height: 72px; object-fit: contain; border-radius: var(--radius-sm); }
.sidebar-logo-text { font-size: 18px; font-weight: 800; letter-spacing: -.4px; color: var(--accent); }
.sidebar-brand {
    font-size: 15px; font-weight: 800; letter-spacing: -.3px;
    padding: 20px 20px 18px;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
    background: var(--sidebar-bg); z-index: 1;
}
.search-section { padding: 16px 20px 0; }

/* 오른쪽 콘텐츠 */
.content { flex: 1; overflow-y: auto; padding: 36px 44px; min-width: 0; background: var(--bg); }

/* 패널 */
.panel-state { display: block; }
.panel-state.hidden { display: none !important; }

/* 초기 안내 */
.welcome-msg {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 65vh; gap: 14px; color: var(--text-sub); text-align: center; line-height: 1.8;
}
.welcome-icon { font-size: 54px; margin-bottom: 4px; }
.welcome-msg p { font-size: 15px; }

/* 진도 목록 헤더 */
.entries-header {
    display: flex; align-items: center; gap: 14px;
    margin-bottom: 24px; padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}
.entries-header .section-title { margin-bottom: 0; }

/* 뒤로 버튼 */
.back-btn {
    background: none; border: 1.5px solid var(--border); cursor: pointer;
    color: var(--text-sub); font-size: 13px; font-weight: 600;
    padding: 6px 12px; border-radius: var(--radius-sm); white-space: nowrap;
    transition: border-color var(--t), color var(--t), background var(--t);
    font-family: inherit;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); filter: none; }

.section-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; letter-spacing: -.3px; }

/* 모바일 */
@media (max-width: 700px) {
    .layout { flex-direction: column; height: auto; min-height: 100vh; }
    .sidebar { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid var(--border); }
    .content { padding: 20px 16px; }
}

/* ── 검색 ── */
.search-row { display: flex; gap: 8px; margin-bottom: 8px; }
.search-row button { white-space: nowrap; flex-shrink: 0; }

input[type="text"], input[type="number"], input[type="password"] {
    flex: 1; padding: 9px 13px;
    border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text);
    font-size: 14px; font-family: inherit; outline: none;
    transition: border-color var(--t), box-shadow var(--t);
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* ── select (학년도·학기) ── */
.select-input {
    flex: 1; width: 100%; padding: 9px 13px;
    border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text);
    font-size: 14px; font-family: inherit; outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    cursor: pointer;
    transition: border-color var(--t), box-shadow var(--t);
}
.select-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

button {
    padding: 9px 16px; border: none; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px; font-weight: 600;
    background: var(--border); color: var(--text);
    font-family: inherit; transition: background var(--t), filter var(--t);
}
button:hover { filter: brightness(.92); }

.btn-accent {
    background: var(--accent); color: #fff;
    width: 100%; padding: 10px 14px; margin-top: 14px; font-size: 14px;
}
.btn-accent:hover { background: var(--accent-dark); filter: none; }

/* ── 검색 결과 리스트 ── */
.result-list {
    list-style: none; border: 1.5px solid var(--border);
    border-radius: var(--radius-sm); overflow: hidden;
    margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
.result-list li { padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background var(--t); }
.result-list li:last-child { border-bottom: none; }
.result-list li:hover { background: var(--accent-light); }
.result-list .school-name { font-weight: 600; font-size: 13px; }
.result-list .school-sub { font-size: 12px; color: var(--text-sub); margin-top: 3px; line-height: 1.4; }

/* ── 선택된 학교 배지 ── */
.selected-school-badge {
    background: var(--accent-light); color: var(--accent);
    border: 1.5px solid var(--border-focus); border-radius: var(--radius-sm);
    padding: 10px 14px; font-weight: 700; font-size: 13px;
    margin-bottom: 12px; line-height: 1.4;
}

/* ── 학년반 섹션 ── */
#class-selector { border-top: 1px solid var(--border); padding: 16px 20px 20px; margin-top: 4px; }

.row { display: flex; gap: 10px; }
.field { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; font-weight: 700; color: var(--text-sub); text-transform: uppercase; letter-spacing: .5px; }

/* ── 과목 목록 ── */
.subject-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.subject-item {
    background: var(--card-bg); border: 1.5px solid var(--border);
    border-radius: var(--radius-sm); padding: 14px 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
.subject-item:hover { border-color: var(--accent); background: var(--accent-light); box-shadow: var(--shadow); }
.subject-item .subject-name { font-size: 15px; font-weight: 600; }
.subject-item .lock-icon { font-size: 14px; color: var(--text-sub); }

/* ── 진도 테이블 ── */
.entry-table {
    width: 100%; border-collapse: collapse;
    background: var(--card-bg); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow);
}
.entry-table th { background: var(--accent); color: #fff; padding: 12px 18px; text-align: left; font-size: 13px; font-weight: 600; letter-spacing: .2px; }
.entry-table td { padding: 13px 18px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; line-height: 1.6; }
.entry-table tr:last-child td { border-bottom: none; }
.entry-table tbody tr:nth-child(even) td { background: var(--bg); }
.entry-table tbody tr:hover td { background: var(--accent-light); transition: background var(--t); }
.date-cell { color: var(--text-sub); font-size: 13px; white-space: nowrap; }
.entry-table th:first-child, .date-cell { width: 1%; white-space: nowrap; }
.entry-table th:nth-child(2), .entry-table td:nth-child(2) { width: 100px; white-space: nowrap; }

/* ── 모달 ── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
    background: var(--card-bg); border-radius: var(--radius);
    padding: 28px 28px 24px; width: 320px;
    box-shadow: var(--shadow-md); border: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 14px;
}
.modal-card h3 { font-size: 16px; font-weight: 700; }
.modal-buttons { display: flex; gap: 8px; justify-content: flex-end; align-items: stretch; }
.modal-buttons button { min-width: 72px; padding: 9px 18px; width: auto; margin-top: 0; font-size: 13px; }

/* ── 상태 텍스트 ── */
.error-text { color: var(--error); font-size: 13px; margin-top: 4px; }
.loading { color: var(--text-sub); font-size: 14px; padding: 16px 0; display: flex; align-items: center; gap: 9px; }
.loading::before {
    content: ''; display: inline-block; width: 15px; height: 15px;
    border: 2px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { color: var(--text-sub); font-size: 14px; padding: 40px 0; text-align: center; }
.hidden { display: none !important; }