/* ==========================================================================
   Speedy Admin — Fullscreen template designer (#/templates/edit)
   Uses the shared theme tokens; flat surfaces, dark/light proof.
   ========================================================================== */

.tpl-editor {
    display: flex;
    flex-direction: column;
    /* Fill the view area below the topbar */
    height: calc(100vh - var(--topbar-h) - 32px);
    min-height: 480px;
    gap: 12px;
}

/* ---- Topbar ---- */
.tpl-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
}

.tpl-topbar-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 14px;
}

.tpl-topbar-title strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.tpl-topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.tabs-compact .tab {
    padding: 5px 12px;
    font-size: 12.5px;
}

/* Locale tabs */
.tpl-locales {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.tpl-locale {
    border: none;
    background: transparent;
    color: var(--text-2);
    font: 600 12px var(--font);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.tpl-locale:hover { color: var(--text); }

.tpl-locale.active {
    background: var(--primary);
    color: #ffffff;
}

/* ---- Body: left panel + preview ---- */
.tpl-body {
    display: flex;
    gap: 12px;
    flex: 1;
    min-height: 0;
}

.tpl-left {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 420px;
    min-width: 340px;
    overflow-y: auto;
}

.tpl-panel-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    margin-bottom: 8px;
}

.tpl-blocks,
.tpl-inspector,
.tpl-code {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    position: relative;
}

/* ---- Block list ---- */
.tpl-block-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tpl-block-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
    user-select: none;
    transition: border-color var(--transition), background var(--transition);
}

.tpl-block-item:hover { border-color: var(--border-strong); }

.tpl-block-item.active {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.tpl-block-item.dragging { opacity: 0.45; }

.tpl-block-item.drop-above { box-shadow: 0 -2px 0 0 var(--primary); }
.tpl-block-item.drop-below { box-shadow: 0 2px 0 0 var(--primary); }

.tpl-drag {
    color: var(--text-3);
    cursor: grab;
    font-size: 11px;
    letter-spacing: -2px;
}

.tpl-block-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.tpl-block-sub {
    font-size: 12px;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.tpl-block-actions {
    display: none;
    gap: 2px;
}

.tpl-block-item:hover .tpl-block-actions { display: flex; }

.tpl-mini {
    border: none;
    background: transparent;
    color: var(--text-3);
    font-size: 12px;
    padding: 2px 5px;
    border-radius: 4px;
    cursor: pointer;
}

.tpl-mini:hover { background: var(--surface-3); color: var(--text); }
.tpl-mini.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---- Palette ---- */
.tpl-palette {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 54px;
    z-index: 20;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    max-height: 320px;
    overflow-y: auto;
}

.tpl-palette-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    border: 1px solid transparent;
    background: transparent;
    text-align: left;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text);
    font: 600 12.5px var(--font);
}

.tpl-palette-item span {
    font-weight: 400;
    font-size: 11.5px;
    color: var(--text-3);
}

.tpl-palette-item:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}

/* ---- Inspector ---- */
.tpl-inspector .field { margin-bottom: 12px; }

.tpl-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin: 0 0 10px;
    cursor: pointer;
    user-select: none;
}

.tpl-color-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tpl-color-row input[type="color"] {
    width: 42px;
    height: 30px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
}

.tpl-color-row select { flex: 1; }

.tpl-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 6px;
}

.tpl-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.tpl-row input { flex: 1; min-width: 0; }

/* ---- Variable chips ---- */
.tpl-vars { margin-top: 14px; }

.tpl-var-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tpl-chip {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    font: 500 11px var(--mono);
    padding: 3px 7px;
    border-radius: 999px;
    cursor: pointer;
    transition: border-color var(--transition), color var(--transition);
}

.tpl-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ---- Code mode ---- */
.tpl-code {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.tpl-code textarea#te-code {
    flex: 1;
    min-height: 320px;
    resize: vertical;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.55;
    white-space: pre;
    tab-size: 2;
}

/* ---- Preview ---- */
.tpl-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.tpl-preview-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 12.5px;
}

.tpl-subject {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.tpl-preview-frame {
    flex: 1;
    background: var(--surface-3);
}

.tpl-preview-frame iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #ffffff;
}

/* ---- Responsive ---- */
@media (max-width: 1080px) {
    .tpl-editor { height: auto; }
    .tpl-body { flex-direction: column; }
    .tpl-left { width: 100%; min-width: 0; }
    .tpl-preview { min-height: 540px; }
}
