:root {
    --primary: #1976d2;
    --primary-hover: #1565c0;
    --primary-light: #e3f2fd;
    --success: #2e7d32;
    --success-light: #e8f5e9;
    --success-border: #a5d6a7;
    --warning: #ed6c02;
    --danger: #d32f2f;
    --danger-light: #ffebee;
    --purple: #7b1fa2;
    --purple-light: #f3e5f5;
    --teal: #00897b;
    --teal-light: #e0f2f1;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #cbd5e1;
    --border-light: #e2e8f0;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --weekend-bg: #f1f5f9;
    --weekend-text: #94a3b8;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    padding-bottom: 60px;
}

.app-container {
    max-width: 1480px;
    margin: 0 auto;
    padding: 24px;
}

/* 頂部導覽列 */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    padding: 16px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    margin-bottom: 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-icon {
    font-size: 32px;
    background: var(--primary-light);
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
}

.header-left h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.header-left .sub-title {
    font-size: 13px;
    color: var(--text-secondary);
}

.db-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.25s ease;
    user-select: none;
}

/* 連線正常 (綠色) */
.db-badge.online {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}
.db-badge.online .status-dot {
    background-color: #22c55e;
    box-shadow: 0 0 0 2px #bbf7d0;
}

/* 連線異常 (紅色文字與紅色圓點) */
.db-badge.offline {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    font-weight: 700;
}
.db-badge.offline .status-dot {
    background-color: #ef4444;
    box-shadow: 0 0 0 2px #fecaca;
}

/* 檢測中 (灰色) */
.db-badge.checking {
    background: #f8fafc;
    color: #64748b;
    border: 1px solid #e2e8f0;
}
.db-badge.checking .status-dot {
    background-color: #94a3b8;
    box-shadow: 0 0 0 2px #e2e8f0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #22c55e;
    box-shadow: 0 0 0 2px #bbf7d0;
    transition: all 0.25s ease;
}

/* 上傳與範例區 */
.upload-section {
    margin-bottom: 20px;
}

.upload-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
}

/* 來源模式切換分頁 (圖檔上傳 vs WebCam 拍照) */
.source-mode-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--border-light);
    padding-bottom: 10px;
}

.source-tab {
    background: transparent;
    border: none;
    padding: 8px 18px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.source-tab:hover {
    background: var(--weekend-bg);
    color: var(--text-primary);
}

.source-tab.active {
    background: var(--primary-light);
    color: var(--primary);
    box-shadow: 0 1px 2px rgba(25, 118, 210, 0.15);
}

/* WebCam 視訊取景面板 */
.webcam-panel {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-top: 4px;
}

.webcam-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px dashed var(--border-light);
}

.webcam-device-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 260px;
}

.webcam-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.webcam-select {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    font-size: 13px;
    background: #ffffff;
    max-width: 380px;
}

.webcam-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-webcam-ctrl {
    background: #ffffff;
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-webcam-ctrl:hover {
    background: #f1f5f9;
}

.webcam-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.webcam-badge.paused {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}

.webcam-badge.paused .status-dot {
    background-color: #ef4444;
    box-shadow: 0 0 0 2px #fecaca;
}

/* 視訊取景器視窗 */
.webcam-stage-box {
    background: #0f172a;
    border-radius: var(--radius-md);
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
    min-height: 380px;
}

.webcam-viewport {
    position: relative;
    max-width: 100%;
    width: 760px;
    line-height: 0;
    overflow: hidden;
    border-radius: 6px;
    background: #000;
}

#webcamVideo {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 6px;
}

#webcamCapturedPhoto {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 6px;
}

/* 輔助對齊框線 */
.webcam-align-overlay {
    position: absolute;
    inset: 16px;
    border: 2px dashed rgba(255, 255, 255, 0.65);
    border-radius: 8px;
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 12px;
    transition: all 0.2s ease;
}

.align-hint {
    background: rgba(15, 23, 42, 0.85);
    color: #f8fafc;
    font-size: 12px;
    padding: 5px 14px;
    border-radius: 9999px;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* 拍照按鈕組 */
.webcam-btn-group {
    display: flex;
    justify-content: center;
    gap: 14px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.btn-webcam-action {
    padding: 10px 22px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-snap-and-run {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.btn-snap-and-run:hover {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.4);
}

.btn-snap-only {
    background: #0ea5e9;
    color: #ffffff;
}

.btn-snap-only:hover {
    background: #0284c7;
}

.btn-retake {
    background: #f1f5f9;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-retake:hover {
    background: #e2e8f0;
}

.upload-dropzone {
    border: 2px dashed #93c5fd;
    background: #f0f7ff;
    border-radius: var(--radius-md);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-dropzone:hover, .upload-dropzone.drag-over {
    border-color: var(--primary);
    background: #e0f2fe;
}

.file-input-hidden {
    display: none;
}

.upload-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.upload-text h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.upload-text .highlight {
    color: var(--primary);
    text-decoration: underline;
}

.upload-text p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* 檔案狀態提示列 */
.file-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    margin-top: 14px;
}

.file-info-text {
    font-size: 13px;
    color: #065f46;
}

.file-info-text strong {
    color: #047857;
}

.btn-text-danger {
    background: none;
    border: none;
    color: #dc2626;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.btn-text-danger:hover {
    text-decoration: underline;
}

/* 模型選擇與執行辨識控制列 */
.model-action-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
    gap: 16px;
    flex-wrap: wrap;
}

.model-select-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 320px;
}

.model-select-group label {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.select-with-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.model-select {
    flex: 1;
    font-weight: 600;
    color: #0f172a;
    border: 1.5px solid #94a3b8;
}

.btn-refresh-models {
    background: white;
    border: 1.5px solid #cbd5e1;
    border-radius: var(--radius-sm);
    height: 38px;
    width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.15s;
}

.btn-refresh-models:hover {
    background: #f1f5f9;
    border-color: var(--primary);
}

.action-btn-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 核心按鈕：開始 AI 圖片辨識 */
.btn-run-ocr {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    font-size: 14px;
    font-weight: 700;
    padding: 9px 22px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-run-ocr:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.4);
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
}

.btn-run-ocr:disabled {
    background: #cbd5e1;
    color: #64748b;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* YOLO 圖形辨識按鈕 */
.btn-yolo {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: white;
    font-size: 14px;
    font-weight: 700;
    padding: 9px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(5, 150, 105, 0.3);
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-yolo:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(5, 150, 105, 0.4);
    background: linear-gradient(135deg, #047857 0%, #065f46 100%);
}

.btn-yolo:disabled {
    background: #cbd5e1;
    color: #64748b;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* 原始記錄表影像展示卡片 */
.image-preview-card {
    margin-top: 16px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
    gap: 10px;
}

.preview-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.preview-icon {
    font-size: 18px;
}

.preview-title-wrap h4 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.image-name-badge {
    background: #e2e8f0;
    color: #475569;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-family: var(--font-mono);
}

.preview-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-tool {
    background: white;
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-tool:hover {
    background: #f1f5f9;
    color: var(--text-primary);
    border-color: #94a3b8;
}

.zoom-text {
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    min-width: 45px;
    text-align: center;
    font-weight: 600;
}

.preview-body {
    padding: 16px;
    background: #0f172a;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    max-height: 520px;
    overflow: auto;
}

.preview-image-container {
    transition: transform 0.2s ease;
    transform-origin: center center;
    display: flex;
    justify-content: center;
}

.preview-image-container img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* YOLO 結果展示卡片 */
.yolo-result-card {
    margin-top: 16px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1.5px solid #10b981;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.yolo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: #ecfdf5;
    border-bottom: 1px solid #a7f3d0;
}

.yolo-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.yolo-icon {
    font-size: 20px;
}

.yolo-title-wrap h4 {
    font-size: 15px;
    font-weight: 700;
    color: #065f46;
}

.yolo-count-badge {
    background: #059669;
    color: white;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.yolo-body {
    padding: 16px;
}

.yolo-summary-bar {
    background: #f8fafc;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--text-primary);
}

.yolo-summary-bar .summary-label {
    color: var(--text-secondary);
}

.yolo-image-box {
    max-height: 480px;
    overflow: auto;
    padding: 12px;
    text-align: center;
    background: #0f172a;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
}

.yolo-image-box img {
    max-width: 100%;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.yolo-tags-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.yolo-tag {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.yolo-tag .tag-name {
    font-weight: 600;
    color: #1e293b;
}

.yolo-tag .tag-conf {
    color: #059669;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

.yolo-interactive-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
}

.interactive-box {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid #ef4444;
    background: rgba(239, 68, 68, 0.2);
    border-radius: 3px;
    cursor: pointer;
    z-index: 20;
    pointer-events: auto;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.interactive-box:hover {
    border: 2.5px solid #dc2626;
    background: rgba(239, 68, 68, 0.45);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
    z-index: 30;
}

.interactive-box .box-del-btn {
    position: absolute;
    top: -9px;
    right: -9px;
    width: 16px;
    height: 16px;
    background: #dc2626;
    color: #ffffff;
    font-size: 10px;
    font-weight: bold;
    line-height: 16px;
    text-align: center;
    border-radius: 50%;
    opacity: 0.85;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.interactive-box:hover .box-del-btn {
    opacity: 1;
    transform: scale(1.15);
}

.interactive-box.is-name-box,
.interactive-box.is-sno-box {
    border: 2.5px solid #ef4444;
    background: rgba(239, 68, 68, 0.22);
    cursor: move;
    z-index: 25;
}

.interactive-box.is-name-box:hover,
.interactive-box.is-sno-box:hover {
    border-color: #b91c1c;
    background: rgba(239, 68, 68, 0.38);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.85);
}

.interactive-box .box-sno-badge {
    position: absolute;
    top: -24px;
    left: -2px;
    background: #ef4444;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 3px;
}


.btn-sample {
    background: #f8fafc;
    border: 1.5px solid #cbd5e1;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: #334155;
    transition: all 0.15s;
}

.btn-sample:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.model-used-badge {
    margin-left: auto;
    background: #fae8ff;
    color: #86198f;
    border: 1px solid #f0abfc;
    border-radius: 9999px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

/* 影像對照卡片 */
.image-preview-card {
    margin-top: 16px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border-light);
}

.preview-header h4 {
    font-size: 14px;
    font-weight: 600;
}

.preview-controls {
    display: flex;
    gap: 8px;
}

.btn-sm {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: white;
    font-size: 12px;
    cursor: pointer;
}

.btn-sm:hover {
    background: #f1f5f9;
}

.btn-outline {
    color: var(--primary);
    border-color: #93c5fd;
}

.image-scroll-box {
    max-height: 380px;
    overflow: auto;
    padding: 12px;
    text-align: center;
    background: #334155;
}

.image-scroll-box img {
    max-width: 100%;
    transition: transform 0.2s ease;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* AI 狀態與比對標籤列 (參考截圖 1) */
.ai-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    border: 1.5px solid #22c55e;
    border-radius: var(--radius-md);
    padding: 10px 18px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}

.status-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.tag-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: #15803d;
}

.tag-badge strong {
    font-size: 16px;
    color: #0284c7;
    margin-left: 4px;
}

.dept-tag {
    color: var(--text-secondary);
    font-weight: 500;
}

.dept-tag strong {
    color: var(--text-primary);
}

.match-badge {
    background: #14532d;
    color: #ffffff;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* AI 摘要列 (紫粉膠囊) */
.ai-summary-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fdf4ff;
    border: 1px solid #f0abfc;
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    margin-bottom: 14px;
    font-size: 13px;
    color: #86198f;
}

.ai-icon {
    font-size: 16px;
}

.summary-title {
    font-weight: 700;
}

/* 表單參數列 */
.form-config-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    border: 1px solid var(--border-light);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

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

.form-group.flex-1 { flex: 1; min-width: 140px; }
.form-group.flex-2 { flex: 2; min-width: 240px; }

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-group .required {
    color: var(--danger);
}

.form-control {
    height: 38px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    font-size: 14px;
    background: white;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.raw-detect-text {
    height: 38px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: #f1f5f9;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    color: #0284c7;
    border: 1px solid var(--border-light);
}

/* 視圖切換 Tab */
.view-tabs-container {
    margin-bottom: 12px;
}

.view-tabs {
    display: flex;
    gap: 10px;
}

.tab-btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: white;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.tab-btn.active {
    background: #0284c7;
    color: white;
    border-color: #0284c7;
    box-shadow: 0 2px 4px rgba(2, 132, 199, 0.25);
}

/* 批次操作工具列 (參考截圖 1) */
.batch-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    gap: 12px;
}

.batch-tools-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.batch-label {
    font-size: 13px;
    font-weight: 700;
    color: #d97706;
}

.btn-batch {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
}

.btn-workday {
    background: #0d9488;
    color: white;
}
.btn-workday:hover { background: #0f766e; }

.btn-all-month {
    background: #7c3aed;
    color: white;
}
.btn-all-month:hover { background: #6d28d9; }

.btn-clear-all {
    background: white;
    color: #dc2626;
    border: 1px solid #f87171;
}
.btn-clear-all:hover { background: #fef2f2; }

.hint-text {
    font-size: 12px;
    color: var(--text-secondary);
}

/* 月度矩陣表格 */
.matrix-table-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 24px;
}

.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: center;
    white-space: nowrap;
}

.matrix-table th, .matrix-table td {
    border: 1px solid var(--border-light);
    padding: 6px 4px;
}

.matrix-table thead th {
    background: #f8fafc;
    color: var(--text-secondary);
    font-weight: 600;
    height: 38px;
}

.matrix-table thead th.th-item {
    text-align: left;
    padding-left: 12px;
    min-width: 200px;
    width: 220px;
}

.matrix-table thead th.th-sk-item {
    text-align: left;
    padding-left: 10px;
    min-width: 180px;
    width: 190px;
}

.matrix-table thead th.th-day {
    min-width: 28px;
    width: 32px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

/* 週末背景深灰 */
.matrix-table .is-weekend {
    background-color: #f1f5f9 !important;
    color: #94a3b8;
}

.matrix-table tbody tr:hover {
    background-color: #fafafa;
}

/* 項目名稱欄位 */
.td-item-info {
    text-align: left !important;
    padding-left: 12px !important;
}

.item-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.item-index-name {
    font-weight: 700;
    color: #0284c7;
    font-size: 13px;
}

.freq-tag {
    background: #64748b;
    color: white;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 999px;
    font-weight: 600;
}

.row-quick-btns {
    display: flex;
    gap: 4px;
}

.btn-mini {
    padding: 1px 6px;
    font-size: 11px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary);
}

.btn-mini:hover {
    background: #f1f5f9;
    color: var(--text-primary);
}

/* SK 對應下拉選單 */
.td-sk-select select {
    width: 100%;
    height: 32px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
    padding: 2px 6px;
    background: white;
}

/* 打勾方格 */
.check-cell {
    cursor: pointer;
    user-select: none;
    font-weight: 700;
    font-size: 15px;
    transition: background 0.1s ease;
}

.check-cell:hover {
    background-color: #e0f2fe !important;
}

.check-cell.checked {
    color: #059669;
    background-color: #ecfdf5;
}

.check-cell.unchecked {
    color: #cbd5e1;
}

/* 單日清單視圖卡片 */
.day-list-card {
    background: white;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    padding: 20px;
    margin-bottom: 24px;
}

.day-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 10px;
}

.count-badge {
    background: #e0f2fe;
    color: #0369a1;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    font-weight: 600;
}

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

.day-list-table th, .day-list-table td {
    border-bottom: 1px solid var(--border-light);
    padding: 10px 12px;
    text-align: left;
    font-size: 13px;
}

.day-list-table th {
    background: #f8fafc;
    color: var(--text-secondary);
}

/* 底部送出欄 */
.submit-bar {
    position: sticky;
    bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    border: 2px solid #0284c7;
    border-radius: var(--radius-lg);
    padding: 16px 24px;
    box-shadow: 0 10px 25px -5px rgba(2, 132, 199, 0.25);
    z-index: 50;
}

.submit-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.submit-info span {
    font-size: 14px;
    color: var(--text-primary);
}

.record-counter {
    font-size: 13px;
    font-weight: 700;
    color: #0284c7;
}

.btn-submit {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    color: white;
    font-size: 16px;
    font-weight: 700;
    padding: 12px 32px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.35);
    transition: transform 0.1s, box-shadow 0.15s;
}

.btn-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(2, 132, 199, 0.45);
}

.btn-submit:active {
    transform: translateY(1px);
}

/* 讀取遮罩 */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.loading-box {
    background: white;
    border-radius: var(--radius-lg);
    padding: 36px 40px;
    text-align: center;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid #0284c7;
    border-radius: 50%;
    margin: 0 auto 18px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-box h3 {
    font-size: 17px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.loading-box p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Toast 提示 */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: white;
    border-left: 4px solid #0284c7;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 500;
    min-width: 280px;
    animation: slideIn 0.25s ease-out;
}

.toast.success { border-left-color: #22c55e; }
.toast.error { border-left-color: #ef4444; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
