/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #e0e0e0;
    background-color: #121212;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background-color: #1e1e1e;
    flex: 1;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #333;
}

header h1 {
    color: #ffffff;
    font-size: 2.5em;
    margin-bottom: 10px;
}

header p {
    color: #b0b0b0;
    font-size: 1.1em;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    margin-bottom: 30px;
    border-bottom: 1px solid #333;
    flex-wrap: wrap;
}

.tab-button {
    background: none;
    border: none;
    padding: 15px 20px;
    cursor: pointer;
    font-size: 16px;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 200px;
    color: #e0e0e0;
}

.tab-button:hover {
    background-color: #2a2a2a;
}

.tab-button.active {
    border-bottom-color: #0d7377;
    color: #0d7377;
    font-weight: bold;
}

.tab-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #ffffff;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 16px;
    background-color: #2a2a2a;
    color: #e0e0e0;
}

.form-group input:focus {
    outline: none;
    border-color: #0d7377;
    box-shadow: 0 0 5px rgba(13,115,119,0.3);
}

.form-help {
    display: block;
    margin-top: 5px;
    font-size: 0.85em;
    color: #999;
    font-style: italic;
}

/* Color Picker Enhancement */
.color-picker-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.color-presets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.color-preset {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 2px solid #444;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.color-preset:hover {
    border-color: #0d7377;
    transform: scale(1.1);
}

.color-preset.active {
    border-color: #0d7377;
    box-shadow: 0 0 0 2px rgba(13,115,119,0.3);
}

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

.color-current-display {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 2px solid #444;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 12px;
}

.color-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0.01;
    pointer-events: none;
    z-index: -1;
}

.color-input-wrapper {
    position: relative;
    display: inline-block;
}

.color-input-real {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.color-custom-btn {
    position: relative;
    z-index: 1;
    padding: 8px 12px;
    background: #2a2a2a;
    border: 1px solid #444;
    color: #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    pointer-events: none; /* Button selbst nicht klickbar, Color Input darüber ist klickbar */
}

.color-input-wrapper:hover .color-custom-btn {
    background: #3a3a3a;
    border-color: #0d7377;
}

/* Grid Options */
.grid-options {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.grid-preset {
    padding: 8px 16px;
    border: 1px solid #444;
    background: #2a2a2a;
    color: #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.grid-preset:hover {
    background-color: #3a3a3a;
}

.grid-preset.selected {
    background-color: #0d7377;
    color: white;
    border-color: #0d7377;
}

/* Custom Grid Controls */
.grid-custom-controls {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 8px;
    margin-top: 15px;
}

.grid-dropdowns {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.dropdown-group {
    flex: 1;
    min-width: 120px;
}

.dropdown-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
    color: #ffffff;
    font-weight: bold;
}

.dropdown-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: #1e1e1e;
    color: #e0e0e0;
    font-size: 16px;
    cursor: pointer;
}

.dropdown-group select:focus {
    outline: none;
    border-color: #0d7377;
    box-shadow: 0 0 5px rgba(13,115,119,0.3);
}

/* Grid Sliders */
.grid-sliders {
    border-top: 1px solid #444;
    padding-top: 20px;
}

.slider-group {
    margin-bottom: 15px;
}

.slider-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: #ffffff;
    font-weight: bold;
}

.slider-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #444;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #0d7377;
    cursor: pointer;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.slider-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #0d7377;
    cursor: pointer;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

#gridWidthValue,
#gridHeightValue {
    color: #0d7377;
    font-weight: bold;
}

/* Grid Preview */
.grid-preview {
    margin-top: 20px;
    padding: 20px;
    background-color: #2a2a2a;
    border-radius: 8px;
}

.grid-preview-container {
    display: grid;
    gap: 2px;
    background-color: #444;
    padding: 10px;
    border-radius: 4px;
    max-width: 400px;
    margin: 0 auto;
    aspect-ratio: 210/297; /* A4 aspect ratio */
}

.grid-cell {
    background-color: #1e1e1e;
    border: 1px solid #555;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #b0b0b0;
    min-height: 30px;
}

/* Design Container */
.side-selector {
    display: flex;
    margin-bottom: 20px;
    background-color: #2a2a2a;
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
}

.side-button {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #b0b0b0;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

.side-button.active {
    background-color: #0d7377;
    color: white;
}

.side-button:hover:not(.active) {
    background-color: #3a3a3a;
    color: #e0e0e0;
}

.design-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

@media (max-width: 768px) {
    .design-container {
        grid-template-columns: 1fr;
    }
}

.design-controls {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 8px;
}

.design-preview {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 8px;
}

/* Card Preview */
.card-preview {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    padding: 20px;
}

.card-template {
    /* Dimensions will be set dynamically by JavaScript based on grid */
    width: 200px;  /* Default fallback */
    height: 280px; /* Default fallback */
    min-width: 250px;  /* Ensure minimum usable size */
    min-height: 350px; /* Ensure minimum usable size */
    background-color: white;
    border: 2px solid black;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: width 0.3s ease, height 0.3s ease; /* Smooth dimension changes */
}

/* Textbox Controls */
.textbox-controls {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #444;
}

.control-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.textbox-item,
.imagebox-item {
    background-color: #1e1e1e;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
    border: 1px solid #444;
}

.textbox-item label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
    color: #fff;
}

.textbox-item input[type="text"] {
    width: 100%;
    margin-bottom: 10px;
    padding: 8px;
    background-color: #2a2a2a;
    border: 1px solid #555;
    border-radius: 4px;
    color: #e0e0e0;
}

.imagebox-item {
    border-left: 3px solid #0d7377;
}

.textbox-item {
    border-left: 3px solid #495057;
}

/* Image boxes on card */
.card-imagebox {
    position: absolute;
    border: 1px dashed #0d7377;
    background-color: rgba(30, 30, 30, 0.9);
    cursor: move;
    min-width: 40px;
    min-height: 30px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b0b0b0;
    font-size: 10px;
    text-align: center;
}

.card-imagebox:hover {
    border-color: #0a5d61;
    background-color: rgba(30, 30, 30, 1);
}

.card-imagebox img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-imagebox.dragging {
    opacity: 0.7;
    z-index: 1000;
}

.textbox-item label {
    font-size: 14px;
    margin-bottom: 5px;
}

.textbox-item input {
    margin-bottom: 5px;
}

.textbox-item .btn-danger {
    font-size: 12px;
    padding: 5px 10px;
}

/* Textboxes on Card */
.card-textbox {
    position: absolute;
    border: 1px dashed #0d7377;
    background-color: rgba(30, 30, 30, 0.9);
    color: #e0e0e0;
    padding: 5px;
    font-size: 12px;
    cursor: move;
    min-width: 40px;
    min-height: 20px;
    word-wrap: break-word;
    resize: both;
    overflow: visible; /* Allow content to be visible */
    white-space: pre-wrap; /* Preserve whitespace and allow wrapping */
    box-sizing: border-box;
}

.card-textbox:hover {
    border-color: #0a5d61;
    background-color: rgba(30, 30, 30, 1);
}

.card-textbox.dragging {
    opacity: 0.7;
    z-index: 1000;
}

/* Content Inputs */
.content-inputs {
    display: grid;
    gap: 20px;
}

.card-input {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #444;
}

.card-input h4 {
    margin-bottom: 15px;
    color: #ffffff;
    border-bottom: 2px solid #0d7377;
    padding-bottom: 10px;
}

.card-side-section {
    margin-bottom: 20px;
    background-color: #1e1e1e;
    padding: 15px;
    border-radius: 6px;
    border-left: 3px solid #0d7377;
}

.side-title {
    color: #0d7377;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #333;
}

.input-field {
    margin-bottom: 15px;
}

.input-field:last-child {
    margin-bottom: 0;
}

.input-field label {
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
    color: #e0e0e0;
    font-weight: 500;
}

.input-field textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #444;
    border-radius: 4px;
    resize: vertical;
    min-height: 60px;
    background-color: #1a1a1a;
    color: #e0e0e0;
    font-family: inherit;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.input-field textarea:focus {
    outline: none;
    border-color: #0d7377;
    box-shadow: 0 0 5px rgba(13,115,119,0.3);
}

.input-field input[type="file"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: #1a1a1a;
    color: #e0e0e0;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.input-field input[type="file"]:focus {
    outline: none;
    border-color: #0d7377;
    box-shadow: 0 0 5px rgba(13,115,119,0.3);
}

.input-field input[type="file"]::file-selector-button {
    background-color: #0d7377;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    margin-right: 10px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.3s ease;
}

.input-field input[type="file"]::file-selector-button:hover {
    background-color: #0a5d61;
}

/* PDF Preview */
.pdf-preview {
    background-color: #2a2a2a;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    max-height: 80vh;
    overflow-y: auto;
}

.pdf-page {
    background-color: white;
    margin: 0 auto 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    position: relative;
    width: 210mm;
    height: 297mm;
    transform-origin: top center;
    display: grid;
    gap: 2mm;
    padding: 10mm;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .pdf-page {
        transform: scale(0.25);
        margin-bottom: calc(-297mm * 0.75 + 20px);
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .pdf-page {
        transform: scale(0.35);
        margin-bottom: calc(-297mm * 0.65 + 20px);
    }
}

@media (min-width: 1025px) {
    .pdf-page {
        transform: scale(0.45);
        margin-bottom: calc(-297mm * 0.55 + 20px);
    }
}

.pdf-card {
    background-color: white;
    border: 1px solid black;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pdf-card-textbox {
    position: absolute;
    font-size: 8px;
    word-wrap: break-word;
    overflow: hidden;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    text-decoration: none;
    display: inline-block;
    transition: all 0.3s ease;
}

.btn-primary {
    background-color: #0d7377;
    color: white;
}

.btn-primary:hover {
    background-color: #0a5d61;
}

.btn-secondary {
    background-color: #495057;
    color: white;
}

.btn-secondary:hover {
    background-color: #383d41;
}

.btn-success {
    background-color: #28a745;
    color: white;
    font-size: 18px;
    padding: 15px 30px;
}

.btn-success:hover {
    background-color: #1e7e34;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

/* Range Slider */
input[type="range"] {
    width: calc(100% - 60px);
    margin-right: 10px;
}

#borderWidthValue {
    font-weight: bold;
    color: #0d7377;
}

/* Watermark */
.card-watermark {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 8px;
    color: rgba(0,0,0,0.3);
    pointer-events: none;
}

/* Export Controls */
.export-controls {
    text-align: center;
    padding: 20px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .tab-nav {
        flex-direction: column;
    }
    
    .tab-button {
        min-width: auto;
    }
    
    .design-container {
        grid-template-columns: 1fr;
    }
    
    .grid-options {
        justify-content: center;
    }
}

/* Image controls panel */
.image-controls-panel {
    background: #2a2a2a;
    border: 1px solid #0d7377;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
    box-shadow: 0 2px 8px rgba(13, 115, 119, 0.3);
}

.image-controls-panel h3 {
    color: #14a085;
    margin-bottom: 15px;
    border-bottom: 1px solid #0d7377;
    padding-bottom: 8px;
}

/* Size controls */
.size-controls {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
}

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

.size-input-group label {
    font-size: 12px;
    color: #a0a0a0;
}

.size-input-group input[type="number"] {
    width: 80px;
    padding: 5px;
    background: #1a1a1a;
    border: 1px solid #0d7377;
    border-radius: 4px;
    color: #ffffff;
    font-size: 14px;
}

.btn-small {
    padding: 5px 10px;
    font-size: 14px;
    min-height: auto;
    height: 32px;
}

/* Card image styling */
.card-image {
    position: absolute;
    cursor: move;
    border: 2px dashed #0d7377;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
    overflow: hidden;
}

.card-image:hover {
    border-color: #14a085;
}

.card-image.selected {
    border-color: #14a085;
    box-shadow: 0 0 10px rgba(20, 160, 133, 0.5);
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Resize handles for images */
.card-image .resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #14a085;
    border: 1px solid #ffffff;
    border-radius: 2px;
}

.card-image .resize-handle.se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.card-image .resize-handle.ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.card-image .resize-handle.sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.card-image .resize-handle.nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

/* Footer */
footer {
    margin-top: 40px;
    padding: 20px 0;
    border-top: 2px solid #333;
    background-color: #1a1a1a;
    text-align: center;
}

footer .impressum p {
    color: #b0b0b0;
    font-size: 0.9em;
    line-height: 1.4;
    margin: 0;
}

footer .impressum a {
    color: #4CAF50;
    text-decoration: none;
    margin: 0 5px;
    transition: color 0.3s ease;
}

footer .impressum a:hover {
    color: #66BB6A;
    text-decoration: underline;
}

footer .impressum a:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}
