/* ==========================================================================
   ЧАСТЬ 1: СТИЛИ ДЛЯ ЛЕВОЙ ПАНЕЛИ И ГЛОБАЛЬНЫЙ КАРКАС
   (Строго изолированы, чтобы не ломать форму справа)
   ========================================================================== */

body {
    font-family: 'Roboto', Arial, sans-serif;
    margin: 0;
    background-color: #e9ebee; /* Исходный фон */
    color: #333; /* Исходный цвет текста */
}

/* Скроллбар для левой панели */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.app-container { display: flex; height: 100vh; overflow: hidden; }

/* ЛЕВАЯ ПАНЕЛЬ */
.controls {
    width: 400px;
    padding: 24px;
    background-color: #ffffff;
    border-right: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    z-index: 10;
}

/* Все инпуты, селекты и лейблы ТОЛЬКО внутри панели управления */
.controls-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.controls h2 { margin: 0; font-size: 22px; font-weight: 700; color: #1f2937; }
.controls label { display: block; margin: 0 0 6px 0; font-weight: 500; font-size: 13px; color: #6b7280; }

.controls input[type="text"], 
.controls input[type="number"], 
.controls select {
    width: 100%; padding: 10px 12px; box-sizing: border-box;
    border: 1px solid #e5e7eb; border-radius: 6px; font-size: 14px;
    background-color: #f9fafb; color: #1f2937; transition: all 0.2s ease;
}
.controls input:focus, .controls select:focus {
    outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); background-color: #fff;
}

/* Все кнопки ТОЛЬКО внутри панели управления */
.controls button {
    width: 100%; padding: 10px 16px; border: none; cursor: pointer;
    border-radius: 6px; font-size: 14px; font-weight: 500;
    transition: all 0.2s ease; display: inline-flex; justify-content: center; align-items: center; gap: 6px;
}
.controls button:disabled { opacity: 0.5; cursor: not-allowed; }

.controls .btn-primary { background-color: #3b82f6; color: white; }
.controls .btn-primary:hover:not(:disabled) { background-color: #2563eb; }

.controls .btn-success { background-color: #10b981; color: white; }
.controls .btn-success:hover:not(:disabled) { background-color: #059669; }

.controls .btn-secondary { background-color: #f3f4f6; color: #4b5563; border: 1px solid #e5e7eb; }
.controls .btn-secondary:hover:not(:disabled) { background-color: #e5e7eb; }

.controls .btn-danger { background-color: #ef4444; color: white; }
.controls .btn-danger:hover:not(:disabled) { background-color: #dc2626; }
.controls .btn-danger.outline { background-color: transparent; border: 1px solid #ef4444; color: #ef4444; }
.controls .btn-danger.outline:hover:not(:disabled) { background-color: #fef2f2; }

/* Кнопки истории */
#history-buttons { display: flex; gap: 6px; }
#history-buttons button { width: 36px; height: 36px; padding: 0; font-size: 18px; background-color: #f3f4f6; color: #4b5563; border: 1px solid #e5e7eb; }
#history-buttons button:hover:not(:disabled) { background-color: #e5e7eb; }

/* Карточки в левой панели */
.control-section { margin-bottom: 24px; }
.control-box { background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; margin-bottom: 12px; }

/* Страна */
#region-input-wrapper { position: relative; }
#ctrl-region-input { padding-right: 30px; }
#clear-region-button { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); cursor: pointer; font-size: 18px; color: #6b7280; }
#clear-region-button:hover { color: #ef4444; }

/* Аккордеон */
.accordion-item { margin-bottom: 12px; }
.accordion-header {
    display: flex; justify-content: space-between; align-items: center; cursor: pointer;
    user-select: none; margin: 0; padding: 14px 16px; background-color: #f9fafb;
    border: 1px solid #e5e7eb; border-radius: 8px; font-size: 15px; font-weight: 600; color: #1f2937; transition: all 0.2s ease;
}
.accordion-header:hover { background-color: #f1f5f9; }
.accordion-header.active { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom-color: transparent; }
.accordion-arrow { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid #6b7280; transition: transform 0.3s ease; }
.accordion-header.active .accordion-arrow { transform: rotate(180deg); }
.accordion-content {
    max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out, padding 0.3s ease-out;
    background: #ffffff; border: 1px solid #e5e7eb; border-top: none;
    border-bottom-left-radius: 8px; border-bottom-right-radius: 8px;
}
.accordion-content.active { max-height: 1500px; padding: 16px; }

/* Внутренности аккордеона */
.helper-text { font-size: 12px; color: #6b7280; margin-top: 0; margin-bottom: 12px; }
#format-buttons { display: flex; flex-direction: column; gap: 10px; transition: opacity 0.3s; }
#format-buttons.disabled { opacity: 0.4; pointer-events: none; }
.format-group { display: flex; gap: 6px; }
.format-group button { flex: 1; height: 40px; padding: 0; font-size: 16px; background-color: #f9fafb; border: 1px solid #e5e7eb; color: #1f2937; }
.format-group button:hover { background-color: #e5e7eb; }
#ctrl-color { width: 40px; height: 40px; padding: 2px; border: 1px solid #e5e7eb; border-radius: 6px; cursor: pointer; }
#ctrl-font-size { width: 80px; text-align: center; }
#ctrl-font { width: 100%; margin-top: 5px; }

.text-actions { display: flex; gap: 10px; }
.image-actions { display: flex; gap: 10px; flex-direction: column; }
.name-generation-group .gender-buttons-wrapper { display: flex; gap: 10px; margin-top: 8px; }
.calculation-button { font-size: 13px; }

.control-toggles { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.toggle-label { display: flex; align-items: center; gap: 8px; font-weight: 600 !important; cursor: pointer; color: #1f2937 !important; margin: 0 !important;}
.control-icon { width: 24px; height: 24px; stroke: #3b82f6; cursor: pointer; transition: stroke 0.3s; }
.control-icon.dimmed { stroke: #6b7280; opacity: 0.5; }

.input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.presets-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.presets-actions button { flex: 1 1 calc(33.333% - 8px); min-width: 80px; padding: 8px 5px; font-size: 13px; }
.bottom-actions hr { border: none; border-top: 1px solid #e5e7eb; margin: 0 0 20px 0; }
.bottom-actions button { margin-top: 12px; padding: 12px; font-size: 15px; }

/* Кнопка и модалка справки */
#help-button { position: fixed; bottom: 24px; left: 24px; width: 48px; height: 48px; border-radius: 50%; background: #1f2937; color: #fff; font-size: 22px; font-weight: bold; border: none; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); transition: all 0.2s ease; z-index: 100; display: flex; align-items: center; justify-content: center;}
#help-button:hover { background: #000; transform: scale(1.05); }
#help-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(15, 23, 42, 0.75); z-index: 10000; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(3px);}
#help-modal .modal-content { background: #fff; padding: 30px 40px; border-radius: 12px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1); width: 90%; max-width: 600px; max-height: 85vh; overflow-y: auto; position: relative; }
#help-modal .modal-content h2 { margin-top: 0; color: #1f2937; font-size: 24px;}
#help-modal .modal-content h4 { margin-top: 24px; border-bottom: 1px solid #e5e7eb; padding-bottom: 8px; color: #3b82f6; font-size: 16px;}
#help-modal .modal-content ul { padding-left: 20px; color: #4b5563; line-height: 1.6;}
#help-modal .modal-content li { margin-bottom: 10px; }
#help-modal .close-button { position: absolute; top: 16px; right: 24px; font-size: 28px; cursor: pointer; color: #6b7280; transition: color 0.2s; border: none; background: none;}
#help-modal .close-button:hover { color: #ef4444; }


/* ==========================================================================
   ЧАСТЬ 2: СТИЛИ ДЛЯ ПРАВОЙ ПАНЕЛИ И ФОРМЫ
   (ОРИГИНАЛЬНЫЙ КОД - АБСОЛЮТНО БЕЗ ИЗМЕНЕНИЙ ИЗ ВАШЕГО ИСХОДНИКА)
   ========================================================================== */

.preview {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 50px;
}

.form-wrapper { position: relative; width: 450px; padding: 30px; background-color: #fff; border-radius: 10px; box-shadow: 0 5px 20px rgba(0,0,0,0.08); box-sizing: border-box; overflow: hidden; background-image: linear-gradient(90deg, #3580ed 50%, transparent 50%), linear-gradient(90deg, #3580ed 50%, transparent 50%), linear-gradient(0deg, #3580ed 50%, transparent 50%), linear-gradient(0deg, #3580ed 50%, transparent 50%); background-repeat: repeat-x, repeat-x, repeat-y, repeat-y; background-size: 10px 2px, 10px 2px, 2px 10px, 2px 10px; background-position: 0 0, 0 100%, 0 0, 100% 0; animation: marching-ants 400ms linear infinite; }
@keyframes marching-ants { from { background-position: 0 0, 0 100%, 0 0, 100% 0; } to { background-position: 10px 0, -10px 100%, 0 -10px, 100% 10px; } }
#snap-guide { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background-color: #ff0000a0; z-index: 999; transform: translateX(-50%); display: none; }
.draggable { position: absolute; cursor: move; user-select: none; transition: opacity 0.3s; }
.editable-text { cursor: text; }
.editable-text[contenteditable="true"], #phone-input-container.editing { outline: 2px solid #6a5acd; cursor: text !important; }
.dynamic-text { top: 150px; left: 10%; width: 80%; text-align: center; }

/* Режим фокуса при редактировании текста */
.form-wrapper.text-editing-mode .draggable:not(.editing):not([contenteditable="true"]) {
    opacity: 0.3;
    pointer-events: none;
}

#top-text { top: 30px; left: 5%; width: 90%; text-align: center; font-size: 14px; line-height: 1.5; color: #555; }
.highlight { color: #d9534f; font-weight: bold; }
#product-area { top: 85px; left: 50%; transform: translateX(-50%); width: 300px; height: 300px; touch-action: none; box-sizing: border-box; }
.image-placeholder { height: 100%; width: 100%; border: 2px solid #ddd; background-color: #fafafa; box-sizing: border-box; }
#product-area img { 
    width: 100%; 
    height: 100%; 
    display: block; 
    object-fit: contain; 
}
#product-area.selected { outline: 2px solid #007bff; outline-offset: 2px; }
#preview-discount { top: 375px; left: 50%; width: auto; transform: translateX(-50%); font-size: 38px; font-weight: 900; white-space: nowrap; }

#price-area {
    top: 395px;
    left: 50%;
    width: auto;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 48px;
    color: #ff0000;
    font-weight: 900;
}
.price .price-old {
    font-size: 28px;
    color: #888;
    text-decoration: line-through;
    margin-right: 15px;
    font-weight: normal;
}

#timer-label { top: 495px; left: 50%; width: auto; transform: translateX(-50%); font-size: 14px; color: #555; white-space: nowrap; }
#preview-timer { top: 520px; left: 50%; width: auto; transform: translateX(-50%); font-size: 40px; font-weight: bold; }

#name-label { top: 580px; left: 10%; width: auto; text-align: center; font-size: 14px; margin-bottom: 8px; }
#preview-name { top: 600px; left: 50%; width: 80%; transform: translateX(-50%); }
#phone-label { top: 655px; left: 10%; width: auto; text-align: center; font-size: 14px; margin-bottom: 8px; }
#phone-input-container { top: 675px; left: 50%; width: 80%; transform: translateX(-50%); }

.simulated-input { min-height: 44px; line-height: 1.2; color: #999; width: 100%; padding: 12px; box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; }
.phone-input-wrapper { display: flex; align-items: center; border: 1px solid #ccc; border-radius: 4px; padding: 0 12px; background-color: #fff; min-height: 44px; box-sizing: border-box; }
.phone-input-wrapper input { border: none; padding-left: 5px; flex-grow: 1; height: 100%; font-size: 16px; pointer-events: none; background: transparent; }
.phone-input-wrapper input:focus { outline: none; }
.form-wrapper.text-editing-mode #phone-input-container.editing input { pointer-events: auto; }
#preview-flag { width: 24px; height: 18px; object-fit: contain; margin-right: 8px; }
#preview-button { top: 740px; left: 50%; width: 80%; transform: translateX(-50%); background-color: #5b99e5; color: white; border: none; padding: 16px; font-size: 18px; font-weight: bold; border-radius: 5px; cursor: pointer; text-transform: uppercase; transition: background-color 0.3s ease, transform 0.2s ease; }
#preview-button:hover { background-color: #4a8ae0; }
#preview-button:active { transform: translateX(-50%) scale(0.96); }
#bottom-text { top: 800px; left: 50%; width: auto; transform: translateX(-50%); text-align: center; font-size: 11px; color: #777; white-space: nowrap; }
.hidden { display: none !important; }
#edit-banner { position: fixed; top: -60px; left: 0; width: 100%; padding: 15px 0; background-color: #6a5acd; color: white; text-align: center; font-size: 20px; font-weight: bold; text-transform: uppercase; cursor: pointer; z-index: 9999; transition: top 0.4s ease-in-out; }
#edit-banner.visible { top: 0; }
.simulation-mode .controls { display: none; }
.simulation-mode .preview { width: 100vw; height: 100vh; padding: 0; align-items: center; justify-content: center; }
.simulation-mode .draggable { cursor: default; }
.simulation-mode .resizable { cursor: default; }
.simulation-mode #product-area.selected { outline: none; }
.simulation-mode .editable-text[contenteditable="true"] { outline: none; }

/* --- Стили для ручек изменения размера --- */
.resize-handle { box-sizing: border-box; position: absolute; width: 12px; height: 12px; background: #fff; border: 2px solid #007bff; z-index: 10; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#product-area.selected .resize-handle { opacity: 1; pointer-events: auto; }
.resize-handle.tl { top: -7px; left: -7px; cursor: nwse-resize; }
.resize-handle.tr { top: -7px; right: -7px; cursor: nesw-resize; }
.resize-handle.bl { bottom: -7px; left: -7px; cursor: nesw-resize; }
.resize-handle.br { bottom: -7px; right: -7px; cursor: nwse-resize; }

/* --- Стили для Drag-and-Drop картинки --- */
#product-area.drag-over {
    outline: 3px dashed #007bff;
    outline-offset: -3px;
    background-color: rgba(0, 123, 255, 0.1);
    transition: all 0.2s ease;
}
#product-area.drag-over .image-placeholder {
    border-color: #007bff;
    background-color: rgba(0, 123, 255, 0.05);
}
#product-area.drag-over img {
    opacity: 0.5;
}