/* ═══════════════════════════════════════════════════════════════════════
   Theme Manager Admin -- Overlay + Editor + Mini Card
   ═══════════════════════════════════════════════════════════════════════ */

/* -- Overlay ----------------------------------------------------------- */
.tm-overlay-wrap {
    position: fixed; inset: 0; z-index: 9000;
    background: var(--bg-overlay);
    display: flex; align-items: center; justify-content: center;
    animation: tm-fade-in 0.2s ease;
}
@keyframes tm-fade-in { from { opacity: 0; } to { opacity: 1; } }

.tm-panel {
    width: 92vw; max-width: 960px; max-height: 88vh;
    min-width: 360px; min-height: 300px;
    background: var(--bg-base);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg, 14px);
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: tm-slide-up 0.25s ease;
    overflow: hidden;
    resize: both;
    position: relative;
}
.tm-panel::after {
    content: '';
    position: absolute; bottom: 2px; right: 2px;
    width: 14px; height: 14px;
    background:
        linear-gradient(135deg, transparent 50%, var(--text-muted) 50%, var(--text-muted) 55%, transparent 55%),
        linear-gradient(135deg, transparent 65%, var(--text-muted) 65%, var(--text-muted) 70%, transparent 70%),
        linear-gradient(135deg, transparent 80%, var(--text-muted) 80%, var(--text-muted) 85%, transparent 85%);
    opacity: 0.3;
    pointer-events: none;
    z-index: 10;
    border-radius: 0 0 var(--radius-lg, 14px) 0;
}
@keyframes tm-slide-up { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.tm-closing { animation: tm-slide-down 0.2s ease forwards; }
@keyframes tm-slide-down { to { opacity: 0; transform: translateY(20px); } }

/* -- Header ------------------------------------------------------------ */
.tm-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
}
.tm-header:active { cursor: grabbing; }
.tm-header-left {
    display: flex; align-items: center; gap: 0.5rem;
}
.tm-header-icon {
    width: 34px; height: 34px; border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-teal));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 14px;
}
.tm-header-left h2 {
    font-size: var(--text-md); font-weight: var(--weight-bold);
    margin: 0; color: var(--text-primary);
}
.tm-badge {
    font-size: 11px; font-weight: 700;
    background: var(--accent-purple-dim, rgba(139,92,246,0.12));
    color: var(--accent-purple);
    padding: 2px 7px; border-radius: 10px;
}
.tm-header-actions { display: flex; gap: 0.35rem; }

.tm-icon-btn {
    width: 32px; height: 32px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle); background: transparent;
    color: var(--text-secondary); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; transition: all 0.15s;
}
.tm-icon-btn:hover { background: var(--bg-surface); color: var(--text-primary); }
.tm-close-btn:hover { color: var(--color-danger); border-color: var(--color-danger-dim); }

/* -- Body / Theme Grid ------------------------------------------------- */
.tm-body {
    flex: 1; overflow-y: auto; padding: 1rem 1.25rem;
}
.tm-loading {
    text-align: center; padding: 3rem 1rem;
    color: var(--text-muted); font-size: var(--text-sm);
}
.tm-empty {
    text-align: center; padding: 3rem 1rem;
    color: var(--text-muted);
}
.tm-empty i { font-size: 2.5rem; margin-bottom: 0.75rem; display: block; color: var(--accent-purple); opacity: 0.5; }
.tm-empty p { font-size: var(--text-sm); max-width: 340px; margin: 0 auto; line-height: 1.6; }

.tm-grid {
    display: grid; grid-template-columns: 1fr;
    gap: 0.65rem;
}

/* -- Theme Card -------------------------------------------------------- */
.tm-card {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    transition: all 0.15s;
}
.tm-card:hover { border-color: var(--border-default); background: var(--bg-elevated); }
.tm-card-active { border-color: var(--accent-teal) !important; box-shadow: 0 0 0 1px var(--accent-teal); }
.tm-card-unpublished { opacity: 0.65; }
.tm-card-unpublished:hover { opacity: 1; }

.tm-card-swatch {
    width: 48px; height: 48px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    position: relative; flex-shrink: 0; font-size: 18px;
}
.tm-card-accent-dot {
    position: absolute; top: 4px; right: 4px;
    width: 10px; height: 10px; border-radius: 50%;
    border: 1.5px solid var(--bg-surface);
}

.tm-card-info { flex: 1; min-width: 0; }
.tm-card-name {
    font-size: var(--text-sm); font-weight: var(--weight-semibold);
    color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tm-card-meta {
    display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
    margin-top: 2px;
}
.tm-card-slug {
    font-size: 11px; color: var(--text-muted);
    font-family: var(--font-mono, monospace);
}
.tm-tag {
    font-size: 9px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.4px; padding: 1px 6px; border-radius: 6px;
}
.tm-tag-builtin { background: var(--accent-purple-dim); color: var(--accent-purple); }
.tm-tag-custom { background: var(--accent-cyan-dim); color: var(--accent-cyan); }
.tm-tag-pub { background: var(--color-profit-dim); color: var(--accent-teal); }
.tm-tag-unpub { background: var(--bg-hover); color: var(--text-muted); }

.tm-card-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.tm-card-btn {
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle); background: transparent;
    color: var(--text-muted); cursor: pointer; font-size: 11px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.tm-card-btn:hover { background: var(--bg-base); color: var(--text-primary); }
.tm-card-delete:hover { color: var(--color-danger); border-color: var(--color-danger-dim); }
.tm-card-publish:hover { color: var(--accent-teal); border-color: var(--accent-teal); }
.tm-card-duplicate:hover { color: var(--accent-cyan); border-color: var(--accent-cyan); }

/* -- Editor ------------------------------------------------------------ */
.tm-editor {
    flex: 1; overflow-y: auto; display: flex; flex-direction: column;
}
.tm-editor-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}
.tm-editor-header h3 {
    margin: 0; font-size: var(--text-md); font-weight: var(--weight-bold);
    color: var(--text-primary);
}
.tm-editor-actions { display: flex; gap: 0.5rem; }

.tm-btn {
    padding: 0.45rem 0.85rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle); font-size: 12px;
    font-weight: 600; cursor: pointer; transition: all 0.15s;
    display: inline-flex; align-items: center; gap: 0.35rem;
}
.tm-btn-ghost {
    background: transparent; color: var(--text-secondary);
}
.tm-btn-ghost:hover { background: var(--bg-surface); color: var(--text-primary); }
.tm-btn-primary {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-teal));
    border: none; color: #fff;
}
.tm-btn-primary:hover { filter: brightness(1.1); }

.tm-editor-body {
    flex: 1; overflow-y: auto; padding: 1rem 1.25rem;
    display: flex; flex-direction: column; gap: 1.25rem;
}

/* -- Meta form --------------------------------------------------------- */
.tm-editor-meta {
    padding: 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}
.tm-form-row {
    display: grid; grid-template-columns: 1fr 1fr 1fr 80px;
    gap: 0.75rem; margin-bottom: 0.75rem;
}
.tm-form-group label {
    display: block; font-size: 11px; font-weight: 600;
    color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.3px; margin-bottom: 4px;
}
.tm-input {
    width: 100%; padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
    background: var(--bg-base); color: var(--text-primary);
    font-size: 13px; font-family: inherit;
    transition: border-color 0.15s;
    box-sizing: border-box;
}
.tm-input:focus { border-color: var(--accent-purple); outline: none; }
.tm-input:disabled { opacity: 0.5; cursor: not-allowed; }

.tm-toggle-label {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 13px; color: var(--text-secondary); cursor: pointer;
}
.tm-toggle-label input[type="checkbox"] {
    accent-color: var(--accent-teal);
    width: 16px; height: 16px;
}

/* -- Color Groups ------------------------------------------------------ */
.tm-color-groups {
    display: flex; flex-direction: column; gap: 0.85rem;
}
.tm-color-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
}
.tm-color-section-title {
    font-size: 12px; font-weight: 700; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.4px;
    margin-bottom: 0.65rem;
    display: flex; align-items: center; gap: 0.4rem;
}
.tm-color-section-title i { font-size: 11px; color: var(--accent-purple); }
.tm-color-rows { display: flex; flex-direction: column; gap: 0.35rem; }

.tm-color-row {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.3rem 0.4rem;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
}
.tm-color-row:hover { background: var(--bg-elevated); }
.tm-color-label {
    flex: 0 0 110px;
    font-size: 12px; font-weight: 600; color: var(--text-primary);
}
.tm-color-prop {
    flex: 1;
    font-size: 10.5px; color: var(--text-muted);
    font-family: var(--font-mono, monospace);
}
.tm-color-picker {
    width: 32px; height: 28px; border: 1px solid var(--border-subtle);
    border-radius: 4px; cursor: pointer; padding: 1px;
    background: transparent;
}
.tm-color-picker::-webkit-color-swatch-wrapper { padding: 1px; }
.tm-color-picker::-webkit-color-swatch { border-radius: 3px; border: none; }
.tm-color-reset {
    width: 24px; height: 24px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; font-size: 10px;
    border-radius: var(--radius-sm); transition: all 0.15s;
    display: inline-flex; align-items: center; justify-content: center;
}
.tm-color-reset:hover { color: var(--accent-amber); background: var(--bg-surface); }

/* -- Range Sliders (Spacing / Radius / Typography) ---------------------- */
.tm-range-slider {
    flex: 1; max-width: 140px; height: 4px;
    -webkit-appearance: none; appearance: none;
    background: var(--bg-elevated);
    border-radius: 2px; cursor: pointer;
    outline: none;
}
.tm-range-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent-teal);
    border: 2px solid var(--bg-base);
    box-shadow: 0 0 4px var(--accent-teal-dim);
    cursor: pointer;
}
.tm-range-slider::-moz-range-thumb {
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent-teal);
    border: 2px solid var(--bg-base);
    box-shadow: 0 0 4px var(--accent-teal-dim);
    cursor: pointer;
}
.tm-range-val {
    font-size: 11px; font-weight: 600;
    color: var(--text-secondary);
    font-family: var(--font-mono, monospace);
    min-width: 48px; text-align: right;
}

/* -- Preview Pane ------------------------------------------------------ */
.tm-preview-pane {
    padding: 0.65rem 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    text-align: center;
}
.tm-preview-label {
    font-size: 11px; font-weight: 700; color: var(--accent-teal);
    text-transform: uppercase; letter-spacing: 0.4px;
    display: flex; align-items: center; justify-content: center; gap: 0.35rem;
    margin-bottom: 0.25rem;
}
.tm-preview-hint {
    font-size: 11px; color: var(--text-muted);
}

/* -- Mini Card --------------------------------------------------------- */
.tm-mini-card {
    position: fixed; bottom: 20px; right: 20px; z-index: 9100;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    background: var(--bg-surface, #111827);
    border: 1px solid var(--border-default, #2d3548);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    width: 260px;
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    transition: opacity 0.25s ease-out, transform 0.25s ease-out, border-color 0.3s;
    cursor: default;
}
.tm-mini-card.tm-mini-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.tm-mini-icon {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px;
    background: var(--accent-purple-dim, rgba(168, 85, 247, 0.12));
    color: var(--accent-purple, #a855f7);
    font-size: 1rem; flex-shrink: 0; cursor: pointer;
}
.tm-mini-info { flex: 1; min-width: 0; cursor: pointer; }
.tm-mini-title { font-size: 0.82rem; font-weight: 600; color: var(--text-primary, #e0e0e0); line-height: 1.2; }
.tm-mini-status { font-size: 0.72rem; font-weight: 600; margin-top: 2px; }
.tm-mini-actions { display: flex; gap: 4px; flex-shrink: 0; }
.tm-mini-btn {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border-default, #2d3548); border-radius: 6px;
    background: transparent; color: var(--text-secondary, #94a3b8);
    font-size: 0.78rem; cursor: pointer; transition: all 0.15s;
}
.tm-mini-btn:hover { border-color: var(--accent-purple, #a855f7); color: var(--text-primary, #e0e0e0); }
.tm-mini-close:hover { border-color: var(--color-danger, #ef4444); color: var(--color-danger, #ef4444); }

/* -- Responsive -------------------------------------------------------- */
@media (max-width: 720px) {
    .tm-panel { width: 96vw; max-height: 92vh; }
    .tm-form-row { grid-template-columns: 1fr 1fr; }
    .tm-color-label { flex: 0 0 80px; }
    .tm-color-prop { display: none; }
}
@media (max-width: 480px) {
    .tm-form-row { grid-template-columns: 1fr; }
    .tm-card { flex-wrap: wrap; }
    .tm-card-actions { width: 100%; justify-content: flex-end; }
}
