/* =========================================================
   MNIST Neural Network Trainer — Dark Theme
   ========================================================= */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #1a202c;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent-blue: #58a6ff;
    --accent-green: #48bb78;
    --accent-red: #f56565;
    --accent-orange: #f6ad55;
    --border: #30363d;
    --radius: 8px;
}

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

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

.app-container {
    min-height: 100vh;
}

/* ---- Header ---- */
.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.app-header h1 {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-primary);
}

.architecture-badge {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--accent-blue);
    font-family: 'SF Mono', monospace;
}

/* ---- Main layout ---- */
.main-layout {
    max-width: 1400px;
    margin: 0 auto;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 1rem;
    padding: 1rem 1.5rem;
}

/* ---- Panels ---- */
.viz-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    overflow: hidden;
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.panel-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.panel-card h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ---- Data upload section ---- */
.data-upload-section {
    display: flex;
    justify-content: center;
    padding: 3rem 1.5rem;
}

.upload-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 600px;
    width: 100%;
}

.upload-card h2 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

.upload-card p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.upload-card h3 {
    font-size: 1rem;
    color: var(--accent-blue);
    margin-bottom: 0.5rem;
}

.upload-card code {
    background: var(--bg-card);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--accent-orange);
}

.load-option {
    margin-bottom: 1rem;
}

.divider {
    display: flex;
    align-items: center;
    margin: 1.25rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.divider::before,
.divider::after {
    content: "";
    flex: 1;
    border-bottom: 1px solid var(--border);
}

.divider span {
    padding: 0 0.75rem;
}

.button-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.server-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.info-label {
    color: var(--text-muted);
}

.info-value {
    color: var(--accent-green);
    font-weight: 600;
    margin-right: 0.5rem;
}

.digit-count {
    background: var(--bg-primary);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-family: 'SF Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.upload-row {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.upload-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.upload-field label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.upload-field input[type="file"] {
    color: var(--text-primary);
    font-size: 0.9rem;
}

.check {
    color: var(--accent-green);
    font-weight: 600;
}

.error-message {
    background: rgba(245, 101, 101, 0.15);
    border: 1px solid var(--accent-red);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-top: 1rem;
    color: var(--accent-red);
    font-size: 0.9rem;
}

/* ---- Buttons ---- */
.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

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

.btn-primary {
    background: var(--accent-blue);
    color: #fff;
    border-color: var(--accent-blue);
}

.btn-primary:hover:not(:disabled) {
    background: #79b8ff;
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background: #2d3748;
}

.btn-danger {
    background: transparent;
    color: var(--accent-red);
    border-color: var(--accent-red);
}

.btn-danger:hover:not(:disabled) {
    background: rgba(245, 101, 101, 0.15);
}

.btn-large {
    padding: 0.75rem 2rem;
    font-size: 1rem;
    width: 100%;
}

/* ---- Training controls ---- */
.training-controls {
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.controls-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.controls-row.sliders {
    margin-top: 0.75rem;
    gap: 1.5rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 200px;
}

.control-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: 'SF Mono', monospace;
}

.control-group input[type="range"] {
    width: 100%;
    accent-color: var(--accent-blue);
}

/* ---- Stats row ---- */
.stats-row {
    display: flex;
    gap: 1.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.05rem;
    font-weight: 600;
    font-family: 'SF Mono', monospace;
    color: var(--accent-blue);
}

/* ---- Network SVG ---- */
.network-viz-container {
    overflow: auto;
}

.network-svg {
    display: block;
    margin: 0 auto;
}

.layer-label {
    fill: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
}

.node {
    cursor: pointer;
    transition: stroke 0.15s;
}

.node:hover {
    stroke: var(--accent-blue);
    stroke-width: 2.5;
}

.node-value {
    fill: var(--text-primary);
    font-size: 7px;
    font-family: 'SF Mono', monospace;
    pointer-events: none;
}

.output-label {
    fill: #fff;
    font-size: 11px;
    font-weight: 700;
    pointer-events: none;
}

.output-value {
    fill: var(--text-secondary);
    font-size: 10px;
    font-family: 'SF Mono', monospace;
}

.ellipsis-label {
    fill: var(--text-muted);
    font-size: 10px;
}

.detail-title {
    fill: var(--accent-blue);
    font-size: 12px;
    font-weight: 600;
}

.detail-text {
    fill: var(--text-secondary);
    font-size: 10px;
    font-family: 'SF Mono', monospace;
}

/* ---- Image preview ---- */
.image-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.mnist-image {
    border: 1px solid var(--border);
    border-radius: 4px;
}

.image-label {
    display: flex;
    gap: 1rem;
    font-size: 0.9rem;
}

.label-text {
    color: var(--text-secondary);
}

.prediction-text.correct {
    color: var(--accent-green);
}

.prediction-text.incorrect {
    color: var(--accent-red);
}

/* ---- Chart ---- */
.chart-container {
    display: flex;
    justify-content: center;
}

.chart-label {
    fill: var(--text-muted);
    font-size: 9px;
    font-family: 'SF Mono', monospace;
}

.chart-legend {
    fill: var(--text-secondary);
    font-size: 9px;
}

/* ---- Model actions ---- */
.model-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.model-actions h3 {
    margin-bottom: 0;
}

/* ---- Loading progress bar ---- */
.loading-section {
    margin: 0.75rem 0;
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: var(--bg-card);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-pulse {
    width: 100%;
    background: linear-gradient(90deg, var(--bg-card) 0%, var(--accent-blue) 50%, var(--bg-card) 100%);
    background-size: 200% 100%;
    animation: pulse-move 1.5s ease-in-out infinite;
}

.progress-fast {
    width: 100%;
    background: var(--accent-green);
    animation: pulse-opacity 0.4s ease-in-out infinite;
}

@keyframes pulse-move {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes pulse-opacity {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.loading-status {
    margin-top: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: 'SF Mono', monospace;
}

/* ---- Model info ---- */
.model-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.model-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 1rem;
}

.model-stat {
    display: flex;
    flex-direction: column;
}

.model-stat .stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.model-stat .stat-value {
    font-size: 0.9rem;
    font-weight: 600;
    font-family: 'SF Mono', monospace;
    color: var(--accent-blue);
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .content-grid {
        grid-template-columns: 1fr;
    }
}
