/* === RESET === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body, html {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    background-color: #f4f4f4;
    font-family: sans-serif;
    transition: background-color 0.2s;
}

/* === СКРОЛЛ-ОБЁРТКА === */
#canvas-wrapper {
    width: 100%;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    display: flex;
    justify-content: center;
    background-color: #ffffff;
}

body.editor-active #canvas-wrapper {
    background-color: #e9e9e9;
}

/* === ХОЛСТ === */
#canvas {
    position: relative;
    width: 1280px;
    flex-shrink: 0;
    min-height: 100vh;
    background-color: #ffffff;
    transition: min-height 0.2s;
    transform-origin: top center;
}

body.editor-active #canvas {
    min-height: 2000px;
    background-image: radial-gradient(#ccc 1px, transparent 1px);
    background-size: 20px 20px;
}

/* === ЭЛЕМЕНТЫ === */
.element {
    position: absolute;
    cursor: grab;
    box-sizing: border-box;
    user-select: none;
}

.element:active {
    cursor: grabbing;
}

.element img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    border-radius: inherit;
}

.element[data-type="text"] {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    min-height: 24px;
    height: auto;
    padding: 4px;
    line-height: 1.4;
}

.element[data-type="text"][contenteditable="true"] {
    cursor: text !important;
    outline: 2px solid #ff6b00 !important;
    box-shadow: 0 0 0 4px rgba(255,107,0,0.25) !important;
    background: rgba(255,255,255,0.9) !important;
    overflow: visible !important;
    user-select: text !important;
}

body.editor-active .element.selected {
    outline: 2px solid #ff6b00;
    box-shadow: 0 0 0 3px rgba(255, 107, 0, 0.25);
}

/* === ЦЕНТРАЛЬНАЯ ЛИНИЯ === */
#center-line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    background: rgba(0, 123, 255, 0.3);
    pointer-events: none;
    display: none;
    z-index: 9999;
}

body.editor-active #center-line {
    display: block;
}

#center-line-label {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: rgba(0, 123, 255, 0.5);
    white-space: nowrap;
    pointer-events: none;
}

#center-line.snap {
    background: rgba(255, 50, 0, 1) !important;
    width: 3px !important;
    box-shadow: 0 0 8px 2px rgba(255, 80, 0, 0.5) !important;
}

/* === ПАНЕЛЬ СВОЙСТВ === */
#properties-panel {
    position: fixed;
    top: 80px;
    right: 16px;
    width: 240px;
    background: rgba(255,255,255,0.97);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.13);
    padding: 14px 16px;
    z-index: 99998;
    display: none;
    flex-direction: column;
    gap: 8px;
    backdrop-filter: blur(8px);
    max-height: calc(100vh - 80px - 140px - 32px);
    padding-bottom: 16px;
    overflow-y: auto;
}

.props-title {
    font-size: 13px;
    font-weight: 700;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.props-subtitle {
    font-size: 11px;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

#properties-panel label {
    font-size: 12px;
    color: #555;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.prop-val {
    font-weight: 700;
    color: #ff6b00;
    font-size: 12px;
}

#properties-panel input[type="range"] {
    width: 100%;
    accent-color: #ff6b00;
    cursor: pointer;
}

#properties-panel input[type="color"] {
    width: 40px;
    height: 28px;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    padding: 0;
}

#properties-panel button {
    width: 100%;
    padding: 8px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    background: #6f42c1;
    color: white;
    transition: background 0.2s;
}

#properties-panel button:hover {
    background: #59359a;
}

#prop-delete-btn {
    background: #dc3545 !important;
    margin-top: 6px;
}

#prop-delete-btn:hover {
    background: #b02a37 !important;
}

/* === ВЫРАВНИВАНИЕ ТЕКСТА === */
.align-btns {
    display: flex;
    gap: 6px;
}

.align-btns .align-btn {
    flex: 1;
    padding: 6px 4px;
    font-size: 16px;
    background: #f0f0f0;
    color: #444;
    border: 2px solid transparent;
    box-shadow: none;
    border-radius: 5px;
    min-width: 36px;
    transition: background 0.15s, border-color 0.15s;
    width: auto;
}

.align-btns .align-btn:hover {
    background: #e0e0e0 !important;
}

.align-btns .align-btn.active {
    border-color: #ff6b00 !important;
    background: #fff3ec !important;
    color: #ff6b00 !important;
}

/* === RESIZE HANDLES === */
.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 2px solid #ff6b00;
    border-radius: 2px;
    z-index: 10000;
    box-sizing: border-box;
}

.resize-handle.tl { top:-5px;  left:-5px;              cursor: nwse-resize; }
.resize-handle.tc { top:-5px;  left:calc(50% - 5px);   cursor: ns-resize;   }
.resize-handle.tr { top:-5px;  right:-5px;              cursor: nesw-resize; }
.resize-handle.ml { top:calc(50% - 5px); left:-5px;    cursor: ew-resize;   }
.resize-handle.mr { top:calc(50% - 5px); right:-5px;   cursor: ew-resize;   }
.resize-handle.bl { bottom:-5px; left:-5px;             cursor: nesw-resize; }
.resize-handle.bc { bottom:-5px; left:calc(50% - 5px); cursor: ns-resize;   }
.resize-handle.br { bottom:-5px; right:-5px;            cursor: nwse-resize; }

body.is-resizing  { user-select: none !important; }
body.is-dragging  {
    user-select: none !important;
    cursor: grabbing !important;
}
body.is-dragging * { cursor: grabbing !important; }

/* === ПАНЕЛЬ РАЗМЕРА САЙТА === */
#height-panel {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 240px;
    background: rgba(255,255,255,0.97);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.13);
    padding: 14px 16px;
    z-index: 99998;
    display: none;
    flex-direction: column;
    gap: 8px;
    backdrop-filter: blur(8px);
}

body.editor-active #height-panel {
    display: flex;
}

#height-panel label {
    font-size: 12px;
    color: #555;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#height-panel input[type="range"] {
    width: 100%;
    accent-color: #007BFF;
    cursor: pointer;
}

/* === DRAG OVER === */
body.drag-over #canvas {
    outline: 3px dashed #007BFF;
    outline-offset: -3px;
}

/* === СЛОИ === */
#layer-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

#layer-controls button {
    flex: 1 1 calc(50% - 4px);
    padding: 5px 4px;
    font-size: 12px;
    background: #2a2a3a;
    color: #ccc;
    border: 1px solid #444;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

#layer-controls button:hover {
    background: #3a3a5a;
    color: #fff;
}

/* Бейдж zIndex */
.element.selected::before {
    content: attr(data-z);
    position: absolute;
    top: -20px;
    left: 0;
    font-size: 10px;
    background: rgba(80,80,200,0.85);
    color: #fff;
    padding: 1px 6px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 99999;
    white-space: nowrap;
}

/* === ВИДЕО КОНТРОЛЫ === */
.video-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 20px 10px 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.75));
    opacity: 0;
    transition: opacity 0.25s ease;
    z-index: 10;
    pointer-events: none;
    border-radius: inherit;
}

.element[data-type="video"]:hover .video-controls {
    opacity: 1;
    pointer-events: auto;
}

.element[data-type="video"].controls-disabled .video-controls {
    display: none !important;
}

.vc-seek-row {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.vc-time, .vc-dur {
    font-size: 11px;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    font-family: monospace;
    flex-shrink: 0;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}

.vc-seek {
    flex: 1;
    height: 4px;
    cursor: pointer;
    border-radius: 2px;
    outline: none;
    border: none;
    appearance: none;
    -webkit-appearance: none;
    background: linear-gradient(
        to right,
        #ff6b00 var(--pct, 0%),
        rgba(255,255,255,0.3) var(--pct, 0%)
    );
}

.vc-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 4px rgba(0,0,0,0.5);
    cursor: pointer;
    transition: transform 0.1s;
}

.vc-seek::-webkit-slider-thumb:hover {
    transform: scale(1.3);
}

.vc-seek::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    border: none;
    cursor: pointer;
}

.vc-bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.vc-bottom-row .vc-play {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.9));
    transition: transform 0.1s;
}

.vc-bottom-row .vc-play:hover {
    transform: scale(1.2);
}

.vc-volume-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow: hidden;
}

.vc-volume-wrap .vc-mute {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.9));
    transition: transform 0.1s;
}

.vc-volume-wrap .vc-mute:hover {
    transform: scale(1.2);
}

.vc-volume {
    width: 0;
    height: 3px;
    cursor: pointer;
    border-radius: 2px;
    outline: none;
    border: none;
    appearance: none;
    -webkit-appearance: none;
    background: rgba(255,255,255,0.4);
    transition: width 0.2s ease, background 0.2s;
    flex-shrink: 0;
}

.vc-volume-wrap:hover .vc-volume {
    width: 60px;
    background: linear-gradient(
        to right,
        #fff calc(var(--pct, 100%) * 1%),
        rgba(255,255,255,0.3) calc(var(--pct, 100%) * 1%)
    );
}

.vc-volume::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 3px rgba(0,0,0,0.5);
    cursor: pointer;
}

.vc-volume::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    border: none;
    cursor: pointer;
}

/* ============================================
   КНОПКА РЕДАКТОРА — левый нижний угол
   ============================================ */
#edit-mode-btn {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: #007BFF;
    color: white;
    font-size: 22px;
    cursor: pointer;
    z-index: 999999;
    box-shadow: 0 4px 16px rgba(0,0,0,0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    line-height: 1;
    padding: 0;
}

#edit-mode-btn:hover {
    background: #0056cc;
    transform: scale(1.1);
}

/* В режиме редактора — зелёная, чуть выше панели инструментов */
body.editor-active #edit-mode-btn {
    background: #28a745;
    bottom: 24px;
    left: 24px;
}

/* ============================================
   ПАНЕЛЬ ИНСТРУМЕНТОВ — левая сторона, вертикально
   ============================================ */
#editor-panel {
    position: fixed;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    display: none;
    flex-direction: column;
    gap: 8px;
    z-index: 99999;
}

#editor-panel button {
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
    text-align: left;
}

#editor-panel button:hover {
    transform: translateX(3px);
    filter: brightness(1.15);
}

#editor-panel #add-text-btn        { background: #28a745; }
#editor-panel #add-text-btn:hover  { background: #1e7e34; }

#editor-panel #add-lottie-btn       { background: #6f42c1; }
#editor-panel #add-lottie-btn:hover { background: #59359a; }

#editor-panel #add-button-btn       { background: #17a2b8; }
#editor-panel #add-button-btn:hover { background: #117a8b; }

#editor-panel #download-site-btn       { background: #fd7e14; }
#editor-panel #download-site-btn:hover { background: #e06b0a; }

#editor-panel #clear-draft-btn       { background: #dc3545; }
#editor-panel #clear-draft-btn:hover { background: #b02a37; }

/* === ЛОГОТИП РЕДАКТОРА (правый верхний угол) === */
#editor-brand {
    position: fixed;
    top: 16px;
    right: 30px;
    text-align: right;
    z-index: 999999;
    display: none;
    pointer-events: none;
    user-select: none;
}

body.editor-active #editor-brand {
    display: block;
}

#editor-brand .brand-name {
    font-size: 28px;
    font-weight: 800;
    color: rgba(0, 0, 0, 0.25);
    letter-spacing: 0.04em;
    line-height: 1;
    font-family: sans-serif;
}

#editor-brand .brand-version {
    font-size: 11px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.25);
    letter-spacing: 0.06em;
    line-height: 1.4;
}