/* ============================================
   CORGO - Industrial Dark Theme
   ============================================ */

:root {
    --bg-body: #0a0e1a;
    --bg-sidebar: #060a14;
    --bg-card: #0f1422;
    --bg-card-hover: #141a2e;
    --bg-table-header: #0c1020;
    --bg-table-row: #0f1422;
    --bg-table-row-alt: #111728;
    --bg-input: #111728;
    --border-color: #1e2740;
    --border-color-light: #2a3555;
    --text-primary: #e2e8f0;
    --text-secondary: #8892a8;
    --text-muted: #5a6478;
    --accent-primary: #6366f1;
    --accent-primary-hover: #818cf8;
    --accent-primary-dim: rgba(99, 102, 241, 0.15);
    --accent-success: #22c55e;
    --accent-success-dim: rgba(34, 197, 94, 0.15);
    --accent-warning: #f59e0b;
    --accent-warning-dim: rgba(245, 158, 11, 0.15);
    --accent-danger: #ef4444;
    --accent-danger-dim: rgba(239, 68, 68, 0.15);
    --accent-info: #06b6d4;
    --accent-info-dim: rgba(6, 182, 212, 0.15);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --transition: 0.2s ease;
}

/* ============ BASE ============ */
* {
    box-sizing: border-box;
}

html, body, main, .main-content {
    height: 100%;
}

body {
    background-color: var(--bg-body) !important;
    color: var(--text-primary) !important;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    margin: 0;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover {
    color: var(--accent-primary-hover);
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 600;
}

hr {
    border-color: var(--border-color) !important;
    opacity: 0.5;
}

/* ============ SCROLLBAR ============ */
.main-content {
    overflow-y: auto;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-body);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color-light);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============ SIDEBAR ============ */
.sidebar {
    background: var(--bg-sidebar) !important;
    border-right: 1px solid var(--border-color);
    width: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    position: relative;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none !important;
    color: var(--text-primary) !important;
}

.sidebar-brand img {
    height: 36px;
    width: 36px;
    border-radius: 8px;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.sidebar-brand-name {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.sidebar-brand-sub {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-nav {
    padding: 12px 8px;
    flex: 1;
    list-style: none;
    margin: 0;
}

.sidebar-nav .nav-item {
    margin-bottom: 2px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary) !important;
    font-size: 13.5px;
    font-weight: 500;
    transition: all var(--transition);
    text-decoration: none;
}

.sidebar-nav .nav-link i {
    font-size: 16px;
    width: 20px;
    text-align: center;
    opacity: 0.7;
}

.sidebar-nav .nav-link:hover {
    background: var(--accent-primary-dim);
    color: var(--accent-primary-hover) !important;
}
.sidebar-nav .nav-link:hover i {
    opacity: 1;
}

.sidebar-nav .nav-link.active {
    background: var(--accent-primary-dim);
    color: var(--accent-primary-hover) !important;
    font-weight: 600;
}
.sidebar-nav .nav-link.active i {
    opacity: 1;
    color: var(--accent-primary);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-success);
    box-shadow: 0 0 8px var(--accent-success);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--accent-success); }
    50% { opacity: 0.6; box-shadow: 0 0 16px var(--accent-success); }
}

.sidebar-footer-text {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============ CONTENT ============ */
.content-area {
    flex: 1;
    padding: 24px 32px;
    overflow-y: auto;
    background: var(--bg-body);
}

.page-header {
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 16px;
    transition: color var(--transition);
}
.back-link:hover {
    color: var(--accent-primary);
}

/* ============ KPI CARDS ============ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: all var(--transition);
}
.kpi-card:hover {
    border-color: var(--border-color-light);
    box-shadow: var(--shadow-md);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}
.kpi-card--primary::before { background: var(--accent-primary); }
.kpi-card--success::before { background: var(--accent-success); }
.kpi-card--warning::before { background: var(--accent-warning); }
.kpi-card--danger::before { background: var(--accent-danger); }
.kpi-card--info::before { background: var(--accent-info); }

.kpi-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin-bottom: 12px;
}
.kpi-icon--primary { background: var(--accent-primary-dim); color: var(--accent-primary); }
.kpi-icon--success { background: var(--accent-success-dim); color: var(--accent-success); }
.kpi-icon--warning { background: var(--accent-warning-dim); color: var(--accent-warning); }
.kpi-icon--danger { background: var(--accent-danger-dim); color: var(--accent-danger); }
.kpi-icon--info { background: var(--accent-info-dim); color: var(--accent-info); }

.kpi-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.kpi-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ============ TABLES ============ */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--border-color);
    --bs-table-striped-bg: var(--bg-table-row-alt);
    --bs-table-hover-bg: var(--bg-card-hover);
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    margin-bottom: 16px;
}

.table thead th {
    background: var(--bg-table-header);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table thead th:first-child {
    border-radius: var(--radius-sm) 0 0 0;
}
.table thead th:last-child {
    border-radius: 0 var(--radius-sm) 0 0;
}

.table tbody tr {
    transition: background var(--transition);
}

.table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    font-size: 13.5px;
}

.table tbody tr:hover {
    background: var(--bg-card-hover);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 24px;
}

.table-container .table {
    margin-bottom: 0;
}

/* ============ CARDS ============ */
.card {
    background: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
    color: var(--text-primary);
}

.card:hover {
    border-color: var(--border-color-light) !important;
}

.card-body {
    padding: 20px !important;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

/* ============ BADGES ============ */
.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 20px;
    letter-spacing: 0.02em;
}

.badge.rounded-pill.text-bg-success,
.badge-success {
    background: var(--accent-success-dim) !important;
    color: var(--accent-success) !important;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.badge.rounded-pill.text-bg-danger,
.badge-danger {
    background: var(--accent-danger-dim) !important;
    color: var(--accent-danger) !important;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.badge.rounded-pill.text-bg-warning,
.badge-warning {
    background: var(--accent-warning-dim) !important;
    color: var(--accent-warning) !important;
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.badge.rounded-pill.text-bg-dark,
.badge.rounded-pill.text-bg-secondary {
    background: rgba(99, 102, 241, 0.1) !important;
    color: var(--accent-primary) !important;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

/* ============ FORMS ============ */
.form-control, .form-select {
    background-color: var(--bg-input) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-xs) !important;
    padding: 10px 14px;
    font-size: 13.5px;
    transition: all var(--transition);
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent-primary) !important;
    box-shadow: 0 0 0 3px var(--accent-primary-dim) !important;
    outline: none;
}

.form-control::placeholder {
    color: var(--text-muted) !important;
}

.form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-text {
    font-size: 12px;
    color: var(--text-muted) !important;
}

.form-text code {
    background: var(--accent-primary-dim);
    color: var(--accent-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

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

/* ============ BUTTONS ============ */
.btn {
    border-radius: var(--radius-xs);
    font-size: 13px;
    font-weight: 500;
    padding: 8px 16px;
    transition: all var(--transition);
    border: none;
}

.btn-primary {
    background: var(--accent-primary) !important;
    color: #fff !important;
}
.btn-primary:hover {
    background: var(--accent-primary-hover) !important;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-danger {
    background: var(--accent-danger-dim) !important;
    color: var(--accent-danger) !important;
    border: 1px solid rgba(239, 68, 68, 0.3) !important;
}
.btn-danger:hover {
    background: var(--accent-danger) !important;
    color: #fff !important;
}

.btn-secondary {
    background: rgba(255,255,255,0.05) !important;
    color: var(--text-secondary) !important;
    border: 1px solid var(--border-color) !important;
}
.btn-secondary:hover {
    background: rgba(255,255,255,0.1) !important;
    color: var(--text-primary) !important;
}

.btn-success {
    background: var(--accent-success-dim) !important;
    color: var(--accent-success) !important;
    border: 1px solid rgba(34, 197, 94, 0.3) !important;
}
.btn-success:hover {
    background: var(--accent-success) !important;
    color: #fff !important;
}

.btn-outline-primary {
    background: transparent !important;
    color: var(--accent-primary) !important;
    border: 1px solid var(--accent-primary) !important;
}
.btn-outline-primary:hover {
    background: var(--accent-primary-dim) !important;
}

.btn-group .btn {
    border-radius: 0;
}
.btn-group .btn:first-child {
    border-radius: var(--radius-xs) 0 0 var(--radius-xs);
}
.btn-group .btn:last-child {
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

/* ============ HTMX INDICATOR ============ */
.htmx-indicator {
    opacity: 0;
    transition: opacity 0.4s ease;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
}

.loading-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--accent-primary-dim);
    border-radius: 20px;
    font-size: 12px;
    color: var(--accent-primary);
}

.loading-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-primary);
    animation: pulse-dot 1s ease-in-out infinite;
}

/* ============ PROGRESS BAR ============ */
progress {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    margin-top: 12px;
    appearance: none;
    -webkit-appearance: none;
}

progress::-webkit-progress-bar {
    background: var(--bg-input);
    border-radius: 3px;
}

progress::-webkit-progress-value {
    background: var(--accent-primary);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ============ LOGS ============ */
#logs tbody {
    height: calc(100vh - 240px);
    overflow-y: auto;
    display: block;
}

#logs thead {
    display: block;
}

#logs td:first-child {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    width: 120px;
    min-width: 120px;
}

#logs td:last-child {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    color: var(--text-secondary);
    word-break: break-all;
}

/* ============ DESCRIPTION LIST ============ */
dl.row dt {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
}

dl.row dd {
    color: var(--text-primary);
    font-size: 13.5px;
}

/* ============ NAVBAR-BRAND COMPAT ============ */
.navbar-brand img {
    height: 32px;
}

/* ============ AGENT STATUS CARD ============ */
.agent-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition);
    cursor: pointer;
}

.agent-card:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary-dim);
    background: var(--bg-card-hover);
}

.agent-card--active {
    border-color: var(--accent-success);
}

.agent-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.agent-icon--online {
    background: var(--accent-success-dim);
    color: var(--accent-success);
}

.agent-icon--offline {
    background: var(--accent-danger-dim);
    color: var(--accent-danger);
}

.agent-icon--stuck {
    background: var(--accent-warning-dim);
    color: var(--accent-warning);
}

.agent-info {
    flex: 1;
}

.agent-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.agent-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    margin-top: 2px;
}

.agent-replicas {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* ============ SECTION DIVIDER ============ */
.section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 24px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

/* ============ EMPTY STATE ============ */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 14px;
    max-width: 300px;
    margin: 0 auto;
}

/* ============ ANIMATIONS ============ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    .sidebar {
        width: 60px !important;
    }
    .sidebar-brand-text,
    .sidebar-footer-text,
    .nav-link span {
        display: none;
    }
    .content-area {
        padding: 16px;
    }
    .kpi-grid {
        grid-template-columns: 1fr 1fr;
    }
}
