/* ===== Color System ===== */
:root {
    /* ── 배경 (Background) ── */
    --bg-body:        #0b0f19;
    --bg-elevated:    #111827;
    --bg-surface:     #1e293b;
    --bg-hover:       #263347;
    --bg-inset:       #0b0f19;

    /* ── 테두리 (Border) ── */
    --border-default: #1e293b;
    --border-bright:  #334155;
    --border-muted:   #162032;

    /* ── 텍스트 (Text) ── */
    --tx-primary:     #e6edf3;
    --tx-secondary:   #8b949e;
    --tx-tertiary:    #6e7681;
    --tx-link:        #58a6ff;

    /* ── 브랜드 (Brand Accent) ── */
    --accent:         #e94560;
    --accent-end:     #c23152;
    --accent-hover:   #d13a54;

    /* ── 상태 시맨틱 (Semantic Status) ── */
    --status-danger:  #f85149;
    --status-warning: #f0b429;
    --status-success: #3fb950;
    --status-info:    #58a6ff;
    --status-purple:  #a371f7;
    --status-neutral: #8b949e;

    /* ── 상태 배경 (Status Backgrounds) ── */
    --status-danger-bg:  rgba(248, 81, 73, 0.12);
    --status-warning-bg: rgba(240, 180, 41, 0.12);
    --status-success-bg: rgba(63, 185, 80, 0.12);
    --status-info-bg:    rgba(88, 166, 255, 0.12);
    --status-purple-bg:  rgba(163, 113, 247, 0.12);

    /* ── 등급 (Grade) ── */
    --grade-A: #3fb950;
    --grade-B: #58a6ff;
    --grade-C: #8b949e;
    --grade-D: #f0b429;
    --grade-E: #f85149;

    /* ── 차트 (Chart) ── */
    --chart-grid:       rgba(255, 255, 255, 0.06);
    --chart-text:       #8b949e;
    --chart-tooltip-bg: rgba(22, 27, 34, 0.95);
    --chart-border:     #111827;

    /* ── 그림자 (Shadow) ── */
    --shadow-card:  0 2px 12px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.5);

    /* ── 기타 ── */
    --drop-zone-active:   rgba(233, 69, 96, 0.1);
    --drop-zone-selected: rgba(63, 185, 80, 0.1);
    --code-bg:            #1c2333;
}

/* ===== Dark Mode Overrides ===== */
/* table-light / bg-light — Bootstrap dark mode 호환 */
.table-light {
    --bs-table-bg: var(--bg-surface) !important;
    --bs-table-color: var(--tx-primary) !important;
    --bs-table-border-color: var(--border-bright) !important;
}
.bg-light {
    background-color: var(--bg-surface) !important;
    color: var(--tx-primary) !important;
}
/* 테이블 헤더 — 본문과 구분되는 약간 밝은 배경 */
.table thead th,
.table > thead {
    background-color: var(--bg-surface);
    color: var(--tx-primary);
}
.dataTables_wrapper .table thead th {
    background-color: var(--bg-surface) !important;
}

/* ===== Global ===== */
html {
    background-color: var(--bg-body);
}

body {
    background-color: var(--bg-body);
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
}

.body-wrapper { width: 100%; }
.content-area { margin: 0 auto; }
.content-area.wide  { max-width: 2000px; }
.content-area.large { max-width: 1700px; }
.content-area.mid   { max-width: 1400px; }
.content-area.narrow { max-width: 1200px; }
.content-area.small { max-width: 1000px; }

/* ===== Navbar ===== */
.main-navbar {
    background: transparent;
    box-shadow: none;
    border-bottom: 1px solid var(--border-default);
    padding: 0.5rem 0;
}

.main-navbar .navbar-brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--tx-primary);
    letter-spacing: -0.3px;
    padding: 0.5rem 0;
}

.main-navbar .navbar-brand:hover {
    color: var(--tx-link);
}

.brand-text {
    background: linear-gradient(90deg, #c9d1d9, #58a6ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Nav groups — large screens: transparent wrapper, items inline */
.nav-group {
    display: contents;
}

/* Nav group labels & dividers */
.nav-group-label {
    display: none;
    align-items: center;
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--tx-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 0.3rem;
    align-self: center;
    user-select: none;
}

.nav-group-divider {
    display: none;
    width: 1px;
    height: 20px;
    background-color: var(--border-default);
    align-self: center;
    margin: 0 0.4rem;
    flex-shrink: 0;
}

/* Large screens (≥1600px): inline single row with labels & dividers */
@media (min-width: 1600px) {
    .nav-group-label {
        display: flex;
    }
    .nav-group-divider {
        display: flex;
    }
}

/* Small screens (<992px): hamburger menu — 2-column: labels | items */
@media (max-width: 991.98px) {
    .nav-pills-custom {
        display: flex;
        flex-direction: column;
        gap: 0;
        padding: 0.3rem 0;
    }
    .nav-group {
        display: grid;
        grid-template-columns: auto 1fr;
        align-items: start;
        padding: 0.3rem 0.5rem;
    }
    .nav-group-label {
        display: flex;
        padding: 0.52rem 0.4rem 0 0;
        align-self: start;
    }
    .nav-group + .nav-group {
        border-top: 1px solid var(--border-default);
    }
    .nav-group-divider {
        display: none;
    }
    .nav-group-items {
        display: flex !important;
        flex-wrap: wrap !important;
        flex-direction: row !important;
        gap: 0.1rem;
    }
    .nav-pills-custom .nav-link {
        font-size: 0.84rem;
        padding: 0.35rem 0.65rem !important;
        border-radius: 5px;
        width: auto !important;
        flex: none !important;
    }
}

.nav-group-items {
    display: contents;
}

/* Nav pills */
.nav-pills-custom {
    gap: 0.35rem;
}

.nav-pills-custom .nav-link {
    color: var(--tx-secondary);
    font-size: 0.88rem;
    font-weight: 500;
    padding: 0.5rem 1.1rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.nav-pills-custom .nav-link:hover {
    color: var(--tx-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-pills-custom .nav-link.active {
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-end));
    box-shadow: 0 2px 10px rgba(233, 69, 96, 0.35);
}

/* Medium screens (992–1599px): groups as side-by-side columns, max 2 rows */
@media (min-width: 992px) and (max-width: 1599.98px) {
    .nav-pills-custom {
        justify-content: center;
        gap: 0.3rem 0.15rem;
        flex-wrap: wrap;
    }
    .nav-group {
        display: grid;
        grid-template-rows: repeat(2, auto);
        grid-auto-flow: column;
        grid-auto-columns: max-content;
        gap: 0.1rem 0.15rem;
        padding: 0.2rem 0.5rem;
        border-right: 1px solid var(--border-bright);
    }
    .nav-group:last-child {
        border-right: none;
    }
    .nav-group-label {
        display: none;
    }
    .nav-group-divider {
        display: none;
    }
    .nav-pills-custom .nav-link {
        font-size: 0.82rem;
        padding: 0.25rem 0.7rem;
    }
}

/* Upload button */
.btn-upload-new {
    color: var(--tx-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    border: 1px solid var(--border-bright);
    border-radius: 8px;
    padding: 0.4rem 1rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.btn-upload-new:hover {
    color: var(--tx-primary);
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--tx-secondary);
}

/* ===== File History ===== */
.history-item {
    border-left: 3px solid transparent;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.history-item:hover {
    border-left-color: var(--accent);
    background-color: var(--bg-hover);
}

/* ===== Upload page ===== */
.upload-card {
    border: none;
    box-shadow: var(--shadow-card);
    border-radius: 16px;
    overflow: hidden;
}

.drop-zone {
    border: 2px dashed var(--border-bright);
    border-radius: 12px;
    padding: 3rem 2rem;
    cursor: pointer;
    transition: all 0.25s ease;
    color: var(--tx-tertiary);
}

.drop-zone:hover,
.drop-zone-active {
    border-color: var(--accent);
    background-color: var(--drop-zone-active);
    color: var(--accent);
}

.drop-zone-selected {
    border-color: var(--status-success);
    background-color: var(--drop-zone-selected);
    color: var(--status-success);
}

/* ===== Dashboard ===== */
.summary-card {
    border: none;
    box-shadow: var(--shadow-card);
    border-radius: 12px;
    border-left: 4px solid var(--accent);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.summary-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.col-md-3:nth-child(1) .summary-card { border-left-color: var(--accent); }
.col-md-3:nth-child(2) .summary-card { border-left-color: var(--status-info); }
.col-md-3:nth-child(3) .summary-card { border-left-color: var(--status-warning); }
.col-md-3:nth-child(4) .summary-card { border-left-color: var(--status-success); }

/* DataTable 검색창 focus shadow 잘림 방지 */
.dataTables_wrapper { padding: 12px; }

/* Returns */
.return-positive {
    color: var(--status-danger);
    font-weight: 600;
}

.return-negative {
    color: var(--status-info);
    font-weight: 600;
}

.return-zero {
    color: var(--status-neutral);
}

/* ===== Tables ===== */
#mainTable th,
#ipoTable th {
    font-size: 0.85rem;
    white-space: nowrap;
    background-color: var(--bg-surface);
}

#mainTable td,
#ipoTable td {
    font-size: 0.85rem;
    vertical-align: middle;
}

/* ===== Cards ===== */
.card {
    border: none;
    box-shadow: var(--shadow-card);
    border-radius: 12px;
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-hover);
}

.card-header {
    background-color: var(--bg-elevated);
    border-bottom: 1px solid var(--border-default);
    border-radius: 12px 12px 0 0 !important;
}

/* ===== Charts ===== */
#marketChart,
#returnChart {
    max-height: 350px;
}

/* ===== Placeholder pages ===== */
.placeholder-page h2 {
    color: var(--tx-primary);
    font-weight: 700;
}

.placeholder-page .text-muted {
    font-size: 1.05rem;
}

/* ===== Watchlist: Traffic Lights ===== */
.traffic-light {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    vertical-align: middle;
}

.traffic-danger { background-color: var(--status-danger); }
.traffic-warning { background-color: var(--status-warning); }
.traffic-safe { background-color: var(--status-success); }
.traffic-unknown { background-color: var(--status-neutral); }

.traffic-lights-group {
    display: flex;
    align-items: center;
    gap: 3px;
}

/* ===== Watchlist: Status Indicator ===== */
.status-indicator {
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-indicator.traffic-danger {
    background: radial-gradient(circle at 35% 35%, #ff6b6b, var(--status-danger));
    box-shadow: 0 0 8px rgba(248, 81, 73, 0.4);
}

.status-indicator.traffic-warning {
    background: radial-gradient(circle at 35% 35%, #ffd166, var(--status-warning));
    box-shadow: 0 0 8px rgba(240, 180, 41, 0.4);
}

.status-indicator.traffic-safe {
    background: radial-gradient(circle at 35% 35%, #6ee7a0, var(--status-success));
    box-shadow: 0 0 8px rgba(63, 185, 80, 0.3);
}

.status-indicator.traffic-unknown {
    background: radial-gradient(circle at 35% 35%, #ced4da, var(--status-neutral));
    box-shadow: 0 0 8px rgba(139, 148, 158, 0.3);
}

/* ===== Watchlist: Company Check Row ===== */
.company-check-row {
    border: 1px solid var(--border-bright);
    border-radius: 10px;
    margin-bottom: 8px;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
    border-left: 4px solid var(--status-neutral);
}

.company-check-row:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.company-check-row.status-border-danger { border-left-color: var(--status-danger); }
.company-check-row.status-border-warning { border-left-color: var(--status-warning); }
.company-check-row.status-border-safe { border-left-color: var(--status-success); }
.company-check-row.status-border-unknown { border-left-color: var(--status-neutral); }

.company-check-header {
    padding: 12px 16px;
    cursor: pointer;
    background-color: var(--bg-elevated);
    transition: background-color 0.15s ease;
}

.company-check-header:hover {
    background-color: var(--bg-hover);
}

/* Collapse arrow rotation */
.collapse-arrow {
    transition: transform 0.25s ease;
    color: var(--tx-tertiary);
}

.company-check-header[aria-expanded="true"] .collapse-arrow {
    transform: rotate(180deg);
}

/* Detail section */
.company-check-detail {
    padding: 0 16px 16px;
    background-color: var(--bg-inset);
    border-top: 1px solid var(--border-default);
}

.company-check-detail .table {
    font-size: 0.85rem;
}

.company-check-detail .table th {
    background-color: var(--bg-surface);
    font-weight: 600;
    white-space: nowrap;
}

/* Check row status highlights */
.check-row-danger { background-color: var(--status-danger-bg); }
.check-row-warning { background-color: var(--status-warning-bg); }
.check-row-exempt { background-color: var(--status-info-bg); }

/* 파생상품평가손실 조정 금액 표시 */
.deriv-adj {
    text-decoration: underline dotted;
    text-underline-offset: 2px;
    cursor: help;
}

/* Exempt (유예) styles */
.traffic-exempt {
    position: relative;
    opacity: 0.5;
}
.traffic-exempt::after {
    content: '';
    position: absolute;
    top: 50%; left: -1px; right: -1px;
    height: 2px;
    background: var(--bg-elevated);
    transform: rotate(-45deg);
}

.badge-exempt {
    background-color: var(--status-info);
    font-size: 0.7em;
}

.badge-division {
    background-color: #2563eb;
    font-size: 0.75em;
    font-weight: 500;
}
.badge-profit-unrealized {
    background-color: #20c997;
}

.badge-desig-admin {
    background-color: var(--status-danger);
    color: #fff;
    font-size: 0.72em;
    font-weight: 600;
}
.badge-desig-caution {
    background-color: var(--status-warning);
    color: #212529;
    font-size: 0.72em;
    font-weight: 600;
}
.badge-desig-review {
    background-color: var(--status-purple);
    color: #fff;
    font-size: 0.72em;
    font-weight: 600;
}

/* ===== Watchlist: Regulation Info Button ===== */
.btn-reg-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    background: none;
    color: var(--tx-tertiary);
    cursor: pointer;
    vertical-align: middle;
    margin-left: 4px;
    border-radius: 50%;
    transition: color 0.15s ease;
}

.btn-reg-info:hover,
.btn-reg-info:focus {
    color: var(--status-info);
    outline: none;
}

.popover {
    max-width: 400px;
}

.popover-body {
    font-size: 0.82rem;
    line-height: 1.55;
    white-space: pre-line;
}

/* ===== Watchlist: Tabs ===== */
#marketTabs .nav-link {
    font-size: 0.9rem;
    color: var(--tx-secondary);
}

#marketTabs .nav-link.active {
    font-weight: 600;
}

/* ===== Watchlist: AI Commentary ===== */
.btn-ai-comment {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
    background-color: var(--status-purple);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    line-height: 1.4;
    vertical-align: middle;
}

.btn-ai-comment:hover {
    background-color: #8b5cf6;
}

.btn-ai-comment:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ai-commentary-box {
    background-color: var(--status-purple-bg);
    border: 1px solid rgba(163, 113, 247, 0.3);
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 12px;
    font-size: 0.83rem;
    line-height: 1.5;
    color: #c4b5fd;
}

.ai-commentary-box.ai-commentary-error {
    background-color: var(--status-danger-bg);
    border-color: rgba(248, 81, 73, 0.3);
    color: #fca5a5;
}

.ai-commentary-label {
    display: inline-block;
    background-color: var(--status-purple);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0px 5px;
    border-radius: 3px;
    margin-right: 4px;
    vertical-align: middle;
}

.ai-commentary-loading {
    padding: 8px 12px;
    margin-bottom: 12px;
    font-size: 0.83rem;
    color: var(--tx-tertiary);
}

/* ===== Watchlist: Adhoc Search Dropdown ===== */
.adhoc-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1050;
    background: var(--bg-elevated);
    border: 1px solid var(--border-bright);
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: var(--shadow-hover);
    max-height: 300px;
    overflow-y: auto;
}

.adhoc-dropdown-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-default);
    font-size: 0.9rem;
}

.adhoc-dropdown-item:last-child {
    border-bottom: none;
}

.adhoc-dropdown-item:hover,
.adhoc-dropdown-item.adhoc-dropdown-active {
    background-color: var(--bg-hover);
}

/* ===== Watchlist: Adhoc Panel Toggle ===== */
.adhoc-toggle {
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-radius: 12px !important;
}

.adhoc-toggle[aria-expanded="true"] {
    border-radius: 12px 12px 0 0 !important;
}

.adhoc-toggle:hover {
    background-color: var(--bg-hover);
}

.adhoc-toggle[aria-expanded="true"] .collapse-arrow {
    transform: rotate(180deg);
}

/* ===== Watchlist: Adhoc History ===== */
.adhoc-history-item {
    position: relative;
}

.adhoc-delete-btn {
    position: absolute;
    top: -7px;
    right: -7px;
    z-index: 10;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 1px solid var(--border-bright);
    background: var(--bg-elevated);
    color: var(--tx-tertiary);
    font-size: 0.85rem;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.adhoc-delete-btn:hover {
    background: var(--status-danger);
    border-color: var(--status-danger);
    color: #fff;
}

/* ===== User Menu Button ===== */
.btn-user-menu {
    color: var(--tx-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    border: 1px solid var(--border-bright);
    border-radius: 8px;
    padding: 0.4rem 0.8rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.btn-user-menu:hover,
.btn-user-menu:focus,
.btn-user-menu.show {
    color: var(--tx-primary);
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--tx-secondary);
}

/* ===== Auth Card ===== */
.auth-card {
    border: none;
    box-shadow: var(--shadow-card);
    border-radius: 16px;
}

/* ===== Auth Brand Button ===== */
.btn-brand {
    background: linear-gradient(135deg, var(--accent), var(--accent-end));
    border: none;
    color: #fff;
}
.btn-brand:hover {
    opacity: 0.9;
    color: #fff;
}

/* ===== 검색 input X(초기화) 버튼 ===== */
.input-clear-wrap { position: relative; display: inline-block; }
.input-clear-wrap > input { padding-right: 24px !important; }
.input-clear-btn {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: none; padding: 0; line-height: 1;
    color: var(--tx-tertiary); font-size: 14px; cursor: pointer; display: none;
}
.input-clear-btn:hover { color: var(--tx-secondary); }
