/* =====================================================================
   Tischdesigner – Styles (Mobile-First)
   Kleines Display: Canvas füllt den Bildschirm, Werkzeuge als Bottom-
   Sheets über einer Bottom-Navigation. Ab 992px: klassisches
   Drei-Spalten-Layout (Werkzeuge | Arbeitsfläche | Eigenschaften).
   ===================================================================== */

:root {
    --td-dark: #241a12;
    --td-dark2: #33251a;
    --td-accent: #e8a33d;
    --td-bg: #efe9e1;
    --td-border: rgba(0, 0, 0, .12);
    --td-header-h: 52px;
    --td-bottomnav-h: calc(58px + env(safe-area-inset-bottom, 0px));
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--td-bg);
    display: flex;
    flex-direction: column;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
}

.min-w-0 { min-width: 0; }

/* Schriften (Vorschau im Schrift-Auswahlmenü; Pfad-Erzeugung via opentype.js) */
@font-face { font-family: "TD Montserrat";  src: url("../fonts/Montserrat.ttf");      font-display: swap; }
@font-face { font-family: "TD Playfair";    src: url("../fonts/PlayfairDisplay.ttf"); font-display: swap; }
@font-face { font-family: "TD GreatVibes";  src: url("../fonts/GreatVibes.ttf");      font-display: swap; }
@font-face { font-family: "TD Pacifico";    src: url("../fonts/Pacifico.ttf");        font-display: swap; }
@font-face { font-family: "TD Bebas";       src: url("../fonts/BebasNeue.ttf");       font-display: swap; }
@font-face { font-family: "TD Amatic";      src: url("../fonts/AmaticSC.ttf");        font-display: swap; }

/* ===== Ladeanzeige ===== */
#loader {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: var(--td-dark);
    color: #f3e8d8;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .3s;
}
#loader.done {
    opacity: 0;
    pointer-events: none;
}

/* ===== Kopfzeile ===== */
.td-header {
    background: var(--td-dark);
    color: #f3e8d8;
    min-height: var(--td-header-h);
    padding: .4rem .6rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    z-index: 1050;
}
.td-logo { font-size: 1.6rem; color: var(--td-accent); }
.td-title { font-weight: 700; line-height: 1.1; }
.td-subtitle { font-size: .72rem; opacity: .7; }
.td-header .btn { min-width: 38px; min-height: 38px; }
#btnLaserView.active {
    background: var(--td-accent);
    border-color: var(--td-accent);
    color: #241a12;
}

/* ===== Hauptlayout ===== */
.td-main {
    flex: 1;
    display: flex;
    min-height: 0;
    position: relative;
}

/* ===== Zeichenfläche ===== */
.td-canvas-wrap {
    flex: 1;
    position: relative;
    min-width: 0;
    min-height: 0;
    background: radial-gradient(ellipse at 50% 40%, #4c4038 0%, #332a24 70%, #292019 100%);
    touch-action: none;               /* Gesten gehören dem Editor, nicht der Seite */
}
#canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: default;
}
#canvas .el { cursor: move; }
#canvas .el.locked { cursor: default; }

.td-canvas-help {
    position: absolute;
    left: 50%;
    bottom: .5rem;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, .45);
    color: #eee3d3;
    font-size: .72rem;
    padding: .25rem .7rem;
    border-radius: 99px;
    pointer-events: none;
    white-space: nowrap;
    max-width: 96%;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 5;
}
.td-float-tools {
    position: absolute;
    top: .5rem;
    right: .5rem;
    display: flex;
    flex-direction: column;
    gap: .3rem;
    z-index: 6;
}
.td-float-tools .btn {
    background: rgba(0, 0, 0, .5);
    color: #eee3d3;
    border: 1px solid rgba(255, 255, 255, .25);
    min-width: 42px;
    min-height: 42px;
}
.td-laser-legend {
    position: absolute;
    top: .5rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, .6);
    color: #fff;
    font-size: .74rem;
    padding: .3rem .8rem;
    border-radius: 99px;
    z-index: 6;
    white-space: nowrap;
}
.td-laser-legend span[class^="lg-"] {
    display: inline-block;
    width: 11px; height: 11px;
    border-radius: 3px;
    vertical-align: -1px;
}
.lg-black { background: #000; border: 1px solid #777; }
.lg-white { background: #fff; }
.lg-red   { background: #e33; }

/* ===== Panels: mobil als Bottom-Sheet ===== */
.td-panel, .td-props {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--td-bottomnav-h);
    background: #fff;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, .25);
    max-height: 58vh;
    display: flex;
    flex-direction: column;
    transform: translateY(110%);
    transition: transform .25s ease;
    z-index: 1040;
}
.td-panel.open, .td-props.open {
    transform: translateY(0);
}
.td-panel-grip {
    padding: .4rem 0 .2rem;
    display: flex;
    justify-content: center;
    cursor: grab;
    flex-shrink: 0;
}
.td-panel-grip span {
    width: 42px; height: 4px;
    border-radius: 4px;
    background: rgba(0, 0, 0, .2);
}
.td-panel-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: .5rem .75rem calc(.75rem + env(safe-area-inset-bottom, 0px));
    flex: 1;
    min-height: 0;
    touch-action: pan-y;
}
.td-props-scroll {
    overflow-y: auto;
    padding: .5rem .75rem calc(.75rem + env(safe-area-inset-bottom, 0px));
    flex: 1;
    min-height: 0;
    touch-action: pan-y;
}

/* Panel-Seiten */
.td-page { display: none; }
.td-page.active { display: block; }

/* Panel-Tabs (Desktop) */
.td-panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--td-border);
    flex-shrink: 0;
}
.td-ptab {
    flex: 1;
    border: 0;
    background: none;
    padding: .55rem .2rem;
    font-size: .72rem;
    color: #6b5a48;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}
.td-ptab .ti { font-size: 1.15rem; }
.td-ptab.active {
    color: #7a4a10;
    border-bottom-color: var(--td-accent);
    font-weight: 600;
}
.td-ptab:hover { background: #f6f1ea; }

/* ===== Bottom-Navigation (mobil) ===== */
.td-bottomnav {
    display: flex;
    background: var(--td-dark);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 1045;
    flex-shrink: 0;
}
.td-bottomnav button {
    flex: 1;
    background: none;
    border: 0;
    color: #cbbba6;
    padding: .45rem 0 .4rem;
    font-size: .66rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    min-height: 54px;
}
.td-bottomnav button .ti { font-size: 1.3rem; }
.td-bottomnav button.active { color: var(--td-accent); }

/* ===== Abschnitte & Buttons ===== */
.td-section-title {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 700;
    color: #6b5a48;
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-bottom: .5rem;
}
.td-hint { font-size: .74rem; color: #8a8178; }
.btn-td {
    background: #f6f1ea;
    border: 1px solid var(--td-border);
    color: #443627;
    text-align: left;
    min-height: 40px;
}
.btn-td:hover { background: #eddfc9; border-color: rgba(0, 0, 0, .25); color: #2c2115; }

.td-type-info {
    font-size: .78rem;
    color: #6b5a48;
    background: #f6f1ea;
    border: 1px solid var(--td-border);
    border-radius: .5rem;
    padding: .45rem .6rem;
}
.td-price { font-size: 1.05rem; font-weight: 700; color: #7a4a10; margin-top: .25rem; }
.td-price-na { font-size: .82rem; font-weight: 600; color: #8a8178; }

/* ===== Bibliotheken: Suche, Kategorien, Raster ===== */
.td-lib-head { margin-bottom: .5rem; }
.td-cat-chips {
    display: flex;
    gap: .3rem;
    overflow-x: auto;
    padding: .4rem 0 .3rem;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    scrollbar-width: thin;
}
.td-chip {
    border: 1px solid var(--td-border);
    background: #f6f1ea;
    color: #55432f;
    border-radius: 99px;
    font-size: .72rem;
    padding: .25rem .65rem;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 30px;
}
.td-chip.active { background: var(--td-accent); border-color: var(--td-accent); color: #241a12; font-weight: 600; }

/* Symbolraster */
.td-motif-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
    gap: .35rem;
}
.td-motif-btn {
    aspect-ratio: 1;
    border: 1px solid var(--td-border);
    border-radius: .5rem;
    background: #f6f1ea;
    padding: 8px;
    cursor: pointer;
    position: relative;
    min-height: 44px;
}
.td-motif-btn:hover { background: #eddfc9; border-color: rgba(0, 0, 0, .3); }
.td-motif-btn svg { width: 100%; height: 100%; fill: #4a3826; pointer-events: none; }
.td-motif-fav {
    position: absolute;
    top: -1px; right: -1px;
    border: 0;
    background: none;
    color: #c9baa6;
    font-size: .85rem;
    padding: 2px 4px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
}
.td-motif-fav.on { color: #e8a33d; }
.td-lib-empty { font-size: .78rem; color: #8a8178; padding: .5rem 0; }

/* Vorlagenraster */
.td-tpl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: .5rem;
}
.td-tpl-card {
    border: 1px solid var(--td-border);
    border-radius: .6rem;
    background: #fff;
    cursor: pointer;
    overflow: hidden;
    text-align: left;
    padding: 0;
}
.td-tpl-card:hover { border-color: rgba(0, 0, 0, .35); }
.td-tpl-thumb {
    background: #e9dcc8;
    aspect-ratio: 3 / 2;
    display: block;
    width: 100%;
}
.td-tpl-thumb svg { width: 100%; height: 100%; display: block; }
.td-tpl-name {
    font-size: .72rem;
    font-weight: 600;
    color: #443627;
    padding: .3rem .45rem .35rem;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Eigenschaften ===== */
.td-props-empty {
    color: #9a9086;
    text-align: center;
    padding: 1.2rem .5rem;
    font-size: .85rem;
}
.td-props-empty .ti { font-size: 1.8rem; display: block; margin-bottom: .4rem; }
.td-props h3 {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 700;
    color: #6b5a48;
    margin: 0 0 .5rem;
    display: flex;
    align-items: center;
    gap: .35rem;
}
.td-prop-group {
    border-bottom: 1px solid var(--td-border);
    padding-bottom: .6rem;
    margin-bottom: .6rem;
}
.td-props .btn { min-height: 36px; }
.td-iconbar {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
}
.td-iconbar .btn {
    flex: 1 0 calc(25% - .25rem);
    min-width: 44px;
}

/* Ebenenliste */
.td-layer-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.td-layer-list li {
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: .3rem .35rem;
    border: 1px solid transparent;
    border-radius: .4rem;
    font-size: .78rem;
    cursor: pointer;
    min-height: 38px;
}
.td-layer-list li:hover { background: #f6f1ea; }
.td-layer-list li.sel { background: #eddfc9; border-color: rgba(0, 0, 0, .2); }
.td-layer-list li.outside { color: #a32d2d; }
.td-layer-list .lname {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.td-layer-list .lbtn {
    border: 0;
    background: none;
    color: #8a8178;
    padding: 4px;
    font-size: .95rem;
    line-height: 1;
    min-width: 30px;
    min-height: 30px;
}
.td-layer-list .lbtn.on { color: #443627; }
.td-layer-list .lbtn:hover { color: #241a12; }

/* ===== Auswahl auf der Zeichenfläche ===== */
.sel-box {
    fill: none;
    stroke: #37a4ff;
    stroke-dasharray: 4 3;
    vector-effect: non-scaling-stroke;
}
.sel-box.outside { stroke: #ff5252; }
.sel-handle { fill: #fff; stroke: #1c8ae6; cursor: nwse-resize; }
.sel-handle.ne, .sel-handle.sw { cursor: nesw-resize; }
.sel-handle.e { cursor: ew-resize; }
.sel-handle.s { cursor: ns-resize; }
.sel-rotate { fill: #fff; stroke: #1c8ae6; cursor: grab; }
.sel-rotate-line { stroke: #1c8ae6; vector-effect: non-scaling-stroke; }
.guide-line { stroke: #ff4d8d; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
.engrave-area { fill: none; stroke: #2f9e6e; stroke-dasharray: 6 5; vector-effect: non-scaling-stroke; opacity: .8; }
.grid-line { stroke: rgba(0,0,0,.14); vector-effect: non-scaling-stroke; }
.el-outside-mark { fill: none; stroke: #ff5252; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }

/* ===== Prüf-Dialog ===== */
.td-check-item {
    display: flex;
    gap: .5rem;
    align-items: flex-start;
    padding: .45rem .5rem;
    border-radius: .4rem;
    font-size: .82rem;
    margin-bottom: .3rem;
}
.td-check-item.err  { background: #fdecea; color: #7c2020; }
.td-check-item.warn { background: #fff6dd; color: #6e5210; }
.td-check-item.ok   { background: #e8f6ee; color: #1c6b43; }
.td-check-item .ti { font-size: 1rem; margin-top: 1px; }
.td-check-item button {
    border: 0; background: none;
    text-decoration: underline;
    color: inherit;
    padding: 0;
    font-size: .78rem;
}

/* ===== Zusammenfassung im Bestell-Dialog ===== */
.td-summary {
    background: #f6f1ea;
    border: 1px solid var(--td-border);
    border-radius: .5rem;
    padding: .6rem .75rem;
    font-size: .8rem;
}
.td-summary .ti { color: #8a6a3c; }

/* ===== Logo-Upload-Dialog ===== */
.lz-drop {
    border: 2px dashed rgba(0, 0, 0, .25);
    border-radius: .75rem;
    padding: 1.6rem 1rem;
    text-align: center;
    color: #6b5a48;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.lz-drop .ti { font-size: 2rem; color: var(--td-accent); }
.lz-drop.lz-over { border-color: var(--td-accent); background: #faf3e6; }
.lz-drop.lz-small { padding: .5rem; }
.lz-drop.lz-small p { display: none; }
.lz-drop.lz-small .ti { font-size: 1.2rem; }
.lz-drop.lz-loading { opacity: .5; pointer-events: none; }
.lz-preview {
    border: 1px solid var(--td-border);
    border-radius: .5rem;
    background:
        conic-gradient(#eee 90deg, #fff 90deg 180deg, #eee 180deg 270deg, #fff 270deg) 0 0/16px 16px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.lz-preview canvas { max-width: 100%; max-height: 100%; }
.lz-result { background: #fff; }

/* =====================================================================
   Ab 992 px: Drei-Spalten-Desktop-Layout
   ===================================================================== */
@media (min-width: 992px) {
    .td-panel {
        position: static;
        transform: none;
        width: 312px;
        flex: 0 0 312px;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
        border-right: 1px solid var(--td-border);
        min-height: 0;
    }
    .td-props {
        position: static;
        transform: none;
        width: 296px;
        flex: 0 0 296px;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
        border-left: 1px solid var(--td-border);
        min-height: 0;
    }
    .td-bottomnav { display: none; }
    .td-panel-grip { display: none; }
    :root { --td-bottomnav-h: 0px; }
}

/* Kompakte Höhen (Smartphone quer) */
@media (max-height: 480px) and (max-width: 991.98px) {
    .td-panel, .td-props { max-height: 76vh; }
    .td-bottomnav button { min-height: 44px; padding: .25rem 0; }
    .td-bottomnav button span { display: none; }
    .td-header { min-height: 44px; padding: .2rem .5rem; }
    .td-subtitle { display: none !important; }
}
