/* ============================================================
 *  css/perceptron.css
 *  @author Alexander Wolf
 *
 *  Styles für das Perceptron-Playground.
 *  Nutzt CSS-Variablen aus style.css (:root).
 *
 *  Layout (Desktop):
 *    ┌─────────────────┬─────────────────┐
 *    │  architecture   │   datatable     │  2fr
 *    ├─────────────────┤   (oder gauss.) │
 *    │  learnrule      ├─────────────────┤  1fr
 *    │  (+error chart) │  scatterplot    │
 *    └─────────────────┴─────────────────┘
 * ============================================================ */

/* ===== LAYOUT ===== */
.perceptron-page .lab-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 3fr 2fr;
    grid-template-areas:
        "architecture datatable"
        "learnrule    scatterplot";
    gap: 10px;
    padding: 10px;
    flex: 1;
    overflow: hidden;
}

/* --- Panels --- */
.perceptron-panel {
    background: var(--sidebar-bg, #fff);
    border: 1px solid var(--border-color, #ddd);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.perceptron-panel .panel-header {
    padding: 8px 12px;
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text-main);
    border-bottom: 2px solid #f0f2f5;
    background: #fafafa;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.perceptron-panel .panel-body {
    padding: 8px 10px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* ===== GRID AREAS ===== */
.perceptron-panel.panel-datatable    { grid-area: datatable; }
.perceptron-panel.panel-architecture { grid-area: architecture; }
.perceptron-panel.panel-scatterplot  { grid-area: scatterplot; }
.perceptron-panel.panel-learnrule    { grid-area: learnrule; }

/* Architecture: no body scroll – the diagram must always be fully visible */
.perceptron-panel.panel-architecture .panel-body {
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== TOOLBAR ===== */
.perceptron-page .lab-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 14px;
    flex-wrap: wrap;
    height: auto;
    min-height: 42px;
}

.perceptron-page .lab-toolbar .toolbar-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.perceptron-page .lab-toolbar label {
    font-size: 0.76rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
    letter-spacing: 0.3px;
}

/* Prevent CSS uppercase from turning η → Η (looks like H) */
.perceptron-page .lab-toolbar label.label-greek {
    text-transform: none;
}

.perceptron-page .lab-toolbar select,
.perceptron-page .lab-toolbar input[type="number"] {
    padding: 4px 6px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 4px;
    font-size: 0.84rem;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    min-width: 60px;
}

.perceptron-page .lab-toolbar select:focus,
.perceptron-page .lab-toolbar input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.3);
}

.perceptron-page .lab-toolbar select option {
    background: var(--text-main);
    color: #fff;
}

/* --- Speed Slider --- */
.speed-slider-group input[type="range"] {
    width: 80px;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

.speed-slider-group .speed-label {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.5);
    min-width: 28px;
}

/* --- Stats in toolbar --- */
.toolbar-stats {
    display: flex;
    gap: 12px;
    margin-left: auto;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
}

.toolbar-stats .stat-item {
    display: flex;
    align-items: center;
    gap: 3px;
}

.toolbar-stats .stat-label {
    font-weight: 700;
}

.toolbar-stats .stat-value {
    font-variant-numeric: tabular-nums;
    color: #fff;
    font-weight: 600;
}

/* ===== DATA TABLE ===== */
.data-table-wrapper {
    overflow-y: auto;
    flex: 1;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.data-table th,
.data-table td {
    padding: 4px 6px;
    text-align: center;
    border-bottom: 1px solid #eee;
}

.data-table th {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    color: var(--text-muted, #7f8c8d);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.4px;
    z-index: 1;
}

.data-table tr {
    background: #fff;
}

.data-table tr:hover {
    background: #f0f7ff;
}

.data-table tr.row-correct {
    background: rgba(46, 204, 113, 0.08);
}

.data-table tr.row-correct:hover {
    background: rgba(46, 204, 113, 0.14);
}

.data-table tr.row-error {
    background: rgba(231, 76, 60, 0.10);
}

.data-table tr.row-error:hover {
    background: rgba(231, 76, 60, 0.16);
}

.data-table tr.row-selected {
    background: rgba(241, 196, 15, 0.18);
    outline: 2px solid var(--accent-yellow);
    outline-offset: -2px;
}

.data-table .label-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.74rem;
    color: #fff;
}

.data-table .label-badge.class-0 {
    background: var(--accent-blue, #3498db);
}

.data-table .label-badge.class-1 {
    background: var(--accent-orange, #e67e22);
}

.data-table .pred-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.74rem;
}

.data-table .pred-badge.correct {
    color: var(--accent-green);
    background: rgba(46, 204, 113, 0.12);
}

.data-table .pred-badge.wrong {
    color: var(--accent-red);
    background: rgba(231, 76, 60, 0.12);
    text-decoration: line-through;
}

/* ===== SCATTER PLOT ===== */
.plot-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
}

.perceptron-plot {
    border-radius: 6px;
    border: 1px solid #eaeaea;
}

/* Scatterplot header: title left, equation middle, toggle right */
.panel-scatterplot .panel-header {
    justify-content: space-between;
}

/* Diagram toggle button */
.btn-diagram-toggle {
    background: transparent;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    transition: background 0.15s;
    white-space: nowrap;
}

.btn-diagram-toggle:hover {
    background: #f0f2f5;
}

.btn-diagram-toggle.active {
    background: rgba(52, 152, 219, 0.12);
    border-color: var(--accent-blue);
}

.equation-inline {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 55%;
    text-align: right;
}

/* Datenpunkt-Animation bei Fehler */
@keyframes errorPulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

.data-point.error-pulse {
    animation: errorPulse 0.8s ease-in-out infinite;
}

/* ===== ARCHITECTURE DIAGRAM ===== */
.arch-wrapper {
    display: flex;
    justify-content: center;
}

.arch-svg {
    max-width: 100%;
    height: auto;
}

.arch-svg text {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.arch-step-graph line,
.arch-step-graph path {
    stroke-linecap: round;
}

/* ===== LEARNING RULE ===== */

/* Header with buttons */
.panel-learnrule .panel-header {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
}

.panel-learnrule .panel-title {
    white-space: nowrap;
}

.learnrule-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.learnrule-actions .btn-step,
.learnrule-actions .btn-train,
.learnrule-actions .btn-reset {
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.78rem;
    transition: filter 0.15s;
    color: #fff;
}

.learnrule-actions .btn-step  { background: var(--accent-blue, #3498db); }
.learnrule-actions .btn-train { background: var(--accent-green, #2ecc71); }
.learnrule-actions .btn-reset { background: var(--accent-yellow, #f1c40f); color: #333; }

.learnrule-actions button:hover  { filter: brightness(90%); }
.learnrule-actions button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-chart-toggle {
    background: transparent;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 4px;
    padding: 3px 6px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: background 0.15s;
}

.btn-chart-toggle:hover {
    background: #f0f2f5;
}

.btn-chart-toggle.active {
    background: rgba(52, 152, 219, 0.12);
    border-color: var(--accent-blue);
}

/* Rule formula */
.learning-rule-display {
    font-size: 0.88rem;
    line-height: 1.7;
}

.learning-rule-display .rule-formula {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 0.92rem;
    padding: 8px 10px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 3px solid var(--accent-blue);
    margin: 4px 0;
}

/* Phase title */
.rule-phase-title {
    font-family: 'Segoe UI', sans-serif;
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--accent-blue, #3498db);
    margin-bottom: 4px;
}

/* Explanation text */
.rule-explanation {
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.82rem;
    color: var(--text-muted, #7f8c8d);
    margin-bottom: 6px;
    line-height: 1.5;
}

.rule-explanation code {
    font-family: 'Georgia', 'Times New Roman', serif;
    background: rgba(52, 152, 219, 0.08);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.88rem;
}

/* Detail table for phase values */
.rule-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
    margin: 4px 0;
}

.rule-detail-table td {
    padding: 2px 6px;
    border-bottom: 1px solid #f0f2f5;
    vertical-align: middle;
}

.rule-detail-table .rule-label {
    font-weight: 700;
    color: var(--text-muted, #7f8c8d);
    white-space: nowrap;
    width: 70px;
    font-size: 0.8rem;
}

/* Weight transition display */
.rule-weight-transition {
    font-family: 'Georgia', serif;
    font-size: 0.88rem;
    margin-top: 4px;
    padding: 4px 6px;
    background: #f0f7ff;
    border-radius: 4px;
    line-height: 1.8;
}

/* Hints */
.rule-hint {
    font-size: 0.78rem;
    color: var(--text-muted, #7f8c8d);
    margin-top: 4px;
    font-style: italic;
    line-height: 1.4;
}

.rule-hint.rule-success {
    color: var(--accent-green, #2ecc71);
    font-style: normal;
    font-weight: 600;
}

.learning-rule-display .weight-old {
    color: var(--accent-red, #e74c3c);
    text-decoration: line-through;
    font-weight: 700;
}

.learning-rule-display .weight-new {
    color: var(--accent-green, #2ecc71);
    font-weight: 700;
}

.learning-rule-display .rule-part {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 4px;
    margin: 0 1px;
}

.learning-rule-display .part-eta {
    background: rgba(52, 152, 219, 0.12);
    color: var(--accent-blue);
}

.learning-rule-display .part-delta {
    background: rgba(231, 76, 60, 0.12);
    color: var(--accent-red);
}

.learning-rule-display .part-input {
    background: rgba(46, 204, 113, 0.12);
    color: var(--accent-green);
}

/* Phase indicator */
.phase-indicator {
    display: flex;
    gap: 4px;
    margin: 6px 0;
}

.phase-indicator .phase-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ddd;
    transition: background 0.2s;
}

.phase-indicator .phase-dot.active {
    background: var(--accent-blue);
}

.phase-indicator .phase-dot.done {
    background: var(--accent-green);
}

/* ===== ERROR CHART VIEW (in bottom-right panel) ===== */
.error-chart-view {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
}

.error-chart-view.hidden {
    display: none;
}

.error-chart-svg {
    border: 1px solid #eaeaea;
    border-radius: 4px;
    background: #fafafa;
    max-width: 100%;
    height: auto;
}

/* ===== GAUSSIAN GENERATOR (inside datatable panel) ===== */
.gaussian-config {
    display: none;
}

.gaussian-config.visible {
    display: block;
}

.gaussian-config .config-title {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text-main);
    margin-bottom: 8px;
}

.gaussian-clusters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.gaussian-cluster-group {
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #eee;
}

.gaussian-cluster-group.cluster-0 {
    border-color: rgba(52, 152, 219, 0.3);
    background: rgba(52, 152, 219, 0.04);
}

.gaussian-cluster-group.cluster-1 {
    border-color: rgba(231, 76, 60, 0.3);
    background: rgba(231, 76, 60, 0.04);
}

.gaussian-cluster-group .cluster-label {
    font-weight: 700;
    font-size: 0.78rem;
    margin-bottom: 6px;
}

.gaussian-slider-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.gaussian-slider-row label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 22px;
}

.gaussian-slider-row input[type="range"] {
    flex: 1;
    accent-color: var(--accent-blue);
}

.gaussian-slider-row .slider-value {
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    min-width: 28px;
    text-align: right;
    font-weight: 600;
}

.gaussian-config .btn-generate {
    display: block;
    width: 100%;
    margin-top: 12px;
    background: linear-gradient(135deg, var(--accent-blue, #3498db), #2980b9);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.92rem;
    letter-spacing: 0.3px;
    transition: filter 0.15s, transform 0.1s;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

.gaussian-config .btn-generate:hover {
    filter: brightness(110%);
    transform: translateY(-1px);
}

.gaussian-config .btn-generate:active {
    transform: translateY(0);
}

/* ===== RESPONSIVE (Mobile) ===== */
@media (max-width: 768px) {
    /* Allow scroll on mobile */
    .perceptron-page {
        overflow-y: auto;
        height: auto;
        min-height: 100vh;
    }

    .perceptron-page .lab-toolbar {
        height: auto;
        min-height: 38px;
        padding: 6px 10px;
        gap: 6px;
    }

    .perceptron-page .lab-toolbar .toolbar-group {
        gap: 4px;
    }

    .perceptron-page .lab-toolbar label {
        font-size: 0.7rem;
    }

    .perceptron-page .lab-toolbar select,
    .perceptron-page .lab-toolbar input[type="number"] {
        font-size: 0.8rem;
        min-width: 50px;
        padding: 3px 5px;
    }

    .toolbar-stats {
        gap: 8px;
        font-size: 0.74rem;
    }

    /* Single column: 1.Perceptron 2.Lernregel 3.Diagramm 4.Tabelle */
    .perceptron-page .lab-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        grid-template-areas:
            "architecture"
            "learnrule"
            "scatterplot"
            "datatable";
        overflow-y: auto;
        padding: 8px;
        gap: 8px;
    }

    /* Give architecture more room on mobile */
    .perceptron-panel.panel-architecture {
        min-height: 200px;
    }

    .gaussian-clusters {
        grid-template-columns: 1fr;
    }

    .learnrule-actions {
        flex-wrap: wrap;
    }

    .equation-inline {
        font-size: 0.7rem;
        max-width: 50%;
    }

    .arch-wrapper {
        overflow-x: auto;
    }
}

/* Tablet: 769px – 1100px */
@media (min-width: 769px) and (max-width: 1100px) {
    .perceptron-page .lab-grid {
        gap: 8px;
        padding: 8px;
    }

    .perceptron-panel .panel-header {
        padding: 6px 10px;
        font-size: 0.82rem;
    }

    .perceptron-panel .panel-body {
        padding: 6px 8px;
    }
}
