:root {
    /* --- Light Mode Defaults --- */
    --color-bg-main: #F8FAFC;
    --color-bg-sidebar: rgba(255, 255, 255, 0.95);
    --color-bg-card: #FFFFFF;
    --color-bg-hover: #F3F4F6;
    --color-border: #E2E8F0;

    --color-text-main: #1A202C;
    --color-text-muted: #718096;

    /* Stats Accent (Keep similar but suitable for light) */
    --color-accent: #f2c94c;
    --color-accent-hover: #ffdb5e;
    --color-accent-dim: rgba(242, 201, 76, 0.1);

    --color-success: #00ffcc;
    /* Keep or darken slightly for contrast on white? keeping neon for now */
    --color-danger: #ff4444;

    /* Typography */
    --font-ui: 'Inter', sans-serif;
    --font-header: 'Josefin Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Spaces */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;

    --radius-sm: 4px;
    --radius-md: 8px;

    /* Header Height */
    --header-height: 70px;
}

/* --- Dark Mode Overrides --- */
html.dark {
    /* Color Palette (Kamos Stats Inspired - Original Dark Theme) */
    --color-bg-main: #050505;
    /* Deep Black */
    --color-bg-sidebar: rgba(10, 10, 10, 0.95);
    --color-bg-card: #111111;
    --color-bg-hover: #1a1a1a;
    --color-border: #333333;

    --color-text-main: #e0e0e0;
    --color-text-muted: #888888;
}

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

body {
    font-family: var(--font-ui);
    background-color: var(--color-bg-main);
    color: var(--color-text-main);
    height: 100vh;
    overflow: hidden;
    /* Subtle Grid Background if desired */
    background-image: linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
}

/* Header Styles removed - handled by JS loader and global styles */

/* Layout */
#app-container {
    display: flex;
    height: 100vh;
    padding-top: 106px;
    /* 16px(top) + 70px(header) + 20px(gap) */
}

/* Sidebar */
#sidebar {
    width: 260px;
    /* Floating Sidebar Style to match Header? No, keep it clean on the left */
    background-color: transparent;
    /* Blends with body */
    border-right: 1px solid var(--color-border);
    /* Very subtle separator */
    display: flex;
    flex-direction: column;
    margin-left: 16px;
    /* Align with header start */
    height: calc(100vh - 122px);
    /* 106px top + 16px bottom padding */
    position: sticky;
    top: 106px;
    border-radius: 16px;
    padding-right: 10px;
    /* Space for scrollbar if needed */
}

.sidebar-nav {
    flex: 1;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: 12px var(--spacing-md);
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-family: var(--font-ui);
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    text-align: left;
    text-decoration: none;
    font-weight: 500;
}

.nav-item:hover {
    background-color: var(--color-bg-hover);
    color: var(--color-text-main);
}

.nav-item.active {
    background-color: var(--color-accent-dim);
    color: var(--color-accent);
    border-left: 2px solid var(--color-accent);
    /* Stats style accent */
}

.nav-item .material-icons {
    font-size: 20px;
}

table th,
table td {
    padding: 16px 24px;
    /* More breathing room */
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.sidebar-footer {
    padding: var(--spacing-md);
    border-top: 1px solid var(--color-border);
}

/* Main Content */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    /* Scroll handled in view-container */
}

/* Views & Scroll Area */
#view-container {
    flex: 1;
    overflow-y: auto;
    /* padding removed to allow full-width views */
    padding-bottom: 120px;
    /* Space for chat bar */
}

.view {
    display: none;
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    /* Default padding for most views */
    padding: var(--spacing-lg);
}

/* Logs View - Full Width */
#view-logs {
    padding: 0;
    /* Maximize space */
}

#view-logs .search-toolbar {
    margin: var(--spacing-md);
    /* Add margin only to toolbar */
    border-radius: var(--radius-md);
}

#view-logs .table-wrapper {
    border-radius: 0;
    /* Flush to edges */
    border-left: none;
    border-right: none;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes rotating {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.rotating {
    animation: rotating 2s linear infinite;
}

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.kpi-card {
    background: linear-gradient(145deg, var(--color-bg-card), var(--color-bg-hover));
    border: 1px solid var(--color-border);
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--color-accent);
    opacity: 0.5;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: var(--spacing-xs);
}

.kpi-value {
    font-size: 2.2rem;
    font-weight: 700;
    font-family: var(--font-header);
    color: var(--color-text-main);
}

.kpi-trend {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* Charts Layout */
.chart-card {
    background-color: var(--color-bg-card);
    border: 1px solid var(--color-border);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
}

.chart-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--color-text-main);
}

.chart-card.wide {
    width: 100%;
}

.chart-wrapper {
    position: relative;
    height: 300px;
    /* Stats charts are usually compact */
    width: 100%;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
}

/* UI Elements */
input,
select {
    background-color: var(--color-bg-main);
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    transition: border-color 0.2s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--color-accent);
}

/* Utilities */
.hidden {
    display: none !important;
}

/* --- Toolbar & Input Groups --- */
.dashboard-toolbar {
    background: var(--color-bg-card);
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    /* Ensure flex items align centered vertically */
    align-items: center !important;
    flex-wrap: wrap;
}

.input-group {
    display: flex;
    align-items: center;
    background-color: var(--color-bg-main);
    /* Matches input bg */
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    /* Padding side */
    height: 40px;
    /* Fixed height for alignment */
    transition: border-color 0.2s;
}

.input-group:focus-within {
    border-color: var(--color-accent);
}

.input-group .input-icon {
    font-size: 20px;
    color: var(--color-text-muted);
    margin-right: 8px;
    display: flex;
    align-items: center;
    /* Ensure icon itself is centered */
}

.kamos-input {
    background: transparent;
    border: none;
    color: var(--color-text-main);
    font-family: var(--font-ui);
    font-size: 0.9rem;
    padding: 0;
    /* Remove padding as container handles it */
    height: 100%;
    /* Fill container height */
    outline: none;
    width: auto;
    min-width: 120px;
}

/* Hide default select arrow and use customized appearance if needed, 
   but for now default system UI with dark theme is okay-ish, 
   or we can trust browser defaults on dark mode */
select.kamos-input {
    cursor: pointer;
    background-color: transparent;
}

select.kamos-input option {
    background-color: var(--color-bg-card);
    color: var(--color-text-main);
}


/* Date input specific fixes */
.kamos-input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    /* White icon for dark mode */
    cursor: pointer;
    opacity: 0.6;
}

.kamos-input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

/* --- Buttons --- */
.primary-btn,
.secondary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    /* Match input height */
    padding: 0 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font-header);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.primary-btn {
    background-color: var(--color-accent);
    color: #050505;
    /* Black text on Gold */
    border-color: var(--color-accent);
    box-shadow: 0 4px 15px rgba(242, 201, 76, 0.2);
}

.primary-btn:hover {
    background-color: var(--color-accent-hover);
    box-shadow: 0 6px 20px rgba(242, 201, 76, 0.3);
    transform: translateY(-1px);
}

.secondary-btn {
    background-color: transparent;
    color: var(--color-text-main);
    border-color: var(--color-border);
}

.secondary-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--color-text-muted);
    color: #fff;
}

.primary-btn .material-icons,
.secondary-btn .material-icons {
    font-size: 20px;
}

/* --- Modal Styles --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal:not(.hidden) .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    background: rgba(17, 17, 17, 0.8);
    backdrop-filter: blur(4px);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
}

.modal-header h2 {
    font-family: var(--font-header);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--color-accent);
    margin: 0;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.close-modal:hover {
    color: var(--color-text-main);
    background-color: var(--color-bg-hover);
    transform: rotate(90deg);
}

.modal-body {
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
    background-color: #050505;
}

#json-viewer {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    color: #e6edf3;
    white-space: pre-wrap;
    word-break: break-all;
    background: #0d1117;
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid #333;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.loading-detail {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--color-text-muted);
    height: 200px;
    font-size: 0.9rem;
}

.loading-detail .material-icons {
    font-size: 40px;
    color: var(--color-accent);
}

/* Scrollbar for Modal Body */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 10px;
}