:root {
    --bg-base: #101214;
    --bg-surface: #1e2126;
    --bg-surface-hover: #292d33;
    --text-primary: #ffffff;
    --text-secondary: #9098a5;

    --brand-purple: #632ca6;
    --brand-purple-light: #8347cf;

    --color-error: #e83e8c;
    --color-warning: #f5a623;
    --color-success: #28a745;
    --color-critical: #ef4444;

    --border-subtle: rgba(255, 255, 255, 0.1);
    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.5);

    --radius-lg: 16px;
    --radius-md: 8px;
    --radius-sm: 4px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body.dark-mode {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 280px;
    min-width: 280px;
    flex-shrink: 0;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow-y: auto;
}

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

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(90deg, #fff, var(--text-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.badge {
    background: var(--brand-purple);
    color: #fff;
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.sidebar-menu {
    margin-bottom: 30px;
}

.menu-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    letter-spacing: 1px;
    margin-bottom: 15px;
}

button {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    margin-bottom: 12px;
}

.btn-primary {
    background-color: var(--brand-purple);
    color: white;
}

.btn-primary:hover {
    background-color: var(--brand-purple-light);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--bg-surface-hover);
}

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

/* Client Filter List */
.clients-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.client-btn {
    background-color: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.client-btn:hover {
    background-color: var(--bg-surface-hover);
    transform: translateX(2px);
}

.client-btn.active {
    background-color: var(--brand-purple);
    border-color: var(--brand-purple-light);
    font-weight: 700;
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background-color: var(--bg-base);
    position: relative;
    padding: 40px 60px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.topbar h1 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 8px;
    letter-spacing: -1px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

.timestamp {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: monospace;
    background: var(--bg-surface);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    background: rgba(16, 18, 20, 0.8);
    backdrop-filter: blur(8px);
    width: 100%;
    height: 100%;
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-subtle);
    border-top-color: var(--brand-purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

.loading-overlay p {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.loading-overlay small {
    color: var(--text-secondary);
}

.hidden {
    display: none !important;
}

/* KPIs Grid */
.kpis-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-bottom: 40px;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: flex-start;
    gap: 20px;
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.error-card::before {
    background-color: var(--color-error);
}

.warning-card::before {
    background-color: var(--color-warning);
}

.success-card::before {
    background-color: var(--color-success);
}

.kpi-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.kpi-content h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.kpi-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Client Section */
.client-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 32px;
    box-shadow: var(--shadow-soft);
}

.client-header {
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 20px;
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.client-header h2 {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.client-error {
    color: var(--color-error);
    background: rgba(232, 62, 140, 0.1);
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(232, 62, 140, 0.2);
    font-weight: 500;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
}

.card {
    background: var(--bg-base);
    border-radius: var(--radius-md);
    padding: 24px;
    border: 1px solid var(--border-subtle);
}

.card h3 {
    font-size: 1.1rem;
    margin-bottom: 20px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 12px;
}

.evt-list {
    list-style: none;
}

.evt-item {
    padding: 12px 16px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 0.85rem;
    display: flex;
    gap: 12px;
    border-left: 3px solid var(--border-subtle);
    line-height: 1.4;
}

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

.evt-item div {
    min-width: 0;
    flex: 1;
}

.evt-item strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-all;
}

.evt-item.is-error {
    border-left-color: var(--color-error);
}

.evt-item.is-warning {
    border-left-color: var(--color-warning);
}

.evt-item.is-info {
    border-left-color: var(--brand-purple);
}

.tag-badge {
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.75rem;
    border: 1px solid var(--border-subtle);
    display: inline-block;
    margin: 2px;
}

/* Table styles for Thresholds */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th,
.data-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

.data-table th {
    color: var(--text-secondary);
    font-weight: 600;
}

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

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Markdown UI Adjustments */
.markdown-body ul,
.markdown-body ol {
    margin-top: 8px;
    margin-bottom: 12px;
    padding-left: 20px;
}

.markdown-body li {
    margin-bottom: 6px;
}

.markdown-body p {
    margin-bottom: 12px;
}

.markdown-body strong {
    color: var(--text-primary);
}

/* --- Print / PDF Export --- */
@media print {

    body,
    .app-container {
        height: auto;
        overflow: visible;
        background-color: var(--bg-base) !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .sidebar {
        display: none !important;
    }

    .main-content {
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }

    .card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}