/**
 * components.css
 * Webhook 监控中心 - 组件样式
 * 包含：告警列表、卡片、模态框、表格、徽章、分页、代码块、时间线、AI分析等
 */

/* ==================== 告警列表 ==================== */
.alerts-section {
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    overflow: hidden;
}

.alert-list {
    /* 告警列表容器 */
}

.alert-item {
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    margin-bottom: 1rem;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    overflow: hidden;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.alert-item:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border-color: #cbd5e1;
    transform: translateY(-2px);
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-item:hover {
    background: #f6f8fa;
}

.alert-header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(248, 250, 252, 0.5);
    border-bottom: 1px solid #e2e8f0;
    cursor: pointer;
}

.alert-left {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.alert-title-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-icon {
    font-size: 1.25rem;
}

.alert-title {
    font-size: 1rem;
    font-weight: 600;
    color: #24292e;
}

.alert-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.875rem;
    color: #586069;
}

.alert-meta-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.alert-right {
    display: flex;
    gap: 0.75rem;
    align-items: start;
}

.alert-time {
    font-size: 0.75rem;
    color: #959da5;
}

.alert-actions {
    display: flex;
    gap: 0.5rem;
}

.alert-details {
    padding: 0 1.5rem 1.5rem;
    display: none;
    border-top: 1px solid #f6f8fa;
}

.alert-item.expanded .alert-details {
    display: block;
    animation: slideDown 0.2s ease-out;
}

.alert-item.expanded .alert-header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(248, 250, 252, 0.5);
    border-bottom: 1px solid #e2e8f0;
    cursor: pointer;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.details-tabs {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid #e1e4e8;
    margin-bottom: 1rem;
    padding-top: 1rem;
}

/* ==================== 卡片组件 ==================== */
.card {
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    overflow: hidden;
}

/* ==================== 模态框 ==================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(36, 41, 46, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 6px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e1e4e8;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #24292e;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid #e1e4e8;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* ==================== 表格 ==================== */
.table {
    width: 100%;
    border-collapse: collapse;
}

/* ==================== 徽章 ==================== */
.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-high { background: #fee2e2; color: #ef4444; border: 1px solid rgba(239,68,68,0.2); }

.badge-medium { background: #fef3c7; color: #f59e0b; border: 1px solid rgba(245,158,11,0.2); }

.badge-low { background: #d1fae5; color: #10b981; border: 1px solid rgba(16,185,129,0.2); }

.badge-duplicate {
    background: #f1f8ff;
    color: #0366d6;
    border: 1px solid #c8e1ff;
}

/* ==================== 分页 ==================== */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    margin-top: 1.5rem;
}

.pagination-info {
    font-size: 0.875rem;
    color: #586069;
}

.pagination-buttons {
    display: flex;
    gap: 0.5rem;
}

.pagination button {
    padding: 0.5rem 1rem;
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
    background: #f6f8fa;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==================== 代码块 ==================== */
.code-block {
    background: #1e1e1e;
    border: 1px solid #2d2d2d;
    border-radius: 8px;
    padding: 1.25rem;
    overflow-x: auto;
    font-size: 0.875rem;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', Consolas, monospace;
    line-height: 1.6;
    max-height: 600px;
    overflow-y: auto;
}

.code-block pre {
    margin: 0;
    color: #d4d4d4;
}

/* JSON 语法高亮 */
.json-key {
    color: #9cdcfe;
}

.json-string {
    color: #ce9178;
}

.json-number {
    color: #b5cea8;
}

.json-boolean {
    color: #569cd6;
}

.json-null {
    color: #569cd6;
}

.json-punctuation {
    color: #d4d4d4;
}

/* 代码块头部 */
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: #2d2d2d;
    border-bottom: 1px solid #3d3d3d;
    border-radius: 8px 8px 0 0;
    margin-bottom: -1px;
}

.code-lang {
    color: #858585;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
}

.code-copy-btn {
    padding: 0.25rem 0.75rem;
    background: #3d3d3d;
    border: 1px solid #4d4d4d;
    border-radius: 4px;
    color: #d4d4d4;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.code-copy-btn:hover {
    background: #4d4d4d;
    border-color: #5d5d5d;
}

.code-wrapper {
    margin: 1rem 0;
}

/* ==================== 时间线 ==================== */
.timeline {
    /* 时间线组件样式 */
}

/* ==================== 证据链 ==================== */
.evidence-list {
    /* 证据链列表样式 */
}

/* ==================== 技能卡片 ==================== */
.skill-card {
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    padding: 1rem;
    transition: all 0.2s;
}

.skill-card:hover {
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.skill-card.disabled {
    opacity: 0.6;
    background: #f6f8fa;
}

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

.skill-name {
    font-weight: 600;
    color: #24292e;
}

.skill-type {
    font-size: 0.75rem;
    color: #586069;
    background: #f6f8fa;
    padding: 0.125rem 0.5rem;
    border-radius: 12px;
}

.skill-type.external-tag {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}

.skill-version {
    font-size: 0.75rem;
    color: #959da5;
    margin-bottom: 0.5rem;
}

.skill-desc {
    font-size: 0.875rem;
    color: #586069;
    margin-bottom: 0.75rem;
    min-height: 1.5rem;
}

.skill-meta {
    font-size: 0.75rem;
    color: #959da5;
    margin-bottom: 0.5rem;
}

.skill-path {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.skill-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    margin-bottom: 0.75rem;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.healthy {
    background: #28a745;
}

.status-indicator.unhealthy {
    background: #d73a49;
}

.status-indicator.unknown {
    background: #959da5;
}

.skill-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* 外部 Skill 卡片特殊样式 */
.external-skill-card {
    border-left: 3px solid #28a745;
}

.external-skill-card:hover {
    border-left-color: #22863a;
}

/* Skill 文档内容样式 */
.skill-doc-content {
    line-height: 1.6;
}

.skill-doc-content h1,
.skill-doc-content h2,
.skill-doc-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #24292e;
}

.skill-doc-content h1 {
    font-size: 1.5rem;
    border-bottom: 1px solid #e1e4e8;
    padding-bottom: 0.5rem;
}

.skill-doc-content h2 {
    font-size: 1.25rem;
}

.skill-doc-content h3 {
    font-size: 1rem;
}

.skill-doc-content p {
    margin-bottom: 1rem;
}

.skill-doc-content code {
    background: #f6f8fa;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.875em;
}

.skill-doc-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.skill-doc-content pre code {
    background: none;
    padding: 0;
}

.skill-doc-content ul,
.skill-doc-content ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.skill-doc-content li {
    margin-bottom: 0.25rem;
}

.skills-section {
    margin-bottom: 2rem;
}

.skills-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.external-skills-section {
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    padding: 1.5rem;
}

.text-muted {
    color: #586069;
}

/* ==================== AI 分析区域 ==================== */
.ai-section {
    background: #f6ffed;
    border: 1px solid #b7eb8f;
    border-radius: 6px;
    padding: 1.5rem;
    margin-top: 1rem;
}

.ai-header {
    font-size: 0.875rem;
    font-weight: 600;
    color: #389e0d;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-content {
    display: grid;
    gap: 1rem;
}

.ai-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ai-label {
    font-size: 0.75rem;
    color: #52c41a;
    font-weight: 600;
    text-transform: uppercase;
}

.ai-value {
    font-size: 0.875rem;
    color: #24292e;
}

.ai-list {
    list-style: none;
    padding-left: 1rem;
}

.ai-list li {
    padding: 0.25rem 0;
    position: relative;
}

.ai-list li:before {
    content: "→";
    position: absolute;
    left: -1rem;
    color: #52c41a;
}

/* ==================== AI 成本监控路由分布 ==================== */
.route-distribution {
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    padding: 1.25rem;
}

.route-item {
    margin-bottom: 1rem;
}

.route-item:last-child {
    margin-bottom: 0;
}

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

.route-label {
    font-size: 0.875rem;
    color: #24292e;
    font-weight: 500;
}

.route-value {
    font-size: 0.875rem;
    color: #586069;
}

.progress-bar {
    height: 8px;
    background: #e1e4e8;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-ai {
    background: linear-gradient(90deg, #667eea, #764ba2);
}

.progress-rule {
    background: linear-gradient(90deg, #f093fb, #f5576c);
}

.progress-cache {
    background: linear-gradient(90deg, #4facfe, #00f2fe);
}

.progress-reuse {
    background: linear-gradient(90deg, #11998e, #38ef7d);
}

/* 绿色高亮卡片 */
.stat-card.highlight-green {
    background: linear-gradient(135deg, #dcffe4 0%, #f0fff4 100%);
    border-color: #b1f1c1;
}

.stat-card.highlight-green .stat-value {
    color: #28a745;
}

/* ==================== 空状态 ==================== */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

.empty-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #24292e;
    margin-bottom: 0.5rem;
}

.empty-text {
    color: #586069;
    font-size: 0.875rem;
}

/* ==================== 加载状态 ==================== */
.loading {
    text-align: center;
    padding: 3rem;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 3px solid #e1e4e8;
    border-top-color: #0366d6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==================== 代码编辑器相关样式 ==================== */
.code-editor {
    /* 代码编辑器样式 */
}

/* ==================== 响应式媒体查询 ==================== */
@media (max-width: 768px) {
    .navbar-content {
        padding: 0 1rem;
    }

    .container {
        padding: 1rem;
    }

    .filter-grid {
        grid-template-columns: 1fr;
    }

    .alert-header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(248, 250, 252, 0.5);
    border-bottom: 1px solid #e2e8f0;
    cursor: pointer;
}

    .alert-right {
        flex-wrap: wrap;
    }
}

/* ==================== Runbook 参数表单 ==================== */
.runbook-parameters {
    margin: 12px 0;
    padding: 12px;
    background: #f8f9fa;
    border-left: 3px solid #0066cc;
    border-radius: 4px;
}

.params-header {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
    color: #333;
}

.params-hint {
    font-size: 12px;
    color: #666;
    margin-bottom: 10px;
}

.param-row {
    margin-bottom: 8px;
}

.param-row label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 3px;
    color: #444;
}

.param-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.param-input:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 2px rgba(0,102,204,0.1);
}

.param-input::placeholder {
    color: #aaa;
}

/* ==================== OpenClaw Markdown 分析内容样式 ==================== */
.openclaw-analysis-content {
    line-height: 1.6;
    font-size: 0.9em;
}

.openclaw-analysis-content h1,
.openclaw-analysis-content h2 {
    margin: 16px 0 10px;
    font-weight: 600;
    color: #24292e;
    border-bottom: 1px solid #e1e4e8;
    padding-bottom: 6px;
}

.openclaw-analysis-content h1 { font-size: 1.3em; }
.openclaw-analysis-content h2 { font-size: 1.15em; }

.openclaw-analysis-content h3,
.openclaw-analysis-content h4 {
    margin: 12px 0 8px;
    font-weight: 600;
    color: #24292e;
}

.openclaw-analysis-content h3 { font-size: 1.05em; }
.openclaw-analysis-content h4 { font-size: 1em; }

.openclaw-analysis-content p {
    margin: 8px 0;
}

.openclaw-analysis-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 0.9em;
}

.openclaw-analysis-content th,
.openclaw-analysis-content td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.openclaw-analysis-content th {
    background: #f5f5f5;
    font-weight: 600;
}

.openclaw-analysis-content tr:nth-child(even) {
    background: #fafafa;
}

.openclaw-analysis-content pre {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.85em;
    margin: 10px 0;
}

.openclaw-analysis-content code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.openclaw-analysis-content pre code {
    background: none;
    padding: 0;
}

.openclaw-analysis-content ul,
.openclaw-analysis-content ol {
    padding-left: 24px;
    margin: 8px 0;
}

.openclaw-analysis-content li {
    margin: 4px 0;
}

.openclaw-analysis-content blockquote {
    border-left: 3px solid #0366d6;
    padding-left: 12px;
    margin: 10px 0;
    color: #586069;
}

.openclaw-analysis-content hr {
    border: none;
    border-top: 1px solid #e1e4e8;
    margin: 16px 0;
}

.openclaw-analysis-content strong {
    font-weight: 600;
    color: #24292e;
}

.openclaw-analysis-content em {
    font-style: italic;
}


/* ==================== Modern Forms & Checkboxes ==================== */
.form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
    cursor: pointer;
}

.form-checkbox:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.form-checkbox input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 4px;
    border: 2px solid #cbd5e1;
    appearance: none;
    background-color: white;
    cursor: pointer;
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.form-checkbox input[type="checkbox"]:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

.form-checkbox input[type="checkbox"]:checked::after {
    content: '✓';
    color: white;
    font-size: 0.85rem;
    font-weight: bold;
}

.form-checkbox label {
    margin: 0;
    cursor: pointer;
    font-weight: 500;
    color: #334155;
    flex-grow: 1;
}

/* Modal fixes for dashboard.html compatibility */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: #ffffff;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: scale(0.95) translateY(10px);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid #e2e8f0;
}

.modal.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.modal-title {
    margin: 0;
    font-size: 1.25rem;
    color: #0f172a;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid #f1f5f9;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    background: #f8fafc;
}

/* ==================== Mobile Responsiveness Components ==================== */
@media (max-width: 768px) {
    /* Cards & Summaries */
    .alert-header, .da-summary {
        padding: 1rem !important;
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .alert-body, .da-details, .rule-card {
        padding: 1rem !important;
    }

    /* Force 1 column for any grid that might overflow on 320px-400px screens */
    .ai-details,
    .da-summary-details,
    div[style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Action Buttons Row - Stack vertically on mobile */
    .rule-actions, .da-btn-row,
    div[style*="display: flex; gap: 1rem; flex-wrap: wrap;"] {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.5rem !important;
    }

    .rule-actions .btn, .da-btn-row .btn,
    div[style*="display: flex; gap: 1rem; flex-wrap: wrap;"] .btn {
        width: 100%;
        justify-content: center;
        margin: 0 !important;
    }

    /* Modals */
    .modal-content {
        width: 95%;
        margin: 1rem;
        max-height: 95vh;
    }
    .modal-header, .modal-body, .modal-footer {
        padding: 1rem;
    }
    .modal-footer {
        flex-direction: column;
    }
    .modal-footer .btn {
        width: 100%;
        margin-left: 0;
        margin-bottom: 0.5rem;
    }

    /* Pagination - wrap gracefully */
    .pagination, .da-pagination {
        flex-wrap: wrap;
        gap: 0.25rem;
        padding: 0.5rem !important;
    }
    .page-btn, .da-page-btn {
        min-width: 28px;
        height: 28px;
        font-size: 0.75rem;
        padding: 0 0.25rem;
    }

    /* Break long words in raw data to prevent horizontal scrolling */
    .raw-data pre, .markdown-body pre {
        white-space: pre-wrap !important;
        word-break: break-all;
    }

    /* Rule Card Header */
    .rule-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
    }
}
