/* Modern Glassmorphic Dark Design System */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #121824;
    --card-bg: rgba(22, 30, 49, 0.65);
    --card-border: rgba(255, 255, 255, 0.08);
    
    --accent-violet: #8b5cf6;
    --accent-violet-glow: rgba(139, 92, 246, 0.35);
    --accent-emerald: #10b981;
    --accent-emerald-glow: rgba(16, 185, 129, 0.3);
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    
    --text-primary: #f8fafc;
    --text-muted: #94a3b8;
    --text-disabled: #475569;
    
    --sidebar-width: 260px;
    --header-height: 80px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Fira Code', monospace;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    height: 100vh;
    overflow: hidden;
}

/* App Layout */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* Sidebar styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    flex-shrink: 0;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 8px 32px 8px;
}

.logo-icon {
    font-size: 24px;
    color: var(--accent-violet);
    text-shadow: 0 0 12px var(--accent-violet-glow);
}

.logo-area h2 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #fff, var(--text-muted));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: none;
    border: none;
    padding: 14px 16px;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: left;
    transition: all var(--transition-normal);
}

.nav-btn i {
    font-size: 18px;
    width: 20px;
    text-align: center;
}

.nav-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.03);
}

.nav-btn.active {
    color: var(--text-primary);
    background-color: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.25);
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.1);
}

.system-status {
    padding-top: 16px;
    border-top: 1px solid var(--card-border);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    transition: background-color var(--transition-normal);
}

.status-dot.id-dot { background-color: var(--text-disabled); }
.status-dot.training-dot { background-color: var(--accent-amber); box-shadow: 0 0 8px var(--accent-amber); animation: pulse 1.5s infinite; }
.status-dot.completed-dot { background-color: var(--accent-emerald); box-shadow: 0 0 8px var(--accent-emerald); }
.status-dot.error-dot { background-color: var(--accent-rose); box-shadow: 0 0 8px var(--accent-rose); }

/* Main Content styling */
.main-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    height: 100%;
    background: radial-gradient(circle at 50% 0%, #1e1e30 0%, var(--bg-primary) 70%);
}

.app-header {
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 32px;
    border-bottom: 1px solid var(--card-border);
    flex-shrink: 0;
}

.header-title h1 {
    font-size: 20px;
    font-weight: 600;
}

.header-title p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Tabs structure */
.tab-content {
    display: none;
    flex-grow: 1;
    height: calc(100vh - var(--header-height));
    padding: 24px;
    overflow-y: auto;
}

.tab-content.active {
    display: flex;
}

/* Common Card Panel styling */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body {
    padding: 20px;
    flex-grow: 1;
    overflow-y: auto;
}

/* Grid Layouts */
.grid-layout {
    display: grid;
    grid-template-columns: 280px 1fr 340px;
    gap: 20px;
    width: 100%;
    height: 100%;
}

/* Buttons style */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 550;
    padding: 10px 18px;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.btn-primary {
    background-color: var(--accent-violet);
    color: #fff;
    box-shadow: 0 4px 12px var(--accent-violet-glow);
}

.btn-primary:hover:not(:disabled) {
    background-color: #9d76fa;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px var(--accent-violet-glow);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--card-border);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-success {
    background-color: var(--accent-emerald);
    color: #fff;
    box-shadow: 0 4px 12px var(--accent-emerald-glow);
}

.btn-success:hover:not(:disabled) {
    background-color: #1ed197;
    transform: translateY(-1px);
}

.btn-danger {
    background-color: var(--accent-rose);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background-color: #f75d77;
    transform: translateY(-1px);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.btn-xs {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 6px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-block {
    width: 100%;
}

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

/* Panel Classes Column */
.panel-classes {
    height: 100%;
}

.class-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.class-input-group input {
    flex-grow: 1;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    color: #fff;
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition-fast);
}

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

.class-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.class-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.class-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.class-item.active {
    border-color: var(--accent-violet);
    background-color: rgba(139, 92, 246, 0.08);
}

.class-item-details {
    display: flex;
    align-items: center;
    gap: 10px;
}

.class-color-badge {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.class-name {
    font-size: 14px;
    font-weight: 500;
}

.class-count {
    font-size: 12px;
    color: var(--text-muted);
    background-color: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 20px;
}

.class-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.class-delete-btn:hover {
    color: var(--accent-rose);
    background-color: rgba(244, 63, 94, 0.1);
}

/* Panel Annotator Column (Center) */
.panel-annotator {
    height: 100%;
}

.annotator-header {
    justify-content: space-between;
}

.canvas-controls {
    display: flex;
    gap: 8px;
}

.annotator-body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #07090f;
    position: relative;
    padding: 0;
}

.canvas-container {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    width: 100%;
    height: 100%;
}

#annotator-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    pointer-events: none; /* Let clicks pass to the drawing canvas */
}

#annotator-canvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
}

.canvas-footer {
    display: flex;
    justify-content: space-between;
    padding: 10px 20px;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    border-top: 1px solid var(--card-border);
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.placeholder-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 48px;
    color: var(--text-disabled);
    margin-bottom: 16px;
}

.placeholder-view p {
    font-size: 14px;
    max-width: 260px;
    line-height: 1.5;
}

/* Panel Gallery Column (Right) */
.panel-gallery {
    height: 100%;
}

.gallery-header {
    justify-content: space-between;
}

.upload-label {
    margin-bottom: 0;
}

.gallery-body {
    padding: 16px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.gallery-item {
    position: relative;
    border-radius: var(--radius-md);
    border: 1px solid var(--card-border);
    background-color: rgba(0,0,0,0.15);
    overflow: hidden;
    aspect-ratio: 1;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.gallery-item:hover {
    border-color: var(--accent-violet);
    transform: scale(1.02);
}

.gallery-item.active {
    border-color: var(--accent-violet);
    box-shadow: 0 0 12px var(--accent-violet-glow);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
}

.gallery-item-badge.labeled {
    background-color: var(--accent-emerald);
    color: #fff;
}

.gallery-item-badge.unlabeled {
    background-color: var(--text-disabled);
    color: var(--text-primary);
}

.gallery-item-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: rgba(15, 23, 42, 0.85);
    border: none;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all var(--transition-fast);
}

.gallery-item:hover .gallery-item-delete {
    opacity: 1;
}

.gallery-item-delete:hover {
    color: #fff;
    background-color: var(--accent-rose);
}

/* TAB 2: TRAINING LAYOUT */
.training-layout {
    grid-template-columns: 320px 1fr;
}

.panel-hyperparams {
    height: 100%;
}

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

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 550;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-group input, .form-group select {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 12px;
    color: #fff;
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition-fast);
}

.form-group input:focus, .form-group select:focus {
    border-color: var(--accent-violet);
}

.form-help {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.train-actions-group {
    margin-top: 32px;
}

.dataset-stats-card {
    margin-top: 24px;
    padding: 16px;
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
}

.dataset-stats-card h4 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 8px;
}

.stat-row:last-child {
    margin-bottom: 0;
}

/* Dashboard container */
.training-dashboard {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
    overflow-y: auto;
}

.panel-progress {
    flex-shrink: 0;
}

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

.train-status-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.train-status-badge.id-badge { background-color: var(--text-disabled); color: #fff; }
.train-status-badge.training-badge { background-color: var(--accent-amber); color: #000; animation: pulse 1.5s infinite; }
.train-status-badge.completed-badge { background-color: var(--accent-emerald); color: #fff; }
.train-status-badge.error-badge { background-color: var(--accent-rose); color: #fff; }

.progress-bar-container {
    width: 100%;
    height: 8px;
    background-color: rgba(0,0,0,0.3);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-violet), var(--accent-emerald));
    border-radius: 4px;
    transition: width 0.4s ease;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.metric-card {
    background-color: rgba(0,0,0,0.2);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

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

.metric-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.charts-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    height: 260px;
    flex-shrink: 0;
}

.chart-card {
    height: 100%;
}

.chart-card .card-body {
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-logs {
    flex-grow: 1;
    min-height: 200px;
}

.logs-header {
    justify-content: space-between;
}

.logs-body {
    padding: 0;
    background-color: #020617;
}

.terminal-view {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    color: #e2e8f0;
    padding: 16px;
    height: 100%;
    width: 100%;
    margin: 0;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* TAB 3: INFERENCE LAYOUT */
.test-layout {
    grid-template-columns: 340px 1fr;
}

.panel-test-upload {
    height: 100%;
}

.test-upload-area {
    border: 2px dashed var(--card-border);
    border-radius: var(--radius-lg);
    padding: 32px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    background-color: rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.test-upload-area:hover {
    border-color: var(--accent-violet);
    background-color: rgba(139, 92, 246, 0.05);
}

.upload-icon {
    font-size: 40px;
    color: var(--text-disabled);
    margin-bottom: 12px;
}

.test-upload-area p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.model-info-box {
    background-color: rgba(139, 92, 246, 0.06);
    border: 1px solid rgba(139, 92, 246, 0.15);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
}

.model-info-box h4 {
    font-size: 13px;
    color: var(--accent-violet);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 6px;
}

.info-desc {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 8px;
}

.results-list h4 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.results-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 280px;
    overflow-y: auto;
}

.no-results {
    font-size: 13px;
    color: var(--text-disabled);
    text-align: center;
    padding: 20px;
}

.result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background-color: rgba(255,255,255,0.02);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
}

.result-tag {
    display: flex;
    align-items: center;
    gap: 8px;
}

.result-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.result-name {
    font-size: 13px;
    font-weight: 550;
}

.result-conf {
    font-size: 12px;
    color: var(--accent-emerald);
    font-family: var(--font-mono);
    font-weight: 600;
}

.panel-test-viewer {
    height: 100%;
}

.test-viewer-body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #07090f;
    padding: 0;
}

#test-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
}

#test-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

/* Animations */
@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}
