/* ============================================
   Preisblatt-Generator - Mobile First Styles
   ============================================ */

:root {
    /* Farbpalette - freundlich, modern */
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-secondary: #64748b;
    --color-success: #059669;
    --color-surface: #ffffff;
    --color-surface-alt: #f8fafc;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    
    /* Abstände */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    
    /* Radien & Schatten */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
    
    /* Typografie */
    --font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-surface-alt);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   Cookie-Banner
   ============================================ */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-text);
    color: white;
    padding: var(--space-lg);
    z-index: 9999;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.cookie-banner.show {
    transform: translateY(0);
}

.cookie-banner-content {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    align-items: flex-start;
}

.cookie-banner p {
    font-size: 0.9rem;
    line-height: 1.5;
}

.cookie-banner a {
    color: #93c5fd;
    text-decoration: underline;
}

.cookie-banner-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.cookie-banner .btn {
    flex-shrink: 0;
}

/* ============================================
   App-Container
   ============================================ */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-md);
    padding-bottom: 120px; /* Platz für Mobile-Ad */
}

/* Sprachauswahl – oben rechts */
.lang-selector-wrapper {
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    z-index: 1000;
}

.lang-label {
    display: none;
}

.lang-select {
    padding: var(--space-sm) var(--space-md);
    font-size: 1rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.lang-select:hover {
    border-color: var(--color-primary);
}

/* Mobile: Sprachauswahl im Layoutfluss, nicht fixed (verhindert Überlagerung beim Scrollen) */
@media (max-width: 768px) {
    .app-header,
    .legal-page,
    .admin-page {
        position: relative;
    }
    .lang-selector-wrapper {
        position: absolute;
        top: var(--space-md);
        right: 0;
    }
}

/* Header */
.app-header {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    margin-bottom: var(--space-lg);
}

.app-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: var(--space-xs);
}

.tagline {
    font-size: 1rem;
    color: var(--color-text-muted);
}

.header-nav {
    margin-top: var(--space-md);
}

.header-nav a {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.header-nav a:hover {
    text-decoration: underline;
}

/* Gespeicherte Vorlagen – Buttonleiste */
.saved-templates-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.saved-templates-bar .bar-label {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-right: var(--space-sm);
}

.saved-templates-bar .template-btn {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.9rem;
    background: var(--color-surface-alt);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.saved-templates-bar .template-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.saved-templates-bar .template-btn .btn-remove-template {
    margin-left: var(--space-sm);
    padding: 0 4px;
    font-size: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
}

.saved-templates-bar .template-btn .btn-remove-template:hover {
    color: #dc2626;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    margin-top: var(--space-lg);
}

.app-footer a {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    text-decoration: none;
}

.app-footer a:hover {
    color: var(--color-primary);
    text-decoration: underline;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.modal-content {
    background: var(--color-surface);
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 100%;
}

.modal-content h3 {
    margin-bottom: var(--space-md);
    font-size: 1.25rem;
}

.modal-content input {
    width: 100%;
    padding: var(--space-md);
    margin-bottom: var(--space-lg);
    font-size: 1rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
}

.modal-actions {
    display: flex;
    gap: var(--space-sm);
}

/* ============================================
   Main Layout - Mobile First
   ============================================ */
.main-wrapper {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    align-items: center;
    width: 100%;
}

/* Eingabebereich */
.input-section {
    width: 100%;
    max-width: 500px;
}

.input-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
}

.input-card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--space-lg);
    color: var(--color-text);
}

/* Formular-Elemente */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-group:last-of-type {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: var(--space-sm);
    color: var(--color-text);
}

input[type="text"],
textarea {
    width: 100%;
    padding: var(--space-md);
    font-size: 1rem;
    font-family: inherit;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* WYSIWYG Rich-Text-Editor (B/I/U Toolbar) */
.rich-text-field {
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.rich-text-field:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.rich-text-toolbar {
    display: flex;
    gap: 2px;
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-surface-alt);
    border-bottom: 1px solid var(--color-border);
}

.toolbar-btn {
    padding: 6px 10px;
    font-size: 0.9rem;
    font-family: inherit;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-text);
    transition: background 0.2s;
}

.toolbar-btn:hover {
    background: var(--color-border);
}

.rich-text-editor-wrap {
    position: relative;
}

.rich-text-editor {
    width: 100%;
    min-height: 80px;
    padding: var(--space-md);
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
}

.rich-text-editor-sm {
    min-height: 48px;
}

.rich-text-placeholder {
    position: absolute;
    left: var(--space-md);
    top: var(--space-md);
    right: var(--space-md);
    color: var(--color-text-muted);
    font-size: 1rem;
    pointer-events: none;
    white-space: pre-wrap;
}

.rich-text-editor-wrap:not(.empty) .rich-text-placeholder {
    display: none;
}

.rich-text-editor-wrap.empty .rich-text-placeholder {
    display: block;
}

/* Preisliste */
.price-list-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.price-item {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: var(--space-sm);
    align-items: center;
}

.price-item input {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.95rem;
}

.price-item .btn-remove {
    padding: var(--space-sm);
    min-width: 40px;
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: all 0.2s;
}

.price-item .btn-remove:hover {
    color: #dc2626;
    border-color: #dc2626;
    background: #fef2f2;
}

/* Hintergrund-Auswahl */
.background-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
}

.bg-option {
    aspect-ratio: 4/3;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s;
    background-size: cover;
    background-position: center;
}

.bg-option:hover {
    transform: scale(1.02);
}

.bg-option.selected {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--color-primary);
}

/* Bild-Upload-Zone */
.image-upload-zone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-xl);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--color-surface-alt);
}

.image-upload-zone:hover,
.image-upload-zone.dragover {
    border-color: var(--color-primary);
    background: rgba(37, 99, 235, 0.05);
}

.image-upload-zone span {
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md) var(--space-lg);
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--color-surface-alt);
    color: var(--color-text);
    border: 2px solid var(--color-border);
}

.btn-secondary:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.btn-download {
    background: var(--color-success);
    color: white;
}

.btn-download:hover {
    background: #047857;
    transform: translateY(-1px);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.9rem;
}

.file-label {
    cursor: pointer;
}

/* Form-Aktionen */
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

.form-actions .btn {
    flex: 1 1 auto;
    min-width: 140px;
}

/* Vorlagen-Suche */
.template-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.template-suggestions {
    display: none;
}

.template-suggestions.show {
    display: block;
}

.template-suggestion {
    padding: var(--space-md);
    cursor: pointer;
    transition: background 0.15s;
}

.template-suggestion:hover {
    background: var(--color-surface-alt);
}

.form-group {
    position: relative;
}

/* ============================================
   Vorschau
   ============================================ */
.preview-section {
    width: 100%;
    max-width: 420px;
}

.preview-wrapper h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--space-md);
    color: var(--color-text);
}

.download-options {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

.download-options label {
    font-size: 0.9rem;
    color: var(--color-text);
    white-space: nowrap;
}

.download-lang-select {
    flex: 1;
    min-width: 0;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: var(--color-surface);
    color: var(--color-text);
}

.btn-download-below {
    width: 100%;
    margin-top: var(--space-sm);
}

.preview-container {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
}

/* Preview-Canvas - Größe passt sich dem Inhalt an */
.preview-canvas {
    width: 100%;
    min-width: 280px;
    max-width: 400px;
    min-height: 360px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: #f1f5f9;
}

/* Inhalt des Preisblatts - heller Text für gute Lesbarkeit auf Farbverläufen */
.preview-content {
    width: 100%;
    min-height: 320px;
    position: relative;
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.preview-headline {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--space-sm);
    text-align: center;
}

.preview-description {
    font-size: 0.9rem;
    margin-bottom: var(--space-md);
    text-align: center;
    opacity: 0.95;
}

.preview-description .preview-line,
.preview-footer .preview-line {
    display: block;
    min-height: 1.5em;
    line-height: 1.5;
}

.preview-description b, .preview-description strong,
.preview-footer b, .preview-footer strong {
    font-weight: 700;
}

.preview-description i, .preview-description em,
.preview-footer i, .preview-footer em {
    font-style: italic;
}

.preview-description u, .preview-footer u {
    text-decoration: underline;
}

.preview-price-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin: var(--space-sm) 0;
}

.preview-price-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    color: #1e293b;
    text-shadow: none;
}

.preview-price-item .name {
    font-weight: 500;
}

.preview-price-item .price {
    font-weight: 700;
    color: var(--color-primary);
}

.preview-footer {
    font-size: 0.9rem;
    text-align: center;
    margin-top: var(--space-md);
    padding-top: var(--space-md);
}

.preview-footer .preview-line:first-child {
    margin-top: 0;
}

/* Hochgeladene Bilder in der Vorschau */
.preview-uploaded-image {
    position: absolute;
    cursor: move;
    user-select: none;
    touch-action: none;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}

.btn-delete-image {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    padding: 0;
    font-size: 1.1rem;
    line-height: 1;
    background: #dc2626;
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.btn-delete-image:hover {
    background: #b91c1c;
}

/* Beim Export: Löschen-Button und Resize-Handle ausblenden */
.preview-content.exporting .btn-delete-image,
.preview-content.exporting .resize-handle {
    display: none !important;
}

/* Wasserzeichen bei „Nur technisch notwendige“ */
.preview-watermark {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    transform: rotate(-30deg);
    transform-origin: center;
    font-size: 1.04rem;
    color: rgba(255, 255, 255, 0.3);
    font-family: var(--font-family);
    z-index: 1;
}
.preview-watermark span {
    white-space: nowrap;
}

.preview-uploaded-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: nwse-resize;
    border-radius: 2px 0 0 0;
    user-select: none;
}

/* ============================================
   Werbebereiche
   ============================================ */
.ad-area {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-placeholder {
    padding: var(--space-xl);
    text-align: center;
    color: var(--color-text-muted);
}

.ad-placeholder span {
    display: block;
    font-weight: 500;
    margin-bottom: var(--space-xs);
}

.ad-placeholder small {
    font-size: 0.8rem;
}

/* Mobile Ad - unten */
.ad-mobile {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    min-height: 80px;
    z-index: 100;
}

/* Desktop Ad - ausgeblendet auf Mobile */
.ad-desktop {
    display: none;
}

/* ============================================
   Desktop Layout (ab 900px)
   ============================================ */
@media (min-width: 900px) {
    .app-container {
        padding: var(--space-xl);
        padding-bottom: var(--space-xl);
    }

    /* Einheitliche Breite: Vorlagen-Bar + Eingabe + Vorschau + Werbung in einer Linie */
    .main-wrapper {
        max-width: none;
        display: grid;
        grid-template-columns: 380px 420px 160px;
        grid-template-rows: auto 1fr;
        gap: var(--space-xl);
        justify-content: center;
        width: 100%;
    }

    .saved-templates-bar {
        grid-column: 1 / -1;
    }

    .main-content {
        grid-column: 1 / -1;
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: var(--space-xl);
    }

    .input-section {
        flex: 0 0 380px;
        max-width: 380px;
    }

    .preview-section {
        flex: 0 0 420px;
        max-width: 420px;
    }

    /* Desktop Ad rechts */
    .ad-desktop {
        display: flex;
        flex: 0 0 160px;
        min-width: 160px;
        min-height: 600px;
        align-self: stretch;
    }

    .ad-mobile {
        display: none;
    }
}

/* Größere Desktops */
@media (min-width: 1200px) {
    .main-wrapper {
        grid-template-columns: 380px 420px 200px;
    }

    .ad-desktop {
        flex: 0 0 200px;
        min-width: 200px;
    }
}
