:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --sidebar: #1e293b;
    --sidebar-active: #334155;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --info: #3b82f6;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 4px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04);
    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

a:hover {
    text-decoration: underline;
}

/* Layout */
.wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    padding: 24px 0;
}

.brand {
    padding: 0 24px 24px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 16px;
}

.brand-dot {
    width: 10px;
    height: 10px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
}

.sidebar nav {
    flex: 1;
    padding: 0 16px;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #cbd5e1;
    text-decoration: none;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar a:hover,
.sidebar a.active {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar a.active {
    box-shadow: inset 3px 0 0 var(--primary);
}

.sidebar .logout {
    margin-top: auto;
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 16px;
    margin: 16px;
}

.main {
    flex: 1;
    margin-left: 260px;
    padding: 32px;
    min-height: 100vh;
}

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

.page-header h1 {
    font-size: 26px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.4px;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.card-header h2,
.card h2,
.card h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

.card-body.compact {
    padding: 16px 24px;
}

.card p {
    margin-top: 0;
    color: var(--text-muted);
    font-size: 14px;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
    line-height: 1;
    white-space: nowrap;
}

.btn:hover {
    background: var(--primary-hover);
    text-decoration: none;
}

.btn-success {
    background: var(--success);
}

.btn-success:hover {
    background: var(--success-hover);
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-warning {
    background: var(--warning);
    color: #1f2937;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 15px;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 11px;
    border-radius: 999px;
    background: #eef2ff;
    color: #4338ca;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.badge-dark {
    background: #1f2937;
    color: #fff;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 8px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px;
    text-align: center;
    transition: transform 0.1s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-card .value {
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    display: block;
    line-height: 1.2;
    margin-bottom: 4px;
}

.stat-card .label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0 20px;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 14px;
    font-family: var(--font);
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input[readonly] {
    background: #f9fafb;
    color: var(--text-muted);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

.form-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 10px;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead {
    background: #f9fafb;
    border-bottom: 2px solid var(--border);
}

th, td {
    padding: 14px 18px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

th {
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
}

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

tbody tr:hover {
    background: #f9fafb;
}

td .badge {
    margin-bottom: 3px;
}

/* Source list */
.source-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px 20px;
    margin: 10px 0;
}

.source-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.source-list label:hover {
    background: #f9fafb;
    border-color: var(--primary);
}

.source-list input {
    margin: 0;
    width: 16px;
    height: 16px;
}

/* Filters */
.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    align-items: end;
    margin-bottom: 4px;
}

.filter-bar .form-group {
    margin-bottom: 0;
}

/* Alerts / status */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    border-left: 4px solid;
}

.alert-danger {
    background: #fef2f2;
    border-color: var(--danger);
    color: #991b1b;
}

.alert-success {
    background: #ecfdf5;
    border-color: var(--success);
    color: #065f46;
}

.alert-info {
    background: #eff6ff;
    border-color: var(--info);
    color: #1e40af;
}

.status-box {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: #f3f4f6;
    border: 1px solid var(--border);
    font-size: 14px;
    display: none;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 40px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 26px;
    font-weight: 800;
    text-align: center;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 28px;
    font-size: 14px;
}

.login-card button {
    width: 100%;
    padding: 14px;
    font-size: 15px;
    margin-top: 10px;
}

/* Empty state */
.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 14px;
}

.empty a {
    color: var(--primary);
    font-weight: 600;
}

/* Utility */
.text-muted {
    color: var(--text-muted);
}

.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info { color: var(--info); }

.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 20px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }

pre {
    background: #f9fafb;
    border: 1px solid var(--border);
    padding: 18px;
    border-radius: var(--radius-sm);
    overflow: auto;
    max-height: 500px;
    font-size: 12px;
    line-height: 1.5;
}

code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: #374151;
}

/* Health check page */
.health-summary {
    padding: 20px 24px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    border-left: 4px solid;
}

.health-summary.ok {
    background: #f0fdf4;
    border-color: var(--success);
    color: #064e3b;
}

.health-summary.fail {
    background: #fef2f2;
    border-color: var(--danger);
    color: #7f1d1d;
}

.health-summary h2 {
    margin: 0 0 6px;
    font-size: 20px;
}

.health-summary p {
    margin: 0;
    font-size: 14px;
}

.health-table tr.ok td {
    background: #f0fdf4;
}

.health-table tr.fail td {
    background: #fef2f2;
}

.health-detail {
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 24px;
}

.health-detail h3 {
    margin: 0 0 12px;
    font-size: 16px;
}

.health-detail p {
    margin: 0 0 8px;
    font-size: 14px;
}

.health-detail .error-text {
    color: var(--danger);
    font-weight: 500;
}

/* Resource meter */
.meter {
    width: 100%;
    height: 28px;
    background: #e5e7eb;
    border-radius: var(--radius-xs);
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    background: var(--success);
    transition: width 0.3s;
    border-radius: var(--radius-xs);
}

.queue-progress {
    width: 100%;
    min-width: 80px;
}

.queue-progress .meter {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 4px;
}

.queue-progress .meter-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.4s;
}

/* Responsive */
@media (max-width: 900px) {
    .sidebar {
        width: 100%;
        position: relative;
        flex-direction: row;
        align-items: center;
        padding: 16px;
    }
    .sidebar nav,
    .sidebar .logout {
        display: none;
    }
    .main {
        margin-left: 0;
    }
    .wrapper {
        flex-direction: column;
    }
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Process detail modal / popup */
.process-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(2px);
}

.process-modal-overlay.active {
    display: flex;
}

.process-modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.process-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    background: #f9fafb;
}

.process-modal-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.process-modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-xs);
    transition: background 0.15s, color 0.15s;
}

.process-modal-close:hover {
    background: var(--border);
    color: var(--text);
}

.process-modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    min-height: 200px;
}

.process-modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: #f9fafb;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.process-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.process-summary .summary-card {
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
}

.process-summary .summary-card .label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 6px;
}

.process-summary .summary-card .value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    word-break: break-word;
}

.process-source-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.process-source {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #fff;
}

.process-source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
    gap: 10px;
    flex-wrap: wrap;
}

.process-source-header .source-title {
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.process-source-body {
    padding: 18px;
    font-size: 13px;
    line-height: 1.6;
}

.process-source-body .detail-row {
    display: flex;
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px dashed var(--border);
    align-items: flex-start;
}

.process-source-body .detail-row:last-child {
    border-bottom: none;
}

.process-source-body .detail-row .detail-label {
    min-width: 100px;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
}

.process-source-body .detail-row .detail-value {
    color: var(--text);
    word-break: break-all;
}

.process-metric-bar {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 6px;
}

.process-metric-bar .fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
}

.process-log-list {
    max-height: 220px;
    overflow-y: auto;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 12px;
    margin-top: 12px;
}

.process-log-list .log-item {
    padding: 6px 0;
    border-bottom: 1px dashed var(--border);
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.process-log-list .log-item:last-child {
    border-bottom: none;
}

.process-log-list .log-code {
    min-width: 40px;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
}

.process-log-list .log-url {
    word-break: break-all;
    color: var(--text);
}

.process-log-list .log-size {
    white-space: nowrap;
    color: var(--text-muted);
    margin-left: auto;
    flex-shrink: 0;
}

.process-resource-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.process-resource-grid .resource-item {
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
}

.process-resource-grid .resource-item .value {
    font-size: 18px;
    font-weight: 800;
    color: var(--text);
    display: block;
}

.process-resource-grid .resource-item .label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 4px;
}

.process-polling {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.process-polling::before {
    content: '';
    width: 10px;
    height: 10px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: process-spin 0.8s linear infinite;
}

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

.process-empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}
