/* ========================================
   全局样式
======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --dark-color: #1e293b;
    --light-color: #f8fafc;
    --border-color: #e2e8f0;
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --transition-speed: 0.3s;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #334155;
    background: #f1f5f9;
}

/* ========================================
   登錄頁面
======================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header i {
    font-size: 48px;
    color: var(--primary-color);
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 24px;
    color: var(--dark-color);
    margin-bottom: 8px;
}

.login-header p {
    color: var(--secondary-color);
    font-size: 14px;
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    margin-bottom: 8px;
    color: var(--dark-color);
    font-weight: 500;
}

.login-form input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.password-input {
    position: relative;
}

.toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--secondary-color);
    cursor: pointer;
    padding: 4px 8px;
}

.btn-login {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-login:hover {
    background: #1d4ed8;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

/* ========================================
   主應用佈局
======================================== */
.main-app {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* ========================================
   手機端漢堡菜單按鈕
======================================== */
.mobile-menu-btn {
    display: none; /* 桌面端隱藏 */
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1001;
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.3s;
}

.mobile-menu-btn:hover {
    background: #1d4ed8;
    transform: scale(1.05);
}

.mobile-menu-btn:active {
    transform: scale(0.95);
}

/* ========================================
   Sidebar 遮罩層（手機端）
======================================== */
.sidebar-overlay {
    display: none; /* 默認隱藏 */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

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

/* ========================================
   Sidebar
======================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark-color);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transition: transform var(--transition-speed) ease;
}

.sidebar-header {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header i {
    font-size: 24px;
    color: var(--primary-color);
}

.sidebar-header span {
    font-size: 18px;
    font-weight: 600;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: all 0.3s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-item.active {
    background: rgba(37, 99, 235, 0.15);
    color: white;
    border-left-color: var(--primary-color);
}

.nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    margin-bottom: 12px;
}

.user-info i {
    font-size: 24px;
}

.btn-logout {
    width: 100%;
    padding: 10px;
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.3);
    color: white;
}

/* ========================================
   主內容區
======================================== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition-speed) ease;
}

.top-bar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-bar h2 {
    font-size: 20px;
    color: var(--dark-color);
}

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

.btn-icon {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--light-color);
    color: var(--secondary-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--primary-color);
    color: white;
}

/* ========================================
   視圖容器
======================================== */
.view {
    display: none;
    padding: 24px;
    flex: 1;
}

.view.active {
    display: block;
}

.view-header {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

/* ========================================
   KPI 卡片
======================================== */
.kpi-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.kpi-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.3s;
}

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.kpi-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.kpi-icon.blue { background: rgba(37, 99, 235, 0.1); color: var(--primary-color); }
.kpi-icon.green { background: rgba(16, 185, 129, 0.1); color: var(--success-color); }
.kpi-icon.orange { background: rgba(245, 158, 11, 0.1); color: var(--warning-color); }
.kpi-icon.purple { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }
.kpi-icon.gold { background: rgba(234, 179, 8, 0.1); color: #eab308; }

.kpi-content {
    flex: 1;
}

.kpi-label {
    font-size: 12px;
    color: var(--secondary-color);
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--dark-color);
}

/* ========================================
   卡片
======================================== */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 24px;
    overflow: hidden;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.card-header h3 {
    font-size: 16px;
    color: var(--dark-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body {
    padding: 24px;
}

/* ========================================
   圖表網格
======================================== */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
}

/* ========================================
   財務總結
======================================== */
.finance-summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.finance-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 20px;
    color: white;
    display: flex;
    align-items: center;
    gap: 16px;
}

.finance-icon {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.finance-label {
    font-size: 12px;
    opacity: 0.9;
    margin-bottom: 4px;
}

.finance-value {
    font-size: 24px;
    font-weight: 700;
}

.finance-table-container {
    overflow-x: auto;
}

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

.finance-table th,
.finance-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.finance-table th {
    background: var(--light-color);
    font-weight: 600;
    color: var(--dark-color);
}

/* ========================================
   表格
======================================== */
.table-controls {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-box {
    flex: 1;
    min-width: 250px;
    position: relative;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--secondary-color);
}

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
}

.filter-group {
    display: flex;
    gap: 12px;
}

.filter-group select {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

.data-table th,
.data-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: var(--light-color);
    font-weight: 600;
    color: var(--dark-color);
    white-space: nowrap;
}

.data-table tbody tr {
    transition: background 0.2s;
}

.data-table tbody tr:hover {
    background: var(--light-color);
}

/* ========================================
   狀態標籤
======================================== */
.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.status-badge.completed {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.status-badge.in-progress {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.status-badge.pending {
    background: rgba(100, 116, 139, 0.1);
    color: var(--secondary-color);
}

/* ========================================
   按鈕
======================================== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background: #1d4ed8;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

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

.btn-secondary:hover {
    background: #475569;
}

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

.btn-success:hover {
    background: #059669;
}

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* ========================================
   Modal
======================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    font-size: 18px;
    color: var(--dark-color);
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--light-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 20px;
    color: var(--secondary-color);
    transition: all 0.3s;
}

.modal-close:hover {
    background: var(--danger-color);
    color: white;
}

.modal-body {
    padding: 24px;
}

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

/* ========================================
   表單
======================================== */
.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.form-row .full-width {
    grid-column: 1 / -1;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--dark-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-group {
    display: flex;
    gap: 8px;
}

.input-group input {
    flex: 1;
}

/* ========================================
   Chips（標籤）
======================================== */
.chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.chip {
    padding: 6px 12px;
    background: var(--light-color);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
}

.chip:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ========================================
   Toggle 按鈕組
======================================== */
.toggle-group {
    display: flex;
    gap: 8px;
}

.toggle-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border-color);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.toggle-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ========================================
   設置頁面
======================================== */
.settings-section {
    margin-bottom: 32px;
}

.settings-section h4 {
    margin-bottom: 16px;
    color: var(--dark-color);
}

.categories-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--light-color);
    border-radius: 8px;
}

.category-info {
    flex: 1;
}

.category-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.category-subcategories {
    font-size: 12px;
    color: var(--secondary-color);
}

/* ========================================
   響應式設計 - 平板
======================================== */
@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .kpi-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========================================
   響應式設計 - 手機端
======================================== */
@media (max-width: 768px) {
    /* 顯示漢堡菜單按鈕 */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Sidebar 默認隱藏（滑出屏幕外） */
    .sidebar {
        transform: translateX(-100%);
    }
    
    /* Sidebar 展開狀態 */
    .sidebar.active {
        transform: translateX(0);
    }
    
    /* 主內容區占滿全屏 */
    .main-content {
        margin-left: 0;
    }
    
    /* Top Bar 樣式調整 */
    .top-bar {
        padding: 0 60px 0 20px; /* 左側留空間給漢堡按鈕 */
    }
    
    .top-bar h2 {
        font-size: 18px;
    }
    
    /* KPI 卡片單列布局 */
    .kpi-cards {
        grid-template-columns: 1fr;
    }
    
    /* 財務卡片單列 */
    .finance-summary-cards {
        grid-template-columns: 1fr;
    }
    
    /* 圖表單列 */
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    /* View 內邊距減小 */
    .view {
        padding: 16px;
    }
    
    /* 表單改為單列 */
    .form-row {
        grid-template-columns: 1fr;
    }
    
    /* Modal 內容寬度調整 */
    .modal-content {
        max-width: 100%;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    /* 按鈕組換行 */
    .view-header {
        flex-direction: column;
    }
    
    .view-header .btn {
        width: 100%;
    }
    
    /* 表格控制項堆疊 */
    .table-controls {
        flex-direction: column;
    }
    
    .search-box {
        width: 100%;
    }
    
    .filter-group {
        width: 100%;
        flex-direction: column;
    }
    
    .filter-group select {
        width: 100%;
    }
    
    /* Sidebar 展開時，內容不換行 */
    .sidebar-nav {
        white-space: nowrap;
    }
    
    /* Card 內邊距調整 */
    .card-body {
        padding: 16px;
    }
    
    /* KPI 卡片字體調整 */
    .kpi-value {
        font-size: 20px;
    }
    
    .kpi-icon {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }
    
    /* 財務卡片字體調整 */
    .finance-value {
        font-size: 20px;
    }
}

/* ========================================
   響應式設計 - 小屏手機
======================================== */
@media (max-width: 480px) {
    /* 登錄頁面 */
    .login-card {
        padding: 24px;
    }
    
    .login-header h1 {
        font-size: 20px;
    }
    
    .login-header i {
        font-size: 36px;
    }
    
    /* 進一步縮小內邊距 */
    .view {
        padding: 12px;
    }
    
    .card-body {
        padding: 12px;
    }
    
    /* 表格字體調整 */
    .data-table {
        font-size: 12px;
    }
    
    .data-table th,
    .data-table td {
        padding: 8px;
    }
    
    /* 按鈕字體調整 */
    .btn {
        font-size: 13px;
        padding: 8px 16px;
    }
    
    /* Modal 頭部 */
    .modal-header {
        padding: 16px;
    }
    
    .modal-header h3 {
        font-size: 16px;
    }
}

/* ========================================
   打印樣式
======================================== */
@media print {
    .sidebar,
    .top-bar,
    .mobile-menu-btn,
    .sidebar-overlay,
    .btn,
    .view-header {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .view {
        padding: 0;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* ========================================
   滾動條美化
======================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--light-color);
}

::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--dark-color);
}

/* ========================================
   動畫
======================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.view.active {
    animation: fadeIn 0.3s ease;
}

/* ========================================
   工具類
======================================== */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--secondary-color);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 16px;
}
