/* ====================================
   TEXT PANEL - Left Side
   ==================================== */

.cdp-text-panel {
    position: fixed;
    top: 0;
    left: -420px;
    width: 420px;
    height: 100vh;
    background: #ffffff;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.15);
    z-index: 11000;
    transition: left 0.3s ease;
}

.cdp-text-panel[data-visible="true"] {
    left: 72px;
}

.cdp-text-panel-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.cdp-text-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}

.cdp-text-panel-header h3 {
    font-size: calc(var(--cdp-font-scale, 1) * 18px);
    font-weight: 600;
    color: #111827;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.cdp-text-header-actions {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.cdp-text-round-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: #ffffff;
    color: #111827;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 8px rgba(15, 23, 42, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cdp-text-round-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.25);
}

.cdp-text-round-btn i {
    font-size: calc(var(--cdp-font-scale, 1) * 16px);
    color: inherit;
}

.cdp-text-panel-close {
    width: 38px;
    height: 38px;
    background: none;
    box-shadow: none;
}

/* Body */
.cdp-text-panel-body {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.cdp-text-group {
    margin-bottom: 24px;
}

.cdp-text-group label {
    display: block;
    font-size: calc(var(--cdp-font-scale, 1) * 14px);
    font-weight: 600;
    color: #374151;
    margin-bottom: 10px;
}

/* Text Input */
.cdp-text-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: calc(var(--cdp-font-scale, 1) * 16px);
    color: #111827;
    transition: all 0.2s;
}

.cdp-text-input:focus {
    outline: none;
    border-color: #d9a300;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Font Scroll */
.cdp-text-font-scroll {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px;
}

.cdp-text-font-item {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 6px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #ffffff;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}

.cdp-text-font-item:hover {
    border-color: #d9a300;
    background: #eff6ff;
}

.cdp-text-font-item.active {
    border-color: #d9a300;
    background: #dbeafe;
}

.cdp-text-font-label {
    font-size: calc(var(--cdp-font-scale, 1) * 13px);
    font-weight: 600;
    color: #374151;
    margin-bottom: 4px;
}

.cdp-text-font-preview {
    font-size: calc(var(--cdp-font-scale, 1) * 20px);
    color: #111827;
}

/* Size Row */
.cdp-text-size-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

#cdpTextSizeSlider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
    outline: none;
    -webkit-appearance: none;
}

#cdpTextSizeSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #d9a300;
    cursor: pointer;
}

#cdpTextSizeValue {
    font-size: calc(var(--cdp-font-scale, 1) * 14px);
    font-weight: 600;
    color: #374151;
    min-width: 50px;
    text-align: right;
}

/* Color Row */
.cdp-text-color-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

#cdpTextColorPicker {
    width: 60px;
    height: 40px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
}

#cdpTextColorHex {
    font-size: calc(var(--cdp-font-scale, 1) * 14px);
    font-weight: 600;
    color: #374151;
    font-family: 'Courier New', monospace;
}

/* Style Buttons */
.cdp-text-style-buttons {
    display: flex;
    gap: 8px;
}

.cdp-text-style-btn {
    width: 44px;
    height: 44px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #ffffff;
    color: #6b7280;
    font-size: calc(var(--cdp-font-scale, 1) * 18px);
    cursor: pointer;
    transition: all 0.2s;
}

.cdp-text-style-btn:hover {
    border-color: #d9a300;
    background: #eff6ff;
    color: #d9a300;
}

.cdp-text-style-btn.active {
    border-color: #d9a300;
    background: #d9a300;
    color: #ffffff;
}

/* Transform Buttons */
.cdp-text-transform-buttons {
    display: flex;
    gap: 8px;
}

.cdp-text-transform-btn {
    flex: 1;
    padding: 8px 16px;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    font-size: calc(var(--cdp-font-scale, 1) * 18px);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cdp-text-transform-btn:hover {
    background: #e5e7eb;
    border-color: #d9a300;
}

.cdp-text-transform-btn:active {
    background: #d1d5db;
}

/* Footer */
.cdp-text-panel-footer {
    padding: 20px 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
}

.cdp-text-btn {
    flex: 1;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: calc(var(--cdp-font-scale, 1) * 15px);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.cdp-text-btn--cancel {
    background: #f3f4f6;
    color: #374151;
}

.cdp-text-btn--cancel:hover {
    background: #e5e7eb;
}

.cdp-text-btn--apply {
    background: #d9a300;
    color: #ffffff;
}

.cdp-text-btn--apply:hover {
    background: #d8a712;
}

/* Text Element on Canvas */
.cdp-text-element {
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    cursor: grab !important;
}

.cdp-text-element:active {
    cursor: grabbing !important;
}

.cdp-text-element:hover {
    outline: 2px dashed #d9a300;
    outline-offset: 4px;
}

/* Resize Handle */
.cdp-text-resize-handle {
    position: absolute;
    bottom: -10px;
    right: -10px;
    width: 24px;
    height: 24px;
    background: #d9a300;
    border: 2px solid white;
    border-radius: 50%;
    cursor: nwse-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: calc(var(--cdp-font-scale, 1) * 11px);
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.cdp-text-element:hover .cdp-text-resize-handle {
    opacity: 1;
}

.cdp-text-tutorial-toast {
    position: fixed;
    bottom: 32px;
    right: 32px;
    background: rgba(17, 24, 39, 0.95);
    color: #f3f4f6;
    padding: 14px 20px;
    border-radius: 999px;
    font-size: calc(var(--cdp-font-scale, 1) * 14px);
    font-weight: 600;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25);
    z-index: 200000;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.cdp-text-tutorial-toast[data-visible="true"] {
    opacity: 1;
    transform: translateY(0);
}

/* ====================================
   Responsive Behaviour
   ==================================== */

@media (max-width: 1024px) {
    .cdp-text-panel {
        width: min(420px, 90vw);
        left: -420px;
    }

    .cdp-text-panel[data-visible="true"] {
        left: 0;
    }
}

@media (max-width: 768px) {
    .cdp-text-panel {
        top: 8px;
        bottom: calc(env(safe-area-inset-bottom) + 8px);
        width: min(78vw, 320px);
        left: -100vw;
        height: auto;
        max-height: calc(100dvh - 16px - env(safe-area-inset-bottom));
        border-radius: 0 18px 18px 0;
        overflow: hidden;
    }

    .cdp-text-panel[data-visible="true"] {
        left: 0;
    }

    .cdp-text-panel-header,
    .cdp-text-panel-footer {
        padding: 16px;
    }

    .cdp-text-panel-body {
        padding: 16px;
    }

    .cdp-text-size-row,
    .cdp-text-color-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .cdp-text-style-buttons,
    .cdp-text-transform-buttons {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .cdp-text-panel-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .cdp-text-header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .cdp-text-panel-footer {
        flex-direction: row;
        align-items: center;
    }

    .cdp-text-btn {
        width: auto;
        flex: 1 1 0;
    }
}

@media (max-width: 768px) {
    .cdp-text-panel {
        height: auto;
        max-height: calc(100dvh - 16px - env(safe-area-inset-bottom));
    }

    .cdp-text-panel-header {
        padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
    }

    .cdp-text-panel-body {
        padding: 10px 12px 12px;
        min-height: 0;
    }

    .cdp-text-panel-footer {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        position: static;
        background: #ffffff;
        z-index: 2;
        margin-top: auto;
        flex-shrink: 0;
    }

    .cdp-text-font-scroll {
        max-height: min(28vh, 240px);
    }
}

@media (max-width: 480px) {
    .cdp-text-panel {
        width: min(74vw, 292px);
        top: 6px;
        bottom: calc(env(safe-area-inset-bottom) + 6px);
        height: auto;
        max-height: calc(100dvh - 12px - env(safe-area-inset-bottom));
    }

    .cdp-text-font-preview {
        font-size: calc(var(--cdp-font-scale, 1) * 16px);
    }

    .cdp-text-input,
    .cdp-text-font-item,
    .cdp-text-btn {
        font-size: calc(var(--cdp-font-scale, 1) * 14px);
    }

    .cdp-text-panel-footer {
        gap: 8px;
    }

    .cdp-text-btn {
        padding: 10px 16px;
        min-height: 44px;
        border-radius: 7px;
        font-size: calc(var(--cdp-font-scale, 1) * 12px);
    }

    .cdp-text-panel-header h3 {
        font-size: calc(var(--cdp-font-scale, 1) * 16px);
    }
}

/* ============================================
   DARK MODE — NEW Add Text Panel
   ============================================ */

body.dark-mode .cdp-text-panel {
    background: #000 !important;
    border-color: #333 !important;
}

body.dark-mode .cdp-text-panel-header {
    background: #111 !important;
    border-bottom: 1px solid #222 !important;
}

body.dark-mode .cdp-text-panel-header h3 {
    color: #fff !important;
}

body.dark-mode .cdp-text-panel-close {
    color: #ccc !important;
}

body.dark-mode .cdp-text-panel-close:hover {
    background: #222 !important;
    color: #fff !important;
}

body.dark-mode .cdp-text-round-btn {
    background: #1f2937;
    color: #f8fafc;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}

body.dark-mode .cdp-text-tutorial-toast {
    background: rgba(15, 23, 42, 0.98);
    color: #fbbf24;
}

body.dark-mode .cdp-text-panel-body {
    background: #000 !important;
    color: #fff !important;
}

body.dark-mode .cdp-text-group label {
    color: #fff !important;
}

/* input box */
body.dark-mode .cdp-text-input {
    background: #111 !important;
    color: #fff !important;
    border-color: #444 !important;
}

/* font list */
body.dark-mode .cdp-text-font-scroll {
    background: #111 !important;
    border-color: #444 !important;
}

body.dark-mode .cdp-text-font-item {
    background: #111 !important;
    border-color: #444 !important;
    color: #fff !important;
}

body.dark-mode .cdp-text-font-item.active {
    background: #1a2f44 !important;
    border-color: #d9a300 !important;
}

body.dark-mode .cdp-text-font-preview {
    color: #fff !important;
}

/* footer buttons */
body.dark-mode .cdp-text-btn--cancel {
    background: #222 !important;
    color: #fff !important;
}

body.dark-mode .cdp-text-btn--apply {
    background: #d9a300 !important;
    color: #fff !important;
}
