/**
 * DataCenter 監控樣式
 * 遵循 TalkStock 品牌設計系統
 */

/* ========== 變數定義 ========== */
:root {
    /* 品牌色 */
    --monitor-primary: #F97316;
    --monitor-primary-hover: #EA580C;

    /* 狀態色 */
    --monitor-success: #10B981;
    --monitor-warning: #F59E0B;
    --monitor-danger: #EF4444;
    --monitor-info: #3B82F6;

    /* 背景色 */
    --monitor-bg: #F5F4EF;
    --monitor-card-bg: #FAFAF7;

    /* 文字色 */
    --monitor-text: #292524;
    --monitor-text-secondary: #78716C;

    /* 間距 */
    --monitor-gap: 1.5rem;
    --monitor-radius: 12px;
}

/* ========== 子導航 ========== */
.monitoring-subnav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: var(--monitor-gap);
    padding: 1rem;
    background: var(--monitor-card-bg);
    border-radius: var(--monitor-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.monitoring-tab {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--monitor-text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.monitoring-tab:hover {
    background: rgba(249, 115, 22, 0.1);
    color: var(--monitor-primary);
}

.monitoring-tab.active {
    background: var(--monitor-primary);
    color: white;
    border-color: var(--monitor-primary);
}

.monitoring-tab:focus-visible {
    outline: 2px solid var(--monitor-primary);
    outline-offset: 2px;
}

/* ========== 內容區 ========== */
.monitoring-content {
    display: none;
    padding: var(--monitor-gap);
}

.monitoring-content.active {
    display: block;
}

/* ========== 統計卡片網格 ========== */
.monitoring-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--monitor-gap);
    margin-bottom: var(--monitor-gap);
}

.stat-card {
    background: var(--monitor-card-bg);
    padding: 1.5rem;
    border-radius: var(--monitor-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--monitor-text);
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--monitor-text-secondary);
}

/* 狀態變化 */
.stat-card.success {
    border-left: 4px solid var(--monitor-success);
}

.stat-card.warning {
    border-left: 4px solid var(--monitor-warning);
}

.stat-card.danger {
    border-left: 4px solid var(--monitor-danger);
}

/* ========== 健康檢查網格 ========== */
.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--monitor-gap);
}

.health-card {
    background: var(--monitor-card-bg);
    padding: 1.5rem;
    border-radius: var(--monitor-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border-left: 4px solid var(--monitor-text-secondary);
}

.health-card.healthy {
    border-left-color: var(--monitor-success);
}

.health-card.unhealthy {
    border-left-color: var(--monitor-danger);
}

.health-icon {
    font-size: 3rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.health-card h3 {
    font-size: 1.25rem;
    color: var(--monitor-text);
    margin-bottom: 0.5rem;
}

.health-status {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.health-card.healthy .health-status {
    color: var(--monitor-success);
}

.health-card.unhealthy .health-status {
    color: var(--monitor-danger);
}

.health-detail {
    font-size: 0.875rem;
    color: var(--monitor-text-secondary);
    margin-bottom: 0.5rem;
}

.health-time {
    font-size: 0.75rem;
    color: var(--monitor-text-secondary);
}

/* ========== 圖表區域 ========== */
.monitoring-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--monitor-gap);
}

.chart-card {
    background: var(--monitor-card-bg);
    padding: 1.5rem;
    border-radius: var(--monitor-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.chart-card h3 {
    font-size: 1.125rem;
    color: var(--monitor-text);
    margin-bottom: 1rem;
}

/* ========== 錯誤提示 ========== */
.monitoring-error {
    background: var(--monitor-card-bg);
    padding: 3rem;
    border-radius: var(--monitor-radius);
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.error-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.monitoring-error h3 {
    font-size: 1.5rem;
    color: var(--monitor-danger);
    margin-bottom: 0.5rem;
}

.monitoring-error p {
    color: var(--monitor-text-secondary);
    margin-bottom: 0.5rem;
}

.error-hint {
    font-size: 0.875rem;
    padding: 1rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 8px;
    margin: 1rem 0;
}

/* ========== 占位符 ========== */
.placeholder {
    background: var(--monitor-card-bg);
    padding: 4rem 2rem;
    border-radius: var(--monitor-radius);
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.placeholder p {
    font-size: 1.125rem;
    color: var(--monitor-text-secondary);
    margin-bottom: 0.5rem;
}

.placeholder p:first-child {
    font-size: 2rem;
}

/* ========== 排程管理 ========== */

/* 載入中 */
.scheduler-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: var(--monitor-text-secondary);
}

.scheduler-loading .loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(249, 115, 22, 0.2);
    border-top-color: var(--monitor-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 排程器狀態列 */
.scheduler-status-bar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
    background: var(--monitor-card-bg);
    border-radius: var(--monitor-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    margin-bottom: var(--monitor-gap);
    flex-wrap: wrap;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-indicator.running .status-dot {
    background: var(--monitor-success);
}

.status-indicator.stopped .status-dot {
    background: var(--monitor-danger);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--monitor-text-secondary);
    font-size: 0.875rem;
}

.status-info .separator {
    color: #D4D4D4;
}

.btn-refresh {
    margin-left: auto;
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--monitor-primary);
    color: var(--monitor-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

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

/* 任務區塊 */
.job-section {
    margin-bottom: var(--monitor-gap);
}

.section-title {
    font-size: 1.125rem;
    color: var(--monitor-text);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid rgba(249, 115, 22, 0.2);
}

/* 任務列表 */
.job-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

/* 任務卡片 */
.job-card {
    background: var(--monitor-card-bg);
    border-radius: var(--monitor-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    border-left: 4px solid var(--monitor-success);
}

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

.job-card.paused {
    border-left-color: var(--monitor-warning);
    opacity: 0.85;
}

.job-card.active {
    border-left-color: var(--monitor-success);
}

/* 任務卡片頭部 */
.job-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.job-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-icon {
    font-size: 1rem;
}

.status-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
}

.status-badge.active {
    background: rgba(16, 185, 129, 0.15);
    color: var(--monitor-success);
}

.status-badge.paused {
    background: rgba(245, 158, 11, 0.15);
    color: var(--monitor-warning);
}

/* 任務操作按鈕 */
.job-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-action {
    padding: 0.375rem 0.75rem;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-pause {
    background: rgba(245, 158, 11, 0.15);
    color: #D97706;
}

.btn-pause:hover {
    background: rgba(245, 158, 11, 0.3);
}

.btn-resume {
    background: rgba(16, 185, 129, 0.15);
    color: #059669;
}

.btn-resume:hover {
    background: rgba(16, 185, 129, 0.3);
}

.btn-run {
    background: rgba(59, 130, 246, 0.15);
    color: #2563EB;
}

.btn-run:hover {
    background: rgba(59, 130, 246, 0.3);
}

/* 任務卡片內容 */
.job-body {
    padding: 1rem;
}

.job-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--monitor-text);
    margin-bottom: 0.25rem;
}

.job-func {
    font-size: 0.75rem;
    color: var(--monitor-text-secondary);
    margin-bottom: 0.75rem;
    font-family: 'Monaco', 'Menlo', monospace;
}

.job-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--monitor-text);
    margin-bottom: 0.5rem;
}

.trigger-icon {
    font-size: 0.875rem;
}

.job-next-run {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.next-run-label {
    color: var(--monitor-text-secondary);
}

.next-run-time {
    font-weight: 500;
    color: var(--monitor-text);
}

.next-run-time.paused {
    color: var(--monitor-warning);
    font-style: italic;
}

/* 無任務提示 */
.no-jobs {
    background: var(--monitor-card-bg);
    padding: 4rem 2rem;
    border-radius: var(--monitor-radius);
    text-align: center;
    color: var(--monitor-text-secondary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.no-jobs p {
    font-size: 1.25rem;
}

/* Toast 提示 */
.monitoring-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 0.875rem 1.5rem;
    background: var(--monitor-text);
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    font-size: 0.875rem;
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
}

.monitoring-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.monitoring-toast.success {
    background: var(--monitor-success);
}

.monitoring-toast.error {
    background: var(--monitor-danger);
}

.monitoring-toast.info {
    background: var(--monitor-info);
}

/* ========== 日股任務區塊 ========== */

/* 區塊標題（含按鈕） */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid rgba(249, 115, 22, 0.2);
}

.section-header .section-title {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* 回補按鈕 */
.btn-backfill {
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, var(--monitor-primary), var(--monitor-primary-hover));
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-backfill:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}

.btn-backfill:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 任務說明 */
.job-description {
    font-size: 0.8rem;
    color: var(--monitor-text-secondary);
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

/* ========== 任務進度區塊 ========== */

.job-progress-section {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--monitor-primary), var(--monitor-success));
    border-radius: 4px;
    transition: width 0.5s ease;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--monitor-text-secondary);
}

.progress-text {
    font-weight: 500;
}

.progress-eta {
    font-style: italic;
}

/* ========== 最近執行狀態 ========== */

.job-last-execution {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.execution-status-icon {
    font-size: 1rem;
}

.execution-time {
    color: var(--monitor-text-secondary);
}

.execution-records {
    color: var(--monitor-text);
    font-weight: 500;
}

.execution-status {
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 500;
}

.execution-status.success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--monitor-success);
}

.execution-status.failed {
    background: rgba(239, 68, 68, 0.15);
    color: var(--monitor-danger);
}

.execution-status.running {
    background: rgba(59, 130, 246, 0.15);
    color: var(--monitor-info);
}

/* ========== 回補對話框 ========== */

.backfill-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.backfill-dialog-overlay.show {
    opacity: 1;
    visibility: visible;
}

.backfill-dialog {
    background: var(--monitor-card-bg);
    border-radius: var(--monitor-radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 480px;
    transform: translateY(-20px);
    transition: transform 0.3s ease;
}

.backfill-dialog-overlay.show .backfill-dialog {
    transform: translateY(0);
}

.backfill-dialog-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.backfill-dialog-header h3 {
    font-size: 1.125rem;
    color: var(--monitor-text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-close-dialog {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--monitor-text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.btn-close-dialog:hover {
    color: var(--monitor-text);
}

.backfill-dialog-body {
    padding: 1.5rem;
}

.backfill-info {
    background: rgba(59, 130, 246, 0.1);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.backfill-info p {
    font-size: 0.875rem;
    color: var(--monitor-text);
    margin: 0 0 0.5rem 0;
}

.backfill-info p:last-child {
    margin-bottom: 0;
}

.backfill-form-group {
    margin-bottom: 1rem;
}

.backfill-form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--monitor-text);
    margin-bottom: 0.5rem;
}

.backfill-form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--monitor-text);
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

.backfill-form-group select:focus {
    outline: none;
    border-color: var(--monitor-primary);
}

.backfill-warning {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(245, 158, 11, 0.1);
    border-radius: 8px;
    font-size: 0.8rem;
    color: #92400E;
}

.backfill-warning-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.backfill-dialog-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.btn-cancel {
    padding: 0.625rem 1.25rem;
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.2);
    color: var(--monitor-text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.btn-cancel:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--monitor-text);
}

.btn-confirm-backfill {
    padding: 0.625rem 1.25rem;
    background: linear-gradient(135deg, var(--monitor-primary), var(--monitor-primary-hover));
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-confirm-backfill:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}

.btn-confirm-backfill:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ========== 運行中狀態 ========== */

.job-card.running {
    border-left-color: var(--monitor-info);
}

.job-card.running .job-header {
    background: rgba(59, 130, 246, 0.05);
}

.status-badge.running {
    background: rgba(59, 130, 246, 0.15);
    color: var(--monitor-info);
    animation: pulse-running 1.5s infinite;
}

@keyframes pulse-running {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

