/* ==========================================================================
   Karo-Mathe A4 – 100 % lokal, Mobile-First & Touch-optimiert (mind. 44x44px)
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    font-family: var(--le-font-sans);
    background: #eef2f6;
    color: var(--le-ink);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    transition: transform 0.12s ease, background-color 0.16s ease, border-color 0.16s ease;
}

button:active:not(:disabled) {
    transform: scale(0.97);
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.mono {
    font-family: var(--le-font-mono);
    font-variant-numeric: tabular-nums;
}

.app-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   KOPFLEISTE (SCHLICHT & KOMPAKT)
   ========================================================================== */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #dbe2ea;
    padding: 8px 12px;
}

.top-bar-inner {
    max-width: 1560px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.brand-title {
    font-size: 1.04rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    color: #0f172a;
}

.scale-chip {
    font-size: 0.74rem;
    font-weight: 800;
    padding: 3px 9px;
    border-radius: 999px;
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}

.top-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.action-btn {
    min-height: 44px;
    padding: 0 12px;
    border-radius: 11px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    font-size: 0.82rem;
    font-weight: 800;
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.action-btn:hover:not(:disabled) {
    background: #f8fafc;
    border-color: #94a3b8;
}

.action-btn.danger {
    color: #dc2626;
}

.action-btn.danger:hover:not(:disabled) {
    background: #fef2f2;
    border-color: #fca5a5;
}

.zoom-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 3px;
}

.zoom-btn {
    min-width: 38px;
    min-height: 38px;
    border-radius: 9px;
    background: #ffffff;
    font-size: 1rem;
    font-weight: 900;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.zoom-val {
    min-width: 48px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 800;
}

/* ==========================================================================
   WERKZEUGLEISTE (OHNE TEXTBALLAST, TOUCH >= 44px)
   ========================================================================== */
.tool-bar {
    background: rgba(255, 255, 255, 0.9);
    border-bottom: 1px solid #e2e8f0;
    padding: 7px 12px;
    z-index: 20;
}

.tool-bar-inner {
    max-width: 1560px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.tool-scroll-row {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 1px;
}

.tool-scroll-row::-webkit-scrollbar {
    display: none;
}

.tool-btn {
    flex-shrink: 0;
    min-height: 44px;
    padding: 0 13px;
    border-radius: 12px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    font-size: 0.84rem;
    font-weight: 800;
    color: #1e293b;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tool-btn:hover {
    background: #f8fafc;
}

.tool-btn.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.opt-btn {
    flex-shrink: 0;
    min-height: 40px;
    padding: 0 11px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    font-size: 0.78rem;
    font-weight: 800;
    color: #334155;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.opt-btn.is-on {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

.opt-btn.is-teal {
    background: #f0fdfa;
    border-color: #5eead4;
    color: #0f766e;
}

.sample-chip {
    flex-shrink: 0;
    min-height: 40px;
    padding: 0 11px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px dashed #94a3b8;
    font-size: 0.78rem;
    font-weight: 800;
    color: #334155;
}

.sample-chip:hover {
    background: #eff6ff;
    border-color: #2563eb;
    color: #1d4ed8;
}

/* ==========================================================================
   HAUPTLAYOUT: KAROBLATT & KOMPAKTES WERTE-PANEL
   ========================================================================== */
.main-workspace {
    flex: 1;
    max-width: 1560px;
    width: 100%;
    margin: 0 auto;
    padding: 12px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 14px;
    min-height: 0;
}

.sheet-viewport {
    background: #e2e8f0;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    padding: 14px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 420px;
}

.hint-pill {
    margin-bottom: 10px;
    padding: 5px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid #cbd5e1;
    font-size: 0.78rem;
    font-weight: 700;
    color: #475569;
    text-align: center;
}

.a4-sheet {
    aspect-ratio: 210 / 297;
    background: #ffffff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 18px 42px -12px rgba(15, 23, 42, 0.22);
    transition: width 0.14s ease;
}

.math-svg {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: crosshair;
}

/* Rechtes Mathe-Panel */
.values-panel {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-self: start;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.panel-head h2 {
    font-size: 1rem;
    font-weight: 900;
    color: #0f172a;
}

.count-pill {
    font-size: 0.75rem;
    font-weight: 800;
    padding: 3px 10px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #334155;
}

.shape-card {
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 12px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shape-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.shape-type-pill {
    font-size: 0.78rem;
    font-weight: 900;
    padding: 4px 10px;
    border-radius: 999px;
}

.color-dots-row {
    display: flex;
    gap: 5px;
}

.color-dot-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 1px #cbd5e1;
}

.color-dot-btn.active {
    box-shadow: 0 0 0 2px #0f172a;
}

.sides-box {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 6px 10px;
}

.side-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 0.82rem;
    border-bottom: 1px solid #f1f5f9;
}

.side-row:last-child {
    border-bottom: none;
}

.side-lbl {
    color: #475569;
    font-weight: 700;
}

.side-val {
    font-weight: 900;
    color: #0f172a;
}

.metric-box {
    border-radius: 11px;
    padding: 9px 11px;
    border: 1px solid;
}

.metric-box.teal {
    background: #f0fdfa;
    border-color: #99f6e4;
}

.metric-box.blue {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.metric-box.orange {
    background: #fff7ed;
    border-color: #fed7aa;
}

.metric-lbl {
    font-size: 0.7rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #334155;
}

.metric-val {
    font-size: 0.96rem;
    font-weight: 900;
    color: #0f172a;
    margin-top: 2px;
}

.metric-formula {
    font-size: 0.73rem;
    color: #475569;
    margin-top: 2px;
}

.shapes-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 170px;
    overflow-y: auto;
}

.shape-list-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.shape-list-item {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: 800;
}

.shape-list-item.active {
    background: #eff6ff;
    border-color: #2563eb;
    color: #1d4ed8;
}

.shape-list-del {
    min-width: 38px;
    min-height: 38px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    color: #dc2626;
    font-size: 0.86rem;
    font-weight: 900;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.shape-list-del:hover {
    background: #fef2f2;
    border-color: #fca5a5;
}

.side-val-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.stepper-group {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.step-btn {
    min-width: 30px;
    min-height: 30px;
    border-radius: 7px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    font-size: 0.92rem;
    font-weight: 900;
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.step-btn:hover {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

.angles-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    font-size: 0.76rem;
    font-weight: 800;
    color: #334155;
}

.angle-chip {
    background: #f1f5f9;
    padding: 2px 7px;
    border-radius: 6px;
}

.legend-box {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 12px;
    padding: 9px 11px;
    font-size: 0.76rem;
    color: #0c4a6e;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 10px;
}

/* Mobile Quick-HUD (nur unter 960px sichtbar) */
.mobile-hud-bar {
    display: none;
}

/* ==========================================================================
   MOBILE & IPAD OPTIMIERUNG
   ========================================================================== */
@media (max-width: 960px) {
    .main-workspace {
        grid-template-columns: 1fr;
        padding: 8px;
        gap: 10px;
    }

    .sheet-viewport {
        padding: 10px;
        min-height: 340px;
    }

    .mobile-hud-bar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        background: #ffffff;
        border: 1px solid #cbd5e1;
        border-radius: 14px;
        padding: 8px 12px;
        font-size: 0.82rem;
    }

    .scale-chip {
        display: none;
    }

    .values-panel {
        width: 100%;
    }
}

@media (max-width: 560px) {
    .top-bar {
        padding: 6px 10px;
    }

    .brand-title {
        font-size: 0.94rem;
    }

    .action-btn span.btn-text-hide-sm {
        display: none;
    }
}

/* ==========================================================================
   SAUBERER 1:1 DIN-A4-DRUCK (210 mm x 297 mm -> 1 Kästchen = exakt 5 mm)
   ========================================================================== */
@page {
    size: 210mm 297mm;
    margin: 0;
}

@media print {
    html,
    body {
        width: 210mm;
        height: 297mm;
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        overflow: hidden !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    .app-shell {
        min-height: 0 !important;
        height: 297mm !important;
        display: block !important;
    }
    .top-bar,
    .tool-bar,
    .values-panel,
    .mobile-hud-bar,
    .hint-pill,
    #selectionLayer,
    #previewLayer {
        display: none !important;
    }
    .main-workspace {
        display: block !important;
        width: 210mm !important;
        height: 297mm !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .sheet-viewport {
        border: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        min-height: 0 !important;
        width: 210mm !important;
        height: 297mm !important;
        background: #ffffff !important;
        overflow: hidden !important;
        display: block !important;
    }
    .a4-sheet {
        width: 210mm !important;
        height: 297mm !important;
        max-width: none !important;
        aspect-ratio: auto !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        page-break-after: avoid;
        break-after: avoid;
    }
    .math-svg {
        width: 210mm !important;
        height: 297mm !important;
    }
}
