/* ========================================
   TMBIA 醫材 HS Code 視覺化平台
   Premium Dark Theme
   ======================================== */

:root {
    --bg-primary: #fdfbf7;
    --bg-secondary: #f4f1ea;
    --bg-card: #ffffff;
    --bg-card-hover: #f9f8f5;
    --border-color: rgba(0, 0, 0, 0.08);
    --border-glow: rgba(37, 99, 235, 0.2);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --accent-blue: #2563eb;
    --accent-cyan: #0891b2;
    --accent-purple: #7c3aed;
    --accent-green: #059669;
    --accent-orange: #ea580c;
    --accent-pink: #db2777;
    --gradient-hero: linear-gradient(135deg, #fdfbf7 0%, #f4f1ea 50%, #fdfbf7 100%);
    --gradient-card: linear-gradient(145deg, #ffffff, #f9f8f5);
    --shadow-lg: 0 15px 35px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px rgba(37, 99, 235, 0.1);
    --radius: 16px;
    --radius-sm: 10px;
    --font-main: 'Inter', 'Noto Sans TC', -apple-system, sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ===== HERO ===== */
.hero {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
}

.hero-bg {
    position: absolute;
    inset: 0;
    background: var(--gradient-hero);
    z-index: 0;
}

.hero-bg::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 40%, rgba(96, 165, 250, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 70% 60%, rgba(167, 139, 250, 0.06) 0%, transparent 50%),
                radial-gradient(circle at 50% 80%, rgba(34, 211, 238, 0.05) 0%, transparent 40%);
    animation: heroGlow 15s ease-in-out infinite;
}

@keyframes heroGlow {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(2%, -2%) rotate(2deg); }
    66% { transform: translate(-1%, 1%) rotate(-1deg); }
}

.hero-content {
    position: relative;
    z-index: 1;
    padding: 2rem;
    max-width: 900px;
}

.hero-badge {
    display: inline-block;
    padding: 8px 24px;
    border-radius: 50px;
    background: rgba(96, 165, 250, 0.1);
    border: 1px solid rgba(96, 165, 250, 0.3);
    color: var(--accent-blue);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 2rem;
    animation: fadeInDown 0.8s ease-out;
}

.hero h1 {
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 1.2rem;
    background: linear-gradient(135deg, #e2e8f0 0%, #60a5fa 50%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: fadeInUp 0.8s ease-out 0.2s both;
}

.hero-subtitle {
    font-size: 1.15rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
    animation: fadeInUp 0.8s ease-out 0.4s both;
}

.hero-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.2rem;
    animation: fadeInUp 0.8s ease-out 0.6s both;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1.5rem 1rem;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--border-glow);
    transform: translateY(-4px);
    box-shadow: var(--shadow-glow);
}

.stat-number {
    display: block;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent-cyan);
    margin-bottom: 0.3rem;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.scroll-indicator {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
    text-align: center;
    animation: fadeInUp 0.8s ease-out 1s both;
}

.scroll-indicator span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    letter-spacing: 2px;
}

.scroll-arrow {
    width: 20px;
    height: 20px;
    margin: 0 auto;
    border-right: 2px solid var(--accent-blue);
    border-bottom: 2px solid var(--accent-blue);
    transform: rotate(45deg);
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: rotate(45deg) translateY(0); opacity: 0.5; }
    50% { transform: rotate(45deg) translateY(8px); opacity: 1; }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== NAV ===== */
.nav-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 2rem;
    background: rgba(253, 251, 247, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent-blue);
    white-space: nowrap;
}

.nav-logo {
    font-size: 1.3rem;
}

.nav-links {
    display: flex;
    gap: 0.3rem;
    flex: 1;
    justify-content: center;
    flex-wrap: wrap;
}

.nav-link {
    padding: 6px 16px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(96, 165, 250, 0.15);
    color: var(--accent-blue);
}

.period-select {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: var(--font-main);
    cursor: pointer;
    outline: none;
    min-width: 160px;
}

.period-select:focus {
    border-color: var(--accent-blue);
}

/* ===== MAIN ===== */
.main-content {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 2rem;
}

.chart-section {
    padding: 4rem 0;
    animation: fadeInUp 0.6s ease-out;
}

.section-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.section-header h2 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.section-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ===== CHART CARDS ===== */
.chart-grid {
    display: grid;
    gap: 1.5rem;
}

.chart-grid.two-col {
    grid-template-columns: 1fr 1fr;
}

.chart-card {
    background: var(--gradient-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 2rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.chart-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple), var(--accent-cyan));
    opacity: 0;
    transition: var(--transition);
}

.chart-card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

.chart-card:hover::before {
    opacity: 1;
}

.chart-card.full-width {
    width: 100%;
}

.chart-card h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 1.2rem;
    color: var(--text-primary);
}

.chart-wrapper {
    position: relative;
}

.doughnut-wrapper {
    height: 450px;
}

.bar-wrapper {
    height: 500px;
}

.top20-wrapper {
    height: 600px;
}

.market-wrapper {
    height: 500px;
}

/* ===== TABLE ===== */
.table-card {
    overflow: visible;
}

.table-wrapper {
    overflow-x: auto;
}

/* DataTables custom dark theme */
.dataTables_wrapper {
    color: var(--text-primary);
}

.dataTables_wrapper .dataTables_filter input {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 8px;
    font-family: var(--font-main);
    outline: none;
    margin-left: 8px;
}

.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--accent-blue);
}

.dataTables_wrapper .dataTables_length select {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 6px;
    font-family: var(--font-main);
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length label,
.dataTables_wrapper .dataTables_filter label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

table.dataTable {
    border-collapse: collapse !important;
    width: 100% !important;
}

table.dataTable thead th {
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.82rem;
    padding: 12px 10px;
    border-bottom: 2px solid var(--border-color) !important;
    white-space: nowrap;
}

table.dataTable tbody td {
    padding: 12px 10px;
    font-size: 0.85rem;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05) !important;
    max-width: 300px;
    line-height: 1.5;
}

table.dataTable tbody tr {
    background: transparent;
}

table.dataTable tbody tr:hover {
    background: rgba(37, 99, 235, 0.05) !important;
}

table.dataTable tbody tr.odd {
    background: rgba(0, 0, 0, 0.03);
}

table.dataTable tbody tr.odd:hover {
    background: rgba(37, 99, 235, 0.05) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    color: var(--text-secondary) !important;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 4px 10px;
    margin: 0 2px;
    font-size: 0.85rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: rgba(96, 165, 250, 0.15) !important;
    color: var(--accent-blue) !important;
    border-color: var(--border-color);
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: rgba(96, 165, 250, 0.2) !important;
    color: var(--accent-blue) !important;
    border-color: var(--accent-blue);
}

/* ===== FOOTER ===== */
.footer {
    margin-top: 4rem;
    padding: 3rem 2rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    background: linear-gradient(to top, rgba(244, 241, 234, 0.8), transparent);
}

.footer p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.footer-sub {
    margin-top: 0.5rem;
    font-size: 0.8rem !important;
    color: var(--text-muted) !important;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .hero-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    .chart-grid.two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .nav-bar {
        flex-direction: column;
        padding: 0.6rem 1rem;
    }
    .nav-links {
        gap: 0.2rem;
    }
    .nav-link {
        padding: 4px 10px;
        font-size: 0.78rem;
    }
    .main-content {
        padding: 0 1rem;
    }
    .chart-card {
        padding: 1.2rem;
    }
    .hero-stats {
        grid-template-columns: 1fr 1fr;
        gap: 0.8rem;
    }
    .stat-number {
        font-size: 1.3rem;
    }
}

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

/* ===== LOADING ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
