* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --sidebar-width: 240px;
}

body {
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

a { text-decoration: none; color: inherit; }

/* ── 로그인 ── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
}

.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .icon { font-size: 48px; }
.login-logo h1 { font-size: 22px; font-weight: 700; margin-top: 8px; color: var(--text); }
.login-logo p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--primary); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: white; width: 100%; padding: 12px; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1.5px solid #fecaca; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; display: none; }

/* ── 레이아웃 ── */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: #1e293b;
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.sidebar-logo {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo .logo-icon { font-size: 28px; }
.sidebar-logo h2 { font-size: 15px; font-weight: 700; margin-top: 4px; }
.sidebar-logo p { font-size: 11px; color: rgba(255,255,255,0.5); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section { padding: 8px 16px 4px; font-size: 10px; font-weight: 700; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 1px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    font-size: 13.5px;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-item.active { background: rgba(37,99,235,0.3); color: white; border-left-color: var(--primary); }
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: rgba(255,255,255,0.5); }
.btn-logout { width: 100%; background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.7); border: none; padding: 8px; border-radius: 6px; cursor: pointer; font-size: 12px; transition: all 0.2s; }
.btn-logout:hover { background: rgba(255,255,255,0.15); color: white; }

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.top-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky; top: 0; z-index: 50;
}
.top-bar h1 { font-size: 18px; font-weight: 700; }
.top-bar-actions { display: flex; gap: 8px; }

.page-content { padding: 28px; flex: 1; }

/* ── 카드 ── */
.card {
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 700; }

/* ── 대시보드 통계 ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-icon { font-size: 28px; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── 프로토콜 목록 ── */
.filter-bar { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-btn {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}
.filter-btn:hover, .filter-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    outline: none;
}
.search-input:focus { border-color: var(--primary); }

.protocol-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.protocol-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.protocol-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.08); border-color: var(--primary); transform: translateY(-1px); }

.protocol-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tag {
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.tag-body { background: #eff6ff; color: #2563eb; }
.tag-phase { background: #f0fdf4; color: #16a34a; }
.tag-level { background: #fef9c3; color: #92400e; }
.tag-target { background: #f5f3ff; color: #7c3aed; }

.protocol-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.protocol-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.protocol-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }

/* ── 프로토콜 상세 ── */
.detail-header { margin-bottom: 24px; }
.detail-tags { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.detail-title { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.detail-meta { font-size: 13px; color: var(--text-muted); }

.detail-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; }

.section-title { font-size: 14px; font-weight: 700; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid var(--primary); display: inline-block; }

.exercise-list { list-style: none; }
.exercise-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.exercise-item:last-child { border-bottom: none; }
.exercise-num {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
    flex-shrink: 0;
}
.exercise-name { font-weight: 600; margin-bottom: 3px; }
.exercise-detail { font-size: 12px; color: var(--text-muted); }

.note-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.note-item { background: var(--bg); border-radius: 8px; padding: 12px; }
.note-author { font-size: 12px; font-weight: 600; color: var(--primary); margin-bottom: 4px; }
.note-text { font-size: 13px; line-height: 1.5; }
.note-time { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.note-input { width: 100%; padding: 10px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 13px; resize: vertical; min-height: 70px; outline: none; font-family: inherit; }
.note-input:focus { border-color: var(--primary); }

/* ── 의사결정 ── */
.decision-tree { display: flex; flex-direction: column; gap: 20px; }
.decision-step {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
}
.step-num { font-size: 12px; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.step-question { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.step-options { display: flex; flex-direction: column; gap: 8px; }
.step-option {
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
}
.step-option:hover { border-color: var(--primary); background: #eff6ff; }
.step-option.selected { border-color: var(--primary); background: #eff6ff; color: var(--primary); font-weight: 600; }

.result-card {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border: 2px solid var(--primary);
    border-radius: 12px;
    padding: 24px;
}
.result-label { font-size: 12px; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.result-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.result-desc { font-size: 14px; color: var(--text-muted); line-height: 1.6; }

/* ── 모달 ── */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
    background: white;
    border-radius: 16px;
    padding: 32px;
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    background: white;
}
select:focus { border-color: var(--primary); }
textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    resize: vertical;
    font-family: inherit;
    min-height: 80px;
}
textarea:focus { border-color: var(--primary); }

.exercise-builder { margin-top: 8px; }
.exercise-builder-item { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.exercise-builder-item input { flex: 1; }
.btn-add-exercise { background: none; border: 1.5px dashed var(--border); border-radius: 8px; padding: 8px; width: 100%; cursor: pointer; color: var(--text-muted); font-size: 13px; transition: all 0.2s; }
.btn-add-exercise:hover { border-color: var(--primary); color: var(--primary); }

/* ── 빈 상태 ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ── 로딩 ── */
.loading { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-muted); gap: 8px; }

/* ── 알림 토스트 ── */
.toast {
    position: fixed;
    bottom: 24px; right: 24px;
    background: #1e293b;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    z-index: 9999;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ── 반응형 ── */
@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
    .sidebar { transform: translateX(-100%); }
    .main-content { margin-left: 0; }
}
