/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue: #0066CC;
    --blue-light: #E8F0FE;
    --blue-dark: #004999;
    --green: #16A34A;
    --red: #DC2626;
    --orange: #F59E0B;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-500: #6B7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
}

/* === Navbar === */
.navbar {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--gray-900);
}
.nav-links { display: flex; gap: .25rem; }
.nav-links a {
    padding: .5rem 1rem;
    border-radius: var(--radius);
    color: var(--gray-500);
    text-decoration: none;
    font-weight: 500;
    font-size: .9rem;
    transition: all .15s;
}
.nav-links a:hover { color: var(--gray-900); background: var(--gray-100); }
.nav-links a.active { color: var(--blue); background: var(--blue-light); }

/* === Container === */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

h1 { font-size: 1.5rem; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; margin-bottom: .75rem; color: var(--gray-700); }
h3 { font-size: 1rem; margin-bottom: .5rem; }

/* === Card === */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: .875rem;
    border: 1px solid var(--gray-300);
    background: #fff;
    color: var(--gray-700);
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
}
.btn:hover { background: var(--gray-100); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-warning { background: var(--orange); color: #fff; border-color: var(--orange); }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }

/* === Inputs === */
.input {
    padding: .5rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .875rem;
    outline: none;
    transition: border-color .15s;
}
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0,102,204,.15); }

/* === Badges === */
.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-completed { background: #DEF7EC; color: var(--green); }
.badge-failed { background: #FEE2E2; color: var(--red); }
.badge-processing { background: var(--blue-light); color: var(--blue); }
.badge-pending { background: var(--gray-100); color: var(--gray-500); }

/* === Pipeline Controls === */
.pipeline-controls { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.pipeline-status { font-weight: 600; color: var(--gray-500); }

.progress-bar-wrap {
    width: 100%;
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: .5rem;
}
.progress-bar {
    height: 100%;
    background: var(--blue);
    border-radius: 4px;
    transition: width .3s;
}
.progress-info {
    display: flex;
    gap: 1rem;
    font-size: .85rem;
    color: var(--gray-500);
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--gray-900); }
.stat-label { font-size: .85rem; color: var(--gray-500); margin-top: .25rem; }
.stat-success .stat-value { color: var(--green); }
.stat-danger .stat-value { color: var(--red); }
.stat-info .stat-value { color: var(--blue); }

/* === Charts === */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
@media (max-width: 768px) { .charts-grid { grid-template-columns: 1fr; } }

/* === Tables === */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--gray-200); }
th { font-weight: 600; color: var(--gray-500); font-size: .8rem; text-transform: uppercase; }
.table-sm th, .table-sm td { padding: .4rem .5rem; }

/* === Filters === */
.filters-bar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* === Pagination === */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; padding-top: 1rem; font-size: .85rem; }

/* === Detail Page === */
.detail-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1rem;
}
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.meta-list { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; font-size: .875rem; }
.meta-list dt { font-weight: 600; color: var(--gray-500); }
.mono { font-family: monospace; font-size: .8rem; }
.detail-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.text-section { margin-top: 1rem; }
.text-section p { font-size: .9rem; color: var(--gray-700); white-space: pre-wrap; }
.raw-json { margin-top: 1rem; }
.raw-json summary { cursor: pointer; font-weight: 600; color: var(--blue); font-size: .85rem; }
.raw-json pre {
    margin-top: .5rem;
    background: var(--gray-100);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: .8rem;
    max-height: 500px;
}
.error-text { color: var(--red); margin-top: .5rem; font-size: .85rem; }

/* === Chat === */
.chat-container { max-width: 800px; }

.chat-messages {
    height: 500px;
    overflow-y: auto;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius) var(--radius) 0 0;
}
.chat-msg { display: flex; margin-bottom: .75rem; }
.chat-msg-user { justify-content: flex-end; }
.chat-msg-assistant { justify-content: flex-start; }
.chat-bubble {
    max-width: 75%;
    padding: .75rem 1rem;
    border-radius: var(--radius);
    font-size: .9rem;
    line-height: 1.5;
}
.chat-msg-user .chat-bubble { background: var(--blue); color: #fff; border-bottom-right-radius: 2px; }
.chat-msg-assistant .chat-bubble { background: var(--gray-100); color: var(--gray-900); border-bottom-left-radius: 2px; }
.chat-sources { margin-top: .5rem; font-size: .8rem; border-top: 1px solid var(--gray-300); padding-top: .4rem; }
.source-link {
    display: inline-block;
    margin: .15rem .25rem;
    padding: .1rem .4rem;
    background: var(--blue-light);
    border-radius: 4px;
    color: var(--blue);
    text-decoration: none;
    font-size: .75rem;
}
.source-link:hover { background: var(--blue); color: #fff; }

.chat-input-bar {
    display: flex;
    gap: .5rem;
    padding: .75rem;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
}
.chat-input { flex: 1; }

/* Typing indicator */
.typing-indicator { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing-indicator span {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--gray-300);
    animation: typing .8s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }
@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Utilities */
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
