/* 變數設定：現代感色彩系統 */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-gray: #f8fafc;
    --border-color: #e2e8f0;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 8px;
}

/* 顏色工具類別 */
.text-red { color: #ef4444 !important; font-weight: 600; }
.text-green { color: #22c55e !important; font-weight: 600; }
.text-black { color: var(--text-main) !important; }

/* 基礎重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-gray);
    color: var(--text-main);
    line-height: 1.5;
    padding: 2.5rem;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
}

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

/* 分頁導覽樣式 */
.tabs-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0.25rem;
    background: #e2e8f0;
    border-radius: 10px;
    width: fit-content;
}

.tab-btn {
    padding: 0.5rem 1.5rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--white);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.btn-secondary {
    background-color: var(--white);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background-color: #f1f5f9;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

/* 卡片與表格樣式 */
.dashboard-card {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.table-responsive {
    overflow: auto;
    max-height: 70vh; /* 設置最大高度以啟用內部垂直捲動，讓標題列置頂 */
    border-radius: var(--radius) var(--radius) 0 0;
}

table {
    width: 100%;
    border-collapse: separate; /* 改為 separate 以確保 sticky 邊框顯示正確 */
    border-spacing: 0;
    text-align: left;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: var(--white);
    padding: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    white-space: nowrap;
    box-shadow: 0 1px 0 var(--border-color); /* 補足 sticky 時的邊框線 */
}

thead th:last-child {
    border-right: none;
}

.header-cell {
    display: flex;
    flex-direction: column; /* 改為垂直排列以容納搜尋框 */
    align-items: flex-start;
    gap: 0.5rem;
}

.header-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-input {
    width: 100%;
    padding: 0.2rem 0.4rem;
    font-size: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: #f1f5f9;
    color: var(--text-main);
    transition: all 0.2s;
}

.filter-input:focus {
    background-color: var(--white);
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
    outline: none;
}

.filter-input::placeholder {
    color: #94a3b8;
}

/* 圖標顏色 */
.icon-muted { color: #cbd5e1; }
.icon-blue { color: var(--primary); }

/* 表格內容 */
tbody tr {
    transition: background-color 0.1s;
}

tbody tr:hover {
    background-color: #f1f5f9;
}

td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    min-width: 120px; /* 確保數字欄位有足夠寬度完整顯示 */
}

td.col-creative {
    min-width: 240px; /* 廣告欄位維持較大寬度 */
}

td.col-product {
    min-width: 100px;
}

.col-product {
    min-width: 100px;
}

td:last-child {
    border-right: none;
    min-width: auto;
}

/* 創意欄位 (圖片 + 文字) */
.creative-cell {
    display: flex;
    flex-direction: column; /* 改為垂直排列 */
    align-items: flex-start;
    gap: 0.75rem;
    width: 240px; /* 寬度配合直式廣告調整 */
    padding: 0.5rem 0;
}

.image-preview-box {
    width: 240px; /* 寬度固定 */
    min-height: 320px; /* 設置最小高度 */
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.image-preview-box img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* 改為 contain 確保圖片完整呈現，不被裁切 */
    background-color: #000; /* 增加深色背景深邃感 */
}

.image-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    color: white;
}

.image-preview-box:hover .image-overlay {
    opacity: 1;
}

/* 輸入框美化 */
input[type="text"] {
    width: 100%;
    padding: 0.25rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    font-size: 0.875rem;
    color: var(--text-main);
    outline: none;
    transition: all 0.2s;
}

input[type="text"]:hover {
    border-color: #cbd5e1;
    background: #ffffff;
}

input[type="text"]:focus {
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 0 0 1px var(--primary);
}

.text-muted-sm {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* 刪除按鈕 */
.delete-btn {
    color: #94a3b8;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.2s;
}

tr:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    color: #ef4444;
    background-color: #fee2e2;
}

/* 頁尾 */
.footer {
    margin-top: 1rem;
    text-align: right;
    font-size: 0.875rem;
    color: var(--text-muted);
}
