/* =============================================
   개미 레이더 — main.css
   ============================================= */

/* CSS 변수 */
:root {
    --color-primary: #1A2B4A;
    --color-primary-light: #2a3f6b;
    --color-up: #FF4444;
    --color-down: #1E6BFF;
    --color-accent: #F5A623;
    --color-bg: #F8F9FA;
    --color-surface: #FFFFFF;
    --color-border: #E2E8F0;
    --color-text: #1A2B4A;
    --color-text-muted: #64748B;
    --color-warning-bg: #FFF8E1;
    --color-warning-border: #F5A623;
    --color-danger-bg: #FFF0F0;
    --color-danger-border: #FF4444;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.1);
    --radius: 8px;
    --radius-sm: 4px;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; height: auto; }

ul { list-style: none; }

/* Container */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 16px;
}

/* =============================================
   헤더
   ============================================= */
.site-header {
    background: var(--color-primary);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.site-header .container {
    display: flex;
    align-items: center;
    gap: 24px;
    height: 60px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.2rem;
    color: #fff;
    white-space: nowrap;
    flex-shrink: 0;
}

.logo:hover { text-decoration: none; opacity: 0.9; }

.logo-icon { font-size: 1.4rem; }

.main-nav {
    display: flex;
    gap: 0;
    flex: 1;
}

.nav-group {
    position: relative;
}

.nav-label {
    display: block;
    padding: 0 16px;
    height: 60px;
    line-height: 60px;
    font-size: 0.9rem;
    color: rgba(255,255,255,.85);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
}

.nav-group:hover .nav-label {
    background: rgba(255,255,255,.1);
    color: #fff;
}

.nav-group ul {
    display: none;
    position: absolute;
    top: 60px;
    left: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0 0 var(--radius) var(--radius);
    min-width: 160px;
    box-shadow: var(--shadow-md);
    z-index: 200;
}

.nav-group:hover ul { display: block; }

.nav-group ul li a {
    display: block;
    padding: 10px 16px;
    font-size: 0.875rem;
    color: var(--color-text);
    white-space: nowrap;
    transition: background .15s;
}

.nav-group ul li a:hover {
    background: var(--color-bg);
    color: var(--color-primary);
    text-decoration: none;
}

.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    margin-left: auto;
}

.nav-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: #fff;
    transition: .2s;
}

/* =============================================
   메인 콘텐츠
   ============================================= */
.main-content { padding: 24px 0 40px; }

/* =============================================
   페이지 헤더
   ============================================= */
.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 8px;
}

.page-header .description {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    max-width: 700px;
    line-height: 1.7;
}

.update-time {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 4px 12px;
    margin-top: 10px;
}

/* =============================================
   테이블 영역
   ============================================= */
.table-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    max-width: 320px;
    padding: 8px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-family: inherit;
    outline: none;
    transition: border-color .15s;
}

.search-input:focus { border-color: var(--color-primary); }

.filter-select {
    padding: 8px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--color-surface);
    cursor: pointer;
    outline: none;
}

.table-wrapper {
    overflow-x: auto;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
}

.stock-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.stock-table thead th {
    background: var(--color-primary);
    color: #fff;
    padding: 12px 14px;
    text-align: right;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background .15s;
}

.stock-table thead th:first-child,
.stock-table thead th.col-name { text-align: left; }

.stock-table thead th:hover { background: var(--color-primary-light); }

.stock-table thead th .sort-icon {
    margin-left: 4px;
    opacity: .5;
    font-size: 0.75rem;
}

.stock-table thead th.sorted-asc .sort-icon::after { content: ' ▲'; opacity: 1; }
.stock-table thead th.sorted-desc .sort-icon::after { content: ' ▼'; opacity: 1; }
.stock-table thead th:not(.sorted-asc):not(.sorted-desc) .sort-icon::after { content: ' ⇅'; }

.stock-table tbody tr {
    border-bottom: 1px solid var(--color-border);
    transition: background .1s;
}

.stock-table tbody tr:last-child { border-bottom: none; }

.stock-table tbody tr:hover { background: #F0F4FF; }

.stock-table tbody td {
    padding: 11px 14px;
    text-align: right;
    vertical-align: middle;
}

.stock-table tbody td:first-child,
.stock-table tbody td.col-name { text-align: left; }

.stock-name-link {
    font-weight: 500;
    color: var(--color-primary);
    transition: color .15s;
}

.stock-name-link:hover {
    color: var(--color-accent);
    text-decoration: none;
}

.stock-code {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* 등락률 색상 */
.change-up { color: var(--color-up); font-weight: 500; }
.change-down { color: var(--color-down); font-weight: 500; }
.change-zero { color: var(--color-text-muted); }

/* 배지 */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-up { background: #FFF0F0; color: var(--color-up); }
.badge-accent { background: #FFF8E1; color: #B8860B; }
.badge-primary { background: #E8EEFF; color: var(--color-primary); }
.badge-success { background: #E6FAF0; color: #1A8A4A; }
.badge-warn { background: var(--color-warning-bg); color: #B86800; }
.badge-danger { background: var(--color-danger-bg); color: var(--color-up); }

/* 신고가 임박 배지 */
.breakout-badge {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* =============================================
   AdSense 배너
   ============================================= */
.ad-banner {
    background: var(--color-surface);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-sm);
    text-align: center;
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.ad-top { margin-bottom: 24px; }
.ad-mid { margin: 24px 0; }
.ad-bottom { margin-top: 32px; }

/* =============================================
   설명 콘텐츠 (SEO 텍스트)
   ============================================= */
.content-section {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 28px;
    margin-top: 32px;
    border: 1px solid var(--color-border);
}

.content-section h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--color-border);
}

.content-section h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-primary);
    margin: 20px 0 10px;
}

.content-section p {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    line-height: 1.8;
    margin-bottom: 12px;
}

.content-section ul {
    list-style: disc;
    padding-left: 20px;
    margin-bottom: 12px;
}

.content-section ul li {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    line-height: 1.8;
    margin-bottom: 4px;
}

.formula-box {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-primary);
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    margin: 16px 0;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    color: var(--color-text);
}

/* =============================================
   FAQ 섹션
   ============================================= */
.faq-section {
    margin-top: 32px;
}

.faq-section h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 16px;
}

.faq-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
}

.faq-question {
    padding: 16px 20px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: background .15s;
}

.faq-question:hover { background: var(--color-bg); }

.faq-question::after {
    content: '+';
    font-size: 1.2rem;
    color: var(--color-text-muted);
    flex-shrink: 0;
    transition: transform .2s;
}

.faq-item.open .faq-question::after { transform: rotate(45deg); }

.faq-answer {
    display: none;
    padding: 0 20px 16px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    line-height: 1.8;
    border-top: 1px solid var(--color-border);
}

.faq-item.open .faq-answer { display: block; }

/* =============================================
   위험 경고 박스
   ============================================= */
.risk-box {
    background: var(--color-danger-bg);
    border: 1px solid var(--color-danger-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin: 16px 0;
    font-size: 0.9rem;
    line-height: 1.7;
}

.risk-box strong { color: var(--color-up); }

.risk-warning {
    background: var(--color-warning-bg);
    border-top: 1px solid var(--color-warning-border);
    padding: 12px 0;
}

.risk-warning p {
    font-size: 0.8rem;
    color: #7D5000;
    text-align: center;
}

/* =============================================
   관련 카테고리 링크
   ============================================= */
.related-links {
    margin-top: 32px;
}

.related-links h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 14px;
}

.related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.related-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-primary);
    transition: all .15s;
    text-align: center;
}

.related-card:hover {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

/* =============================================
   홈 카테고리 카드
   ============================================= */
.home-hero {
    background: linear-gradient(135deg, var(--color-primary) 0%, #2a4080 100%);
    color: #fff;
    padding: 48px 0;
    margin: -24px 0 32px;
}

.home-hero h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.home-hero p {
    font-size: 1rem;
    opacity: .85;
    max-width: 560px;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.category-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    transition: all .2s;
    cursor: pointer;
}

.category-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-3px);
    border-color: var(--color-primary);
    text-decoration: none;
}

.category-card .cat-icon { font-size: 2rem; margin-bottom: 10px; }

.category-card .cat-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 6px;
}

.category-card .cat-desc {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    line-height: 1.6;
}

.category-card .cat-tag {
    display: inline-block;
    margin-top: 10px;
    padding: 3px 10px;
    background: var(--color-bg);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* =============================================
   종목 상세 페이지
   ============================================= */
.stock-detail-header {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.stock-detail-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-primary);
}

.stock-detail-header .stock-code-badge {
    display: inline-block;
    padding: 3px 10px;
    background: var(--color-bg);
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-left: 10px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 14px;
    margin: 20px 0;
}

.metric-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.metric-card .metric-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.metric-card .metric-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-primary);
}

.metric-card .metric-value.accent { color: var(--color-accent); }

.appeared-in {
    background: #E8EEFF;
    border: 1px solid #C4D0FF;
    border-radius: var(--radius);
    padding: 16px 20px;
    margin: 20px 0;
}

.appeared-in h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 10px;
}

.appeared-in ul {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.appeared-in ul li a {
    display: inline-block;
    padding: 4px 12px;
    background: var(--color-primary);
    color: #fff;
    border-radius: 20px;
    font-size: 0.8rem;
}

.appeared-in ul li a:hover {
    background: var(--color-primary-light);
    text-decoration: none;
}

/* 기관 순매수 미니 바 차트 */
.mini-bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 30px;
}

.mini-bar {
    flex: 1;
    background: var(--color-primary);
    opacity: 0.6;
    border-radius: 2px 2px 0 0;
    transition: opacity .15s;
    min-width: 6px;
}

.mini-bar:last-child { opacity: 1; }

/* =============================================
   스켈레톤 로딩 UI
   ============================================= */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton-row {
    height: 44px;
    margin-bottom: 1px;
}

/* =============================================
   배당 안정성 등급
   ============================================= */
.grade-A { color: #1A8A4A; font-weight: 700; }
.grade-B { color: var(--color-accent); font-weight: 700; }
.grade-C { color: var(--color-up); font-weight: 700; }

/* =============================================
   반응형 — 768px 이하
   ============================================= */
@media (max-width: 768px) {
    .site-header .container { height: 56px; }

    .main-nav {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--color-primary);
        padding: 12px 0 20px;
        box-shadow: var(--shadow-md);
    }

    .main-nav.open { display: flex; }

    .nav-group { width: 100%; }

    .nav-label {
        height: auto;
        line-height: 1;
        padding: 12px 16px;
        font-weight: 700;
        font-size: 0.85rem;
        pointer-events: none;
    }

    .nav-group ul {
        display: block !important;
        position: static;
        box-shadow: none;
        border: none;
        background: transparent;
    }

    .nav-group ul li a {
        color: rgba(255,255,255,.85);
        background: transparent;
        padding: 8px 16px 8px 24px;
    }

    .nav-group ul li a:hover {
        background: rgba(255,255,255,.1);
        color: #fff;
    }

    .nav-toggle { display: flex; }

    .page-header h1 { font-size: 1.4rem; }

    .home-hero { padding: 32px 0; }
    .home-hero h1 { font-size: 1.5rem; }

    .category-grid { grid-template-columns: 1fr 1fr; gap: 12px; }

    .metrics-grid { grid-template-columns: repeat(3, 1fr); }

    .table-controls { flex-direction: column; align-items: stretch; }
    .search-input { max-width: 100%; }

    .content-section { padding: 20px; }

    .related-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .category-grid { grid-template-columns: 1fr; }
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .related-grid { grid-template-columns: 1fr; }
}

/* =============================================
   사이트 푸터
   ============================================= */
.site-footer {
    background: var(--color-primary);
    color: rgba(255,255,255,.8);
    padding: 40px 0 20px;
    margin-top: 40px;
}

.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 2fr;
    gap: 32px;
    margin-bottom: 32px;
}

.footer-col strong {
    display: block;
    color: #fff;
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.footer-col p {
    font-size: 0.8rem;
    line-height: 1.7;
    margin-bottom: 8px;
}

.footer-col ul li {
    margin-bottom: 6px;
}

.footer-col ul li a {
    font-size: 0.8rem;
    color: rgba(255,255,255,.7);
    transition: color .15s;
}

.footer-col ul li a:hover {
    color: #fff;
    text-decoration: none;
}

.footer-bottom {
    border-top: 1px solid rgba(255,255,255,.15);
    padding-top: 20px;
    text-align: center;
}

.footer-bottom p {
    font-size: 0.75rem;
    color: rgba(255,255,255,.55);
    margin-bottom: 4px;
}

@media (max-width: 768px) {
    .footer-grid { grid-template-columns: 1fr 1fr; gap: 24px; }
}

@media (max-width: 480px) {
    .footer-grid { grid-template-columns: 1fr; }
}
