/**
 * SMS Template Editor Styles
 */

/* ═══════════════════════════════════════════════════════════════════
   TEMPLATE EDITOR MODAL
   ═══════════════════════════════════════════════════════════════════ */

#template-editor-modal {
    position: fixed;
    inset: 0;
    z-index: 1080;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 20px;
}

#template-editor-modal.hidden {
    display: none !important;
}

.template-editor-body {
    display: flex;
    gap: 20px;
    min-height: 400px;
}

.template-editor-main {
    flex: 1;
    min-width: 0;
}

.template-editor-sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--card-bg, #f8f9fa);
    border-radius: 8px;
    padding: 15px;
    max-height: 500px;
    overflow-y: auto;
}

.template-editor-sidebar h4 {
    margin: 0 0 5px 0;
    font-size: 14px;
    font-weight: 600;
}

.template-editor-sidebar .help-text {
    font-size: 12px;
    color: var(--text-muted, #6c757d);
    margin: 0 0 15px 0;
}

/* Variable Picker */
.var-picker-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.var-group h5 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #6c757d);
    margin: 0 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color, #dee2e6);
}

.var-btn {
    display: inline-block;
    background: var(--badge-bg, #e9ecef);
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary, #212529);
    cursor: pointer;
    transition: all 0.15s ease;
    margin: 2px;
}

.var-btn:hover {
    background: var(--primary-light, #e7f1ff);
    border-color: var(--primary, #0066ff);
    color: var(--primary, #0066ff);
}

.var-btn:active {
    transform: scale(0.95);
}

/* Preview Box */
.tpl-preview-box {
    background: var(--card-bg, #f8f9fa);
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 8px;
    padding: 15px;
    min-height: 80px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.tpl-preview-box em {
    color: var(--text-muted, #6c757d);
}

.tpl-preview-box .var-missing {
    background: #fff3cd;
    color: #856404;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

/* Character Count */
.tpl-char-count {
    text-align: right;
    font-size: 12px;
    color: var(--text-muted, #6c757d);
    margin-top: 5px;
}

.tpl-char-count.warning {
    color: #f59e0b;
}

.tpl-char-count.over {
    color: #ef4444;
    font-weight: 600;
}

/* Form Row for side-by-side inputs */
.form-row {
    display: flex;
    gap: 15px;
}

.form-group-half {
    flex: 1;
}

/* ═══════════════════════════════════════════════════════════════════
   CONTEXT MENU
   ═══════════════════════════════════════════════════════════════════ */

.context-menu {
    position: fixed;
    z-index: 2000;
    min-width: 160px;
    background: var(--dropdown-bg, #ffffff);
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 6px 0;
    font-size: 13px;
}

.context-menu-item {
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s ease;
}

.context-menu-item:hover {
    background: var(--hover-bg, #f8f9fa);
}

.context-menu-item.context-menu-danger {
    color: #dc3545;
}

.context-menu-item.context-menu-danger:hover {
    background: #fee2e2;
}

.context-menu-divider {
    height: 1px;
    background: var(--border-color, #dee2e6);
    margin: 6px 0;
}

/* ═══════════════════════════════════════════════════════════════════
   TEMPLATE ADMIN SECTION
   ═══════════════════════════════════════════════════════════════════ */

.template-admin-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px dashed var(--border-color, #dee2e6);
    text-align: center;
}

.template-admin-section .btn-sm {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ═══════════════════════════════════════════════════════════════════
   TEMPLATE ITEMS ENHANCEMENTS
   ═══════════════════════════════════════════════════════════════════ */

.template-item {
    position: relative;
    cursor: pointer;
}

.template-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.template-item::after {
    content: '';
    position: absolute;
    top: 5px;
    right: 5px;
    width: 18px;
    height: 18px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236c757d' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='1'/%3E%3Ccircle cx='12' cy='5' r='1'/%3E%3Ccircle cx='12' cy='19' r='1'/%3E%3C/svg%3E") no-repeat center;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.template-item:hover::after {
    opacity: 0.5;
}

/* ═══════════════════════════════════════════════════════════════════
   MODAL SIZE VARIANT
   ═══════════════════════════════════════════════════════════════════ */

.modal-container.modal-lg {
    max-width: 900px;
    width: 95%;
}

/* ═══════════════════════════════════════════════════════════════════
   DARK MODE
   ═══════════════════════════════════════════════════════════════════ */

[data-theme="dark"] .template-editor-sidebar {
    background: var(--card-bg, #1e1e2e);
}

[data-theme="dark"] .var-btn {
    background: var(--badge-bg, #2a2a3e);
    border-color: var(--border-color, #3a3a4e);
    color: var(--text-primary, #e4e4e7);
}

[data-theme="dark"] .var-btn:hover {
    background: var(--primary-dark, #1a3a6e);
    border-color: var(--primary, #3b82f6);
    color: var(--primary-light, #93c5fd);
}

[data-theme="dark"] .tpl-preview-box {
    background: var(--card-bg, #1e1e2e);
    border-color: var(--border-color, #3a3a4e);
}

[data-theme="dark"] .tpl-preview-box .var-missing {
    background: #422006;
    color: #fbbf24;
}

[data-theme="dark"] .context-menu {
    background: var(--dropdown-bg, #1e1e2e);
    border-color: var(--border-color, #3a3a4e);
}

[data-theme="dark"] .context-menu-item:hover {
    background: var(--hover-bg, #2a2a3e);
}

[data-theme="dark"] .context-menu-item.context-menu-danger:hover {
    background: #450a0a;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .template-editor-body {
        flex-direction: column;
    }
    
    .template-editor-sidebar {
        width: 100%;
        max-height: 200px;
    }
    
    .modal-container.modal-lg {
        max-width: 100%;
        width: 100%;
        margin: 0;
        border-radius: 0;
        height: 100vh;
    }
}

/* ═══════════════════════════════════════════════════════════════════
   TEMPLATE DESCRIPTION TOOLTIP
   ═══════════════════════════════════════════════════════════════════ */

.template-tooltip {
    position: fixed;
    z-index: 9999;
    background: var(--tooltip-bg, #1a1a2e);
    color: var(--tooltip-text, #fff);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    max-width: 280px;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    animation: tooltipFadeIn 0.15s ease-out;
}

.template-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 20px;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid var(--tooltip-bg, #1a1a2e);
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
