/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@700;800;900&display=swap');

:root {
    /* Colors - Dark Theme optimized */
    --bg-app: #0f172a;
    /* Slate 900 */
    --bg-surface: #1e293b;
    /* Slate 800 */
    --bg-surface-hover: #334155;
    /* Slate 700 */
    --bg-secondary: #1e293b;
    --bg-tertiary: #0b1120;
    /* Darker Slate */

    --primary: #6366f1;
    /* Indigo 500 */
    --primary-hover: #4f46e5;
    /* Indigo 600 */
    --primary-glow: rgba(99, 102, 241, 0.4);

    --accent: #ca3ba1;
    /* Pink/Magenta */

    --text-main: #f8fafc;
    /* Slate 50 */
    --text-muted: #94a3b8;
    /* Slate 400 */

    --border: #334155;
    /* Slate 700 */
    --border-light: rgba(255, 255, 255, 0.1);

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Spacing & Radius */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
}

/* Light Mode Overrides */
.light-mode {
    --bg-app: #f8fafc;
    /* Slate 50 */
    --bg-surface: #ffffff;
    --bg-surface-hover: #f1f5f9;
    /* Slate 100 */
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    /* Slate 100 */

    --text-main: #0f172a;
    /* Slate 900 */
    --text-muted: #64748b;
    /* Slate 500 */

    --border: #e2e8f0;
    /* Slate 200 */
    --border-light: rgba(0, 0, 0, 0.05);

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-glow: rgba(79, 70, 229, 0.2);

    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    /* Removed height: 100vh and display: flex to allow natural scrolling */
    min-height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-app);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

/* --- Layout --- */
.sidebar {
    width: 260px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0; /* Remove horizontal padding for full-width items */
    height: 100vh;
    position: fixed;
    transition: transform 0.3s ease;
    z-index: 50;
}

.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 2rem 3rem;
    min-height: 100vh;
}

/* --- Components --- */
.logo {
    font-family: 'Poppins', 'Inter', sans-serif;
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    color: var(--text-main);
    margin-bottom: 2.5rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0 1.5rem; /* Add padding back to logo */
    text-decoration: none;
}

.logo span {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.9rem;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0 0.8rem;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    font-size: 0.95rem;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
}

.nav-item.active {
    background-color: rgba(99, 102, 241, 0.1); /* Subtle background */
    color: var(--primary);
    font-weight: 600;
    border-left: 3px solid var(--primary); /* Accent border on left */
    border-radius: 4px; /* Slightly tighter radius */
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.search-bar {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 0.6rem 1rem;
    border-radius: 50px;
    width: 300px;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.search-bar:focus {
    border-color: var(--primary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    position: relative;
    padding: 0.5rem;
    border-radius: 50%;
    transition: color 0.2s;
}

.btn-icon:hover {
    color: var(--text-main);
    background-color: var(--bg-surface);
}

.btn-icon.has-badge::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background-color: var(--danger);
    border-radius: 50%;
    border: 2px solid var(--bg-app);
}

.user-profile {
    position: relative;
}

.notification-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 56px;
    width: 320px;
    max-height: 380px;
    overflow: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
    z-index: 1200;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px) scale(0.98);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.notification-menu.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.notification-menu-header {
    position: sticky;
    top: 0;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    font-weight: 700;
    color: var(--text-main);
}

.notification-menu-list {
    display: flex;
    flex-direction: column;
}

.notification-menu-empty {
    padding: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.notification-item {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
}

.notification-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-item.unread {
    background: var(--primary-glow);
}

.notification-item-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.2rem;
}

.notification-item-close {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    width: 22px;
    height: 22px;
}

.notification-item-close:hover {
    color: var(--text-main);
    background: var(--bg-surface);
}

.notification-item-message {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.notification-item-time {
    margin-top: 0.3rem;
    font-size: 0.74rem;
    color: var(--text-muted);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ddd6f3, #faaca8);
    border: 2px solid var(--bg-surface);
    transition: border-color 0.2s;
}

.avatar:hover {
    border-color: var(--primary);
}

/* Avatar Dropdown Menu */
.avatar-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
    z-index: 1200;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px) scale(0.98);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
    overflow: hidden;
}

.avatar-menu.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.avatar-menu-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    transition: background 0.15s;
}

.avatar-menu-item:hover {
    background: var(--bg-surface-hover);
}

.avatar-menu-item i {
    width: 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.avatar-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 0.25rem 0;
}

.avatar-menu-logout {
    color: var(--danger) !important;
}

.avatar-menu-logout i {
    color: var(--danger) !important;
}

/* Cards & Dashboard */
.grid-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    border-color: var(--primary);
}

.card h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.card .value {
    font-size: 1.8rem;
    font-weight: 700;
}

.card .trend {
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

.trend.up {
    color: var(--success);
}

.trend.down {
    color: var(--danger);
}

/* Main Action Section */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.btn {
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
    filter: brightness(1.1);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--bg-surface-hover);
}


/* Active Training Grid */
.active-trainings {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.training-card {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    border: 1px solid var(--border);
}

.training-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.training-title {
    font-weight: 600;
}

.training-model {
    font-size: 0.8em;
    color: var(--text-muted);
    display: block;
}

.badge {
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    height: fit-content;
}

.badge.success {
    color: var(--success);
    background: rgba(16, 185, 129, 0.1);
}

.badge.warning {
    color: var(--warning);
    background: rgba(245, 158, 11, 0.1);
}

.badge.running {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.metrics-row {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.metric {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.metric span {
    display: block;
    color: var(--text-main);
    font-weight: 600;
    font-size: 1.1rem;
}

.progress-container {
    width: 100%;
    background: var(--bg-app);
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    width: 0%;
    transition: width 0.5s ease;
}

/* Table */
.table-container {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1rem 1.5rem;
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

td {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
}

tr:hover td {
    background: var(--bg-surface-hover);
}

.tag {
    background: var(--bg-app);
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    display: inline-block;
    margin-right: 4px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-surface);
    width: 90%;
    max-width: 600px;
    border-radius: var(--radius-lg);
    padding: 2rem;
    border: 1px solid var(--border);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.step-indicator {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.step {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
}

.step.active {
    background: var(--primary);
}

.modal-body h3 {
    margin-bottom: 1rem;
}

.model-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.model-option {
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.model-option:hover,
.model-option.selected {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}


/* Preprocessing Pipeline UI */
.pipeline-tools {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.tool-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 0.8rem;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.tool-btn:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.pipeline-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-app);
    padding: 1rem;
    border-radius: var(--radius-md);
    min-height: 200px;
}

.pipeline-step {
    width: 100%;
    padding: 0.8rem;
    text-align: center;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    position: relative;
    border: 1px solid var(--border);
}

.pipeline-step.raw {
    background: rgba(255, 255, 255, 0.05);
    border-style: dashed;
}

.pipeline-step.added {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

.pipeline-step .remove-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--danger);
    opacity: 0.7;
}

.pipeline-step .remove-btn:hover {
    opacity: 1;
}

.arrow-down {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.code-block {
    background: #000;
    padding: 1rem;
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: 0.8rem;
    color: #a5b4fc;
    overflow-x: auto;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }
}

/* Hyperparameter Layout Helper - Forced Unified Design */
.hp-split-container,
.hp-grid-fallback {
    background: var(--bg-tertiary) !important;
    padding: 1.5rem !important;
    border-radius: 8px !important;
    border: 1px solid var(--border) !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* Split Layout (Grid - Robust) */
.hp-split-container {
    display: grid !important;
    grid-template-columns: 1fr 3fr !important;
    gap: 2rem !important;
    align-items: start !important;
}

.hp-left {
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
}

.hp-right {
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
}

/* Grid Fallback (Grid 1fr 1fr) */
.hp-grid-fallback {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 2rem !important;
}

/* Reset inner items to be clean/transparent */
.hp-split-container .param-item,
.hp-grid-fallback .param-item {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    /* Remove bottom margin to let gap handle spacing */
    box-shadow: none !important;
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box !important;
    height: auto !important;
}

/* Ensure inputs pop out against tertiary background */
.hp-split-container .param-input,
.hp-grid-fallback .param-input {
    width: 100% !important;
    background: var(--bg-app) !important;
    border-color: var(--border) !important;
}

.hp-split-container .param-input:hover,
.hp-grid-fallback .param-input:hover {
    border-color: var(--primary) !important;
}