/* ====================================================================
   1. Globale Stile & Variablen
   ==================================================================== */

:root {
    /* Generische Control-Variablen */
    --control-height: 28px;
    --control-radius: 5px;

    /* Layer-Grid-Variablen */
    --layer-title-col: 340px;
    --layer-lambda-col: 90px;
    --lambda-thickness-gap: 60px;
    --layer-thickness-col: 140px;
    --layer-column-gap: 6px;

    /* Mobile Feintuning */
    --mobile-col-gap: 8px;
    --mobile-row-gap: 6px;
    --mobile-layer-padding: 10px;

    /* Bootstrap-like chevron for form-select */
    --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

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

body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    background-color: #f4f4f4;
    color: #333;
}

h1, h2 {
    margin: 0;
    color: #007bff;
}

/* ====================================================================
   2. Seitenlayout & Haupt-Controls
   ==================================================================== */

.container-ucalc {
    max-width: 1000px;
    margin: 20px auto;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.container-ucalc p {
    font-size: 14px;
}

/* Schutz vor externem CSS - nur Basis-Elemente ohne eigene Klassen */
.container-ucalc h1 {
    font-size: 1.75rem;
    line-height: 1.2;
}

.container-ucalc h2 {
    font-size: 1.5rem;
    line-height: 1.3;
}

.container-ucalc h3 {
    font-size: 1.25rem;
    line-height: 1.4;
}

.container-ucalc label {
    font-size: 14px;
}


.container-ucalc select,
.container-ucalc option,
.container-ucalc optgroup {
    font-size: 1rem;
}

.container-ucalc input[type="text"],
.container-ucalc input[type="number"],
.container-ucalc input[type="search"] {
    font-size: 14px;
}

.container-ucalc strong {
    font-size: inherit;
    font-weight: 600;
}

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

.header-locale {
    display: flex;
    align-items: center;
    gap: 8px;
}

.locale-icon {
    display: inline-block;
    margin-right: 2px;
    font-size: 18px;
}

#localeSelect {
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: .375rem;
    padding: 6px 8px;
    min-height: 30px;
}

.controls {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.controls-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 0;
}

.controls-secondline {
    justify-content: flex-start;
}

.direction-label {
    white-space: nowrap;
    padding: 0 10px;
    display: inline-block;
}

.select-wrap {
    display: inline-block;
    background-color: #d5d5d5;
    padding: 1px;
    border-radius: .374rem;
    margin-bottom: 10px;
}

.select-wrap::after { content: none; }
.select-wrap:focus-within::after { content: none; }

.material-direction-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    display: inline-block;
    padding: 0.375rem 2.25rem 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    color: #212529;
    background-color: #fff;
    background-image: var(--bs-form-select-bg-img);
    background-repeat: no-repeat;
    background-position: right .75rem center;
    background-size: 16px 12px;
    border: 1px solid #ced4da;
    border-radius: .375rem;
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
    cursor: pointer;
}

.material-direction-select:focus {
    outline: none;
    border-color: #86b7fe;
    box-shadow: 0 0 0 .25rem rgba(13, 110, 253, .25);
}

/* Button: Neue Schicht hinzufügen */
.btn-add-layer {
    padding: 12px 30px;
    background-color: #42b90f;
    color: white;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.btn-add-layer:hover {
    background-color: #369c0c;
}

/* Buttons: Export (URL, Markdown, PDF) */
.btn-export {
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    font-size: 14px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.btn-export:hover {
    background-color: #0056b3;
}

/* Button: Custom Material hinzufügen (+) */
.btn-add-custom {
    padding: 8px 12px;
    background-color: #007bff;
    color: white;
    font-size: 14px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    min-width: 50px;
    line-height: 1;
}

.btn-add-custom:hover {
    background-color: #218838;
}

/* ====================================================================
   3. Layer-Komponente
   ==================================================================== */

.layers-container {
    min-height: 100px;
    padding: 10px;
    background-color: #fafafa;
    border: 1px solid #ddd;
    border-radius: 5px;
}

/* Shared grid layout for base and additional material rows */
.grid-columns {
    display: grid;
    grid-template-columns: var(--layer-title-col, 1fr) var(--layer-lambda-col, 160px) var(--lambda-thickness-gap) var(--layer-thickness-col, 100px) auto; /* Titel | λ | Spacer | Dicke | Aktionen */
    align-items: center;
    column-gap: var(--layer-column-gap, 6px);
}

/* Basis-Layout für eine Schicht-Zeile */
.layer {
    border: 1px solid #ddd;
    padding: 10px;
    margin: 10px 0;
    border-radius: 5px;
    transition: opacity 0.2s, background-color 0.2s;
    background-color: hsl(var(--h, 0), calc(var(--s, 60) * 1%), calc(var(--l, 90) * 1%));
    color: var(--text, #111);
}

.layer.layer-header {
    background-color: #f0f0f0;
    color: #222;
}

.layer.dragging {
    opacity: 0.5;
    background-color: #e0e0e0;
}

.layer.drag-over {
    border: 2px dashed #007bff;
    background-color: #f0f8ff;
}

/* Deaktivierter Layer: optisch abgedimmt und gestrichelt */
.layer.layer-disabled {
    opacity: 0.8;
    position: relative;
}

.layer.layer-disabled::after,
.additional-material.layer-disabled::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 5px;
    background: repeating-linear-gradient(
        -45deg,
        rgba(0, 0, 0, 0.10) 0 8px,
        rgba(255, 255, 255, 0.1) 8px 16px
    );
}

.layer.layer-disabled .thickness,
.additional-material.layer-disabled .composite-fraction-input {
    pointer-events: none;
}

/* Base material content (main material of layer) */
.base-material .material-title {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: bold;
}

.base-material .material-lambda {
    text-align: right;
    white-space: nowrap;
}

.base-material .material-lambda .lambda-value {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

/* Dicke-Eingabe (Thickness) & Stepper */
.base-material .thickness-cell {
    grid-column: 4;
    position: relative;
    max-width: var(--layer-thickness-col, 100px);
}

/* Base styles for all thickness inputs (shared) */
.base-material .thickness-cell .thickness {
    border: 1px solid #ddd;
    font-size: 16px;
    line-height: 1;
    text-align: right;
    padding-right: 2.2em;
    -moz-appearance: textfield;
    appearance: textfield;
    height: 100%;
    width: 100%;
}

/* Normal editable inputs (in stepper) */
.base-material .thickness-cell .stepper .thickness {
    background-color: #ffffffbf;
    border-right: 0;
    border-radius: var(--control-radius) 0 0 var(--control-radius);
}

/* Readonly inputs for R-based materials (air layers) */
.base-material .thickness-cell .stepper .thickness-readonly {
    background-color: #f8f9fa;
    border-right: 1px solid #ddd;  /* Restore border when no buttons */
    border-radius: var(--control-radius);  /* Full radius when no buttons */
    color: #495057;
    cursor: not-allowed;
    opacity: 0.85;
}

/* Hide stepper buttons for readonly materials */
.base-material .thickness-cell .stepper-readonly .stepper-btn {
    display: none;
}

.base-material .thickness-cell .stepper .thickness:focus {
    outline: none;
    border-color: #007bff;
}

.base-material .thickness-cell .thickness::-webkit-inner-spin-button,
.base-material .thickness-cell .thickness::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.base-material .thickness-cell .stepper {
    display: flex;
    align-items: center;
    gap: 0;
    height: var(--control-height);
    overflow: hidden;
}

.base-material .thickness-cell .input-wrapper {
    position: relative;
    flex: 1 1 auto;
    height: 100%;
}

.base-material .thickness-cell .unit-suffix {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: #000;
    opacity: 0.65;
    font-size: 16px;
    line-height: 1;
}

.base-material .thickness-cell .stepper-btn {
    height: 100%;
    padding: 0 8px;
    background-color: #e2e8f0;
    color: #000;
    border: 1px solid #ddd;
    border-left: 0;
    cursor: pointer;
    user-select: none;
    line-height: 1;
    border-radius: 0;
    display: block;
}

.base-material .thickness-cell .stepper-btn:hover {
    background-color: #cbd5e1;
}

.base-material .thickness-cell .stepper-btn:last-child {
    border-top-right-radius: var(--control-radius);
    border-bottom-right-radius: var(--control-radius);
}

/* R-Wert Visualisierung pro Schicht */
.layer .r-metrics {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    width: 100%;
}

.layer.layer-disabled .r-label {
    display: none;
}

.layer .r-label {
    font-size: 12px;
    opacity: 0.8;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    display: block;
    line-height: 1.1;
    align-self: center;
    order: 1;
}

.layer .r-visual {
    height: 6px;
    background: rgba(0, 0, 0, 0.10);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    overflow: hidden;
    align-self: center;
    flex: 1 1 auto;
    order: 2;
}

.layer .rbar-fill {
    height: 100%;
    width: 0%;
    background: currentColor;
    opacity: 0.35;
    transition: width 0.2s ease;
}

/* ====================================================================
   Composite Layer Styles
   ==================================================================== */


/* Composite controls container (spans full width like r-metrics) */
.composite-controls {
    grid-column: 1 / -1;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}


/* Additional material content (secondary material for composite layers) */
.additional-material {
    position: relative;
    padding: 4px;
    margin: 4px -4px 0 -4px;
    border-radius: 5px;
}

/* Apply category background colors to additional row */
.additional-material[class*="cat-"] {
    background: hsl(var(--h), calc(var(--s) * 1%), calc(var(--l) * 1%));
    color: var(--text, inherit);
}

/* Column 1: Material cell (name + small button) */
.composite-material-cell {
    grid-column: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.composite-material-title {
    flex: 1;
    font-weight: 500;
    font-size: 16px;
}

/* Column 2: Lambda value */
.composite-lambda-cell {
    grid-column: 2;
    text-align: right;
    font-weight: 500;
    font-size: 16px;
}

/* Column 3: Empty spacer (matches main layer gap) */
.composite-spacer-cell {
    grid-column: 3;
}

/* Column 4: Fraction input (in thickness column position) */
.composite-fraction-cell {
    grid-column: 4;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.composite-fraction-cell .input-wrapper {
    position: relative;
    display: inline-block;
    width: 90px;
}

.composite-fraction-cell .unit-suffix {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: #000;
    opacity: 0.65;
    font-size: 16px;
    line-height: 1;
}

.composite-fraction-input {
    width: 100%;
    padding: 4px 24px 4px 8px;
    font-size: 16px;
    text-align: right;
    border: 1px solid #ccc;
    border-radius: var(--control-radius);
    height: var(--control-height);
    box-sizing: border-box;
    background-color: #ffffffbf;
}

.composite-fraction-input:focus {
    outline: none;
    border-color: #007bff;
}

/* Column 5: Actions (menu button, right-aligned) */
.composite-actions-cell {
    grid-column: 5;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

/* Effective values display */
.composite-effective {
    font-size: 12px;
    white-space: nowrap;
    opacity: 0.8;
}

/* Mobile: 2-row layout for additional material (same as base-material) */
@media (max-width: 768px) {
    .additional-material {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            'mat lam'
            'frc act';
        row-gap: var(--mobile-row-gap, 6px);
        column-gap: var(--mobile-col-gap, 8px);
    }
    
    .composite-material-cell { grid-area: mat; min-width: 0; }
    .composite-lambda-cell { grid-area: lam; text-align: right; }
    .composite-fraction-cell { grid-area: frc; justify-content: flex-start; }
    .composite-actions-cell { grid-area: act; justify-self: end; }
    
    .composite-spacer-cell {
        display: none;
    }
}

/* Aktionen (Drag Handle & Menü) */
.base-material .layer-actions {
    grid-column: 5;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 6px;
}

.drag-handle {
    cursor: grab;
    font-size: 18px;
    color: inherit;
    padding: 5px;
    margin: 0;
    user-select: none;
    width: 24px;
    text-align: center;
}

.drag-handle:active {
    cursor: grabbing;
}

.layer-actions .layerMenuBtn, 
.composite-actions-cell .layerMenuBtn {
    font-size: 16px;
    padding: 4px 6px;
    line-height: 1;
    border: none;
    background: transparent;
    cursor: pointer;
    color: inherit;
    margin: 0;
    opacity: 0.8;
}

.layer-actions .layerMenuBtn:hover,
.composite-actions-cell .layerMenuBtn:hover {
    opacity: 1;
}

.layer-menu-popover {
    position: absolute;
    display: none;
    background: #fff;
    color: #222;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    padding: 6px 0;
    min-width: 240px;
    z-index: 2000;
}

.layer-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Menu Item Base */
.menu-item {
    padding: 8px 12px;
    cursor: pointer;
}

.menu-item:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* Menu Item States */
.menu-item.is-hidden {
    display: none;
}

/* Menu Item Icons (all items for consistent alignment) */
.menu-item::before {
    content: '';
    display: inline-block;
    width: 20px;
    margin-right: 8px;
    text-align: center;
    opacity: 0.7;
    font-size: 16px;
}

.menu-item.js-action-toggle::before { 
    content: '○';  /* Empty circle (disabled) */
}

.menu-item.js-action-toggle.is-enabled::before { 
    content: '◉';  /* Filled circle (enabled) */
    opacity: 1;
}

.menu-item.js-action-swap::before { 
    content: '⇄';  /* Swap arrows */
}

.menu-item.js-action-insert-above::before { 
    content: '↑';  /* Up arrow */
}

.menu-item.js-action-insert-below::before { 
    content: '↓';  /* Down arrow */
}

.menu-item.js-action-add-material::before { 
    content: '➕';  /* Plus sign */
}

.menu-item.js-action-swap-additional::before { 
    content: '⇄';  /* Swap arrows */
}

.menu-item.js-action-reset-fraction::before { 
    content: '↻';  /* Refresh/reset arrow */
}

.menu-item.js-action-remove-additional::before { 
    content: '✕';  /* X mark */
}

.menu-item.js-action-delete::before { 
    content: '🗑';  /* Trash bin */
}

/* Menu Item Action-Specific Styles */
.menu-item.js-action-delete, .menu-item.js-action-remove-additional {
    color: #b00020;
}

/* ====================================================================
   4. Ergebnis- & Export-Block
   ==================================================================== */

.result {
    margin-top: 20px;
    padding: 10px;
    border-top: 2px solid #007bff;
    background-color: #f9f9f9;
    border-radius: 0 0 5px 5px;
}

.result p {
    margin: 5px 0;
}

.result .result-line {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.result .result-line.is-empty .unit {
    visibility: hidden;
}

.result .result-line .label {
    font-weight: 500;
    font-size: 1.1rem;
}

.result .result-line .value {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    display: inline-block;
    min-width: 4.5ch;
    text-align: right;
}

.result .result-line .unit {
    opacity: 0.85;
    font-size: 1rem;
}

.result .result-line.uvalue .value {
    font-size: 1.8rem;
    font-weight: 600;
    color: #42b90f;
}

.result .result-line.uvalue .unit {
    color: #42b90f;
}

.share-export {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Button with Progress Animation */
.button-with-progress {
    position: relative;
    overflow: hidden;
}

.button-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background-color: rgba(255, 255, 255, 0.3);
    transition: width 0s;
    pointer-events: none;
}

.button-progress.fill-animation {
    animation: fillBar 1.2s ease-in-out;
}

@keyframes fillBar {
    0% { width: 0%; }
    100% { width: 100%; }
}

.button-with-progress .button-text {
    position: relative;
    z-index: 1;
}

/* ====================================================================
   5. Modal für Materialauswahl
   ==================================================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 20px;
    width: 90%;
    max-width: 500px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

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

.modal-close {
    background: transparent;
    color: #007bff;
    border: none;
    font-size: 20px;
    font-weight: bold;
    line-height: 1;
    padding: 6px;
    cursor: pointer;
    border-radius: 4px;
}

.modal-close:hover {
    background: rgba(0,0,0,0.06);
    color: #333;
}

/* Material-Liste */
.material-list {
    max-height: 450px;
    overflow-y: auto;
    margin-top: 10px;
    border-top: 1px solid #ddd;
}

.material-category-header {
    background-color: #f0f0f0;
    padding: 8px 10px;
    margin-top: 10px;
    font-size: 1em;
    font-weight: bold;
    color: #333;
    border-bottom: 1px solid #ccc;
    border-top: 1px solid #ccc;
    position: sticky;
    top: 0;
    z-index: 1;
}

.material-option {
    padding: 10px;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    transition: background-color 0.2s;
    display: grid;
    grid-template-columns: 1fr auto auto; /* Titel | λ | Aktionen */
    column-gap: 8px;
    align-items: center;
    background-color: hsl(var(--h, 0), calc(var(--s, 60) * 1%), calc(var(--l, 90) * 1%));
    color: var(--text, #111);
}

.material-option p {
    margin: 0;
}

/* Virtual scrolling placeholder with skeleton loading effect */
.material-option.placeholder {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    cursor: default;
    pointer-events: none;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.material-option:hover {
    filter: brightness(90%);
}

.material-option:focus {
    outline: 2px solid rgba(0, 123, 255, 0.8);
    outline-offset: 2px;
}

.material-option .material-title {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.material-option .material-lambda {
    white-space: nowrap;
    text-align: right;
}

.material-option .material-lambda .lambda-value {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

.material-option .material-lambda::after {
    content: " W/(m·K)";
    opacity: 0.85;
    margin-left: 4px;
    font-size: 0.95em;
}

.material-option .material-option-actions {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 6px;
}

.material-option .material-option-actions .material-edit-btn,
.material-option .material-option-actions .material-delete-btn {
    background: transparent;
    color: inherit;
    border: none;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    min-width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.material-option .material-option-actions .material-edit-btn:hover,
.material-option .material-option-actions .material-edit-btn:focus-visible,
.material-option .material-option-actions .material-delete-btn:hover,
.material-option .material-option-actions .material-delete-btn:focus-visible {
    background: rgba(0,0,0,0.08);
    outline: none;
}

/* Sortier-Control im Modal */
.sort-group.segmented {
    display: inline-grid;
    grid-auto-flow: column;
    gap: 6px;
    padding: 4px;
    font-size: 12px;
    background: #f2f4f7;
    border: 1px solid #e3e7ee;
    border-radius: 999px;
}

.sort-group.segmented input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.sort-group.segmented label {
    padding: 6px 10px;
    border-radius: 999px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: background-color .2s ease, color .2s ease, box-shadow .2s ease;
}

.sort-group.segmented input[type="radio"]:focus + label {
    outline: 2px solid #7ab8ff;
    outline-offset: 2px;
}

.sort-group.segmented input[type="radio"]:checked + label {
    background: #007bff;
    color: #fff;
    box-shadow: inset 0 1px 0 rgba(0,0,0,0.05);
}

/* Custom-Material-Formular im Modal */
.modal-content input {
    margin: 10px 0;
    padding: 8px;
    width: calc(100% - 16px);
    border: 1px solid #ddd;
    border-radius: 3px;
}

.modal-content input:focus {
    outline: none;
    border-color: #007bff;
}

.custom-material-section {
    margin-top: 12px;
}

.custom-material-section h3 {
    margin: 20px 0 0 0;
}

.custom-material-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.custom-material-row input {
    flex: 1 1 auto;
}

.custom-material-row #customMaterialName {
    flex: 2 1 65%;
    min-width: 0;
}

.custom-material-row #customMaterialLambda {
    flex: 0 0 85px;
}

.custom-material-row #customMaterialLambda::placeholder {
    font-size: 11px;
    opacity: 0.8;
}

/* ====================================================================
   6. Responsive, Print & Media Queries
   ==================================================================== */

@media (max-width: 480px) {
    .container-ucalc h1 {
        font-size: 1.5em;
    }

    .container-ucalc h2 {
        font-size: 1.2em;
    }

    .base-material p {
        font-size: 0.9em;
    }

    .layer .r-label { font-size: 11px; }
}

@media (max-width: 768px) {
    .container-ucalc {
        margin: 10px;
        padding: 15px;
    }

    .header-row {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .select-wrap, .material-direction-select {
        width: 100%;
     }

    /* Kompaktes 2-Zeilen-Layout für Base Material */
    .base-material {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            'ttl lam'
            'thi act';
        column-gap: var(--mobile-col-gap, 8px);
        row-gap: var(--mobile-row-gap, 6px);
        align-items: center;
    }
    
    .layer {
        padding: var(--mobile-layer-padding, 10px);
    }

    .base-material .material-title { grid-area: ttl; min-width: 0; }
    .base-material .material-lambda { grid-area: lam; text-align: right; }
    .base-material .thickness-cell { grid-area: thi; max-width: var(--layer-thickness-col, 100px); }
    .base-material .thickness { width: 100%; }
    .base-material .layer-actions { grid-area: act; justify-self: end; }
    .layer .r-metrics { margin-top: 8px; }
    .drag-handle { align-self: center; }

    .layer.layer-header {
        padding: var(--mobile-layer-padding, 10px);
    }
    
    .layer.layer-header .grid-columns {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            'ttl lam'
            'thi act';
        row-gap: var(--mobile-row-gap, 6px);
        column-gap: var(--mobile-col-gap, 8px);
    }
    
    .layer.layer-header .material-title { grid-area: ttl; }
    .layer.layer-header .material-lambda { grid-area: lam; text-align: right; }
    .layer.layer-header .thickness-header { grid-area: thi; text-align: left; }
    .layer.layer-header .actions-header { grid-area: act; text-align: right; justify-self: end; }

    .modal-content {
        width: 95%;
        margin: 5% auto;
    }

    .sort-group.segmented {
        gap: 4px;
        padding: 3px;
    }
    .sort-group.segmented label {
        padding: 6px 8px;
    }
}

/* Desktop: Header column positioning */
@media (min-width: 769px) {
    .layer-header .material-lambda { text-align: right; }
    .layer-header .thickness-header { grid-column: 4; text-align: left; }
    .layer-header .actions-header { grid-column: 5; justify-self: end; text-align: right; }
}

/* Print-Header (standardmäßig unsichtbar) */
.print-header {
    display: none;
}

/* Print-Stile */
@media print {
    html, body {
        background: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .container-ucalc {
        box-shadow: none !important;
        border-radius: 0 !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0.5in !important;
    }
    
    .header-row,
    .controls,
    .share-export,
    .modal {
        display: none !important;
    }
    
    .layer {
        break-inside: avoid;
        page-break-inside: avoid;
        transition: none !important;
    }
    
    .layer .rbar-fill { 
        transition: none !important; 
    }
    
    .print-header {
        display: block !important;
        text-align: left;
        margin-bottom: 1.5rem;
    }
    
    #layersContainer {
        margin-top: 0 !important;
        padding-top: 0 !important;
        border: none !important;
    }
    
    #result {
        margin-top: 1.5rem;
        border-top: 2px solid #ccc !important;
        padding-top: 1rem;
        break-before: auto;
    }
    
    .print-header h1 {
        font-size: 18pt;
        color: #000 !important;
        margin: 0 0 0.25rem 0;
    }
    
    .print-header .print-subtitle {
        font-size: 11pt;
        color: #555 !important;
        margin: 0;
    }
    
    .direction-hint,
    .layer-order-notice {
        display: none;
    }
}

/* ====================================================================
   7. Direction Hint & Layer Order Notice
   ==================================================================== */

/* Richtungshinweis über dem Layer-Container */
.direction-hint {
    text-align: center;
    font-size: 0.9em;
    color: #6c757d;
    padding: 8px 0 4px 0;
    font-weight: 500;
    letter-spacing: 0.5px;
    user-select: none;
}

/* Disclaimer zur Schichtreihenfolge */
.layer-order-notice {
    display: none;
    margin: 12px 0 20px 0;
    padding: 12px 16px;
    background-color: #e7f3ff;
    border-left: 4px solid #2196f3;
    border-radius: 4px;
    font-size: 0.9em;
    color: #333;
    line-height: 1.5;
}

.layer-order-notice strong {
    color: #1976d2;
    font-weight: 600;
}