/* ========================================
   Email Template Previewer — Styles
   Premium dark theme with glassmorphism
   ======================================== */

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #6C63FF;
    --primary-hover: #7B73FF;
    --primary-glow: rgba(108, 99, 255, 0.25);
    --accent: #A855F7;
    --accent-hover: #B96BFF;
    --success: #22C55E;
    --warning: #F59E0B;
    --error: #EF4444;
    --info: #3B82F6;

    --bg-root: #0A0A0F;
    --bg-surface: #111118;
    --bg-elevated: #1A1A24;
    --bg-card: rgba(26, 26, 36, 0.8);
    --bg-hover: rgba(108, 99, 255, 0.08);

    --border: rgba(255, 255, 255, 0.06);
    --border-active: rgba(108, 99, 255, 0.4);

    --text-primary: #F1F1F4;
    --text-secondary: #9CA3AF;
    --text-tertiary: #6B7280;
    --text-inverse: #111118;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--primary-glow);

    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-smooth: 350ms cubic-bezier(0.4, 0, 0.2, 1);

    --toolbar-h: 56px;
    --panel-header-h: 40px;
}

html {
    height: 100%;
    font-size: 14px;
}

body {
    height: 100%;
    font-family: var(--font-body);
    background: var(--bg-root);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--toolbar-h);
    padding: 0 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-shrink: 0;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-right {
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo h1 {
    font-size: 1rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

/* ---------- Client Presets ---------- */
.client-presets {
    display: flex;
    gap: 4px;
    padding: 3px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.preset-btn {
    padding: 5px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.preset-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.preset-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px var(--primary-glow);
}

/* ---------- Device Preview Buttons ---------- */
.responsive-toggles {
    display: flex;
    gap: 2px;
    padding: 3px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.device-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.device-btn:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.device-btn.active {
    color: var(--primary);
    background: rgba(108, 99, 255, 0.12);
}

/* ---------- Toolbar Actions ---------- */
.toolbar-actions {
    display: flex;
    gap: 6px;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.action-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-active);
    background: var(--bg-hover);
    transform: translateY(-1px);
}

.action-btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    border: none;
}

.action-btn.primary:hover {
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

/* ---------- Workspace ---------- */
.workspace {
    display: flex;
    height: calc(100vh - var(--toolbar-h));
    overflow: hidden;
}

/* ---------- Editor Panel ---------- */
.editor-panel {
    display: flex;
    flex-direction: column;
    width: 45%;
    min-width: 300px;
    border-right: 1px solid var(--border);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--panel-header-h);
    padding: 0 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab-bar {
    display: flex;
    gap: 2px;
}

.tab {
    padding: 4px 16px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    position: relative;
}

.tab:hover {
    color: var(--text-secondary);
}

.tab.active {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 2px;
    background: var(--primary);
    border-radius: 1px;
}

.editor-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* ---------- Code Editor ---------- */
.editor-container {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
    background: var(--bg-root);
}

.line-numbers {
    width: 44px;
    padding: 12px 8px 12px 0;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--text-tertiary);
    background: var(--bg-root);
    border-right: 1px solid var(--border);
    overflow: hidden;
    user-select: none;
    flex-shrink: 0;
}

.code-editor {
    display: none;
    flex: 1;
    padding: 12px 16px;
    border: none;
    outline: none;
    background: var(--bg-root);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    tab-size: 2;
    resize: none;
    overflow: auto;
    white-space: pre;
}

.code-editor.active {
    display: block;
}

.code-editor::placeholder {
    color: var(--text-tertiary);
}

.code-editor::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.code-editor::-webkit-scrollbar-track {
    background: transparent;
}

.code-editor::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.code-editor::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ---------- Resize Handle ---------- */
.resize-handle {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    transition: background var(--transition-fast);
    position: relative;
    flex-shrink: 0;
}

.resize-handle:hover,
.resize-handle.dragging {
    background: var(--primary);
    box-shadow: 0 0 8px var(--primary-glow);
}

/* ---------- Preview Panel ---------- */
.preview-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 300px;
}

.panel-title {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.preview-info {
    display: flex;
    gap: 8px;
    align-items: center;
}

.client-label,
.resolution-label {
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: 4px;
    background: var(--bg-elevated);
    color: var(--text-tertiary);
    border: 1px solid var(--border);
}

.client-label {
    color: var(--primary);
    border-color: rgba(108, 99, 255, 0.2);
}

.preview-container {
    flex: 1;
    padding: 16px;
    background: var(--bg-elevated);
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.preview-frame-wrapper {
    width: 100%;
    height: 100%;
    transition: all var(--transition-smooth);
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.preview-frame-wrapper.tablet {
    max-width: 768px;
}

.preview-frame-wrapper.mobile {
    max-width: 375px;
    border-radius: var(--radius-xl);
    box-shadow:
        var(--shadow-lg),
        inset 0 0 0 3px rgba(255, 255, 255, 0.1);
}

#preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

/* ---------- Modals ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn var(--transition-base);
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: slideUp var(--transition-smooth);
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 1.4rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

/* ---------- Template Grid ---------- */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    padding: 20px;
    overflow-y: auto;
}

.template-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-base);
}

.template-card:hover {
    border-color: var(--border-active);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.template-card-preview {
    height: 130px;
    background: #fff;
    overflow: hidden;
    position: relative;
}

.template-card-preview iframe {
    width: 200%;
    height: 200%;
    border: none;
    transform: scale(0.5);
    transform-origin: top left;
    pointer-events: none;
}

.template-card-info {
    padding: 10px 12px;
}

.template-card-info h3 {
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 3px;
}

.template-card-info p {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

/* ---------- A11y Report ---------- */
.a11y-report {
    padding: 20px;
    overflow-y: auto;
}

.a11y-score {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.score-circle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
    flex-shrink: 0;
}

.score-circle.good {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    border: 2px solid var(--success);
}

.score-circle.warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    border: 2px solid var(--warning);
}

.score-circle.error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error);
    border: 2px solid var(--error);
}

.score-details h3 {
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.score-details p {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.a11y-issues {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.a11y-issue {
    display: flex;
    gap: 10px;
    padding: 12px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--border);
}

.a11y-issue.error {
    border-left-color: var(--error);
}

.a11y-issue.warning {
    border-left-color: var(--warning);
}

.a11y-issue.info {
    border-left-color: var(--info);
}

.a11y-issue.pass {
    border-left-color: var(--success);
}

.issue-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
}

.a11y-issue.error .issue-icon {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error);
}

.a11y-issue.warning .issue-icon {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.a11y-issue.info .issue-icon {
    background: rgba(59, 130, 246, 0.15);
    color: var(--info);
}

.a11y-issue.pass .issue-icon {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.issue-content h4 {
    font-size: 0.8rem;
    margin-bottom: 2px;
}

.issue-content p {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

/* ---------- Toast ---------- */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
}

.toast {
    padding: 10px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 0.8rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideInRight var(--transition-smooth);
    backdrop-filter: blur(12px);
    max-width: 320px;
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--error);
}

.toast.info {
    border-left: 3px solid var(--info);
}

.toast.fade-out {
    animation: fadeOut var(--transition-base) forwards;
}

/* ---------- Animations ---------- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(80px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(80px);
    }
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
    .action-btn span {
        display: none;
    }

    .action-btn {
        padding: 6px 8px;
    }

    .preset-btn {
        padding: 5px 10px;
        font-size: 0.72rem;
    }
}

@media (max-width: 900px) {
    .toolbar {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 12px;
        gap: 8px;
    }

    .toolbar-center {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .client-presets {
        overflow-x: auto;
    }
}

@media (max-width: 768px) {
    .workspace {
        flex-direction: column;
    }

    .editor-panel {
        width: 100%;
        height: 45%;
        min-width: unset;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .resize-handle {
        width: 100%;
        height: 5px;
        cursor: row-resize;
    }

    .preview-panel {
        min-width: unset;
    }

    .responsive-toggles {
        display: none;
    }

    .template-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

/* ---------- Focus Styles ---------- */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

button:focus:not(:focus-visible) {
    outline: none;
}

/* ---------- Scrollbar (global) ---------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}