/* ========================================
   諦豐科技 Wedify - 後台管理樣式
======================================== */

/* CSS Variables */
:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --secondary: #ec4899;
    --accent: #14b8a6;
    
    --dark: #0f172a;
    --dark-light: #1e293b;
    --gray-900: #111827;
    --gray-800: #1f2937;
    --gray-700: #374151;
    --gray-600: #4b5563;
    --gray-500: #6b7280;
    --gray-400: #9ca3af;
    --gray-300: #d1d5db;
    --gray-200: #e5e7eb;
    --gray-100: #f3f4f6;
    --white: #ffffff;
    
    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #ec4899 100%);
    --gradient-secondary: linear-gradient(135deg, #14b8a6 0%, #6366f1 100%);
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    
    --radius-sm: 0.375rem;
    --radius: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    
    --transition: all 0.3s ease;
    --font-sans: 'Poppins', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
    
    --sidebar-width: 260px;
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    background-color: var(--dark);
    color: var(--gray-300);
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

a {
    text-decoration: none;
    color: inherit;
}

/* ========================================
   側邊欄
======================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark-light);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
    transition: var(--transition);
}

.sidebar.collapsed {
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--white);
}

.logo-text {
    display: flex;
    flex-direction: column;
}

.logo-en {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--white);
    line-height: 1.2;
}

.logo-zh {
    font-size: 0.7rem;
    color: var(--gray-400);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.5rem;
    color: var(--gray-400);
    transition: var(--transition);
    position: relative;
}

.nav-item:hover {
    color: var(--white);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    color: var(--white);
    background: rgba(99, 102, 241, 0.1);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--gradient-primary);
}

.nav-item i {
    width: 20px;
    text-align: center;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--secondary);
    color: var(--white);
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.back-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--gray-400);
    padding: 0.5rem 0;
    transition: var(--transition);
}

.back-link:hover {
    color: var(--primary-light);
}

/* ========================================
   主要內容區
======================================== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 頂部導航 */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--dark-light);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--gray-300);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
}

.header-left h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--white);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.admin-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.admin-name {
    color: var(--gray-300);
    font-size: 0.95rem;
}

.admin-avatar {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--white);
}

/* 內容區塊 */
.content-section {
    display: none;
    padding: 2rem;
    flex: 1;
}

.content-section.active {
    display: block;
}

/* ========================================
   統計卡片
======================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--dark-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.blue {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-light);
}

.stat-icon.purple {
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
}

.stat-icon.green {
    background: rgba(20, 184, 166, 0.1);
    color: var(--accent);
}

.stat-icon.pink {
    background: rgba(236, 72, 153, 0.1);
    color: var(--secondary);
}

.stat-info h3 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--white);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-info p {
    color: var(--gray-400);
    font-size: 0.9rem;
}

/* ========================================
   儀表板卡片
======================================== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.dashboard-card {
    background: var(--dark-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--white);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-header h3 i {
    color: var(--primary-light);
}

.card-header a {
    color: var(--primary-light);
    font-size: 0.875rem;
}

.card-header a:hover {
    text-decoration: underline;
}

.card-body {
    padding: 1rem 1.5rem;
    max-height: 300px;
    overflow-y: auto;
}

.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--gray-500);
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.empty-state.large i {
    font-size: 4rem;
}

/* 最近項目 */
.recent-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.recent-item:last-child {
    border-bottom: none;
}

.recent-avatar {
    width: 40px;
    height: 40px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-light);
    font-weight: 600;
}

.recent-info {
    flex: 1;
}

.recent-info h4 {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--white);
    margin-bottom: 0.125rem;
}

.recent-info p {
    font-size: 0.8rem;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.recent-time {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* ========================================
   聊天區塊
======================================== */
.chat-container {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0;
    background: var(--dark-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    overflow: hidden;
    height: calc(100vh - 180px);
}

.chat-list {
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
}

.chat-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-list-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--white);
}

.refresh-btn {
    background: rgba(99, 102, 241, 0.1);
    border: none;
    color: var(--primary-light);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.refresh-btn:hover {
    background: var(--primary);
    color: var(--white);
}

.chat-list-body {
    flex: 1;
    overflow-y: auto;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: var(--transition);
}

.chat-list-item:hover,
.chat-list-item.active {
    background: rgba(99, 102, 241, 0.1);
}

.chat-list-item .avatar {
    width: 45px;
    height: 45px;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-weight: 600;
    flex-shrink: 0;
}

.chat-list-item .info {
    flex: 1;
    min-width: 0;
}

.chat-list-item .info h4 {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--white);
    margin-bottom: 0.25rem;
}

.chat-list-item .info p {
    font-size: 0.8rem;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-item .meta {
    text-align: right;
    flex-shrink: 0;
}

.chat-list-item .meta .time {
    font-size: 0.7rem;
    color: var(--gray-500);
}

.chat-list-item .meta .unread {
    background: var(--secondary);
    color: var(--white);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 600;
    margin-top: 0.25rem;
    display: inline-block;
}

/* 聊天詳情 */
.chat-detail {
    display: flex;
    flex-direction: column;
}

.chat-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 45px;
    height: 45px;
    background: var(--gradient-secondary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-weight: 600;
}

.chat-user-info h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--white);
}

.chat-user-info span {
    font-size: 0.8rem;
    color: var(--gray-500);
}

.chat-detail-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.admin-message {
    max-width: 70%;
    display: flex;
    flex-direction: column;
}

.admin-message.user {
    align-self: flex-start;
}

.admin-message.bot,
.admin-message.admin {
    align-self: flex-end;
}

.admin-message .content {
    padding: 0.875rem 1rem;
    border-radius: var(--radius-lg);
    line-height: 1.5;
}

.admin-message.user .content {
    background: rgba(255, 255, 255, 0.05);
    color: var(--gray-300);
    border-bottom-left-radius: var(--radius-sm);
}

.admin-message.bot .content {
    background: rgba(20, 184, 166, 0.1);
    color: var(--accent);
    border-bottom-right-radius: var(--radius-sm);
}

.admin-message.admin .content {
    background: var(--gradient-primary);
    color: var(--white);
    border-bottom-right-radius: var(--radius-sm);
}

.admin-message .time {
    font-size: 0.7rem;
    color: var(--gray-500);
    margin-top: 0.375rem;
    padding: 0 0.25rem;
}

.admin-message .label {
    font-size: 0.65rem;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
    padding: 0 0.25rem;
}

.chat-detail-input {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
}

.chat-detail-input input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    color: var(--white);
    font-family: inherit;
    font-size: 0.95rem;
}

.chat-detail-input input:focus {
    outline: none;
    border-color: var(--primary);
}

.send-btn {
    width: 45px;
    height: 45px;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--radius-md);
    color: var(--white);
    cursor: pointer;
    transition: var(--transition);
}

.send-btn:hover {
    transform: scale(1.05);
}

/* ========================================
   表格
======================================== */
.table-container {
    background: var(--dark-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.table-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--white);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.export-btn {
    background: rgba(20, 184, 166, 0.1);
    border: 1px solid rgba(20, 184, 166, 0.3);
    color: var(--accent);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.export-btn:hover {
    background: var(--accent);
    color: var(--white);
}

.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 1rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.data-table th {
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
    color: var(--gray-300);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    color: var(--gray-300);
    font-size: 0.95rem;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.empty-cell {
    text-align: center !important;
    padding: 3rem !important;
    color: var(--gray-500);
}

.action-btn {
    background: rgba(99, 102, 241, 0.1);
    border: none;
    color: var(--primary-light);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    margin-right: 0.5rem;
}

.action-btn:hover {
    background: var(--primary);
    color: var(--white);
}

.action-btn.delete {
    background: rgba(236, 72, 153, 0.1);
    color: var(--secondary);
}

.action-btn.delete:hover {
    background: var(--secondary);
    color: var(--white);
}

.message-preview {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========================================
   彈窗
======================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: var(--dark-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    z-index: 201;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal.open {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--white);
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--gray-400);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
}

.close-modal:hover {
    color: var(--white);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: calc(90vh - 70px);
}

.modal-body .detail-row {
    margin-bottom: 1rem;
}

.modal-body .detail-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.375rem;
}

.modal-body .detail-value {
    color: var(--white);
    font-size: 1rem;
    line-height: 1.6;
}

/* ========================================
   響應式設計
======================================== */
@media (max-width: 1024px) {
    .chat-container {
        grid-template-columns: 280px 1fr;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .menu-toggle {
        display: block;
    }
    
    .chat-container {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .chat-list {
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .chat-detail-messages {
        min-height: 300px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .content-section {
        padding: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-icon {
        width: 50px;
        height: 50px;
        font-size: 1.25rem;
    }
    
    .stat-info h3 {
        font-size: 1.5rem;
    }
}
