/* ===== Global Styles ===== */
* {
    box-sizing: border-box;
    /* touch-action: none; HIER ENTFERNT: Verhindert sonst sauberes Scrollen/Tappen in Formularfeldern */
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Haupt-Tab Navigation */
.main-tabs {
    display: flex;
    background-color: #2c3e50;
    padding: 5px 5px 0 5px;
    gap: 5px;
    flex-shrink: 0;
    z-index: 10;
}

.main-tab-btn {
    flex: 1;
    padding: 12px 15px;
    font-size: 1.1rem;
    font-weight: bold;
    border: none;
    background-color: #34495e;
    color: #ecf0f1;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    text-align: center;
}

.main-tab-btn.active {
    background-color: #3d566e;
    color: #ecf0f1;
}

/* Inaktive Tabs komplett ausblenden */
.tab-view:not(.active) {
    display: none !important;
}

/* Aktiven View-Container auf volle Höhe setzen */
.tab-view.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
    height: calc(100vh - 80px); /* Höhe an deine Header/Tab-Leiste anpassen */
}

.preview-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    background: #ecf0f1;
    border-bottom: 1px solid #bdc3c7;
    font-size: 14px;
    color: #2c3e50;
    flex-shrink: 0;
}

.preview-toolbar select {
    min-height: 32px;
    padding: 2px 6px;
    font-size: 14px;
}

#three-container {
width: 100%;
height: 100%;
flex: 1;
overflow: hidden;
}

/* Ansichten-Flexbox Container */
.app-view {
    display: none;
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.app-view.active {
    display: flex;
    flex-direction: column;
}

#view-cutlist {
height: 100%;
width: 100%;
position: relative; /* WICHTIG: Auf 'relative' geändert, damit es nicht über den Tabs schwebt */
overflow: hidden;
}

/* Der isolierte Scroll-Container */
.cutlist-scroll-area {
    flex: 1;
    width: 100%;
    height: 100%;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: contain;
}

/* Inhalts-Container */
.cutlist-container {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    box-sizing: border-box;
}

/* ===== Toolbar ===== */
#toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #2c3e50;
    color: #ecf0f1;
    flex-shrink: 0;
    min-height: 60px;
    z-index: 5;
}

#toolbar button {
background: #34495e;
border: none;
color: #ecf0f1;
padding: 10px 16px;
border-radius: 6px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: background 0.15s, transform 0.1s;
touch-action: manipulation;
min-height: 44px;
min-width: 44px;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

#toolbar button:active { transform: scale(0.95); }
#toolbar button.active {
background: #1abc9c;
color: #fff;
box-shadow: 0 0 0 2px #16a085;
}
#toolbar button:hover { background: #3d566e; }

#toolbar button.disabled {
opacity: 0.4;
cursor: not-allowed;
pointer-events: none; /* Verhindert Klicks komplett */
}

#toolbar .spacer { flex: 1; }

/* Umschalter vorderes / hinteres Profilende (nur bei konischem Profil sichtbar) */
#toolbar button.side-toggle.hidden { display: none; }
#toolbar button.side-toggle.side-back {
background: #c0392b;
box-shadow: 0 0 0 2px #96281b;
}
#toolbar button.side-toggle.side-back:hover { background: #a93226; }

/* ===== Zoom Group ===== */
.zoom-group {
    display: flex;
    gap: 2px;
    background: #1e2b38;
    padding: 4px;
    border-radius: 8px;
}

.zoom-group button {
    padding: 6px 12px;
    min-width: 36px;
    min-height: 36px;
    font-size: 18px;
    background: #2c3e50;
    border-radius: 4px;
}

/* ===== Main Area (Canvas + Touch Panel) ===== */
#main-area {
display: flex;
flex: 1;
height:91%;
overflow: hidden;
}

/* Toast Container oben rechts */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

/* Toast Nachricht */
.toast {
    background-color: #323232;
    color: #ffffff;
    padding: 12px 20px;
    border-radius: 6px;
    font-family: sans-serif;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-warning {
    border-left: 5px solid #ff9800;
}

.toast-info {
    border-left: 5px solid #1abc9c;
}

/* ===== Label-Bearbeitung (Länge/Winkel per Klick auf das Maß) ===== */
.label-edit-popup {
    position: fixed;
    transform: translate(-50%, -130%);
    display: flex;
    align-items: center;
    gap: 4px;
    background: #ffffff;
    border: 1px solid #ced4da;
    border-radius: 8px;
    padding: 6px 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    z-index: 50;
}

.label-edit-lock-btn.hidden {
    display: none;
}

.label-edit-popup.hidden {
    display: none;
}

.label-edit-popup input[type="number"] {
    width: 84px;
    padding: 8px;
    font-size: 1.05rem;
    border: 1px solid #ced4da;
    border-radius: 6px;
    text-align: center;
}

.label-edit-unit {
    font-size: 0.95rem;
    color: #495057;
    font-weight: 600;
    padding-right: 2px;
}

.label-edit-lock-btn,
.label-edit-ok-btn {
    min-width: 40px;
    min-height: 40px;
    font-size: 1.1rem;
    border: none;
    border-radius: 6px;
    background: #e9ecef;
    cursor: pointer;
    touch-action: manipulation;
}

.label-edit-lock-btn.active {
    background: #f39c12;
}

.label-edit-ok-btn {
    background: #27ae60;
    color: #fff;
}

/* Auf Touch-Geräten (Tablet/Stift) deutlich grössere Trefferflächen, da
   Zahleneingabe und Tippen auf die Buttons sonst mit dem Stift fummelig
   wird. Reagiert auf den Eingabetyp (pointer: coarse), nicht auf die
   Bildschirmbreite, damit auch ein Tablet im Querformat/mit grossem
   Display erfasst wird. */
@media (pointer: coarse) {
    .label-edit-popup {
        gap: 8px;
        padding: 10px;
        border-radius: 12px;
    }

    .label-edit-popup input[type="number"] {
        width: 130px;
        padding: 14px;
        font-size: 1.6rem;
        border-radius: 8px;
    }

    .label-edit-unit {
        font-size: 1.3rem;
    }

    .label-edit-lock-btn,
    .label-edit-ok-btn {
        min-width: 56px;
        min-height: 56px;
        font-size: 1.6rem;
        border-radius: 8px;
    }

    .info-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 1.3rem;
    }

    .info-panel-close {
        min-width: 44px;
        min-height: 44px;
        font-size: 1.3rem;
    }
}

/* ===== Canvas ===== */
#canvas-container {
flex: 1;
position: relative;
background: #ffffff;
overflow: hidden;
}

.canvas-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Verhindert das Aufblähen/Schrumpfen durch Scrollbars */
}

#canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none; /* Verhindert das Standard-Scrollen und Zoom des iPads auf dem Canvas */
user-select: none;
-webkit-user-select: none;
-webkit-touch-callout: none;
cursor: crosshair;
}

/* Zuschnitt-Tabelle */
.cutlist-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
}

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

.cutlist-table input {
    width: 100%;
    padding: 6px;
    box-sizing: border-box;
    text-align: center;
}

.btn-remove-row {
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
}

/* Zusammenfassung */
.summary-waste {
    margin-left: 8px;
    font-size: 0.9em;
    opacity: 0.85;
}

.summary-waste.hidden {
    display: none;
}

.cutlist-summary {
    margin-top: 15px;
    padding: 10px;
    /* background: #f8f9fa; */
    border-radius: 6px;
    font-size: 14px;
}



/* 2-Spalten Grid für Kopfdaten */
.project-header-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 25px;
    background-color: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-weight: bold;
    font-size: 0.95rem;
    color: #495057;
}

.form-group input {
    padding: 12px 15px;
    font-size: 1.1rem; /* Minderung des Auto-Zooms auf iOS */
    border: 1px solid #ced4da;
    border-radius: 6px;
}

.form-group select {
    padding: 12px 15px;
    font-size: 1.1rem; /* Minderung des Auto-Zooms auf iOS */
    border: 1px solid #ced4da;
    border-radius: 6px;
}

/* Aktions-Button & Summary */
.cutlist-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.btn-primary-touch {
    padding: 14px 24px;
    font-size: 1.1rem;
    font-weight: bold;
    background-color: #27ae60;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.summary-badge {
    font-size: 1.2rem;
    background-color: #e8f4f8;
    padding: 10px 20px;
    border-radius: 8px;
    color: #2980b9;
}

/* Tabelle Touch-optimiert */
.touch-table {
    width: 100%;
    border-collapse: collapse;
    background-color: white;
}

.touch-table th {
    background-color: #f1f3f5;
    padding: 15px;
    text-align: left;
    font-size: 1rem;
    border-bottom: 2px solid #dee2e6;
}

.touch-table td {
    padding: 10px;
    border-bottom: 1px solid #e9ecef;
    vertical-align: middle;
}

/* Inputs in der Tabelle groß gestalten */
.touch-table input[type="number"],
.touch-table input[type="text"] {
    width: 100%;
    padding: 12px;
    font-size: 1.1rem;
    border: 1px solid #ced4da;
    border-radius: 6px;
    box-sizing: border-box;
}

/* Vergrößerte Checkbox */
.touch-checkbox {
    width: 28px;
    height: 28px;
    cursor: pointer;
    accent-color: #27ae60;
}

/* Stückzahl-Steuerung (Plus/Minus Buttons) */
.qty-control {
    display: flex;
    align-items: center;
    gap: 5px;
}

.qty-btn {
    width: 44px;
    height: 44px;
    font-size: 1.3rem;
    font-weight: bold;
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 6px;
}


/* ===== Status Bar ===== */
/* Immer einzeilig: würde die Leiste umbrechen und höher werden, ändert sich
   die Zeichenfläche. Reicht der Platz nicht, lässt sich der Inhalt seitlich
   wischen, statt umzubrechen. */
#status-bar {
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 6px 16px;
background: #ecf0f1;
border-top: 1px solid #bdc3c7;
font-size: 14px;
color: #2c3e50;
flex-shrink: 0;
min-height: 40px;
gap: 12px;
}

#status-bar .info-group {
display: flex;
flex-wrap: nowrap;
align-items: center;
gap: 12px;
flex: 0 1 auto;
min-width: 0;
overflow-x: auto;
white-space: nowrap;
scrollbar-width: none;
}

#status-bar .info-group::-webkit-scrollbar {
display: none;
}

#status-bar .info-group > * {
flex-shrink: 0;
}

#status-bar .info-btn {
flex-shrink: 0;
}

#status-bar .total-length {
flex-shrink: 0;
white-space: nowrap;
}

#status-bar .status-end {
display: flex;
align-items: center;
gap: 8px;
margin-left: auto;
flex-shrink: 0;
}

/* Kleine Buttons in der Statusleiste (steckbares Profil) */
.status-btn {
    padding: 4px 10px;
    min-height: 32px;
    border: 1px solid #bdc3c7;
    border-radius: 6px;
    background: #ffffff;
    color: #2c3e50;
    font-size: 13px;
    cursor: pointer;
    touch-action: manipulation;
}

.status-btn:hover {
    background: #f4f6f7;
}

.status-btn.hidden {
    display: none;
}

.status-divider {
    color: #ccc;
}

.total-length {
    font-size: 14px;
    color: #2c3e50;
}

.total-length strong {
    color: #2c3e50;
}

/* ===== Info-Button & Info-Panel ===== */
.info-btn {
    margin-left: auto;
    min-width: 32px;
    min-height: 32px;
    padding: 4px 10px;
    font-size: 1rem;
    line-height: 1;
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 6px;
    cursor: pointer;
    touch-action: manipulation;
}

.info-btn:hover {
    background-color: #dfe4e6;
}

.info-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.info-panel-overlay.hidden {
    display: none;
}

.info-panel {
    position: relative;
    background: #ffffff;
    border-radius: 10px;
    padding: 28px 26px 22px;
    max-width: 720px;
    width: calc(100% - 40px);
    max-height: calc(100% - 40px);
    overflow-y: auto;
    box-sizing: border-box;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

/* Info-Text links, Tastenkürzel rechts; auf schmalen Bildschirmen untereinander */
.info-panel-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 640px) {
    .info-panel-body {
        grid-template-columns: 1fr;
        gap: 18px;
    }
}

.info-panel-shortcuts h3 {
    margin: 0 0 8px;
    color: #2c3e50;
    font-size: 0.95rem;
}

.info-panel-shortcuts dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 12px;
    margin: 0;
    font-size: 0.85rem;
    align-items: baseline;
}

.info-panel-shortcuts dt {
    white-space: nowrap;
    color: #7f8c8d;
}

.info-panel-shortcuts dd {
    margin: 0;
    color: #2c3e50;
}

.info-panel-shortcuts kbd {
    display: inline-block;
    min-width: 1.4em;
    padding: 1px 5px;
    border: 1px solid #ccd3d6;
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #f4f6f7;
    color: #2c3e50;
    font-family: inherit;
    font-size: 0.8rem;
    text-align: center;
}

/* DXF-Dialog (konisches Profil) */
.info-panel.dxf-dialog {
    max-width: 440px;
}

.dxf-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 0 12px;
    color: #2c3e50;
    font-size: 0.92rem;
    line-height: 1.35;
    cursor: pointer;
}

.dxf-option input {
    margin-top: 3px;
    width: 18px;
    height: 18px;
}

.dxf-length-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 18px 28px;
    font-size: 0.92rem;
    color: #2c3e50;
}

.dxf-length-row.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.dxf-length-row select {
    min-height: 32px;
    font-size: 0.92rem;
}

.dxf-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.dxf-btn {
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid #bdc3c7;
    border-radius: 6px;
    background: #ffffff;
    color: #2c3e50;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}

.dxf-btn-primary {
    background: #1abc9c;
    border-color: #16a085;
    color: #ffffff;
}

.info-panel h2 {
    margin: 0 0 4px;
    color: #2c3e50;
}

.info-panel-version {
    margin: 0 0 14px;
    color: #7f8c8d;
    font-size: 0.9rem;
}

.info-panel-desc {
    margin: 0 0 18px;
    color: #2c3e50;
    font-size: 0.92rem;
    line-height: 1.4;
}

.info-panel-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    margin: 0;
    font-size: 0.9rem;
}

.info-panel-meta dt {
    color: #7f8c8d;
}

.info-panel-meta dd {
    margin: 0;
    color: #2c3e50;
    font-weight: 600;
}

.info-panel-close {
    position: absolute;
    top: 10px;
    right: 10px;
    min-width: 32px;
    min-height: 32px;
    border: none;
    border-radius: 6px;
    background: #e9ecef;
    cursor: pointer;
    font-size: 1rem;
    touch-action: manipulation;
}

.info-panel-close:hover {
    background: #dfe4e6;
}


/* ===== Handy (Hochformat, schmaler als 640 px) =====
   Tablet und PC bleiben unverändert. lbl-long/lbl-short: lange bzw. kurze
   Beschriftung; desktop-only/mobile-only: nur dort sichtbar. */
.lbl-short,
.mobile-only {
    display: none !important;
}

.mobile-menu {
    position: fixed;
    right: 8px;
    z-index: 60;
    display: flex;
    flex-direction: column;
    min-width: 220px;
    padding: 6px;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
}

.mobile-menu.hidden {
    display: none;
}

.mobile-menu button {
    min-height: 48px;
    padding: 10px 14px;
    border: none;
    border-radius: 6px;
    background: none;
    color: #2c3e50;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
}

.mobile-menu button:active,
.mobile-menu button:hover {
    background: #f1f3f5;
}

.mobile-menu button.disabled {
    opacity: 0.4;
    pointer-events: none;
}

@media (max-width: 640px) {
    .lbl-long,
    .desktop-only {
        display: none !important;
    }

    .lbl-short {
        display: inline !important;
    }

    .mobile-only {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Tabs: eine schlanke Zeile */
    .main-tab-btn {
        padding: 8px 6px;
        font-size: 0.95rem;
    }

    /* Toolbar: eine Zeile mit den Zeichen-Aktionen, Rest im Menü "⋯" */
    #toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 4px;
        padding: 6px;
        min-height: 0;
        scrollbar-width: none;
    }

    #toolbar::-webkit-scrollbar {
        display: none;
    }

    #toolbar button {
        flex-shrink: 0;
        min-width: 40px;
        padding: 8px 7px;
        font-size: 14px;
    }

    #toolbar #btn-more {
        margin-left: auto;
        font-size: 20px;
        line-height: 1;
    }

    /* Statusleiste: nur Abwicklung + ⚙ + ℹ; Optionen als Feld darüber */
    #status-bar {
        position: relative;
        gap: 8px;
        padding: 4px 8px;
        font-size: 13px;
    }

    #status-bar .info-group {
        display: none;
    }

    #status-bar.options-open .info-group {
        display: flex;
        position: absolute;
        left: 0;
        right: 0;
        bottom: 100%;
        z-index: 40;
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
        padding: 16px;
        overflow: visible;
        white-space: normal;
        background: #ffffff;
        border-top: 1px solid #bdc3c7;
        box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.15);
        font-size: 16px;
    }

    #status-bar.options-open .info-group .status-divider {
        display: none;
    }

    #status-bar.options-open .info-group .toggle-option {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    #status-bar.options-open .info-group input[type="checkbox"] {
        width: 22px;
        height: 22px;
    }

    #status-bar.options-open .status-btn {
        min-height: 44px;
        font-size: 15px;
    }

    #status-bar.options-open .status-btn.hidden {
        display: none;
    }

    /* Stückliste & Projekt: einspaltig, Positionen als Karten */
    .cutlist-container {
        padding: 12px;
    }

    .project-header-grid {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
    }

    .cutlist-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .summary-badge {
        font-size: 1rem;
        text-align: center;
    }

    .touch-table thead {
        display: none;
    }

    .touch-table,
    .touch-table tbody {
        display: block;
        background: none;
    }

    .touch-table tr {
        display: block;
        position: relative;
        margin-bottom: 12px;
        padding: 8px 12px;
        background: #ffffff;
        border: 1px solid #dee2e6;
        border-radius: 10px;
    }

    .touch-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 6px 0;
        border: none;
        text-align: left !important;
    }

    .touch-table td[data-label]::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-weight: bold;
        color: #495057;
    }

    .touch-table td.cell-pos {
        font-size: 1.1rem;
        padding-right: 50px;
    }

    .touch-table td.cell-pos::before {
        content: 'Pos.';
    }

    .touch-table td.cell-pos {
        justify-content: flex-start;
        gap: 6px;
    }

    .touch-table td.cell-delete {
        position: absolute;
        top: 4px;
        right: 6px;
        padding: 0;
    }

    .touch-table td.cell-delete button {
        min-width: 44px;
        min-height: 44px;
    }

    .touch-table td[data-label] > input[type="number"],
    .touch-table td[data-label] > input[type="text"] {
        width: auto;
        flex: 1;
        min-width: 0;
        max-width: 60%;
    }
}
