* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    max-width: 100%;
}

html {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
    position: relative;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #3b82f6;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --text-light: #64748b;
    --border-color: #e2e8f0;
    --card-bg: #ffffff;
    --sidebar-width: 250px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

.dashboard-container {
    display: flex;
    min-height: 100vh;
}

/* 側邊欄 */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: white;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 2rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.sidebar-header p {
    font-size: 0.875rem;
    color: rgba(255,255,255,0.7);
}

.sidebar-nav {
    padding: 1rem 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1.5rem;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
}

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

.nav-item.active {
    background: rgba(59, 130, 246, 0.2);
    color: white;
    border-left-color: var(--primary-color);
}

.nav-item .icon {
    font-size: 1.25rem;
    margin-right: 0.75rem;
}

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

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 12px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.btn-logout:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-logout .icon {
    font-size: 1.1rem;
}

/* 主內容區 */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
}

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

.top-header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.mobile-menu-btn {
    display: none;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
        background: var(--primary-color);
        color: white;
        border: none;
        border-radius: 0.375rem;
        padding: 0.5rem;
        font-size: 1.25rem;
        cursor: pointer;
        transition: background 0.3s ease;
    }
    
    .mobile-menu-btn:hover {
        background: #2563eb;
    }
    
    .header-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .time-display {
        font-size: 0.75rem;
    }
}

.btn-refresh {
    padding: 0.625rem 1.25rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.3s ease;
}

.btn-refresh:hover {
    background: #2563eb;
}

.time-display {
    font-size: 0.875rem;
    color: var(--text-light);
}

/* 頁面區塊 */
.section {
    display: none;
}

.section.active {
    display: block;
}

/* 統計卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

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

.stat-icon {
    font-size: 3rem;
}

.stat-info h3 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-info p {
    font-size: 0.875rem;
    color: var(--text-light);
}

/* 圖表容器 */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chart-card h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

/* 最近活動 */
.recent-activity {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.recent-activity h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.activity-item {
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.activity-icon {
    font-size: 1.5rem;
}

/* 區塊標題 */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

.filters {
    display: flex;
    gap: 1rem;
}

.filters input,
.filters select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
}

/* 表格 */
.table-container {
    background: var(--card-bg);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

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

.data-table thead {
    background: var(--bg-color);
}

.data-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-color);
    border-bottom: 2px solid var(--border-color);
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

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

.btn-upgrade {
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%) !important;
    color: white !important;
    border: none !important;
    padding: 6px 12px !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    transition: all 0.2s !important;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3) !important;
    margin-right: 0.5rem !important;
    display: inline-block !important;
}

.btn-upgrade:hover {
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
}

.btn-upgrade:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.btn-action {
    padding: 0.375rem 0.75rem;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.75rem;
    margin-right: 0.5rem;
}

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

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

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

/* 模式卡片 */
.mode-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.mode-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.mode-card h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.mode-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.mode-stat {
    text-align: center;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
}

.mode-stat .label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-light);
    margin-bottom: 0.25rem;
}

.mode-stat .value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* 分析卡片 */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.analytics-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.analytics-card h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

/* 彈窗樣式 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 0.75rem;
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    transition: color 0.3s ease;
}

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

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.conversation-detail {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message-item {
    padding: 1rem;
    border-radius: 0.5rem;
    background: var(--bg-color);
}

.message-item.user {
    background: #dbeafe;
    margin-left: 2rem;
}

.message-item.ai {
    background: #f0f9ff;
    margin-right: 2rem;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.message-role {
    font-weight: 600;
    color: var(--primary-color);
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-light);
}

.message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* 防止水平滾動 - 全局規則 */
* {
    max-width: 100%;
}

html,
body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    position: relative;
}

.dashboard-container {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

.main-content {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* 確保所有容器都不會橫向溢出 */
.container,
.content-section,
.section,
.tab-content,
.tab-panel {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* 響應式設計 */
@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }
    
    .main-content {
        margin-left: 200px;
    }
    
    .charts-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 0;
        overflow: hidden;
        position: fixed;
        left: -100%;
        transition: left 0.3s ease;
    }
    
    .sidebar.active {
        left: 0;
        width: 280px;
        z-index: 10001;
    }
    
    .main-content {
        margin-left: 0;
        padding: 1rem;
    }
    
    .top-header {
        flex-direction: row;
        gap: 1rem;
        align-items: center;
        padding: 1rem;
    }
    
    .top-header h1 {
        font-size: 1.5rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .stat-icon {
        font-size: 2rem;
    }
    
    .mode-stats {
        grid-template-columns: 1fr;
    }
    
    .mode-stats-grid {
        grid-template-columns: 1fr;
    }
    
    .analytics-grid {
        grid-template-columns: 1fr;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .filters {
        flex-direction: column;
        width: 100%;
    }
    
    .filters input,
    .filters select {
        width: 100%;
    }
    
    /* 手機版表格改為卡片式佈局 */
    .table-container {
        overflow-x: hidden;
        width: 100%;
        max-width: 100%;
    }
    
    /* 在手機版隱藏表格標題 */
    .data-table thead {
        display: none !important;
    }
    
    /* 確保表格不會橫向滾動 */
    .data-table {
        width: 100%;
        max-width: 100%;
        table-layout: fixed;
    }
    
    .data-table td,
    .data-table th {
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 0;
    }
    
    /* 手機版卡片容器 */
    .mobile-cards-container {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* 自定義卡片樣式 */
    .mobile-card {
        background: white;
        border: 1px solid var(--border-color);
        border-radius: 0.75rem;
        padding: 1rem;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    .mobile-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.75rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid var(--border-color);
    }
    
    .mobile-card-title {
        font-weight: 600;
        color: var(--primary-color);
    }
    
    .mobile-card-badge {
        background: var(--primary-color);
        color: white;
        padding: 0.25rem 0.5rem;
        border-radius: 0.25rem;
        font-size: 0.75rem;
    }
    
    .mobile-card-row {
        display: flex;
        justify-content: space-between;
        margin-bottom: 0.5rem;
        padding: 0.5rem 0;
    }
    
    .mobile-card-label {
        font-weight: 500;
        color: var(--text-light);
        min-width: 80px;
    }
    
    .mobile-card-value {
        flex: 1;
        text-align: right;
        color: var(--text-color);
        word-break: break-word;
        overflow-wrap: break-word;
        max-width: 60%;
    }
    
    .mobile-card-actions {
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid var(--border-color);
        display: flex;
        gap: 0.5rem;
    }
    
    .mobile-card-actions .btn-action {
        flex: 1;
        text-align: center;
    }
    
    /* 調整按鈕大小 */
    .btn-action {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
        margin-right: 0.25rem;
        white-space: nowrap;
    }
    
    /* 統計卡片在手機上更緊湊 */
    .stat-card {
        padding: 1rem;
        gap: 1rem;
    }
    
    .stat-icon {
        font-size: 2rem;
    }
    
    .stat-info h3 {
        font-size: 1.5rem;
    }
    
    .stat-info p {
        font-size: 0.75rem;
    }
    
    /* 圖表容器在手機上 */
    .chart-card,
    .analytics-card {
        padding: 1rem;
        overflow: hidden;
    }
    
    .chart-card h3,
    .analytics-card h3 {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }
    
    /* 圖表在手機上更小 */
    .chart-card,
    .analytics-card {
        padding: 1rem;
    }
    
    /* 彈窗在手機上全螢幕 */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        border-radius: 0.5rem;
    }
    
    .message-item.user,
    .message-item.ai {
        margin-left: 0;
        margin-right: 0;
    }
    
    .sidebar-header h2 {
        font-size: 1.25rem;
    }
    
    /* 區塊標題在手機上 */
    .section-header h2 {
        font-size: 1.25rem;
    }
    
    /* 表單元素在手機上 */
    .filters input,
    .filters select {
        font-size: 0.875rem;
        padding: 0.5rem;
    }
    
    /* 重新整理按鈕在手機上 */
    .btn-refresh {
        font-size: 0.75rem;
        padding: 0.5rem 1rem;
    }
    
    /* 頁面標題在手機上 */
    #page-title {
        font-size: 1.25rem;
    }
    
    /* 管理員設定頁面在手機上 */
    .settings-container {
        padding: 1rem !important;
    }
    
    .settings-card {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }
    
    .export-options,
    .import-options {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    
    .export-options button,
    .import-options button,
    .import-options select {
        width: 100%;
        font-size: 0.875rem;
        padding: 0.75rem 1rem;
    }
    
    /* 圖表容器在視窗大小改變時重新調整 */
    .charts-container {
        flex-direction: column;
    }
    
    .chart-card {
        margin-bottom: 1rem;
    }
    
    /* 最近活動在手機上 */
    .recent-activity {
        padding: 1rem;
    }
    
    .activity-list {
        max-height: 300px;
        overflow-y: auto;
    }
    
    /* 模式卡片在手機上 */
    .mode-card {
        margin-bottom: 1rem;
    }
    
    /* 確保所有按鈕在手機上可點擊 */
    .btn-action,
    .btn-view,
    .btn-delete,
    .btn-subscribe {
        min-height: 44px;
        min-width: 44px;
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
    
    /* 確保所有容器都不會橫向滾動 */
    .main-content {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .content-section {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .section-header {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        flex-wrap: wrap;
    }
    
    .filters {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* 統計卡片在手機上 */
    .stats-grid {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .stat-card {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* 圖表容器 */
    .chart-card,
    .analytics-card {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    /* 彈窗內容 */
    .modal-content {
        width: 95%;
        max-width: 95%;
        box-sizing: border-box;
    }
    
    /* 分頁控制 */
    .pagination {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    /* 標籤頁容器 */
    .tabs-container {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    
    .tabs-container::-webkit-scrollbar {
        height: 4px;
    }
    
    .tabs-container::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 2px;
    }
    
    /* 確保所有輸入框和選擇框都不會超出 */
    input,
    textarea,
    select {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* 按鈕容器 */
    .mobile-card-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .mobile-card-actions .btn-action {
        flex: 1 1 auto;
        min-width: 0;
        max-width: 100%;
    }
}

/* Badge 樣式 */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background-color: #10b981;
    color: white;
}

.badge-danger {
    background-color: #ef4444;
    color: white;
}

/* 按鈕顏色 */
.btn-success {
    background: #10b981;
    color: white;
}

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

.btn-danger {
    background: #ef4444;
    color: white;
}

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

.btn-subscribe {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    margin-right: 0.5rem;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background 0.3s ease;
}
