/* ==================== textbook-manager.css ==================== */
/* 교재제작 화면과 동일한 레이아웃 스타일 */

/* 화면 전체 레이아웃 */
#textbookManagerScreen {
    width: 100%;
    height: 100vh;
}

#textbookManagerScreen.active {
    display: flex;
}

/* ========== 좌측 사이드바 (교재제작과 동일) ========== */
#textbookManagerScreen .sidebar {
    width: 260px;
    background: var(--menu-bg);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    height: 100vh;
    transition: background-color 0.3s ease;
}

#textbookManagerScreen .sidebar-header {
    padding: 18px;
    background: var(--primary);
    color: white;
    transition: background-color 0.3s ease;
}

#textbookManagerScreen .sidebar-header h2 {
    font-size: 18px;
    margin: 0;
}

#textbookManagerScreen .sidebar-content {
    flex: 1;
    padding: 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#textbookManagerScreen .sidebar-footer {
    margin-top: auto;
    padding: 15px 18px 18px;
    border-top: 1px solid rgba(155, 136, 219, 0.2);
}

/* ========== 가운데 작업 영역 (교재제작과 동일) ========== */
#textbookManagerScreen .main-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    gap: 16px;
    max-height: 100vh;
}

#textbookManagerScreen .calendar-section {
    flex: 1;
    background: var(--white);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

/* ========== 우측 패널 (빌드업과 동일) ========== */
#textbookManagerScreen .items-section {
    width: 260px;
    background: var(--white);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 40px);
}

/* ========== 학년 탭 (사이드바 내부) ========== */
.textbook-grade-tabs {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.grade-tab-btn {
    width: 100%;
    padding: 12px 8px;
    border: none;
    background: var(--surface);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.grade-tab-btn:hover {
    background: var(--surface-muted);
    color: var(--primary);
    transform: translateX(2px);
}

.grade-tab-btn.active {
    background: var(--primary);
    color: white;
}

/* ========== 교재 목록 (우측 패널) ========== */
.textbook-list {
    flex: 1;
    overflow-y: auto;
}

.textbook-item {
    padding: 12px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.textbook-item:hover {
    background: var(--surface-muted);
    border-color: var(--primary);
}

.textbook-item.selected {
    background: var(--primary);
    border-color: var(--primary);
}

.textbook-item.selected .textbook-name,
.textbook-item.selected .textbook-count,
.textbook-item.selected .textbook-info {
    color: white;
}

.textbook-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.textbook-count {
    font-size: 11px;
    color: var(--text-muted);
}

.textbook-info {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
}

/* ========== 작업 영역 헤더 ========== */
.textbook-work-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--subtle);
}

.textbook-work-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}

.textbook-work-actions {
    display: flex;
    gap: 8px;
}

.textbook-work-actions button {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.textbook-work-actions .btn-save {
    background: var(--primary);
    color: white;
}

.textbook-work-actions .btn-save:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.textbook-work-actions .btn-delete {
    background: #FFE8EA;
    color: #DC5F6F;
}

.textbook-work-actions .btn-delete:hover {
    background: #FFD5D9;
    transform: translateY(-1px);
}

.textbook-work-actions .btn-copy {
    background: #E8F5E9;
    color: #2E7D32;
}

.textbook-work-actions .btn-copy:hover {
    background: #C8E6C9;
    transform: translateY(-1px);
}

/* ========== 폼 그룹 ========== */
.textbook-form-group {
    margin-bottom: 20px;
}

.textbook-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.textbook-form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    transition: all 0.2s;
}

.textbook-form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(106, 59, 255, 0.1);
}

.textbook-form-group textarea {
    width: 100%;
    min-height: 400px;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    font-family: '맑은 고딕', 'Malgun Gothic', 'Segoe UI', sans-serif;
    line-height: 1.7;
    background: var(--surface);
    color: #333;
    transition: all 0.2s;
    resize: vertical;
}

.textbook-form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(106, 59, 255, 0.1);
}

.textbook-type-count {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ========== 교재 편집 2단 레이아웃 ========== */
.textbook-edit-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    align-items: start;
}

.textbook-edit-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.textbook-edit-right {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.textbook-form-group-flex {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.textbook-form-group-flex textarea {
    flex: 1;
    min-height: 500px;
}

/* ========== 컴팩트 버튼 그룹 ========== */
.textbook-compact-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.textbook-compact-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--surface);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    flex: 1;
    min-width: 0;
    text-align: center;
}

.textbook-compact-btn:hover {
    border-color: var(--primary);
    background: var(--surface-muted);
    transform: translateY(-1px);
}

.textbook-compact-btn input[type="radio"] {
    display: none;
}

.textbook-compact-btn span {
    display: block;
    text-align: center;
    width: 100%;
}

.textbook-compact-btn input[type="radio"]:checked + span {
    font-weight: 600;
    color: white;
}

.textbook-compact-btn input[type="radio"]:checked ~ span {
    font-weight: 600;
    color: white;
}

/* 체크된 상태 스타일 - JavaScript로 클래스 추가하거나 :has() 사용 */
.textbook-compact-btn.checked {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.textbook-compact-btn.checked span {
    color: white;
    font-weight: 600;
}

/* :has() 지원 브라우저용 (폴백) */
@supports selector(:has(*)) {
    .textbook-compact-btn:has(input[type="radio"]:checked) {
        border-color: var(--primary);
        background: var(--primary);
        color: white;
    }
    
    .textbook-compact-btn:has(input[type="radio"]:checked) span {
        color: white;
        font-weight: 600;
    }
}

/* ========== 학년 옵션 그리드 ========== */
.textbook-grade-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
}

/* ========== 고등학교 학년 선택 (한 줄) ========== */
.textbook-grade-options-high {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
}

.textbook-grade-option-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--surface);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    flex: 1;
}

.textbook-grade-option-btn:hover {
    border-color: var(--primary);
    background: var(--surface-muted);
    transform: translateY(-1px);
}

.textbook-grade-option-btn.checked {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    font-weight: 600;
}

.textbook-grade-options label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--surface);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.textbook-grade-options label:hover {
    border-color: var(--primary);
    background: var(--surface-muted);
    transform: translateY(-1px);
}

.textbook-grade-options label input[type="radio"] {
    margin: 0;
    margin-right: 6px;
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.textbook-grade-options label.checked {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    font-weight: 600;
}

.textbook-grade-options label.checked span,
.textbook-grade-options label.checked * {
    color: white !important;
}

/* :has() 지원 브라우저용 (폴백) */
@supports selector(:has(*)) {
    .textbook-grade-options label:has(input[type="radio"]:checked) {
        border-color: var(--primary);
        background: var(--primary);
        color: white;
        font-weight: 600;
    }
    
    .textbook-grade-options label:has(input[type="radio"]:checked) span,
    .textbook-grade-options label:has(input[type="radio"]:checked) * {
        color: white !important;
    }
}

/* ========== 반응형 ========== */
@media (max-width: 1200px) {
    .textbook-edit-layout {
        grid-template-columns: 280px 1fr;
        gap: 20px;
    }
}

@media (max-width: 900px) {
    .textbook-edit-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .textbook-edit-left {
        order: 2;
    }
    
    .textbook-edit-right {
        order: 1;
    }
    
    .textbook-form-group-flex textarea {
        min-height: 400px;
    }
}

/* ========== 우측 패널 헤더 ========== */
.items-header {
    font-size: 16px;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--subtle);
}

/* ========== 우측 패널 액션 ========== */
.items-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--subtle);
}

.items-actions button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    background: var(--primary);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.items-actions button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}
/* ========== 우측 패널 버튼 (학생관리와 동일) ========== */
#textbookManagerScreen .sidebar-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--subtle);
}

#textbookManagerScreen .sidebar-buttons .btn-s {
    padding: 8px 6px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    white-space: nowrap;
    font-weight: 500;
}

#textbookManagerScreen .sidebar-buttons .btn-s.edit {
    background: #E8E2F5;
    color: var(--primary);
}

#textbookManagerScreen .sidebar-buttons .btn-s.edit:hover {
    background: #DDD5ED;
    transform: translateY(-1px);
}

#textbookManagerScreen .sidebar-buttons .btn-s.delete {
    background: #FFE8EA;
    color: #DC5F6F;
}

#textbookManagerScreen .sidebar-buttons .btn-s.delete:hover {
    background: #FFD5D9;
    transform: translateY(-1px);
}

/* ========== 유형매칭툴 모드 ========== */
#textbookToolMode {
    height: calc(100vh - 40px);
    max-height: calc(100vh - 40px);
    overflow: hidden;
    flex-direction: column;
}

#textbookToolMode .editor-tool-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
    max-height: 100%;
    align-items: stretch;
    overflow: hidden;
}

#textbookToolMode .editor-tool-left,
#textbookToolMode .editor-tool-right {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#textbookToolMode .editor-tool-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    flex: 1;
}

#textbookToolMode .editor-tool-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    display: block;
}

#textbookToolMode .editor-tool-stats {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

#textbookToolMode .editor-tool-textarea {
    flex: 1;
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    line-height: 1.6;
    background: var(--surface);
    color: #333;
    resize: none;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

#textbookToolMode .editor-tool-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(106, 59, 255, 0.1);
}

#textbookToolMode .editor-tool-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}

#textbookToolMode .editor-tool-header-label-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

#textbookToolMode .editor-tool-actions {
    display: flex;
    gap: 6px;
}

#textbookToolMode .editor-tool-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    background: var(--surface);
    min-height: 0;
}

#textbookToolMode .editor-tool-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.6;
}

#textbookToolMode .editor-tool-tree-item {
    margin-bottom: 4px;
}

#textbookToolMode .editor-tool-tree-item-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}

#textbookToolMode .editor-tool-tree-item-label:hover {
    background: var(--surface-muted);
}

#textbookToolMode .editor-tool-tree-item-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

#textbookToolMode .editor-tool-tree-item-label .tree-icon {
    font-size: 12px;
    color: var(--text-muted);
    width: 16px;
    text-align: center;
}

#textbookToolMode .editor-tool-tree-item-label .tree-text {
    font-size: 13px;
    color: var(--text);
}

#textbookToolMode .editor-tool-tree-item-label.major .tree-text {
    font-weight: 700;
    color: var(--primary);
}

#textbookToolMode .editor-tool-tree-item-label.middle .tree-text {
    font-weight: 600;
}

#textbookToolMode .editor-tool-tree-item-label.minor .tree-text {
    font-weight: 500;
}

#textbookToolMode .editor-tool-tree-item-label.type {
    padding-left: 20px;
}

#textbookToolMode .editor-tool-tree-item-label.type .tree-text {
    font-weight: 400;
    font-size: 12px;
    color: var(--text-muted);
}

#textbookToolMode .editor-tool-tree-children {
    margin-left: 20px;
    margin-top: 4px;
}

#textbookToolMode .btn-copy-selected {
    padding: 6px 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

#textbookToolMode .btn-copy-selected:hover:not(:disabled) {
    background: var(--primary-dark);
}

#textbookToolMode .btn-copy-selected:disabled {
    background: var(--surface-muted);
    color: var(--text-muted);
    cursor: not-allowed;
}

#textbookToolMode .btn-select-action {
    padding: 6px 10px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

#textbookToolMode .btn-select-action:hover {
    background: var(--surface-muted);
    border-color: var(--primary);
}

.btn-toggle-editor-tool {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-toggle-editor-tool:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

/* ========== 매칭 결과 상황판 ========== */
.match-status-panel {
    margin: 12px 0;
    padding: 12px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 12px;
}

.match-status-header {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #e0e0e0;
}

.match-status-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.match-stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.match-stat-label {
    color: #666;
    font-size: 11px;
}

.match-stat-value {
    font-weight: 600;
    font-size: 12px;
}

.match-stat-value.success {
    color: #2e7d32;
}

.match-stat-value.warning {
    color: #f57c00;
}

.match-stat-value.error {
    color: #d32f2f;
}

.match-status-details {
    max-height: 200px;
    overflow-y: auto;
}

.match-detail-section {
    margin-bottom: 12px;
}

.match-detail-section:last-child {
    margin-bottom: 0;
}

.match-detail-title {
    font-weight: 600;
    font-size: 11px;
    margin-bottom: 6px;
    color: #333;
}

.match-detail-title.success {
    color: #2e7d32;
}

.match-detail-list {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.match-detail-item {
    display: flex;
    gap: 6px;
    padding: 4px 0;
    font-size: 11px;
    line-height: 1.4;
    border-bottom: 1px solid #f0f0f0;
}

.match-detail-item:last-child {
    border-bottom: none;
}

.match-detail-number {
    color: #999;
    min-width: 20px;
    flex-shrink: 0;
}

.match-detail-text {
    color: #333;
    flex: 1;
}