@import url("//fonts.googleapis.com/earlyaccess/notosanskr.css");

/* ===== Design Tokens ===== */
:root {
    --c-primary: #009956;
    --c-primary-dark: #005e35;
    --c-primary-soft: #e6f4ec;
    --c-bg: #f3f5f7;
    --c-surface: #ffffff;
    --c-border: #e5e7eb;
    --c-border-soft: #f0f2f4;
    --c-text: #111827;
    --c-text-2: #4b5563;
    --c-text-3: #9ca3af;
    --c-danger: #dc2626;
    --c-danger-soft: #fee2e2;
    --c-success: #059669;
    --c-success-soft: #d1fae5;
    --c-warning: #d97706;
    --shadow-sm: 0 1px 2px rgba(16,24,40,0.05);
    --shadow-md: 0 4px 12px rgba(16,24,40,0.06), 0 1px 3px rgba(16,24,40,0.04);
    --shadow-lg: 0 20px 40px rgba(16,24,40,0.18);
    --radius: 8px;
    --radius-sm: 6px;
    --sidebar-w: 240px;
}

/* ===== Reset & Base ===== */
* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    font-size: 13px;
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; color: var(--c-text); }

/* ===== Layout ===== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: linear-gradient(180deg, #0a4d2c 0%, var(--c-primary-dark) 100%);
    color: #d2e9df;
    padding: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar .brand {
    padding: 22px 22px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.2px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sidebar .brand::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--c-primary);
    box-shadow: 0 0 0 4px rgba(0,153,86,0.25);
}
.sidebar .nav { padding: 14px 10px; flex: 1; }
.sidebar .nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    color: #d2e9df;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    transition: background-color .15s ease, color .15s ease;
    margin-bottom: 2px;
}
.sidebar .nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar .nav a.active {
    background: rgba(255,255,255,0.14);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--c-primary);
}
.sidebar .nav a::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.55;
    flex-shrink: 0;
}
.sidebar .foot {
    padding: 14px 22px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 11px;
    color: rgba(210,233,223,0.5);
}

.main {
    flex: 1;
    padding: 32px 36px;
    overflow: auto;
    min-width: 0;
}

/* ===== Page Title ===== */
.page-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 22px;
    color: var(--c-text);
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-title::before {
    content: "";
    width: 4px;
    height: 18px;
    background: var(--c-primary);
    border-radius: 2px;
}

/* ===== Toolbar ===== */
.toolbar {
    background: var(--c-surface);
    padding: 14px 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    border: 1px solid var(--c-border);
}

.search-input {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    width: 240px;
    font-size: 13px;
    font-family: inherit;
    background: var(--c-surface);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.search-input:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(0,153,86,0.12);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    line-height: 1;
    transition: background-color .15s ease, transform .05s ease, box-shadow .15s ease;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    background: var(--c-primary);
    color: #fff;
    box-shadow: 0 1px 2px rgba(0,153,86,0.25);
}
.btn-primary:hover { background: #008149; }
.btn-secondary {
    background: var(--c-surface);
    color: var(--c-text-2);
    border-color: var(--c-border);
}
.btn-secondary:hover { background: #f8f9fa; border-color: #d1d5db; }
.btn-danger {
    background: var(--c-danger);
    color: #fff;
    box-shadow: 0 1px 2px rgba(220,38,38,0.25);
}
.btn-danger:hover { background: #b91c1c; }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12px; }

/* ===== Tables ===== */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--c-surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--c-border);
    font-size: 13px;
}
thead th {
    background: #fafbfc;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--c-text-2);
    font-size: 12px;
    letter-spacing: 0.2px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--c-border);
    white-space: nowrap;
}
tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--c-border-soft);
    color: var(--c-text);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color .12s ease; }
tbody tr:hover { background: #fafbfc; }

.table-loading, .table-empty {
    text-align: center;
    padding: 40px 16px;
    color: var(--c-text-3);
    font-size: 13px;
}

/* ===== Badges (사용여부 등) ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}
.badge-on { background: var(--c-success-soft); color: var(--c-success); }
.badge-off { background: #f3f4f6; color: var(--c-text-3); }

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    inset: 0;
    background: rgba(15,23,42,0.45);
    backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal.show { display: flex; animation: fadeIn .15s ease; }
.modal-content {
    background: var(--c-surface);
    padding: 24px 26px;
    border-radius: var(--radius);
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp .2s ease;
}
.modal-content h3 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--c-border-soft);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Forms ===== */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--c-text-2);
    font-size: 12px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    color: var(--c-text);
    background: var(--c-surface);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-group textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(0,153,86,0.12);
}

/* ===== Messages ===== */
.msg {
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 13px;
    border: 1px solid transparent;
}
.msg.error { background: var(--c-danger-soft); color: #991b1b; border-color: #fecaca; }
.msg.success { background: var(--c-success-soft); color: #065f46; border-color: #a7f3d0; }

/* ===== Action buttons in table rows ===== */
td .btn + .btn { margin-left: 6px; }

/* ===== Dashboard cards (홈에서 사용) ===== */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.stat-card .label {
    color: var(--c-text-3);
    font-size: 12px;
    margin-bottom: 8px;
    letter-spacing: 0.2px;
}
.stat-card .value {
    font-size: 24px;
    font-weight: 700;
    color: var(--c-text);
    line-height: 1.2;
}
.stat-card .meta {
    margin-top: 6px;
    font-size: 11px;
    color: var(--c-text-3);
}

/* ===== 대시보드 ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.kpi-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease;
}
.kpi-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.kpi-label {
    color: var(--c-text-3);
    font-size: 11px;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
}
.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--c-text);
    line-height: 1.15;
    letter-spacing: -0.5px;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.kpi-value .unit {
    font-size: 13px;
    font-weight: 500;
    color: var(--c-text-3);
    letter-spacing: 0;
}
.kpi-meta {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--c-text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-meta b { color: var(--c-text-2); font-weight: 600; }

.panel-grid {
    display: grid;
    gap: 16px;
    margin-bottom: 16px;
}
.panel-grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 980px) { .panel-grid.two { grid-template-columns: 1fr; } }

.panel-head .legend { display: flex; gap: 12px; font-size: 11px; color: var(--c-text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

.chart-wrap { width: 100%; min-height: 200px; }

/* 가로 막대 (분포) */
.hbar-list { display: flex; flex-direction: column; gap: 16px; }
.hbar-row {
    display: grid;
    grid-template-columns: 160px 1fr 110px;
    gap: 14px;
    align-items: center;
    font-size: 13px;
    line-height: 1.4;
    padding: 4px 0;
}
.hbar-label {
    color: var(--c-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}
.hbar-track {
    height: 10px;
    background: #f3f4f6;
    border-radius: 999px;
    overflow: hidden;
}
.hbar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--c-primary), #00c46d);
    border-radius: 999px;
    transition: width .3s ease;
}
.hbar-value {
    text-align: right;
    font-weight: 600;
    color: var(--c-text);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    white-space: nowrap;
}
.hbar-value .text-muted { font-weight: 400; margin-left: 2px; }
.hbar-row.clickable { cursor: pointer; border-radius: var(--radius-sm); padding: 6px 8px; margin: 0 -8px; }
.hbar-row.clickable:hover { background: #fafbfc; }

/* ===== 학습용 데이터 수집 (training.html) ===== */
.tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.tabs .tab {
    background: transparent;
    border: 1px solid transparent;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--c-text-2);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.tabs .tab:hover { background: var(--c-border-soft); color: var(--c-text); }
.tabs .tab.active {
    background: var(--c-primary-soft);
    border-color: #c8e6d4;
    color: var(--c-primary-dark);
}
.export-group { display: flex; gap: 6px; flex-wrap: wrap; }

.fb-up   { color: var(--c-success); font-size: 16px; }
.fb-down { color: var(--c-danger);  font-size: 16px; }

.cell-rev {
    margin-top: 5px;
    font-size: 11.5px;
    color: var(--c-text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.rev-pill {
    display: inline-block;
    background: var(--c-primary-soft);
    color: var(--c-primary-dark);
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 600;
    margin-right: 6px;
    letter-spacing: 0.2px;
}

.train-textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.6;
    color: var(--c-text);
    background: var(--c-surface);
    resize: vertical;
    min-height: 80px;
    transition: border-color .15s ease, box-shadow .15s ease;
    font-feature-settings: "tnum";
}
.train-textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(0,153,86,0.12);
}
.cm-preview-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}

.status-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    background: #fafbfc;
    border: 1px solid var(--c-border-soft);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}
.status-options label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--c-text);
    cursor: pointer;
    user-select: none;
    padding: 4px 8px;
    border-radius: 4px;
}
.status-options label:hover { background: var(--c-surface); }
.status-options input[type="radio"] { accent-color: var(--c-primary); }

/* ===== AI 채팅 통계 (chats.html) ===== */
.chat-filters {
    display: flex;
    gap: 12px;
    padding: 14px 20px;
    border-top: 1px solid var(--c-border-soft);
    border-bottom: 1px solid var(--c-border-soft);
    background: #fafbfc;
    flex-wrap: wrap;
    align-items: flex-end;
}
.chat-filters .form-group { margin-bottom: 0; min-width: 140px; flex: 1; }
.chat-filters input[type="text"],
.chat-filters input[type="date"],
.chat-filters select {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    background: var(--c-surface);
    color: var(--c-text);
}
.chat-filters input:focus, .chat-filters select:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(0,153,86,0.12);
}
.chat-filters .btn { margin-bottom: 0; }

.cell-q {
    max-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--c-text);
}

/* 페이지네이션 */
.pagination {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 14px 16px;
    border-top: 1px solid var(--c-border-soft);
    flex-wrap: wrap;
}
.pg-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--c-border);
    background: var(--c-surface);
    border-radius: var(--radius-sm);
    color: var(--c-text-2);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
}
.pg-btn:hover:not(:disabled) { background: #f3f4f6; }
.pg-btn.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.pg-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* 채팅 상세 모달 본문 */
.cm-body {
    padding: 18px 24px;
    overflow: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
}
.cm-block { width: 100%; min-width: 0; }
.cm-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.4px;
    color: var(--c-text-3);
    text-transform: uppercase;
    margin-bottom: 6px;
}
.cm-content {
    background: #fafbfc;
    border: 1px solid var(--c-border-soft);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.65;
    color: var(--c-text);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 360px;
    overflow: auto;
}
.cm-question { border-left: 3px solid var(--c-primary); background: var(--c-primary-soft); }
.cm-answer   { border-left: 3px solid #2563eb; background: #eff6ff; white-space: normal; }

/* ===== 마크다운 본문 (cm-answer) ===== */
.cm-answer h1, .cm-answer h2, .cm-answer h3, .cm-answer h4, .cm-answer h5, .cm-answer h6 {
    margin: 14px 0 8px;
    font-weight: 700;
    color: var(--c-text);
    line-height: 1.35;
}
.cm-answer h1 { font-size: 18px; }
.cm-answer h2 { font-size: 16px; }
.cm-answer h3 { font-size: 14.5px; }
.cm-answer h4, .cm-answer h5, .cm-answer h6 { font-size: 13.5px; }
.cm-answer h1:first-child, .cm-answer h2:first-child, .cm-answer h3:first-child { margin-top: 0; }
.cm-answer p { margin: 0 0 10px; line-height: 1.7; }
.cm-answer p:last-child { margin-bottom: 0; }
.cm-answer strong { color: var(--c-text); font-weight: 700; }
.cm-answer em { color: var(--c-text-2); }
.cm-answer ul, .cm-answer ol {
    margin: 8px 0 12px;
    padding-left: 22px;
    line-height: 1.7;
}
.cm-answer ul li { list-style: disc; }
.cm-answer ol li { list-style: decimal; }
.cm-answer li { margin: 2px 0; }
.cm-answer li > p { margin-bottom: 4px; }
.cm-answer code {
    background: rgba(15,23,42,0.06);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    color: #b1361e;
}
.cm-answer pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0 12px;
    font-size: 12px;
    line-height: 1.55;
}
.cm-answer pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: inherit;
}
.cm-answer blockquote {
    border-left: 3px solid #cbd5e1;
    margin: 8px 0;
    padding: 4px 12px;
    color: var(--c-text-2);
    background: rgba(15,23,42,0.03);
    border-radius: 0 4px 4px 0;
}
.cm-answer table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12.5px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: none;
    width: auto;
    min-width: 240px;
}
.cm-answer thead th {
    background: #fafbfc;
    text-transform: none;
    font-size: 12px;
    letter-spacing: 0;
    padding: 8px 12px;
}
.cm-answer tbody td { padding: 8px 12px; }
.cm-answer a { color: #2563eb; text-decoration: underline; }
.cm-answer hr { border: none; border-top: 1px solid var(--c-border-soft); margin: 14px 0; }
.cm-answer img { max-width: 100%; height: auto; border-radius: 4px; }

/* ===== 원문 소스 카드 (UI 원문 패널과 동일 톤) ===== */
.src-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.src-card {
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    background: var(--c-surface);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.src-card:hover {
    border-color: var(--c-primary);
    box-shadow: 0 2px 8px rgba(0,153,86,0.08);
}
.src-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 8px;
}
.src-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
    flex: 1;
}
.src-label {
    color: var(--c-primary-dark);
    font-weight: 700;
    font-size: 13.5px;
    white-space: nowrap;
}
.src-file {
    color: var(--c-text);
    font-size: 13.5px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-all;
}
.src-page-top {
    color: var(--c-primary-dark);
    font-weight: 700;
    font-size: 12.5px;
    background: var(--c-primary-soft);
    padding: 3px 10px;
    border-radius: 999px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.src-cont {
    color: var(--c-text-2);
    font-size: 12.5px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    background: #fafbfc;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border-soft);
    max-height: 180px;
    overflow: auto;
    margin-bottom: 10px;
}
.src-imgs-label {
    font-size: 11.5px;
    color: var(--c-text-3);
    margin: 4px 0 6px;
    font-weight: 500;
}
.src-imgs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.src-imgs a {
    display: inline-flex;
    flex-direction: column;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    line-height: 0;
    background: #fafbfc;
    transition: border-color .15s ease, transform .05s ease;
    text-decoration: none;
}
.src-imgs a:hover { border-color: var(--c-primary); }
.src-imgs a:active { transform: translateY(1px); }
.src-imgs img {
    max-width: 220px;
    max-height: 140px;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
}
.src-imgs a.img-fail { display: none; }
.src-img-cap {
    line-height: 1;
    padding: 6px 8px;
    font-size: 10.5px;
    color: var(--c-text-3);
    background: #fff;
    border-bottom: 1px solid var(--c-border-soft);
    font-family: ui-monospace, Menlo, monospace;
}
.src-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--c-border-soft);
    flex-wrap: wrap;
}
.src-foot-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 11.5px;
    color: var(--c-text-3);
    min-width: 0;
}
.src-file-id code {
    background: #f3f4f6;
    color: var(--c-text-2);
    padding: 1px 7px;
    border-radius: 4px;
    font-family: ui-monospace, Menlo, monospace;
    font-size: 11px;
    margin-left: 4px;
}
.src-raw-name {
    color: var(--c-text-3);
    font-family: ui-monospace, Menlo, monospace;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}
.src-ext {
    background: var(--c-border-soft);
    color: var(--c-text-2);
    padding: 1px 7px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.src-foot-actions { display: flex; align-items: center; gap: 8px; }
.src-open-link {
    color: var(--c-primary-dark);
    background: var(--c-primary-soft);
    border: 1px solid #c8e6d4;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    text-decoration: none;
    transition: background-color .15s ease;
}
.src-open-link:hover { background: #d6ecdf; }
.src-pdf-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border: 1px solid #fde2c0;
    background: #fff8ec;
    color: #b45309;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    text-decoration: none;
    transition: background-color .15s ease;
    font-variant-numeric: tabular-nums;
}
.src-pdf-badge:hover { background: #fef0d3; }
.src-pdf-icon {
    background: #b45309;
    color: #fff;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

/* ===== 참조 파일 링크 (sphinxaicomment 이동) ===== */
.cm-refs {
    list-style: none;
    margin: 0;
    padding: 0;
}
.cm-refs li {
    margin-bottom: 6px;
}
.cm-refs li a.ref-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--c-border-soft);
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    background: var(--c-surface);
    color: var(--c-text);
    text-decoration: none;
    transition: border-color .15s ease, background .15s ease, transform .05s ease;
}
.cm-refs li a.ref-link:hover {
    border-color: var(--c-primary);
    background: var(--c-primary-soft);
}
.cm-refs li a.ref-link:active { transform: translateY(1px); }
.cm-refs .ref-id {
    background: #f3f4f6;
    padding: 1px 6px;
    border-radius: 4px;
    color: var(--c-text-2);
    font-family: ui-monospace, Menlo, monospace;
    font-size: 11.5px;
}
.cm-refs .ref-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cm-refs .ref-ext {
    color: var(--c-text-3);
    text-transform: uppercase;
    font-size: 11px;
}
.cm-refs .ref-open {
    color: var(--c-primary-dark);
    font-size: 11.5px;
    font-weight: 600;
    background: var(--c-primary-soft);
    padding: 3px 8px;
    border-radius: 999px;
}
.modal-foot-left { color: var(--c-text-2); font-size: 12px; align-items: center; }

/* ===== Misc ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
::-webkit-scrollbar-track { background: transparent; }

/* Compact responsive */
@media (max-width: 960px) {
    .sidebar { width: 64px; }
    .sidebar .brand span,
    .sidebar .nav a span,
    .sidebar .foot { display: none; }
    .main { padding: 20px; }
}

/* ===== 화면별 권한관리 (permissions.html) ===== */
.perm-layout {
    display: grid;
    grid-template-columns: minmax(360px, 460px) 1fr;
    gap: 16px;
    align-items: start;
}
@media (max-width: 1180px) {
    .perm-layout { grid-template-columns: 1fr; }
}

.panel {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.panel-head {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--c-border-soft);
    background: #fafbfc;
}
.panel-title { font-size: 14px; font-weight: 600; color: var(--c-text); }
.panel-sub { font-size: 11px; color: var(--c-text-3); margin-top: 2px; }
.panel-body { padding: 18px 20px; }
.panel-body.p-0 { padding: 0; }
.perm-head-actions { display: flex; gap: 8px; align-items: center; }

/* 권한 메뉴 테이블은 패널 안에서 border/shadow 중복 제거 */
.perm-menu-table,
.perm-matrix-table {
    border: none;
    border-radius: 0;
    box-shadow: none;
}
.perm-menu-table thead th,
.perm-matrix-table thead th {
    background: #fcfcfd;
    text-transform: none;
    font-size: 11px;
    letter-spacing: 0.1px;
}

.menu-row { cursor: pointer; }
.menu-row.selected { background: var(--c-primary-soft) !important; }
.menu-row.selected td:first-child { box-shadow: inset 3px 0 0 var(--c-primary); }
.menu-row code {
    background: #f3f4f6;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11.5px;
    color: var(--c-text-2);
    font-family: ui-monospace, Menlo, monospace;
}

.text-muted { color: var(--c-text-3); font-size: 12px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn + .btn { margin-left: 4px; }

/* 권한 매트릭스 */
.perm-matrix-table .col-grop { width: 200px; }
.perm-matrix-table .col-perm { width: 88px; text-align: center; }
.perm-matrix-table .col-row-actions { width: 150px; text-align: right; white-space: nowrap; }
.perm-matrix-table tbody td.col-perm { text-align: center; }

.perm-th {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
}
.col-toggle {
    background: transparent;
    border: 1px solid var(--c-border);
    border-radius: 4px;
    width: 20px;
    height: 20px;
    line-height: 1;
    font-size: 10px;
    cursor: pointer;
    color: var(--c-text-3);
    padding: 0;
}
.col-toggle:hover { background: #f3f4f6; color: var(--c-text); }

.grp-name { font-weight: 500; color: var(--c-text); }
.grp-id { margin-top: 2px; }
.grp-id code {
    background: #f3f4f6;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--c-text-3);
    font-family: ui-monospace, Menlo, monospace;
}

/* iOS 스타일 토글 스위치 */
.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    vertical-align: middle;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 999px;
    transition: background-color .15s ease;
    cursor: pointer;
}
.switch .slider::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    transition: transform .15s ease;
}
.switch input:checked + .slider { background: var(--c-primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus + .slider { box-shadow: 0 0 0 3px rgba(0,153,86,0.18); }

/* 그룹별 권한 요약 뷰 */
.gs-row .col-perm { text-align: center; }
.gs-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    font-family: ui-monospace, Menlo, monospace;
}
.gs-num.on  { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.gs-num.off { background: #f3f4f6; color: var(--c-text-3); }
.gs-row.gs-empty .grp-name { color: var(--c-text-3); }
.gs-row.gs-empty .grp-id code { color: var(--c-text-3); }

/* 단축 칩 버튼 */
.chip {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 9px;
    border-radius: 999px;
    background: var(--c-primary-soft);
    color: var(--c-primary-dark);
    border: 1px solid #c8e6d4;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}
.chip:hover { background: #d6ecdf; }
.chip + .chip { margin-left: 4px; }
.chip-off {
    background: #f3f4f6;
    color: var(--c-text-2);
    border-color: var(--c-border);
}
.chip-off:hover { background: #e5e7eb; }

/* 페이지 상단 액션바 */
.page-actions {
    display: flex;
    justify-content: flex-end;
    margin: -8px 0 14px;
}

/* ===== 그룹별 권한 부여 모달 (large) ===== */
.modal-content.modal-lg {
    max-width: 900px;
    width: 95%;
    padding: 0;
    display: flex;
    flex-direction: column;
    max-height: 92vh;
}
.modal-content.modal-lg .modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 24px 14px;
    border-bottom: 1px solid var(--c-border-soft);
}
.modal-content.modal-lg .modal-head h3 {
    margin: 0;
    padding: 0;
    border: none;
    font-size: 17px;
}
.modal-content.modal-lg .modal-sub {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--c-text-3);
}
.modal-close {
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: var(--c-text-3);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    padding: 0;
}
.modal-close:hover { background: #f3f4f6; color: var(--c-text); }

.gp-toolbar {
    display: flex;
    gap: 14px;
    align-items: flex-end;
    padding: 14px 24px;
    background: #fafbfc;
    border-bottom: 1px solid var(--c-border-soft);
    flex-wrap: wrap;
}
.gp-toolbar .form-group label { margin-bottom: 4px; }
.gp-toolbar select,
.gp-toolbar input[type="text"] {
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    background: var(--c-surface);
    color: var(--c-text);
    width: 100%;
}
.gp-toolbar select:focus,
.gp-toolbar input[type="text"]:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(0,153,86,0.12);
}
.gp-summary {
    font-size: 12px;
    color: var(--c-text-2);
    align-self: center;
    margin-left: auto;
}
.kbd {
    display: inline-block;
    padding: 1px 6px;
    background: var(--c-primary-soft);
    color: var(--c-primary-dark);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    font-family: ui-monospace, Menlo, monospace;
    line-height: 1.4;
}

.gp-matrix-wrap {
    flex: 1;
    overflow: auto;
    padding: 0;
}
.gp-matrix-table {
    border: none;
    border-radius: 0;
    box-shadow: none;
}
.gp-matrix-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fcfcfd;
}
.gp-matrix-table .col-menu { width: auto; min-width: 280px; }

#gpModalMsg:not(:empty) { padding: 0 24px; }

.modal-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    border-top: 1px solid var(--c-border-soft);
    background: #fafbfc;
}
.modal-foot-left { display: flex; gap: 6px; }
.modal-foot-right { display: flex; gap: 8px; }

/* 저장 버튼 변경 강조 */
.btn-pulse {
    animation: pulse 1.4s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(0,153,86,0.5);
}
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(0,153,86,0.45); }
    70%  { box-shadow: 0 0 0 10px rgba(0,153,86,0); }
    100% { box-shadow: 0 0 0 0 rgba(0,153,86,0); }
}
