/* ═══════════════════════════════════════════════════════════
   AI-APT 관리자 백오피스 — 디자인 시스템
   ai-apt.innogait.com
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

/* ─── CSS 변수 ─── */
:root {
    --bg-main: #0B1120;
    --bg-sidebar: #111827;
    --bg-card: #1E293B;
    --bg-card-hover: #253347;
    --bg-input: #0F172A;
    --border: #334155;
    --border-subtle: #1E293B;

    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-tertiary: #64748B;
    --text-muted: #475569;

    --primary: #6366F1;
    --primary-hover: #818CF8;
    --primary-subtle: rgba(99,102,241,0.12);
    --primary-glow: rgba(99,102,241,0.25);

    --success: #10B981;
    --success-subtle: rgba(16,185,129,0.12);
    --warning: #F59E0B;
    --warning-subtle: rgba(245,158,11,0.12);
    --danger: #EF4444;
    --danger-subtle: rgba(239,68,68,0.12);
    --info: #3B82F6;
    --info-subtle: rgba(59,130,246,0.12);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 20px var(--primary-glow);

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

    --sidebar-width: 260px;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, textarea, select {
    font: inherit; color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    outline: none;
    transition: border-color var(--transition-fast);
}
input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-subtle);
}
textarea { resize: vertical; min-height: 100px; }

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

/* ─── 사이드바 ─── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition-normal);
}
.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-subtle);
}
.sidebar-logo {
    display: flex; align-items: center; gap: 12px;
}
.sidebar-logo-icon {
    width: 40px; height: 40px; border-radius: 14px;
    background: linear-gradient(135deg, #6366F1, #818CF8);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    box-shadow: var(--shadow-glow);
}
.sidebar-logo-text h1 {
    font-size: 18px; font-weight: 800; letter-spacing: -0.3px;
    background: linear-gradient(135deg, #E0E7FF, #A5B4FC);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.sidebar-logo-text p {
    font-size: 12px; color: var(--text-tertiary); margin-top: 2px;
}

.sidebar-nav { flex: 1; padding: 12px; overflow-y: auto; }
.sidebar-nav-label {
    font-size: 11px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 1px;
    padding: 8px 12px 6px; margin-top: 8px;
}
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border-radius: var(--radius-md);
    color: var(--text-secondary); font-weight: 500; font-size: 14px;
    transition: all var(--transition-fast);
    margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active {
    background: var(--primary-subtle); color: var(--primary-hover);
    font-weight: 600;
}
.nav-item .icon { font-size: 18px; width: 24px; text-align: center; }
.nav-item .badge {
    margin-left: auto;
    font-size: 11px; font-weight: 700;
    background: var(--danger);
    color: #fff;
    padding: 2px 8px; border-radius: var(--radius-full);
}

.sidebar-footer {
    padding: 16px; border-top: 1px solid var(--border-subtle);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-footer .avatar {
    width: 36px; height: 36px; border-radius: 10px;
    background: linear-gradient(135deg, #334155, #475569);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
}
.sidebar-footer .info { flex: 1; }
.sidebar-footer .info .name { font-size: 13px; font-weight: 600; }
.sidebar-footer .info .role { font-size: 11px; color: var(--text-tertiary); }

/* ─── 메인 ─── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}
.page-header {
    padding: 28px 32px 20px;
    display: flex; align-items: center; justify-content: space-between;
}
.page-header h2 {
    font-size: 24px; font-weight: 800; letter-spacing: -0.3px;
}
.page-header .subtitle {
    font-size: 14px; color: var(--text-secondary); margin-top: 4px;
}
.page-content { padding: 0 32px 40px; }

/* ─── 카드 (글래스모피즘) ─── */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition-normal);
}
.glass-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}
.card-title {
    font-size: 15px; font-weight: 700;
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 14px;
}
.card-title .icon { font-size: 18px; }

/* ─── 통계 카드 그리드 ─── */
.stats-grid {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 16px; margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--accent-color, var(--primary));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.stat-card .label {
    font-size: 13px; color: var(--text-tertiary); font-weight: 500;
    display: flex; align-items: center; gap: 6px;
}
.stat-card .value {
    font-size: 32px; font-weight: 900; margin-top: 8px;
    letter-spacing: -1px;
}
.stat-card .trend {
    font-size: 13px; font-weight: 600; margin-top: 6px;
    display: flex; align-items: center; gap: 4px;
}
.stat-card .trend.up { color: var(--success); }
.stat-card .trend.down { color: var(--danger); }

/* ─── 버튼 ─── */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px; border-radius: var(--radius-md);
    font-weight: 600; font-size: 14px;
    transition: all var(--transition-fast);
}
.btn-primary {
    background: var(--primary); color: #fff;
    box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}
.btn-outline {
    border: 1px solid var(--border); color: var(--text-secondary);
}
.btn-outline:hover {
    border-color: var(--primary); color: var(--primary);
    background: var(--primary-subtle);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

/* ─── 테이블 ─── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left; padding: 12px 16px;
    font-size: 12px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 14px 16px; font-size: 14px;
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}
.data-table tr:hover td { background: rgba(255,255,255,0.02); }

/* ─── 배지 ─── */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: var(--radius-full);
    font-size: 12px; font-weight: 600;
}
.badge-success { background: var(--success-subtle); color: var(--success); }
.badge-warning { background: var(--warning-subtle); color: var(--warning); }
.badge-danger { background: var(--danger-subtle); color: var(--danger); }
.badge-info { background: var(--info-subtle); color: var(--info); }

/* ─── 탭 ─── */
.tab-bar {
    display: flex; gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.tab-item {
    padding: 12px 20px; font-size: 14px; font-weight: 500;
    color: var(--text-tertiary);
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}
.tab-item:hover { color: var(--text-primary); }
.tab-item.active {
    color: var(--primary); border-bottom-color: var(--primary);
    font-weight: 600;
}

/* ─── 업로드 존 ─── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    transition: all var(--transition-normal);
    cursor: pointer;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-subtle);
}
.upload-zone .icon { font-size: 48px; margin-bottom: 12px; }
.upload-zone .text { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.upload-zone .hint { font-size: 13px; color: var(--text-tertiary); }

/* ─── 모달 ─── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity var(--transition-normal);
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-content {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 90%; max-width: 600px; max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform var(--transition-normal);
}
.modal-overlay.active .modal-content { transform: scale(1); }
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
}

/* ─── 채팅 미리보기 ─── */
.chat-preview {
    max-height: 400px; overflow-y: auto;
    padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.chat-msg {
    max-width: 80%; padding: 12px 16px;
    border-radius: 16px; font-size: 14px; line-height: 1.6;
}
.chat-msg.user {
    align-self: flex-end;
    background: var(--primary); color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
    align-self: flex-start;
    background: var(--bg-card); border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-msg .time {
    font-size: 11px; color: var(--text-muted); margin-top: 4px;
}

/* ─── 프롬프트 편집 ─── */
.prompt-editor {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px; line-height: 1.7;
    min-height: 200px; width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
}

/* ─── 토글 ─── */
.toggle-switch {
    position: relative; width: 44px; height: 24px;
    display: inline-block;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--text-muted);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.toggle-slider::before {
    content: '';
    position: absolute; width: 18px; height: 18px;
    left: 3px; bottom: 3px;
    background: #fff; border-radius: 50%;
    transition: transform var(--transition-fast);
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ─── 반응형 ─── */
@media (max-width: 1200px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr; }
    .page-header { padding: 20px 16px 12px; }
    .page-content { padding: 0 16px 24px; }
}

/* ─── 애니메이션 ─── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-in {
    animation: fadeIn 0.4s ease forwards;
}
.animate-in:nth-child(2) { animation-delay: 0.05s; }
.animate-in:nth-child(3) { animation-delay: 0.1s; }
.animate-in:nth-child(4) { animation-delay: 0.15s; }

/* ─── 섹션 가시성 ─── */
.page-section { display: none; }
.page-section.active { display: block; }

/* ─── 진행률 바 ─── */
.progress-bar {
    height: 6px; background: var(--bg-input);
    border-radius: var(--radius-full); overflow: hidden;
}
.progress-bar .fill {
    height: 100%; border-radius: var(--radius-full);
    transition: width var(--transition-slow);
}

/* ─── 리스트 ─── */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-item {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px; border-radius: var(--radius-md);
    background: var(--bg-input); border: 1px solid var(--border-subtle);
    transition: all var(--transition-fast);
}
.doc-item:hover { border-color: var(--border); background: var(--bg-card); }
.doc-item .doc-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.doc-item .doc-info { flex: 1; }
.doc-item .doc-info .name { font-size: 14px; font-weight: 600; }
.doc-item .doc-info .meta { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.doc-item .doc-actions { display: flex; gap: 6px; }

/* ─── 2컬럼 그리드 ─── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
