/* ============================================
   CSS CUSTOM PROPERTIES (Design Tokens)
   ============================================ */
:root {
    /* Color Palette - Light Theme */
    --color-primary: hsl(220, 13%, 18%);
    --color-primary-hover: hsl(220, 13%, 25%);
    --color-secondary: hsl(220, 10%, 40%);
    --color-secondary-hover: hsl(220, 10%, 50%);
    --color-accent: hsl(221, 83%, 53%);
    --color-accent-hover: hsl(221, 83%, 48%);
    --color-success: hsl(142, 71%, 45%);
    --color-warning: hsl(45, 93%, 47%);
    --color-danger: hsl(0, 84%, 60%);

    /* Backgrounds */
    --bg-primary: hsl(0, 0%, 100%);
    --bg-secondary: hsl(210, 17%, 98%);
    --bg-tertiary: hsl(210, 17%, 96%);
    --bg-editor: hsl(0, 0%, 100%);
    --bg-preview: hsl(0, 0%, 100%);
    --bg-header: hsl(0, 0%, 100%);
    --bg-divider: hsl(210, 17%, 92%);
    --bg-button: hsl(220, 13%, 18%);
    --bg-button-hover: hsl(220, 13%, 25%);
    --bg-button-secondary: hsl(210, 17%, 96%);
    --bg-button-secondary-hover: hsl(210, 17%, 92%);

    /* Text Colors */
    --text-primary: hsl(220, 13%, 18%);
    --text-secondary: hsl(220, 10%, 46%);
    --text-tertiary: hsl(220, 9%, 66%);
    --text-inverse: hsl(0, 0%, 100%);
    --text-code: hsl(338, 95%, 56%);

    /* Borders */
    --border-color: hsl(210, 18%, 87%);
    --border-color-hover: hsl(210, 18%, 75%);
    --border-radius-sm: 6px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 2px hsla(220, 13%, 18%, 0.04), 0 1px 3px hsla(220, 13%, 18%, 0.06);
    --shadow-md: 0 2px 4px hsla(220, 13%, 18%, 0.04), 0 4px 12px hsla(220, 13%, 18%, 0.08);
    --shadow-lg: 0 8px 16px hsla(220, 13%, 18%, 0.08), 0 12px 32px hsla(220, 13%, 18%, 0.12);
    --shadow-glow: 0 0 0 3px hsla(221, 83%, 53%, 0.1);

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Typography */
    --font-family-base: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-family-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    --font-size-xs: 0.6875rem;
    --font-size-sm: 0.8125rem;
    --font-size-base: 0.9375rem;
    --font-size-lg: 1.0625rem;
    --font-size-xl: 1.1875rem;
    --font-size-2xl: 1.375rem;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme */
[data-theme="dark"] {
    --color-primary: hsl(210, 12%, 93%);
    --color-primary-hover: hsl(210, 12%, 96%);
    --color-secondary: hsl(210, 10%, 60%);
    --color-secondary-hover: hsl(210, 10%, 70%);
    --color-accent: hsl(221, 83%, 53%);
    --color-accent-hover: hsl(221, 83%, 58%);
    --color-success: hsl(142, 71%, 55%);

    --bg-primary: hsl(220, 13%, 11%);
    --bg-secondary: hsl(220, 13%, 13%);
    --bg-tertiary: hsl(220, 13%, 16%);
    --bg-editor: hsl(220, 13%, 11%);
    --bg-preview: hsl(220, 13%, 11%);
    --bg-header: hsl(220, 13%, 13%);
    --bg-divider: hsl(220, 13%, 20%);
    --bg-button: hsl(210, 12%, 93%);
    --bg-button-hover: hsl(210, 12%, 96%);
    --bg-button-secondary: hsl(220, 13%, 16%);
    --bg-button-secondary-hover: hsl(220, 13%, 20%);

    --text-primary: hsl(210, 12%, 93%);
    --text-secondary: hsl(210, 10%, 68%);
    --text-tertiary: hsl(210, 9%, 50%);
    --text-inverse: hsl(220, 13%, 18%);
    --text-code: hsl(338, 95%, 66%);

    --border-color: hsl(220, 13%, 22%);
    --border-color-hover: hsl(220, 13%, 30%);

    --shadow-sm: 0 1px 2px hsla(0, 0%, 0%, 0.3), 0 1px 3px hsla(0, 0%, 0%, 0.4);
    --shadow-md: 0 2px 4px hsla(0, 0%, 0%, 0.3), 0 4px 12px hsla(0, 0%, 0%, 0.5);
    --shadow-lg: 0 8px 16px hsla(0, 0%, 0%, 0.4), 0 12px 32px hsla(0, 0%, 0%, 0.6);
    --shadow-glow: 0 0 0 3px hsla(221, 83%, 53%, 0.15);
}

/* ============================================
   RESET & BASE STYLES
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family-base);
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    transition: background-color var(--transition-base), color var(--transition-base);
}

/* ============================================
   LAYOUT
   ============================================ */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
}

/* ============================================
   HEADER
   ============================================ */
.app-header {
    background: var(--bg-header);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    position: relative;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px var(--spacing-xl);
    gap: var(--spacing-lg);
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 24px;
    height: 24px;
    color: var(--text-primary);
}

.logo-section h1 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.header-actions-list {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}



/* Mobile FAB and action sheet */
.mobile-fab {
    position: fixed;
    right: 16px;
    bottom: 92px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-accent);
    color: white;
    border: none;
    box-shadow: var(--shadow-lg);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1300;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.mobile-fab:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px hsla(221, 83%, 53%, 0.35);
}

.mobile-fab svg {
    width: 22px;
    height: 22px;
}

.mobile-actions-toggle {
    position: fixed;
    right: 16px;
    bottom: 28px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1300;
}

.mobile-actions-toggle svg {
    width: 24px;
    height: 24px;
}

.mobile-actions-sheet {
    position: fixed;
    inset: 0;
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 1400;
}

.mobile-actions-sheet.open {
    display: flex;
}

.mobile-actions-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

.mobile-actions-panel {
    position: relative;
    width: 100%;
    max-width: 480px;
    margin: 0 12px 20px;
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 14px;
    border: 1px solid var(--border-color);
    animation: slideUp var(--transition-base) ease;
}

.mobile-actions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.mobile-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--spacing-xs);
}

@keyframes slideUp {
    from {
        transform: translateY(12px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Buttons */
.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font-family: var(--font-family-base);
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.action-btn svg {
    width: 16px;
    height: 16px;
}

.action-btn.primary {
    background: var(--bg-button);
    color: var(--text-inverse);
}

.action-btn.primary:hover {
    background: var(--bg-button-hover);
    box-shadow: var(--shadow-sm);
}

.action-btn.secondary {
    background: var(--bg-button-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.action-btn.secondary:hover {
    background: var(--bg-button-secondary-hover);
    border-color: var(--border-color-hover);
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: var(--bg-button-secondary);
    color: var(--text-primary);
    border-color: var(--border-color-hover);
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

.action-toggle {
    display: none;
}

/* Theme Toggle */
#themeToggle {
    position: relative;
}

.theme-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity var(--transition-base), transform var(--transition-base);
}

.theme-icon.sun {
    opacity: 1;
}

.theme-icon.moon {
    opacity: 0;
}

[data-theme="dark"] .theme-icon.sun {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(180deg);
}

[data-theme="dark"] .theme-icon.moon {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg);
}

/* Status Bar */
.status-bar {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
    padding: 8px var(--spacing-xl);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 12px;
}

.status-bar .save-indicator {
    white-space: nowrap;
    gap: 4px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-label {
    color: var(--text-tertiary);
    font-weight: 400;
}

.status-value {
    color: var(--text-secondary);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.save-status {
    margin-left: auto;
}

.save-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.save-icon {
    width: 14px;
    height: 14px;
    color: inherit;
}

.save-indicator.saving .save-icon {
    animation: pulse 1.5s ease-in-out infinite;
    color: var(--text-tertiary);
}

.save-indicator.saved .save-icon {
    color: var(--color-success);
}

.save-indicator.error .save-icon {
    color: var(--color-danger);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   EDITOR CONTAINER
   ============================================ */
.editor-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Editor & Preview Panes */
.editor-pane,
.preview-pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    background: var(--bg-secondary);
}

.pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px var(--spacing-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.pane-header h2 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.clear-btn,
.toggle-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-tertiary);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.clear-btn:hover {
    color: var(--color-danger);
    border-color: var(--color-danger);
    background: var(--bg-tertiary);
}

.toggle-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-color-hover);
    background: var(--bg-tertiary);
}

.clear-btn svg,
.toggle-btn svg {
    width: 13px;
    height: 13px;
}

/* Markdown Input */
.markdown-input {
    flex: 1;
    padding: var(--spacing-lg);
    font-family: var(--font-family-mono);
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    background: var(--bg-editor);
    border: none;
    outline: none;
    resize: none;
    overflow-y: auto;
    transition: background-color var(--transition-base), color var(--transition-base);
}

.markdown-input::placeholder {
    color: var(--text-tertiary);
}

/* HTML Preview */
.html-preview {
    flex: 1;
    padding: var(--spacing-xl) var(--spacing-xl);
    overflow-y: auto;
    background: var(--bg-preview);
    transition: background-color var(--transition-base);
    font-size: 15px;
    line-height: 1.7;
}

/* Preview Content Styling */
.html-preview h1,
.html-preview h2,
.html-preview h3,
.html-preview h4,
.html-preview h5,
.html-preview h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
    letter-spacing: -0.015em;
}

.html-preview h1 {
    font-size: 2rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
    margin-bottom: 0.7em;
}

.html-preview h2 {
    font-size: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
    margin-bottom: 0.6em;
}

.html-preview h3 {
    font-size: 1.25rem;
}

.html-preview h4 {
    font-size: 1.0625rem;
}

.html-preview h5 {
    font-size: 0.9375rem;
}

.html-preview h6 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.html-preview p {
    margin-bottom: var(--spacing-md);
    line-height: 1.8;
}

.html-preview a {
    color: var(--color-accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition-fast);
}

.html-preview a:hover {
    border-bottom-color: var(--color-accent);
}

.html-preview code {
    padding: 0.2em 0.4em;
    font-family: var(--font-family-mono);
    font-size: 0.9em;
    background: var(--bg-tertiary);
    color: var(--text-code);
    border-radius: var(--border-radius-sm);
}

.html-preview pre {
    margin: var(--spacing-md) 0;
    padding: var(--spacing-md);
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-md);
    overflow-x: auto;
}

.html-preview pre code {
    padding: 0;
    background: transparent;
    color: inherit;
}

.html-preview blockquote {
    margin: var(--spacing-md) 0;
    padding-left: var(--spacing-lg);
    border-left: 3px solid var(--color-accent);
    color: var(--text-secondary);
    font-style: italic;
}


.html-preview ul,
.html-preview ol {
    margin: var(--spacing-md) 0;
    padding-left: var(--spacing-xl);
}

.html-preview li {
    margin-bottom: var(--spacing-sm);
}

.html-preview table {
    width: 100%;
    margin: var(--spacing-md) 0;
    border-collapse: collapse;
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

.html-preview th,
.html-preview td {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-color);
    text-align: left;
}

.html-preview th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.html-preview img {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius-md);
    margin: var(--spacing-md) 0;
}

.html-preview hr {
    margin: var(--spacing-xl) 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

/* Divider */
.divider {
    width: 1px;
    background: var(--border-color);
    cursor: col-resize;
    position: relative;
    touch-action: none;
    transition: background-color var(--transition-fast);
}

.divider:hover {
    background: var(--color-accent);
    width: 2px;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 32px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.divider:hover::before {
    opacity: 1;
}

/* ============================================
   TOAST NOTIFICATION
   ============================================ */
.toast {
    position: fixed;
    bottom: var(--spacing-xl);
    right: var(--spacing-xl);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-lg);
    transform: translateY(150%);
    opacity: 0;
    transition: all var(--transition-base);
    z-index: 1000;
    font-size: 13px;
    font-weight: 500;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-icon {
    width: 16px;
    height: 16px;
    color: var(--color-success);
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-color-hover);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 1200px) {
    .header-content {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .header-actions-list {
        flex-wrap: wrap;
        row-gap: var(--spacing-xs);
        justify-content: flex-start;
    }

    .status-bar {
        flex-wrap: wrap;
        gap: var(--spacing-sm);
    }
}

@media (max-width: 992px) {
    .header-actions-list {
        width: 100%;
        /* Use visibility hidden instead of display: none so children can override it */
        visibility: hidden;
        position: absolute;
        pointer-events: none;

        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: var(--spacing-xs);
        padding-top: var(--spacing-sm);
    }

    .header-actions-list.open {
        visibility: visible;
        position: static;
        pointer-events: auto;
    }

    /* Force template menu to be visible even if parent list is hidden */
    .template-menu {
        visibility: visible;
        pointer-events: auto;
    }

    .action-toggle {
        display: flex;
    }

    .editor-container {
        min-height: calc(100vh - 240px);
    }

    .template-menu {
        width: min(480px, 95vw);
        right: auto;
        left: 0;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: var(--spacing-sm);
        padding: 12px var(--spacing-md);
    }

    .header-actions {
        width: 100%;
        flex-direction: column;
        align-items: center;
        gap: var(--spacing-sm);
        display: none;
    }

    .action-toggle {
        display: none;
    }

    .header-actions-list {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: var(--spacing-sm);
        justify-items: center;
    }

    .action-btn,
    .icon-btn {
        padding: 7px 10px;
        justify-content: center;
    }

    .header-actions-list+.status-bar {
        margin-top: var(--spacing-xs);
    }

    .mobile-fab,
    .mobile-actions-toggle {
        display: flex;
    }

    /* Template menu as full-screen on mobile */
    .template-menu {
        position: fixed;
        inset: 0;
        width: 100%;
        max-height: none;
        border-radius: 0;
        display: none;
        overflow: auto;
        z-index: 1500;
    }

    .template-menu:not(.hidden) {
        display: block;
    }

    .template-menu-header {
        position: sticky;
        top: 0;
        z-index: 2;
    }

    .status-bar {
        flex-wrap: nowrap;
        gap: var(--spacing-xs);
        align-items: center;
        justify-content: space-between;
    }

    .editor-container {
        flex-direction: column;
        min-height: auto;
        gap: var(--spacing-sm);
    }

    .divider {
        width: 100%;
        height: 4px;
        cursor: row-resize;
    }

    .editor-pane,
    .preview-pane {
        min-height: 240px;
    }

    .pane-header {
        position: sticky;
        top: 0;
        z-index: 10;
        padding: 10px var(--spacing-md);
    }
}

@media (max-width: 480px) {
    .pane-header h2 {
        font-size: 11px;
    }

    .markdown-input,
    .html-preview {
        padding: var(--spacing-md);
    }
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.html-preview>* {
    animation: fadeIn var(--transition-base) ease-out;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

button:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ============================================
   TEMPLATE DROPDOWN
   ============================================ */
.template-dropdown {
    position: relative;
}

.template-menu {
    position: fixed;
    top: 60px;
    right: 20px;
    width: 400px;
    max-height: calc(100vh - 80px);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 1500;
    animation: slideDown 0.2s ease-out;
}

@media (max-width: 768px) {
    .template-menu {
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        border: none;
    }
}

.template-menu.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.template-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.template-menu-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}

.close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.close-btn svg {
    width: 14px;
    height: 14px;
}

.template-list {
    max-height: 500px;
    overflow-y: auto;
    padding: 8px;
}

.template-category {
    margin-bottom: 12px;
}

.category-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 12px 4px 12px;
}

.template-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
    margin-bottom: 2px;
}

.template-item:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

.template-icon {
    font-size: 24px;
    line-height: 1;
    flex-shrink: 0;
}

.template-info {
    flex: 1;
    min-width: 0;
}

.template-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.template-desc {
    font-size: 11px;
    color: var(--text-tertiary);
    line-height: 1.4;
}

/* Help Modal Styles */
.help-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    opacity: 1;
    transition: opacity var(--transition-normal);
}

.help-modal.hidden {
    display: none;
    opacity: 0;
}

.help-modal-content {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 900px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.help-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.help-modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.help-tabs {
    display: flex;
    gap: 12px;
    padding: 20px 30px;
    background: var(--bg-primary);
    border-bottom: 2px solid var(--border-color);
    justify-content: center;
    align-items: center;
    overflow-x: visible;
}


.help-tab {
    padding: 14px 28px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    max-width: 180px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.help-tab:hover {
    background: var(--bg-tertiary);
    border-color: var(--color-primary);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.help-tab.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.help-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.help-tab-content {
    display: none;
}

.help-tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.help-content h1 {
    font-size: 24px;
    color: var(--text-primary);
    margin: 0 0 16px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.help-content h2 {
    font-size: 20px;
    color: var(--text-primary);
    margin: 24px 0 12px 0;
    padding-top: 8px;
}

.help-content h3 {
    font-size: 16px;
    color: var(--text-primary);
    margin: 16px 0 8px 0;
}

.help-content h4 {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 12px 0 6px 0;
    font-weight: 600;
}

.help-content p {
    margin: 8px 0;
    line-height: 1.6;
    color: var(--text-secondary);
}

.help-content ul,
.help-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.help-content li {
    margin: 4px 0;
    line-height: 1.6;
    color: var(--text-secondary);
}

.help-content code {
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 13px;
    color: var(--color-accent);
}

.help-content pre {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: var(--border-radius-md);
    overflow-x: auto;
    margin: 12px 0;
}

.help-content pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    color: var(--text-primary);
}

.help-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.help-content th,
.help-content td {
    padding: 8px 12px;
    text-align: left;
    border: 1px solid var(--border-color);
}

.help-content th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
}

.help-content td {
    color: var(--text-secondary);
}

.help-content blockquote {
    margin: 12px 0;
    padding: 12px 16px;
    border-left: 3px solid var(--color-accent);
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.help-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 20px 0;
}

.help-content strong {
    color: var(--text-primary);
    font-weight: 600;
}

.help-content a {
    color: var(--color-accent);
    text-decoration: none;
}

.help-content a:hover {
    text-decoration: underline;
}

.help-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin: 16px 0;
}

.help-card {
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
}

.help-card h4 {
    margin-top: 0;
}

@media (max-width: 768px) {
    .help-modal-content {
        max-width: 100%;
        max-height: 95vh;
    }

    .help-tabs {
        padding: 12px;
        gap: 6px;
    }

    .help-tab {
        padding: 8px 14px;
        font-size: 13px;
    }

    .help-content {
        padding: 16px;
    }

    .help-content h1 {
        font-size: 20px;
    }

    .help-content h2 {
        font-size: 18px;
    }
}

/* Help grid layout for template categories */
.help-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.help-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
}

.help-card h4 {
    margin-top: 0;
    margin-bottom: 0.75rem;
    color: var(--primary-color);
}

.help-card ul {
    margin: 0;
    padding-left: 1.25rem;
}

.help-card ul li {
    margin-bottom: 0.25rem;
}