/* ==========================================================================
   LUDA Analytics Platform — 디자인 시스템
   ========================================================================== */

:root {
    --brand-900: #0b1526;
    --brand-800: #111e33;
    --brand-700: #18263f;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eaf1ff;
    --accent: #0ea5e9;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0891b2;

    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --canvas: #f4f6fa;
    --border: #e4e9f2;
    --text: #16213a;
    --text-muted: #6b7a90;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(16, 30, 54, 0.06);
    --shadow-md: 0 6px 18px rgba(16, 30, 54, 0.08);

    /* Bootstrap 오버라이드 */
    --bs-primary: var(--primary);
    --bs-body-color: var(--text);
    --bs-body-bg: var(--canvas);
    --bs-border-color: var(--border);
}

html {
    font-size: 14px;
}

body {
    background-color: var(--canvas);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: 'Inter', 'Noto Sans KR', 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
}

.content,
main {
    flex: 1;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -0.01em;
}

h1 { font-size: 1.55rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1.05rem; }
h5 { font-size: 0.95rem; }
h6 { font-size: 0.875rem; }

a {
    text-decoration: none;
}

.text-muted {
    color: var(--text-muted) !important;
}

/* --------------------------------------------------------------- 네비게이션 */
.app-navbar {
    background: var(--brand-900);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
}

.app-navbar .navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-weight: 700;
    font-size: 0.98rem;
    letter-spacing: -0.01em;
    color: #fff;
}

.app-navbar .brand-mark {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    color: #fff;
    font-size: 0.95rem;
}

.app-navbar .brand-sub {
    color: rgba(255, 255, 255, 0.45);
    font-weight: 500;
    font-size: 0.78rem;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
    padding-left: 0.55rem;
    margin-left: 0.15rem;
}

.app-navbar .nav-link {
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.7rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link:focus {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.app-navbar .nav-link.active {
    color: #fff;
    background: rgba(37, 99, 235, 0.35);
    box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.35);
}

.app-navbar .nav-link i {
    margin-right: 0.3rem;
    opacity: 0.9;
}

.app-navbar .dropdown-menu {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 0.85rem;
    padding: 0.35rem;
}

.app-navbar .dropdown-item {
    border-radius: 6px;
    padding: 0.45rem 0.6rem;
}

.app-navbar .dropdown-item:active {
    background: var(--primary);
}

.navbar-divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 0.5rem;
}

/* --------------------------------------------------------- 페이지 헤더/섹션 */
.page-header {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.page-header .page-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.15rem;
}

.page-header .page-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 0;
}

.section-label {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

/* ----------------------------------------------------------------- 카드 */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    padding: 0.7rem 1rem;
}

.card-footer {
    background: var(--surface-muted);
    border-top: 1px solid var(--border);
}

.data-card .card-body {
    padding: 1.25rem;
}

.data-card {
    transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.data-card:hover {
    border-color: #c8d6ee;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* ------------------------------------------------------------- KPI 타일 */
.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 0.95rem 1.1rem;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.stat-tile::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--primary);
    opacity: 0.85;
}

.stat-tile.tile-success::before { background: var(--success); }
.stat-tile.tile-warning::before { background: var(--warning); }
.stat-tile.tile-info::before    { background: var(--info); }

.stat-tile .stat-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.stat-tile .stat-value {
    font-size: 1.45rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.stat-tile .stat-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* ---------------------------------------------------------------- 차트 */
.chart-card .card-body {
    padding: 0.5rem;
}

.chart-card .insight-box {
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
    padding: 0.6rem 1rem;
    line-height: 1.6;
    border-radius: 0 0 var(--radius) var(--radius);
}

.chart-card .insight-box strong {
    color: var(--primary-dark);
}

.insight-placeholder {
    opacity: 0.65;
}

/* /visualize 의 단일 차트 영역 */
#chart {
    width: 100%;
    height: 600px;
}

#chartContainer .card-body {
    min-height: 600px;
}

.plotly {
    width: 100%;
}

/* /analytics 의 고급 분석 차트 */
.analytics-chart {
    width: 100%;
    min-height: 400px;
}

@media (max-width: 768px) {
    #chart {
        height: 500px;
    }

    #chartContainer .card-body {
        min-height: 500px;
    }
}

/* --------------------------------------------------------------- 버튼 */
.btn {
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-outline-primary {
    color: var(--primary-dark);
    border-color: #c3d4f5;
}

.btn-outline-primary:hover {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* --------------------------------------------------------------- 테이블 */
.table {
    font-size: 0.85rem;
    --bs-table-striped-bg: #fafbfd;
}

.table thead th {
    background-color: var(--surface-muted);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.table tbody td {
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}

.table-responsive {
    border-radius: 0 0 var(--radius) var(--radius);
}

/* ----------------------------------------------------------------- 폼 */
.form-control,
.form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border);
    font-size: 0.875rem;
}

.form-control:focus,
.form-select:focus {
    border-color: #93b4f7;
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.15);
}

.form-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
}

.form-text {
    font-size: 0.78rem;
}

/* --------------------------------------------------------------- 알림 */
.alert {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    box-shadow: var(--shadow-sm);
}

/* ------------------------------------------------------------- 탭/배지 */
.nav-tabs {
    border-bottom: 1px solid var(--border);
}

.nav-tabs .nav-link {
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 0.9rem;
}

.nav-tabs .nav-link:hover {
    color: var(--text);
    border-bottom-color: #cdd7e6;
}

.nav-tabs .nav-link.active {
    color: var(--primary-dark);
    background: transparent;
    border-bottom-color: var(--primary);
}

.badge-soft {
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 600;
    border-radius: 999px;
    padding: 0.3rem 0.6rem;
    font-size: 0.72rem;
}

/* ------------------------------------------------------------- 빈 상태 */
.empty-state {
    background: var(--surface);
    border: 1px dashed #cfd8e6;
    border-radius: var(--radius);
    padding: 3rem 1.5rem;
    text-align: center;
}

.empty-state i {
    font-size: 2.5rem;
    color: #b9c4d6;
}

/* --------------------------------------------------------------- 푸터 */
.app-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 1rem 0;
    margin-top: auto;
}

.app-footer-link {
    color: var(--primary-dark);
    text-decoration: none;
}

.app-footer-link:hover {
    text-decoration: underline;
}

/* ----------------------------------------------------------- 매뉴얼 */
.manual-toc {
    position: sticky;
    top: 84px;
}

.manual-toc .list-group-item {
    border: none;
    border-left: 2px solid transparent;
    font-size: 0.85rem;
    padding: 0.45rem 1rem;
    color: var(--text-muted);
}

.manual-toc .list-group-item:hover {
    background: var(--primary-soft);
    border-left-color: var(--primary);
    color: var(--primary-dark);
}

.manual-section {
    scroll-margin-top: 84px;
}

.manual-heading {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.manual-subheading {
    font-size: 1rem;
    font-weight: 600;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}

.manual-table {
    font-size: 0.9rem;
    line-height: 1.6;
}

.manual-table code {
    white-space: nowrap;
}

.manual-steps,
.manual-list {
    padding-left: 1.1rem;
    margin-bottom: 0;
}

.manual-steps li,
.manual-list li {
    margin-bottom: 0.4rem;
    line-height: 1.65;
}

.manual-callout {
    margin-top: 1rem;
    background: var(--primary-soft);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.9rem;
    font-size: 0.88rem;
}

.manual-callout i {
    color: var(--primary-dark);
    margin-right: 0.35rem;
}

/* --------------------------------------------------------- 스크롤바 */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #c7d0de;
    border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a9b5c7;
}

/* ------------------------------------------------------------- 반응형 */
@media (max-width: 768px) {
    .table { font-size: 0.8rem; }
    .card { margin-bottom: 0.5rem; }
    .stat-tile .stat-value { font-size: 1.25rem; }
}

/* ------------------------------------------------------------- 분석 리포트 인쇄 */
@media print {
    .app-navbar,
    .app-footer,
    .d-print-none {
        display: none !important;
    }

    .analytics-report {
        max-width: 100%;
    }

    .analytics-report .table {
        font-size: 0.72rem;
    }

    .analytics-report h5 {
        break-after: avoid;
    }

    .analytics-chart {
        break-inside: avoid;
    }
}
