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

:root {
    --bg-main: #0b0f19;
    --bg-card: rgba(17, 24, 39, 0.7);
    --border-color: rgba(255, 255, 255, 0.07);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --color-primary: #3b82f6;
    --color-primary-glow: rgba(59, 130, 246, 0.35);
    
    --color-green: #10b981;
    --color-green-glow: rgba(16, 185, 129, 0.25);
    --color-yellow: #f59e0b;
    --color-yellow-glow: rgba(245, 158, 11, 0.25);
    --color-red: #ef4444;
    --color-red-glow: rgba(239, 68, 68, 0.3);
    
    --sidebar-width: 180px;
    --transition-speed: 0.3s;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

/* 捲軸美化 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* --- 側邊欄 Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 10;
}

.logo-section {
    padding: 16px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
}

.logo-section h2 {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.2px;
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.user-info {
    padding: 16px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-details h4 {
    font-size: 14px;
    font-weight: 500;
}

.user-details span {
    font-size: 11px;
    color: var(--text-secondary);
}

.nav-menu {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 10px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition-speed);
    cursor: pointer;
}

.nav-item:hover, .nav-item.active {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    border-left: 3px solid var(--color-primary);
    background: rgba(59, 130, 246, 0.1);
}

.logout-section {
    padding: 16px 8px;
    border-top: 1px solid var(--border-color);
}

/* --- 主工作區 Main Content --- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 24px;
    min-width: 0; /* 防止 Flex 容器被子項目撐大，確保內部表格能正常橫向滾動 */
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.top-bar h1 {
    font-size: 24px;
    font-weight: 600;
}

.actions-bar {
    display: flex;
    gap: 12px;
}

/* 按鈕樣式 */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease-in-out;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 4px 12px var(--color-primary-glow);
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px var(--color-primary-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
    background: var(--color-red);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* --- 卡片 Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.stat-card span {
    font-size: 13px;
    color: var(--text-secondary);
}

.stat-card h2 {
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.stat-card .trend {
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.trend.up { color: var(--color-green); }
.trend.down { color: var(--color-red); }

/* --- 面板 Tabs --- */
.tab-content {
    display: none;
    animation: fadeIn 0.4s ease;
}

.tab-content.active {
    display: block;
}

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

.panel-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    margin-bottom: 24px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.panel-header h3 {
    font-size: 18px;
    font-weight: 600;
}

/* --- 表格 Table --- */
.table-container {
    width: 100%;
    overflow-x: auto;
}

.stock-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

.stock-table th {
    padding: 12px 10px; /* 縮減 padding 以防止寬表格在低解析度螢幕下擠壓 */
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.stock-table td {
    padding: 12px 10px; /* 縮減 padding 以防止寬表格在低解析度螢幕下擠壓 */
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    vertical-align: middle;
}

.stock-table td button,
.stock-table td .btn,
.stock-table td a {
    white-space: nowrap; /* 確保操作按鈕不會折行 */
}

.stock-table tbody tr {
    transition: background 0.2s;
    cursor: pointer;
}

.stock-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.stock-name-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stock-code {
    font-weight: 600;
    color: #93c5fd;
}

.stock-name {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Badge 標籤 */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.badge-green {
    background: var(--color-green-glow);
    color: var(--color-green);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-yellow {
    background: var(--color-yellow-glow);
    color: var(--color-yellow);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-red {
    background: var(--color-red-glow);
    color: var(--color-red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* --- 彈窗對話盒 Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-box {
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-box {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 20px;
}

.modal-close:hover {
    color: var(--text-primary);
}

/* 表單樣式 */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* --- 即時紅色警告視窗 Emergency Alert --- */
.alert-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.alert-card {
    background: linear-gradient(135deg, #1e1b1b, #0f0a0a);
    border: 2px solid #ef4444;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    padding: 32px;
    text-align: center;
    box-shadow: 0 0 40px rgba(239, 68, 68, 0.4);
    animation: alertPulse 2s infinite alternate, bounceIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes alertPulse {
    0% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.3); }
    100% { box-shadow: 0 0 45px rgba(239, 68, 68, 0.65); }
}

@keyframes bounceIn {
    from { opacity: 0; transform: scale(0.3); }
    to { opacity: 1; transform: scale(1); }
}

.alert-icon {
    font-size: 48px;
    color: #ef4444;
    margin-bottom: 16px;
    animation: flash 1s infinite;
}

@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.alert-card h2 {
    color: #ef4444;
    margin-bottom: 12px;
    font-weight: 700;
    font-size: 24px;
}

.alert-card p {
    color: #d1d5db;
    margin-bottom: 24px;
    font-size: 15px;
    line-height: 1.6;
}

.alert-list {
    background: rgba(239, 68, 68, 0.08);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 28px;
    text-align: left;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-item {
    font-size: 13.5px;
    color: #fca5a5;
    padding: 6px 0;
    border-bottom: 1px solid rgba(239, 68, 68, 0.1);
}

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

/* --- 手動更新旋轉動畫 --- */
.spin-icon {
    display: inline-block;
    transition: transform 0.5s ease;
}

.refreshing .spin-icon {
    animation: rotate 1s linear infinite;
}

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

/* --- 詳細資訊側拉面板 Drawers --- */
.drawer-overlay {
    position: fixed;
    top: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    z-index: 90;
}

.drawer {
    position: fixed;
    top: 0;
    right: -480px;
    width: 100%;
    max-width: 480px;
    height: 100vh;
    background: #0f172a;
    border-left: 1px solid var(--border-color);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.4);
    z-index: 91;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.drawer.active {
    right: 0;
}

.drawer-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chart-container {
    width: 100%;
    height: 220px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 12px;
}

.drawer-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.detail-item {
    background: rgba(255, 255, 255, 0.02);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.detail-item label {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 4px;
}

.detail-item span {
    font-size: 15px;
    font-weight: 600;
}

/* 登入註冊卡片 */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100vw;
    background: radial-gradient(circle at top right, #1e1b4b, #0b0f19);
}

.auth-card {
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    padding: 40px 32px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
    text-align: center;
}

.auth-card h2 {
    font-size: 26px;
    margin-bottom: 8px;
    font-weight: 700;
}

.auth-card p {
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-size: 14px;
}

.auth-link {
    margin-top: 20px;
    font-size: 13.5px;
    color: var(--text-secondary);
}

.auth-link a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-link a:hover {
    text-decoration: underline;
}

.form-error {
    color: #f87171;
    font-size: 12.5px;
    margin-bottom: 12px;
    text-align: left;
    display: none;
}

/* --- 響應式手機版與版面自適應設計 (RWD) --- */

/* 1. 手機/平板選單控制元件 */
.hamburger-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 99;
    display: none;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* 2. 針對手機與平板版樣式切換的斷點 (< 1024px) */
@media (max-width: 1023px) {
    /* 顯示漢堡選單按鈕 */
    .hamburger-btn {
        display: inline-flex;
    }

    /* 將側邊選單轉換為側滑式抽屜 */
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px; /* 預設收回 */
        width: 260px;
        height: 100vh;
        z-index: 100;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
        transition: left var(--transition-speed) cubic-bezier(0.16, 1, 0.3, 1);
        background: rgba(15, 23, 42, 0.95); /* 手機版提高背景不透明度 */
    }

    .sidebar.active {
        left: 0; /* 滑出選單 */
    }

    /* 主工作區自適應寬度 */
    .main-content {
        margin-left: 0;
        padding: 16px;
        width: 100%;
        min-width: 0; /* 防止子元素撐爆容器 */
    }

    /* 頂部控制列改為直向堆疊或包裹 */
    .top-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 20px;
    }

    .top-bar .actions-bar {
        width: 100%;
    }

    .top-bar .actions-bar .btn {
        width: 100%;
        justify-content: center;
        padding: 12px;
    }

    /* 卡片概覽區域調整 */
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 16px;
        margin-bottom: 20px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card h2 {
        font-size: 22px;
    }

    /* 面板標頭調整 */
    .panel-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
    }

    .panel-header h3 {
        font-size: 16px;
        text-align: center;
    }

    .panel-header .btn {
        width: 100%;
        justify-content: center;
        padding: 12px;
    }

    /* 個股多空分析輸入區自適應 */
    #tab-analysis .panel-card div[style*="display: flex"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
    }

    #tab-analysis .panel-card div[style*="display: flex"] button,
    #tab-analysis .panel-card div[style*="display: flex"] input {
        width: 100% !important;
    }

    /* 彈窗對話框大小自適應 */
    .modal-box {
        width: calc(100% - 32px);
        margin: 16px;
        padding: 20px;
    }

    .modal-footer {
        flex-direction: column;
        gap: 10px;
    }

    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }

    /* 側拉詳細分析面板自適應 */
    .drawer {
        width: 100%;
        max-width: 100%;
        right: -100%;
    }
    
    .drawer.active {
        right: 0;
    }
}

/* 3. 針對超小手機螢幕 (< 480px) 的精細微調 */
@media (max-width: 479px) {
    .main-content {
        padding: 12px;
    }

    .stats-grid {
        grid-template-columns: 1fr; /* 單欄排列以獲得最佳閱讀體驗 */
        gap: 12px;
    }

    .panel-card {
        padding: 16px;
        border-radius: 12px;
    }

    .auth-card {
        padding: 30px 20px;
        margin: 16px;
        border-radius: 16px;
    }

    .auth-card h2 {
        font-size: 22px;
    }
}



