:root {
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --profit: #10b981;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--glass-shadow);
}

.dashboard-container {
    display: flex;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
    gap: 20px;
}

/* Sidebar */
.sidebar {
    width: 250px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 8px;
}

.brand h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.nav-links li a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    padding: 12px 16px;
    border-radius: 8px;
    display: block;
    transition: all 0.3s ease;
}

.nav-links li:hover a {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.nav-links li.active a {
    color: var(--text-main);
    background: var(--accent);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.top-nav {
    display: flex;
    align-items: center;
    padding: 16px 32px;
}

.glass-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 8px;
    outline: none;
    font-size: 0.9rem;
    color-scheme: dark;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: url('https://ui-avatars.com/api/?name=Admin&background=random') no-repeat center/cover;
}

.content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    padding-bottom: 20px;
}

/* KPIs */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.kpi-card {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.3s ease;
}

.kpi-card:hover {
    transform: translateY(-5px);
}

.kpi-card h3 {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
}

.value-loading {
    animation: pulse 1.5s infinite;
}

/* Tab Views */
.tab-content {
    display: none;
    flex-direction: column;
    gap: 20px;
}

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

/* Layout */
.desktop-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.panel {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel-header h2 {
    font-size: 1.25rem;
    margin-bottom: 4px;
}

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

/* Table */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
}

tbody tr {
    transition: background 0.2s ease;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.profit-text {
    color: var(--profit);
    font-weight: 700;
}

.danger-text {
    color: var(--danger);
    font-weight: 700;
}

/* Seasonal Planner */
.seasonal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.season-card {
    background: rgba(255, 255, 255, 0.03);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.season-card h4 {
    color: var(--accent);
    margin-bottom: 8px;
}

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

/* AI Chat Widget */
.ai-chat-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: white;
    padding: 16px 24px;
    border-radius: 30px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
    z-index: 100;
    transition: transform 0.2s;
}
.ai-chat-btn:hover {
    transform: scale(1.05);
}

.ai-chat-window {
    position: fixed;
    bottom: 90px;
    right: 30px;
    width: 350px;
    height: 450px;
    display: flex;
    flex-direction: column;
    z-index: 101;
    overflow: hidden;
}

.chat-header {
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header h4 { margin: 0; }
.chat-header button {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

.chat-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.msg.ai {
    background: rgba(255, 255, 255, 0.1);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.msg.user {
    background: var(--accent);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-footer {
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    gap: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-footer input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 10px 14px;
    border-radius: 8px;
    outline: none;
}

.chat-footer button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

@media (max-width: 1024px) {
    .dashboard-container {
        flex-direction: column;
        padding: 15px;
    }
    .sidebar {
        width: 100%;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 20px;
        padding: 20px;
    }
    .nav-links {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }
    .desktop-layout {
        grid-template-columns: 1fr;
    }
    .top-nav {
        flex-wrap: wrap;
        gap: 15px;
    }
}

@media (max-width: 768px) {
    .dashboard-container {
        padding: 10px;
    }
    .sidebar {
        padding: 16px;
        gap: 12px;
    }
    .nav-links {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        width: 100%;
    }
    .nav-links li {
        flex: 1;
        min-width: 110px;
        text-align: center;
    }
    .nav-links li a {
        padding: 10px 8px;
        font-size: 0.8rem;
    }
    .top-nav {
        flex-direction: column;
        align-items: flex-start;
        padding: 16px;
    }
    .date-picker-container {
        flex-direction: column;
        align-items: stretch !important;
        width: 100%;
        margin-left: 0 !important;
    }
    .date-picker-container input, .date-picker-container button {
        width: 100%;
    }
    .user-profile {
        margin-left: 0 !important;
        width: 100%;
        justify-content: flex-end;
    }
    .seasonal-grid {
        grid-template-columns: 1fr;
    }
    th, td {
        padding: 8px;
        font-size: 0.85rem;
    }
    
    /* 庫存調度表格在手機版卡片化佈局 */
    #transfers-table, 
    #transfers-table thead, 
    #transfers-table tbody, 
    #transfers-table th, 
    #transfers-table td, 
    #transfers-table tr {
        display: block;
    }
    #transfers-table thead {
        display: none;
    }
    #transfers-table tr {
        margin-bottom: 16px;
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 12px;
        padding: 12px;
        background: rgba(255, 255, 255, 0.02);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    #transfers-table td {
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        position: relative;
        padding: 10px 12px 10px 40% !important;
        text-align: right;
        min-height: 38px;
        white-space: normal !important;
    }
    #transfers-table td:last-child {
        border-bottom: none;
    }
    #transfers-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 12px;
        width: 35%;
        padding-right: 10px;
        text-align: left;
        font-weight: 600;
        color: var(--text-muted);
    }
    
    /* 商品名稱區塊特殊優化：100% 展開，不擠在右側 */
    #transfers-table td[data-label="商品名稱"] {
        padding-left: 12px !important;
        text-align: left;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 8px;
        margin-bottom: 8px;
    }
    #transfers-table td[data-label="商品名稱"]::before {
        display: none;
    }
    
    .ai-chat-window {
        width: calc(100vw - 40px);
        right: 20px;
        bottom: 80px;
    }
}

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

/* 調貨建議模擬器專屬樣式 */
.sim-input {
    width: 80px;
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: 6px;
    outline: none;
    transition: all 0.3s ease;
}

.sim-input:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.3);
}

.glass-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.glass-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.05);
}

.glass-btn:active {
    transform: translateY(0);
}

.btn-preset {
    border-color: rgba(59, 130, 246, 0.3);
}

.btn-preset:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

/* 狀態標籤 */
.sim-tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    border: 1px solid transparent;
}

.tag-emergency {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

.tag-normal {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.3);
}

.tag-safe {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.3);
}

.tag-supplier {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.3);
}

/* 決策軌跡步驟卡片 */
.step-card {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.step-card:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* 媒體查詢自適應 */
@media (max-width: 1024px) {
    .simulator-layout {
        grid-template-columns: 1fr !important;
    }
}
