        :root {
            --primary: #3b82f6;
            --primary-hover: #2563eb;
            --primary-light: #eff6ff;
            --secondary: #64748b;
            --success: #10b981;
            --danger: #ef4444;
            --bg-app: #f8fafc;
            --bg-panel: #ffffff;
            --bg-hover: #f1f5f9;
            --border-color: #e2e8f0;
            --border-dark: #cbd5e1;
            --text-main: #0f172a;
            --text-muted: #64748b;
            --text-light: #94a3b8;
            --radius-md: 14px;
            --radius-sm: 8px;
            --radius-lg: 16px;
            --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
            --shadow-sm: 0 2px 4px 0 rgba(0, 0, 0, 0.05);
            --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.08);
            --shadow-lg: 0 12px 32px -4px rgba(0, 0, 0, 0.1);
        }

        /* Custom Tour Popover Styles */
        .driver-popover.cv-tour-popover {
            background: #ffffff;
            border-radius: 12px;
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
            border: 1px solid #e5e7eb;
            max-width: 320px;
            padding: 16px;
        }
        
        .driver-popover.cv-tour-popover .driver-popover-title {
            font-size: 16px;
            font-weight: 600;
            color: #1f2937;
            padding-right: 24px;
        }
        
        .driver-popover.cv-tour-popover .driver-popover-description {
            font-size: 13px;
            color: #6b7280;
            line-height: 1.5;
            margin-top: 6px;
        }
        
        .driver-popover.cv-tour-popover .driver-popover-progress-text {
            font-size: 11px;
            color: #9ca3af;
            font-weight: 500;
        }
        
        .driver-popover.cv-tour-popover .driver-popover-navigation-btns {
            gap: 8px;
            margin-top: 12px;
        }
        
        .driver-popover.cv-tour-popover button {
            border-radius: 6px;
            padding: 8px 14px;
            font-size: 13px;
            font-weight: 500;
            transition: all 0.15s;
        }
        
        .driver-popover.cv-tour-popover .driver-popover-next-btn {
            background: #3b82f6;
            color: white;
            border: none;
            text-shadow: none;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
            font-weight: 600;
        }
        
        .driver-popover.cv-tour-popover .driver-popover-next-btn:hover {
            background: #2563eb;
        }
        
        .driver-popover.cv-tour-popover .driver-popover-prev-btn {
            background: #f3f4f6;
            color: #374151;
            border: 1px solid #e5e7eb;
        }
        
        .driver-popover.cv-tour-popover .driver-popover-prev-btn:hover {
            background: #e5e7eb;
        }
        
        /* Fix close/X button */
        .driver-popover.cv-tour-popover .driver-popover-close-btn {
            position: absolute;
            top: 8px;
            right: 8px;
            width: 24px;
            height: 24px;
            padding: 0;
            font-size: 16px;
            line-height: 24px;
            background: #f3f4f6;
            color: #6b7280;
            border: none;
            border-radius: 4px;
        }
        
        .driver-popover.cv-tour-popover .driver-popover-close-btn:hover {
            background: #e5e7eb;
            color: #374151;
        }

        @media (max-width: 480px) {
            .driver-popover.cv-tour-popover {
                max-width: calc(100vw - 32px);
                padding: 14px;
            }
            
            .driver-popover.cv-tour-popover .driver-popover-title {
                font-size: 15px;
            }
            
            .driver-popover.cv-tour-popover .driver-popover-description {
                font-size: 12px;
            }
        }

        * {
            box-sizing: border-box;
            outline: none;
            -webkit-tap-highlight-color: transparent;
        }

        body {
            margin: 0;
            display: flex;
            height: 100vh;
            font-family: 'Inter', -apple-system, sans-serif;
            background: var(--bg-app);
            color: var(--text-main);
            overflow: hidden;
        }

        /* --- LEFT PANEL: EDITOR --- */
        .editor {
            flex: 0 0 520px;
            min-width: 360px;
            max-width: 860px;
            background: linear-gradient(180deg, #ffffff 0%, #f9fafb 40%, #f3f4f6 100%);
            border-right: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            z-index: 20;
            box-shadow: 2px 0 18px rgba(15, 23, 42, 0.10);
            transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.15s ease-out;
        }

        .editor-header {
            padding: 20px 24px 16px;
            background: radial-gradient(circle at top left, #f9fafb 0, #ffffff 55%, #eef2ff 120%);
            border-bottom: 1px solid var(--border-color);
            z-index: 10;
        }

        .brand-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
        }

        .app-logo {
            font-size: 16px;
            font-weight: 700;
            color: var(--text-main);
            display: flex;
            align-items: center;
            gap: 10px;
            letter-spacing: -0.3px;
            text-decoration: none;
        }

        .app-logo svg {
            width: 28px;
            height: 28px;
            color: var(--primary);
        }

        .app-logo img {
            height: 33px;
            width: auto;
            max-width: 220px;
            display: block;
            object-fit: contain;
            border-radius: 0;
        }

        .beta-badge {
            font-size: 10px;
            background: var(--primary-light);
            color: var(--primary);
            padding: 4px 10px;
            border-radius: 20px;
            border: 1px solid #bfdbfe;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.3px;
        }

        /* Toolbar Actions */
        .action-bar {
            display: flex;
            gap: 6px;
            overflow-x: auto;
            padding-bottom: 4px;
            scrollbar-width: none;
            margin-bottom: 12px;
        }

        .action-bar::-webkit-scrollbar {
            display: none;
        }

        .btn-icon {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 8px 12px;
            background: var(--bg-hover);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            color: var(--text-muted);
            font-size: 12px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
            white-space: nowrap;
            flex-shrink: 0;
        }

        .btn-icon:hover {
            background: var(--bg-panel);
            border-color: var(--border-dark);
            color: var(--text-main);
            box-shadow: var(--shadow-sm);
        }

        .btn-icon:active {
            transform: scale(0.98);
        }

        .dropdown-trigger {
            gap: 4px;
            position: relative;
            padding-right: 24px;
        }
        
        .dropdown-menu-popover {
            position: fixed;
            background: var(--bg-panel);
            border: 1px solid var(--border-color);
            border-radius: var(--radius-sm);
            box-shadow: var(--shadow-lg);
            padding: 6px;
            display: flex;
            flex-direction: column;
            gap: 4px;
            min-width: 160px;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-8px);
            transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
            z-index: 9999;
        }
        
        .dropdown-menu-popover.active {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }

        .dropdown-item {
            display: flex;
            align-items: center;
            background: transparent;
            border: none;
            color: var(--text-main);
            padding: 10px 12px;
            border-radius: 6px;
            font-size: 13px;
            font-weight: 500;
            text-align: left;
            cursor: pointer;
            transition: all 0.15s ease;
            width: 100%;
        }

        .dropdown-item:hover {
            background: var(--bg-hover);
            color: var(--primary);
        }

        .dropdown-trigger::after {
            content: '';
            position: absolute;
            right: 12px;
            top: 50%;
            width: 6px;
            height: 6px;
            border-right: 2px solid currentColor;
            border-bottom: 2px solid currentColor;
            transform: translateY(-65%) rotate(45deg);
            pointer-events: none;
            opacity: 0.6;
            transition: all 0.2s ease;
        }

        .dropdown-trigger:hover::after {
            opacity: 1;
        }

        .btn-primary {
            background: var(--primary);
            color: white;
            border: 1px solid var(--primary);
            box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
        }

        .btn-primary:hover {
            background: var(--primary-hover);
            box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
        }

        .btn-magic {
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
            color: white;
            border: none;
            font-weight: 600;
            box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
        }

        .btn-magic:hover {
            box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
            transform: translateY(-1px);
        }

        /* Progress Bar */
        .progress-track {
            height: 5px;
            background: #e5e7eb;
            border-radius: 999px;
            margin-top: 12px;
            overflow: hidden;
            position: relative;
        }

        .progress-head {
            margin-top: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 11px;
            font-weight: 600;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.04em;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, var(--primary) 0%, #06b6d4 100%);
            transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
            border-radius: 3px;
        }

        /* Editor Content Area */
        .editor-content {
            flex: 1;
            overflow-y: auto;
            padding: 24px;
            scroll-behavior: smooth;
            background: var(--bg-app);
        }

        .editor-content::-webkit-scrollbar {
            width: 6px;
        }

        .editor-content::-webkit-scrollbar-thumb {
            background: var(--border-dark);
            border-radius: 3px;
        }

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

        /* Accordion Cards */
        details {
            position: relative;
            background: var(--bg-panel);
            border: 1px solid var(--border-color);
            border-radius: var(--radius-md);
            margin-bottom: 12px;
            transition: all 0.2s ease;
            box-shadow: var(--shadow-xs);
            overflow: hidden;
        }

        /* Header action buttons (Auto-fill, Table format, Label, move up/down,
           etc.) live inside <summary> itself, in the same single-line row as
           the title, not as a sibling of <summary>. Chromium 131+ wraps
           everything after <summary> in an internal ::details-content box
           that collapses to zero height and stops painting when the
           <details> is closed — no author CSS on a sibling can override
           that, so a sibling row silently disappears (and its buttons
           become unreachable) whenever the section is collapsed. <summary>
           itself is the one part of a closed <details> guaranteed to keep
           rendering, so this row has to be its child. Interactive content
           inside <summary> works fine in every evergreen browser; every
           button here already calls event.stopPropagation() so clicking it
           doesn't also toggle the section open/closed.
           display:contents dissolves this div's own box so its children
           (chip buttons, and the move-up/down span injected by
           renderInlineSectionReorderControls()) become direct flex items of
           <summary>, sitting right after the title on one line. */
        .summary-actions {
            display: contents;
        }

        details:hover {
            border-color: var(--border-dark);
            box-shadow: var(--shadow-sm);
        }

        details[open] {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
        }

        summary {
            padding: 14px 18px;
            font-weight: 600;
            font-size: 13px;
            color: var(--text-main);
            cursor: pointer;
            list-style: none;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 8px;
            user-select: none;
            transition: background 0.2s;
            letter-spacing: 0.3px;
        }

        summary:hover {
            background: var(--bg-hover);
        }

        details[open] summary {
            background: var(--primary-light);
            border-bottom: 1px solid var(--border-color);
        }

        /* Only ONE item per row may carry margin-left:auto — when a flex line
           has two auto-margin items, the free space splits EVENLY between
           them instead of the first one consuming it all, which left a gap
           between the arrows and the chevron. So the chevron's own auto
           margin is cancelled (margin-left:0) whenever a
           .section-reorder-controls sibling is present to do the pushing
           instead; the chevron then just follows it immediately. For
           sections with no reorder controls at all (Personal Details,
           Highlight Banners), the chevron keeps its own auto margin so it
           still lands on the far right. */
        summary::after {
            content: '';
            width: 16px;
            height: 16px;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%233b82f6' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
            background-size: contain;
            background-repeat: no-repeat;
            transition: transform 0.2s;
            opacity: 0.6;
            margin-left: auto;
            flex-shrink: 0;
        }

        summary:has(.section-reorder-controls)::after {
            margin-left: 0;
        }

        .section-reorder-controls {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            margin-left: auto;
        }

        details[open] summary::after {
            transform: rotate(180deg);
        }

        .section-body {
            padding: 18px;
            background: var(--bg-panel);
            border-top: 1px solid var(--border-color);
            animation: slideIn 0.2s ease-out;
        }

        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateY(-4px);
            }

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

        /* Form Controls */
        .form-group {
            margin-bottom: 14px;
            position: relative;
        }

        label {
            display: block;
            font-size: 10px;
            font-weight: 700;
            color: var(--text-muted);
            margin-bottom: 6px;
            text-transform: uppercase;
            letter-spacing: 0.6px;
        }

        /* Same look as `label`, for heading text that introduces a group of
           dynamically-added fields (e.g. "Projects (All)") rather than
           labelling one specific input — using <label> there with no `for`
           target trips "label not associated with a form field" checks. */
        .form-label-heading {
            display: block;
            font-size: 10px;
            font-weight: 700;
            color: var(--text-muted);
            margin-bottom: 6px;
            text-transform: uppercase;
            letter-spacing: 0.6px;
        }

        .form-control {
            width: 100%;
            padding: 10px 12px;
            font-size: 14px;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            background: var(--bg-panel);
            color: var(--text-main);
            font-family: inherit;
            transition: all 0.2s;
        }

        .form-control:focus {
            border-color: var(--primary);
            background: var(--primary-light);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
        }

        .form-control::placeholder {
            color: var(--text-light);
        }

        textarea.form-control {
            min-height: 100px;
            resize: vertical;
            line-height: 1.5;
        }

        .summary-rich-editor {
            background: transparent;
            border: 0;
            border-radius: 0;
            overflow: visible;
        }

        .summary-rich-toolbar.ql-toolbar.ql-snow {
            border: 1px solid var(--border-color);
            border-bottom: 0;
            background: #f8fafc;
            border-radius: 12px 12px 0 0 !important;
        }

        .summary-rich-container.ql-container.ql-snow {
            border: 1px solid var(--border-color);
            min-height: 120px;
            font-family: inherit;
            font-size: 14px;
            color: var(--text-main);
            background: var(--bg-panel);
            border-radius: 0 0 12px 12px !important;
        }

        .summary-rich-container .ql-editor {
            min-height: 120px;
            line-height: 1.5;
            padding: 10px 12px;
            border-radius: 0 0 12px 12px !important;
        }

        .summary-rich-toolbar.ql-toolbar.ql-snow:focus-within,
        .summary-rich-container.ql-container.ql-snow:focus-within {
            border-color: var(--primary);
        }

        .inline-rich-editor {
            border: 0;
            border-radius: 0;
            background: transparent;
            box-shadow: none;
        }

        .inline-rich-toolbar.ql-toolbar.ql-snow {
            border: 1px solid var(--border-color);
            border-bottom: 0;
            border-radius: 12px 12px 0 0 !important;
            margin: 0;
            background: #f8fafc;
        }

        .inline-rich-container.ql-container.ql-snow {
            border: 1px solid var(--border-color);
            border-radius: 0 0 12px 12px !important;
            min-height: 78px;
        }

        .inline-rich-container .ql-editor {
            min-height: 78px;
            border-radius: 0 0 12px 12px !important;
        }

        .inline-rich-editor:focus-within {
            border: 0;
            box-shadow: none;
        }

        .inline-rich-toolbar.ql-toolbar.ql-snow:focus-within,
        .inline-rich-container.ql-container.ql-snow:focus-within {
            border-color: var(--primary);
        }

        /* Make the Quill "link" button discoverable: show a "Link" label + accent
           colour so users realise they can hyperlink selected text. */
        .inline-rich-toolbar.ql-toolbar.ql-snow button.ql-link,
        .summary-rich-toolbar.ql-toolbar.ql-snow button.ql-link {
            width: auto !important;
            padding: 2px 6px !important;
            display: inline-flex !important;
            align-items: center;
            gap: 3px;
        }
        .inline-rich-toolbar.ql-toolbar.ql-snow button.ql-link::after,
        .summary-rich-toolbar.ql-toolbar.ql-snow button.ql-link::after {
            content: 'Link';
            font-size: 12px;
            font-weight: 600;
            color: var(--primary);
        }
        .inline-rich-toolbar.ql-toolbar.ql-snow button.ql-link .ql-stroke,
        .summary-rich-toolbar.ql-toolbar.ql-snow button.ql-link .ql-stroke {
            stroke: var(--primary);
        }

        /* Contextual hint that appears only while a rich editor is focused. */
        .rich-editor-hint {
            display: none;
            font-size: 11px;
            line-height: 1.4;
            color: var(--text-muted);
            margin: 5px 2px 0;
        }
        .rich-editor-hint strong {
            color: var(--primary);
            font-weight: 600;
        }
        .rich-editor-wrap:focus-within .rich-editor-hint {
            display: block;
        }

        .summary-link-popover {
            position: fixed;
            z-index: 1100;
            width: 260px;
            background: #ffffff;
            border: 1px solid var(--border-color);
            border-radius: 10px;
            box-shadow: 0 10px 24px rgba(15, 23, 42, 0.15);
            padding: 10px;
            display: none;
        }

        .summary-link-popover-title {
            font-size: 11px;
            font-weight: 700;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 8px;
        }

        .summary-link-input {
            width: 100%;
            padding: 8px 10px;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            font-size: 13px;
            color: var(--text-main);
            outline: none;
        }

        .summary-link-input:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
        }

        .summary-link-actions {
            margin-top: 8px;
            display: flex;
            gap: 8px;
            justify-content: flex-end;
        }

        .summary-link-btn {
            border: 1px solid var(--border-color);
            background: #f8fafc;
            color: var(--text-main);
            font-size: 12px;
            font-weight: 600;
            border-radius: 8px;
            padding: 6px 10px;
            cursor: pointer;
        }

        .summary-link-apply {
            color: #ffffff;
            background: var(--primary);
            border-color: var(--primary);
        }

        /* Chips / Quick Fill */
        .chip-container {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            margin-bottom: 10px;
        }

        .chip {
            background: var(--bg-hover);
            color: var(--text-muted);
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 11px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.15s;
            border: 1px solid transparent;
        }

        .chip:hover {
            background: var(--border-color);
            color: var(--text-main);
        }

        .chip.active {
            background: var(--primary-light);
            color: var(--primary);
            border-color: var(--primary);
        }

        .btn-mini {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 4px;
            padding: 4px 8px;
            font-size: 10px;
            font-weight: 600;
            border-radius: 999px;
            border: 1px solid var(--border-color);
            background: #f9fafb;
            color: var(--text-muted);
            cursor: pointer;
            transition: all 0.15s ease-out;
            white-space: nowrap;
        }

        .btn-mini svg {
            width: 10px;
            height: 10px;
        }

        .btn-mini:hover {
            border-color: var(--primary);
            background: var(--primary-light);
            color: var(--primary);
            box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
        }

        .btn-mini:active {
            transform: scale(0.97);
        }


        /* List Item Styling */
        .list-item {
            background: #fff;
            border: 1px solid #ddd;
            border-radius: 6px;
            padding: 10px;
            padding-top: 30px; /* Space for actions */
            margin-bottom: 10px;
            position: relative;
        }

        .item-actions {
            position: absolute;
            top: 5px;
            right: 5px;
            display: flex;
            gap: 5px;
        }

        .action-btn {
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: #f1f1f1;
            border-radius: 4px;
            cursor: pointer;
            font-size: 12px;
            color: #555;
            user-select: none;
        }

        .action-btn:hover {
            background: #e1e1e1;
            color: #000;
        }

        .action-btn.delete {
            background: #ffebee;
            color: #c62828;
        }

        .action-btn.delete:hover {
            background: #ffcdd2;
        }

        .action-btn.merge-toggle {
            min-width: 58px;
            width: auto;
            padding: 0 10px;
            border-radius: 999px;
            background: #eef6ff;
            color: #2563eb;
            font-weight: 600;
            border: 1px solid #bfdbfe;
            letter-spacing: 0.01em;
        }

        .action-btn.merge-toggle:hover {
            background: #dbeafe;
            color: #1d4ed8;
            border-color: #93c5fd;
        }

        .action-btn.merge-toggle.active {
            background: #eff6ff;
            color: #1d4ed8;
            border-color: #60a5fa;
            box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.25);
        }

        .btn-dashed {
            width: 100%;
            padding: 12px;
            border: 1.5px dashed var(--border-dark);
            background: transparent;
            color: var(--text-muted);
            font-weight: 500;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            font-size: 13px;
        }

        .btn-dashed:hover {
            border-color: var(--primary);
            color: var(--primary);
            background: var(--primary-light);
        }

        /* Character Counter */
        .char-counter {
            font-size: 10px;
            color: var(--text-light);
            text-align: right;
            margin-top: 4px;
            font-variant-numeric: tabular-nums;
        }

        .char-counter.limit {
            color: #f59e0b;
        }

        .char-counter.over {
            color: var(--danger);
            font-weight: 600;
        }

        /* Column Resize Handle */
        .resize-handle {
            width: 6px;
            cursor: col-resize;
            background: linear-gradient(to bottom, #e5e7eb, #cbd5e1);
            box-shadow: 1px 0 0 rgba(148, 163, 184, 0.9), -1px 0 0 rgba(148, 163, 184, 0.4);
            flex: 0 0 6px;
            position: relative;
            z-index: 25;
        }

        .resize-handle::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 2px;
            height: 44px;
            border-radius: 999px;
            background: linear-gradient(to bottom, #9ca3af, #6b7280);
            transform: translate(-50%, -50%);
            opacity: 0.8;
        }

        /* History Strip */
        .history-strip {
            margin-top: 14px;
            padding: 8px 0 4px;
        }

        .history-header {
            font-size: 10px;
            letter-spacing: 0.12em;
            text-transform: uppercase;
            color: var(--text-light);
            font-weight: 600;
            margin-bottom: 6px;
        }

        .history-list {
            display: flex;
            gap: 8px;
            overflow-x: auto;
            padding-bottom: 4px;
            scrollbar-width: thin;
        }

        .history-list::-webkit-scrollbar {
            height: 4px;
        }

        .history-list::-webkit-scrollbar-thumb {
            background: #cbd5e1;
            border-radius: 999px;
        }

        .history-card {
            border: 1px solid var(--border-color);
            border-radius: 999px;
            padding: 6px 10px 6px 12px;
            background: rgba(255, 255, 255, 0.9);
            box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
            font-size: 11px;
            display: inline-flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
            gap: 6px;
            min-width: 140px;
            cursor: pointer;
            transition: all 0.16s ease-out;
            text-align: left;
            position: relative;
        }

        .history-card:hover {
            border-color: var(--primary);
            box-shadow: 0 4px 10px rgba(37, 99, 235, 0.12);
            transform: translateY(-1px);
        }

        .history-title {
            font-weight: 600;
            color: var(--text-main);
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
        }

        .history-meta {
            font-size: 10px;
            color: var(--text-light);
            margin-top: 2px;
        }

        .history-main {
            display: flex;
            flex-direction: column;
            min-width: 0;
        }

        .history-delete {
            border: none;
            background: transparent;
            color: var(--text-light);
            font-size: 12px;
            width: 20px;
            height: 20px;
            border-radius: 999px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            cursor: pointer;
            transition: background 0.15s ease, color 0.15s ease, transform 0.05s ease;
        }

        .history-delete:hover {
            background: #fee2e2;
            color: var(--danger);
        }

        .history-delete:active {
            transform: scale(0.92);
        }

        .history-empty {
            font-size: 11px;
            color: var(--text-light);
            padding: 6px 0;
        }

        /* --- RIGHT PANEL: PREVIEW --- */
        .preview {
            flex: 1;
            background: radial-gradient(circle at top, #f3f4f6 0, #e5e7eb 40%, #d1d5db 100%);
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 32px 32px;
            overflow-y: auto;
            position: relative;
        }

        /* Floating Pill Template Selector */
        .template-floater {
            position: sticky;
            top: 0;
            z-index: 50;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(12px);
            padding: 6px 12px;
            border-radius: 99px;
            box-shadow: var(--shadow-md);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            margin-bottom: 24px;
            border: 1px solid rgba(255, 255, 255, 0.8);
            max-width: 100%;
            width: max-content;
            box-sizing: border-box;
        }

        .floater-pill {
            border: none;
            background: transparent;
            display: flex;
            align-items: center;
            gap: 6px;
            cursor: pointer;
            border-radius: 999px;
            padding: 5px 8px;
            color: var(--text-main);
            transition: background 0.2s ease;
            flex-shrink: 0;
        }

        .floater-pill:hover {
            background: rgba(148, 163, 184, 0.15);
        }

        .floater-dropdown-wrap {
            position: relative;
            display: inline-flex;
            align-items: center;
            flex-shrink: 0;
        }

        .floater-dropdown-menu {
            position: absolute;
            top: calc(100% + 10px);
            left: 50%;
            transform: translateX(-50%) translateY(6px);
            background: #ffffff;
            border: 1px solid #e2e8f0;
            border-radius: 18px;
            box-shadow: 0 16px 36px rgba(15, 23, 42, 0.16), 0 4px 12px rgba(15, 23, 42, 0.08);
            padding: 16px;
            z-index: 1000;
            opacity: 0;
            pointer-events: none;
            visibility: hidden;
            transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s;
        }

        .floater-dropdown-menu.open {
            opacity: 1;
            pointer-events: all;
            visibility: visible;
            transform: translateX(-50%) translateY(0);
        }

        .color-dropdown-menu {
            width: 300px;
        }

        .font-dropdown-menu {
            width: 360px;
        }

        .template-font-tabs {
            display: flex;
            align-items: center;
            gap: 6px;
            margin-bottom: 10px;
        }

        .template-font-tab {
            padding: 4px 10px;
            border-radius: 999px;
            border: 1px solid #e2e8f0;
            background: #f8fafc;
            color: #64748b;
            font-size: 11px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.15s ease;
        }

        .template-font-tab:hover {
            color: #1e293b;
            background: #f1f5f9;
        }

        .template-font-tab.active {
            border-color: #6366f1;
            background: #6366f1;
            color: #ffffff;
        }

        .floater-color-preview {
            width: 13px;
            height: 13px;
            border-radius: 50%;
            border: 1.5px solid rgba(0, 0, 0, 0.15);
            background: #2F557F;
            display: inline-block;
            margin-right: 2px;
            flex-shrink: 0;
        }

        .undo-redo-pill {
            gap: 6px;
            cursor: default;
            padding: 4px 6px;
            flex-shrink: 0;
        }

        .undo-redo-pill:hover {
            background: transparent;
        }

        .undo-redo-group {
            display: inline-flex;
            align-items: center;
            gap: 4px;
        }

        .undo-redo-btn {
            width: 28px;
            height: 28px;
            border-radius: 999px;
            border: 1px solid #d1d5db;
            background: #ffffff;
            color: var(--text-main);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.18s ease;
            box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
        }

        .undo-redo-btn svg {
            display: block;
            width: 13px;
            height: 13px;
            stroke-width: 2.1;
        }

        .undo-redo-btn:hover {
            border-color: #94a3b8;
            background: #f8fafc;
        }

        .undo-redo-btn:disabled {
            opacity: 0.45;
            cursor: not-allowed;
            background: #f1f5f9;
        }

        .mobile-history-controls {
            display: none;
        }

        .template-label {
            font-size: 11px;
            font-weight: 600;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        @media (max-width: 1400px) {
            .undo-redo-pill .template-label {
                display: none;
            }
        }

        @media (max-width: 1240px) {
            .template-floater {
                gap: 4px;
                padding: 4px 8px;
            }
            .floater-pill {
                padding: 4px 6px;
                gap: 4px;
            }
            .template-label {
                display: none;
            }
        }

        .template-select {
            border: none;
            background: transparent;
            font-size: 13px;
            font-weight: 600;
            color: var(--text-main);
            cursor: pointer;
            padding-right: 4px;
        }

        .template-select:hover {
            color: var(--primary);
        }

        /* Template Sidebar */
        .template-sidebar {
            position: fixed;
            top: 0;
            right: 0;
            width: 420px;
            height: 100vh;
            background: #fff;
            box-shadow: -4px 0 20px rgba(0,0,0,0.15);
            z-index: 1000;
            transform: translateX(100%);
            transition: transform 0.3s ease;
            display: flex;
            flex-direction: column;
        }

        .template-sidebar.open {
            transform: translateX(0);
        }

        .template-sidebar-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 16px 20px;
            border-bottom: 1px solid #e5e7eb;
            background: #f9fafb;
        }

        .template-sidebar-header h3 {
            margin: 0;
            font-size: 16px;
            font-weight: 600;
            color: #1f2937;
        }

        .template-sidebar-close {
            background: transparent;
            border: none;
            font-size: 24px;
            cursor: pointer;
            color: #6b7280;
            line-height: 1;
            padding: 4px;
        }

        .template-sidebar-close:hover {
            color: #1f2937;
        }

        .template-grid {
            flex: 1;
            overflow-y: auto;
            padding: 16px;
            display: flex;
            flex-direction: column;
            gap: 16px;
            scroll-snap-type: y mandatory;
        }

        .template-card {
            min-height: 400px;
            flex-shrink: 0;
            border-radius: 12px;
            border: 3px solid #e5e7eb;
            cursor: pointer;
            overflow: hidden;
            position: relative;
            transition: all 0.2s ease;
            background: #fff;
            scroll-snap-align: start;
        }

        .template-card:hover {
            border-color: var(--primary);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
        }

        .template-card.active {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
        }

        /* Premium (locked) templates: keep the preview visible but scrimmed so
           it reads as aspirational, marked with a gold PREMIUM pill. */
        .template-card.locked {
            border-color: #ece0c8;
        }
        .template-card.locked .template-card-preview {
            filter: saturate(0.9);
        }
        .template-lock-scrim {
            position: absolute;
            inset: 0;
            z-index: 1;
            pointer-events: none;
            background: linear-gradient(180deg,
                rgba(28, 24, 16, 0.04) 0%,
                rgba(28, 24, 16, 0.10) 55%,
                rgba(28, 24, 16, 0.24) 100%);
        }
        .template-card.locked:hover {
            border-color: #e8a020;
            box-shadow: 0 8px 22px rgba(200, 128, 26, 0.28);
        }
        .template-card.locked:hover .template-lock-scrim {
            background: linear-gradient(180deg,
                rgba(28, 24, 16, 0.02) 0%,
                rgba(28, 24, 16, 0.06) 55%,
                rgba(28, 24, 16, 0.16) 100%);
        }
        .template-premium-badge {
            position: absolute;
            top: 9px;
            right: 9px;
            z-index: 2;
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 4px 9px 4px 7px;
            font-size: 10px;
            font-weight: 800;
            letter-spacing: 0.6px;
            color: #4a2f08;
            background: linear-gradient(135deg, #f7d774 0%, #e8a020 55%, #cf8617 100%);
            border-radius: 999px;
            box-shadow: 0 2px 6px rgba(160, 100, 20, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.55);
        }

        .template-card-preview {
            height: calc(100% - 45px);
            overflow: hidden;
            position: relative;
            background: #f9fafb;
        }

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

        .template-card-name {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            padding: 12px;
            background: linear-gradient(transparent, rgba(255,255,255,0.95));
            font-size: 14px;
            font-weight: 600;
            text-align: center;
            color: #1f2937;
        }

        .template-theme-panel {
            margin: 14px 16px 0;
            padding: 16px;
            border: 1px solid #e5e7eb;
            border-radius: 18px;
            background:
                radial-gradient(circle at top left, rgba(59, 130, 246, 0.09), transparent 38%),
                linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
            box-shadow: 0 10px 26px rgba(15, 23, 42, 0.05);
        }

        .template-theme-head {
            display: flex;
            align-items: flex-start;
            justify-content: space-between;
            gap: 12px;
            margin-bottom: 14px;
        }

        .template-theme-title {
            font-size: 15px;
            font-weight: 800;
            color: #0f172a;
            letter-spacing: -0.01em;
        }

        .template-theme-subtitle {
            font-size: 12px;
            color: #64748b;
            margin-top: 4px;
            line-height: 1.45;
        }

        .template-theme-reset {
            border: 1px solid #dbe3ef;
            background: #ffffff;
            color: #475569;
            border-radius: 999px;
            padding: 6px 10px;
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .template-theme-reset:hover {
            border-color: #93c5fd;
            color: #1d4ed8;
            background: #eff6ff;
        }

        .template-theme-swatches {
            display: grid;
            grid-template-columns: repeat(6, minmax(0, 1fr));
            gap: 12px;
            margin-bottom: 14px;
        }

        .template-theme-swatch {
            width: 100%;
            aspect-ratio: 1;
            border-radius: 999px;
            border: 4px solid rgba(255, 255, 255, 0.85);
            box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08), inset 0 0 0 1px rgba(15, 23, 42, 0.06);
            cursor: pointer;
            transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
        }

        .template-theme-swatch:hover {
            transform: translateY(-1px) scale(1.03);
            box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
        }

        .template-theme-swatch.active {
            border-color: #6366f1;
            box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15), 0 8px 18px rgba(99, 102, 241, 0.18);
        }

        .template-theme-custom label {
            display: block;
            font-size: 12px;
            font-weight: 600;
            color: #475569;
            margin-bottom: 8px;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }

        .template-theme-custom-row {
            display: grid;
            grid-template-columns: 58px minmax(0, 1fr) auto;
            gap: 10px;
            align-items: center;
        }

        #theme-accent-picker {
            width: 58px;
            height: 46px;
            border: 1px solid #dbe3ef;
            border-radius: 14px;
            padding: 5px;
            background: #ffffff;
            cursor: pointer;
            box-shadow: inset 0 0 0 1px rgba(255,255,255,0.7);
        }

        #theme-accent-value {
            height: 46px;
            border-radius: 14px;
            font-weight: 600;
            letter-spacing: 0.02em;
        }

        .template-theme-chip {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            height: 46px;
            padding: 0 14px;
            border-radius: 14px;
            border: 1px solid #dbe3ef;
            background: #ffffff;
            color: #64748b;
            font-size: 12px;
            font-weight: 700;
            white-space: nowrap;
        }

        .template-font-grid {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 8px;
            max-height: 300px;
            overflow-y: auto;
            padding-right: 2px;
        }

        .template-font-grid::-webkit-scrollbar {
            width: 4px;
        }

        .template-font-grid::-webkit-scrollbar-thumb {
            background: #cbd5e1;
            border-radius: 4px;
        }

        .template-font-card {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            justify-content: center;
            padding: 8px 10px;
            border-radius: 12px;
            border: 1.5px solid #e2e8f0;
            background: #ffffff;
            cursor: pointer;
            text-align: left;
            transition: all 0.18s ease;
            user-select: none;
        }

        .template-font-card:hover {
            border-color: #93c5fd;
            background: #f8fafc;
            transform: translateY(-1px);
        }

        .template-font-card.active {
            border-color: #6366f1;
            background: #eff6ff;
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
        }

        .template-font-name {
            font-size: 13px;
            font-weight: 700;
            color: #0f172a;
            line-height: 1.2;
        }

        .template-font-preview {
            font-size: 10.5px;
            color: #64748b;
            margin-top: 2px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            width: 100%;
        }

        .template-sidebar-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.3);
            z-index: 999;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.3s ease;
        }

        .template-sidebar-overlay.open {
            opacity: 1;
            pointer-events: all;
        }

        .table-format-panel-wrap {
            display: none;
            margin-bottom: 14px;
            padding: 12px;
            border: 1px solid #dbe5f3;
            border-radius: 14px;
            background: #f8fbff;
        }

        .table-format-panel-wrap.open {
            display: block;
        }

        .table-format-panel-head {
            display: flex;
            align-items: flex-start;
            justify-content: space-between;
            gap: 12px;
            margin-bottom: 10px;
        }

        .table-format-title {
            font-size: 13px;
            font-weight: 700;
            color: var(--text-main);
        }

        .table-format-subtitle {
            margin-top: 2px;
            font-size: 12px;
            color: var(--text-sub);
        }

        .table-format-panel {
            display: grid;
            gap: 10px;
        }

        .table-format-row {
            display: grid;
            grid-template-columns: minmax(120px, 160px) 1fr;
            gap: 12px;
            align-items: center;
        }

        .table-format-label {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            font-size: 13px;
            font-weight: 600;
            color: var(--text-main);
        }

        .table-format-controls {
            display: grid;
            grid-template-columns: minmax(0, 1fr) 70px auto;
            gap: 8px;
            align-items: center;
        }

        .table-format-range {
            width: 100%;
        }

        .table-format-number {
            width: 100%;
            padding: 8px 10px;
            border: 1px solid #cbd5e1;
            border-radius: 10px;
            background: #fff;
            color: var(--text-main);
            font: inherit;
        }

        .table-format-unit {
            font-size: 12px;
            font-weight: 600;
            color: var(--text-sub);
        }

        /* Mobile Responsive Sidebar */
        @media (max-width: 768px) {
            .template-sidebar {
                width: 100%;
            }
            
            .template-card {
                min-height: 350px;
            }
            
            .template-card-preview iframe {
                width: 300%;
                height: 300%;
                transform: scale(0.333);
            }

            .table-format-row {
                grid-template-columns: 1fr;
            }

            .table-format-controls {
                grid-template-columns: minmax(0, 1fr) 62px auto;
            }
        }

        .preview-wrapper {
            width: 100%;
            max-width: 880px;
            position: relative;
            aspect-ratio: 1 / 1.414;
            background: radial-gradient(circle at top, #f9fafb 0, #f3f4f6 45%, #e5e7eb 100%);
            box-shadow: 0 18px 45px rgba(15, 23, 42, 0.35);
            border-radius: 18px;
            padding: 16px;
            box-sizing: border-box;
            overflow: hidden;
        }

        .reorder-overlay {
            position: fixed;
            inset: 0;
            background: rgba(15, 23, 42, 0.25);
            z-index: 998;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease;
        }

        .reorder-overlay.open {
            opacity: 1;
            pointer-events: all;
        }

        .reorder-drawer {
            position: fixed;
            top: 0;
            right: 0;
            width: 360px;
            height: 100vh;
            background: #ffffff;
            box-shadow: -8px 0 28px rgba(2, 6, 23, 0.2);
            z-index: 999;
            transform: translateX(100%);
            transition: transform 0.25s ease;
            display: flex;
            flex-direction: column;
            pointer-events: none;
        }

        .reorder-drawer.open {
            transform: translateX(0);
            pointer-events: auto;
        }

        .reorder-drawer-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            padding: 16px;
            border-bottom: 1px solid var(--border-color);
            background: #f8fafc;
        }

        .reorder-title {
            font-weight: 700;
            font-size: 15px;
            color: var(--text-main);
        }

        .reorder-subtitle {
            font-size: 12px;
            color: var(--text-muted);
        }

        .reorder-drawer-list {
            flex: 1;
            overflow-y: auto;
            padding: 14px;
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .reorder-item {
            display: flex;
            align-items: center;
            gap: 10px;
            border: 1px solid var(--border-color);
            border-radius: 10px;
            background: #ffffff;
            padding: 10px 12px;
            box-shadow: var(--shadow-xs);
            cursor: grab;
        }

        .reorder-item:active {
            cursor: grabbing;
        }

        .reorder-item.drag-over {
            border-color: var(--primary);
            box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
        }

        .reorder-item-handle {
            font-size: 13px;
            color: var(--text-muted);
            letter-spacing: 1px;
            user-select: none;
        }

        .reorder-item-label {
            flex: 1;
            font-size: 13px;
            font-weight: 600;
            color: var(--text-main);
        }

        .reorder-mini-actions {
            display: inline-flex;
            gap: 4px;
        }

        .reorder-mini-btn {
            width: 24px;
            height: 24px;
            border-radius: 6px;
            border: 1px solid var(--border-color);
            background: #f8fafc;
            color: var(--text-muted);
            cursor: pointer;
            font-size: 12px;
            line-height: 1;
            padding: 0;
        }

        .reorder-mini-btn:disabled {
            opacity: 0.4;
            cursor: not-allowed;
        }

        /* Group/Ungroup toggle needs to fit a word, unlike the square arrow buttons. */
        .reorder-group-btn {
            width: auto;
            height: 24px;
            padding: 0 10px;
            border-radius: 999px;
            border: 1px solid var(--border-color);
            background: #f8fafc;
            color: var(--text-muted);
            font-size: 11px;
            font-weight: 600;
            line-height: 1;
            cursor: pointer;
            transition: background .15s ease, color .15s ease, border-color .15s ease;
        }

        .reorder-group-btn:hover:not(:disabled) {
            background: #eff6ff;
            border-color: #bfdbfe;
            color: #1d4ed8;
        }

        .reorder-group-btn.active {
            background: #1d4ed8;
            border-color: #1d4ed8;
            color: #ffffff;
        }

        .reorder-group-btn.active:hover {
            background: #1e40af;
            border-color: #1e40af;
        }

        .reorder-group-btn:disabled {
            opacity: 0.4;
            cursor: not-allowed;
        }

        .reorder-grouped-tag {
            display: inline-block;
            margin-left: 6px;
            padding: 1px 7px;
            border-radius: 999px;
            background: #eff6ff;
            border: 1px solid #bfdbfe;
            color: #1d4ed8;
            font-size: 10px;
            font-weight: 600;
            vertical-align: middle;
        }

        .reorder-drawer-actions {
            padding: 12px 16px;
            border-top: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            gap: 8px;
            background: #ffffff;
        }

        iframe {
            width: 100%;
            height: 100%;
            border: none;
            display: block;
            background: #fff;
            border-radius: 12px;
            overflow: hidden;
        }

        /* Loading Overlay */
        .loading-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(255, 255, 255, 0.85);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.3s;
            backdrop-filter: blur(2px);
        }

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* DOCX Export Info Popup */
.docx-info-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, backdrop-filter 0.25s ease;
    z-index: 1500;
    padding: 20px;
}

.docx-info-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.docx-info-card {
    width: min(92vw, 420px);
    background: #ffffff;
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    transform: translateY(10px);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Template paywall modals (login + buy) ───────────────────────── */
.tpl-gate-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 1600;
    padding: 20px;
}
.tpl-gate-overlay.active {
    opacity: 1;
    pointer-events: all;
}
.tpl-gate-card {
    position: relative;
    overflow: hidden;
    width: min(94vw, 460px);
    background: #ffffff;
    border-radius: var(--radius-lg);
    padding: 32px 26px 24px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}
/* Soft gold glow behind the emblem for depth. */
.tpl-gate-card::before {
    content: '';
    position: absolute;
    top: -70px;
    left: 50%;
    transform: translateX(-50%);
    width: 240px;
    height: 240px;
    background: radial-gradient(circle, rgba(232, 160, 32, 0.20) 0%, rgba(232, 160, 32, 0) 70%);
    pointer-events: none;
}
.tpl-gate-card > * {
    position: relative;
}
.tpl-gate-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: transparent;
    border: 0;
    font-size: 22px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
}
.tpl-gate-emblem {
    width: 60px;
    height: 60px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(135deg, #f7d774 0%, #e8a020 55%, #cf8617 100%);
    border-radius: 18px;
    box-shadow: 0 8px 20px rgba(200, 128, 26, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.tpl-gate-card h3 {
    margin: 4px 0 8px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
}
.tpl-gate-text {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0 auto 16px;
    max-width: 340px;
}
.tpl-gate-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 6px;
}
.tpl-gate-btn-primary,
.tpl-gate-btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid transparent;
}
.tpl-gate-btn-primary {
    background: var(--primary);
    color: #fff;
}
.tpl-gate-btn-primary:hover {
    filter: brightness(0.95);
}
.tpl-gate-btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border-color);
}
.tpl-gate-btn-ghost:hover {
    background: #f8fafc;
}
.tpl-course-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 4px 0 18px;
    text-align: left;
}
.tpl-course-card {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 13px 15px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    text-decoration: none;
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.tpl-course-card:hover {
    border-color: #e8a020;
    box-shadow: 0 6px 16px rgba(200, 128, 26, 0.20);
    transform: translateY(-1px);
}
.tpl-course-icon {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b8791a;
    background: linear-gradient(135deg, #fdf3dc 0%, #f8e3b0 100%);
    border: 1px solid rgba(200, 128, 26, 0.18);
}
.tpl-course-info {
    flex: 1;
    min-width: 0;
}
.tpl-course-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
}
.tpl-course-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 2px;
}
.tpl-course-cta {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 13px;
    font-weight: 700;
    color: #c8801a;
    white-space: nowrap;
}
.tpl-course-card:hover .tpl-course-cta {
    color: #a86913;
}

.docx-info-overlay.open .docx-info-card {
    transform: translateY(0);
}

.docx-info-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    position: relative;
}

.docx-info-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eff6ff;
    color: var(--primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
}

.docx-info-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}

.docx-info-close {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: var(--bg-hover);
    color: var(--text-muted);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.docx-info-close:hover {
    background: var(--border-color);
    color: var(--text-main);
}

.docx-info-body {
    margin-bottom: 20px;
}

.docx-info-text {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 16px;
    line-height: 1.5;
}

.docx-tip-box {
    background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
    border: 1px solid #bbf7d0;
    border-radius: 12px;
    padding: 16px;
    position: relative;
}

.docx-tip-badge {
    display: inline-block;
    background: #dcfce7;
    color: #15803d;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 999px;
    margin-bottom: 8px;
}

.docx-tip-box p {
    margin: 0;
    font-size: 13px;
    color: #166534;
    line-height: 1.6;
    font-weight: 500;
}

.docx-link {
    color: #10b981;
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1.5px solid rgba(16, 185, 129, 0.3);
    transition: all 0.15s ease;
}

.docx-link:hover {
    color: #059669;
    border-bottom-color: #059669;
}

.docx-info-actions {
    display: flex;
    justify-content: flex-end;
}

.docx-info-actions button {
    min-width: 90px;
    padding: 10px 18px;
    font-weight: 600;
    font-size: 13px;
    border-radius: 10px;
}

.ai-prompt-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1400;
    padding: 20px;
}

.ai-prompt-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.ai-prompt-card {
    width: min(92vw, 440px);
    background: #fff;
    border-radius: 16px;
    padding: 18px 18px 16px;
    box-shadow: 0 22px 50px rgba(15, 23, 42, 0.18);
    border: 1px solid rgba(148, 163, 184, 0.4);
}

.ai-prompt-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ai-prompt-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
}

.ai-prompt-close {
    border: none;
    background: #f8fafc;
    color: #0f172a;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.ai-prompt-sub {
    margin: 8px 0 12px;
    font-size: 12px;
    color: #64748b;
}

.ai-prompt-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 10px;
}

.ai-prompt-chip {
    border: 1px solid #dbe5f5;
    background: #f8fbff;
    color: #1f3f74;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
}

.ai-prompt-chip:hover {
    background: #eef5ff;
    border-color: #c8d8f2;
}

.ai-prompt-card textarea.form-control {
    min-height: 90px;
    resize: vertical;
}

.ai-prompt-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 12px;
}

.ai-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1450;
    padding: 20px;
}

.ai-preview-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.ai-preview-card {
    width: min(94vw, 920px);
    background: #fff;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    box-shadow: 0 22px 50px rgba(15, 23, 42, 0.18);
    padding: 16px;
}

.ai-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.ai-preview-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
}

.ai-preview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.ai-preview-pane {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #f8fafc;
    min-height: 220px;
    display: flex;
    flex-direction: column;
}

.ai-preview-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
    padding: 10px 12px;
}

.ai-preview-content {
    margin: 0;
    padding: 12px;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.45;
    color: #0f172a;
    white-space: pre-wrap;
    overflow: auto;
    max-height: min(56vh, 420px);
}

.diff-line {
    display: block;
    padding: 3px 6px;
    border-radius: 6px;
    margin-bottom: 2px;
}

.diff-unchanged {
    background: transparent;
}

.diff-added {
    background: #ecfdf3;
    color: #065f46;
    border-left: 3px solid #22c55e;
}

.diff-removed {
    background: #fef2f2;
    color: #991b1b;
    border-left: 3px solid #ef4444;
}

.diff-empty {
    color: #94a3b8;
    font-style: italic;
}

@media (max-width: 640px) {
    .ai-prompt-overlay {
        padding: 12px;
        align-items: flex-end;
    }

    .ai-prompt-card {
        width: 100%;
        border-radius: 18px 18px 10px 10px;
        padding: 16px;
    }

    .ai-preview-overlay {
        padding: 10px;
        align-items: flex-end;
    }

    .ai-preview-card {
        width: 100%;
        border-radius: 16px 16px 10px 10px;
        padding: 12px;
    }

    .ai-preview-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .ai-preview-content {
        max-height: 32vh;
        font-size: 12px;
    }
}

        .spinner {
            width: 36px;
            height: 36px;
            border: 3px solid var(--border-color);
            border-top-color: var(--primary);
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }

        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }

        /* Mobile Nav */
        .mobile-nav {
            display: none;
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 60px;
            background: var(--bg-panel);
            border-top: 1px solid var(--border-color);
            z-index: 100;
            justify-content: space-around;
            align-items: center;
            padding-bottom: env(safe-area-inset-bottom);
        }

        .nav-tab {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100%;
            color: var(--text-light);
            font-size: 10px;
            font-weight: 600;
            gap: 4px;
            cursor: pointer;
            transition: color 0.2s;
        }

        .nav-tab.active {
            color: var(--primary);
        }

        .nav-tab svg {
            width: 20px;
            height: 20px;
            stroke-width: 2;
        }

        /* Toast */
        #toast {
            position: fixed;
            bottom: 30px;
            left: 50%;
            transform: translateX(-50%) translateY(20px);
            background: var(--text-main);
            color: white;
            padding: 11px 22px;
            border-radius: 99px;
            font-size: 13px;
            font-weight: 500;
            box-shadow: var(--shadow-lg);
            opacity: 0;
            transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
            pointer-events: none;
            z-index: 9999;
        }

        #toast.show {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }

        /* --- CV REVIEWER --- */
        .reviewer-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.98);
            backdrop-filter: blur(5px);
            z-index: 2000;
            display: none;
            overflow-y: auto;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .reviewer-overlay.active {
            display: block;
            opacity: 1;
        }

        .reviewer-container {
            max-width: 800px;
            margin: 0 auto;
            background: var(--bg-app);
            min-height: 100vh;
            box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
            position: relative;
            display: flex;
            flex-direction: column;
        }

        .reviewer-header-bar {
            padding: 16px 24px;
            background: white;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .reviewer-body {
            padding: 32px 24px;
            flex: 1;
        }

        .hero-section {
            text-align: center;
            margin-bottom: 40px;
        }

        .hero-section h2 {
            font-size: 28px;
            font-weight: 800;
            margin-bottom: 10px;
            background: linear-gradient(135deg, var(--primary) 0%, #06b6d4 100%);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .hero-section p {
            color: var(--text-muted);
            font-size: 16px;
            max-width: 500px;
            margin: 0 auto;
            line-height: 1.5;
        }

        .upload-section {
            max-width: 480px;
            margin: 0 auto;
        }

        .drop-area {
            border: 2px dashed var(--border-dark);
            border-radius: 16px;
            padding: 40px;
            text-align: center;
            background: white;
            transition: all 0.2s;
            cursor: pointer;
        }

        .drop-area:hover,
        .drop-area.dragover {
            border-color: var(--primary);
            background: var(--primary-light);
        }

        .icon-cloud {
            font-size: 48px;
            margin-bottom: 16px;
            display: block;
        }

        .drop-area p {
            margin: 8px 0;
            font-weight: 500;
            color: var(--text-main);
        }

        .drop-area .sub-text {
            font-size: 13px;
            color: var(--text-light);
            font-weight: 400;
            margin-bottom: 20px;
        }

        .preview-area {
            text-align: center;
            max-width: 400px;
            margin: 0 auto;
        }

        .preview-thumb {
            border: 1px solid var(--border-color);
            border-radius: 8px;
            overflow: hidden;
            margin-bottom: 16px;
            background: white;
            box-shadow: var(--shadow-md);
        }

        .preview-thumb canvas {
            width: 100%;
            height: auto;
            display: block;
        }

        .file-info {
            display: flex;
            flex-direction: column;
            gap: 4px;
            margin-bottom: 20px;
            font-size: 14px;
            font-weight: 500;
        }

        .preview-actions {
            display: flex;
            gap: 10px;
            justify-content: center;
        }

        /* Results */
        .score-section {
            text-align: center;
            margin-bottom: 28px;
        }

        .score-section-title {
            font-size: 18px;
            font-weight: 600;
            color: var(--text-main);
            margin-bottom: 16px;
        }

        .score-container {
            position: relative;
            width: 130px;
            height: 130px;
            margin: 0 auto 12px;
            filter: drop-shadow(0 4px 12px rgba(37, 99, 235, 0.15));
        }

        .score-chart {
            transform: rotate(-90deg);
            width: 100%;
            height: 100%;
        }

        .score-bg {
            fill: none;
            stroke: #e2e8f0;
            stroke-width: 3.5;
        }

        .score-progress {
            fill: none;
            stroke: url(#scoreGradient);
            stroke-width: 3.5;
            stroke-linecap: round;
            transition: stroke-dasharray 1.5s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .score-value {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 32px;
            font-weight: 800;
            color: var(--primary);
            letter-spacing: -0.02em;
        }

        .score-label {
            font-size: 14px;
            font-weight: 500;
            color: var(--text-muted);
            margin-top: 4px;
        }

        .score-notes {
            text-align: center;
            margin-bottom: 32px;
            background: white;
            padding: 16px;
            border-radius: 12px;
            border: 1px solid var(--border-color);
            font-size: 14px;
            line-height: 1.5;
            color: var(--text-muted);
        }

        /* Tabs */
        .tabs {
            display: flex;
            gap: 8px;
            margin-bottom: 24px;
            border-bottom: 1px solid var(--border-color);
            padding-bottom: 1px;
        }

        .tab-btn {
            background: none;
            border: none;
            padding: 10px 16px;
            font-weight: 600;
            color: var(--text-light);
            cursor: pointer;
            border-bottom: 2px solid transparent;
            transition: all 0.2s;
        }

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

        .tab-btn.active {
            color: var(--primary);
            border-bottom-color: var(--primary);
        }

        .tab-content {
            display: none;
            animation: fadeIn 0.3s ease;
        }

        .tab-content.active {
            display: block;
        }

        /* Review Cards */
        .review-card {
            background: white;
            border: 1px solid var(--border-color);
            border-radius: 12px;
            margin-bottom: 16px;
            overflow: hidden;
            transition: all 0.2s;
        }

        .review-card .section-header {
            padding: 16px 20px;
            background: #f8fafc;
            cursor: pointer;
            display: flex;
            justify-content: space-between;
            align-items: center;
            user-select: none;
            font-weight: 600;
            color: var(--text-main);
        }

        .review-card .section-header:hover {
            background: #f1f5f9;
        }

        .review-card .toggle-icon {
            transition: transform 0.2s;
            font-size: 12px;
            opacity: 0.5;
        }

        .review-card .content-area {
            padding: 20px;
            display: none;
            border-top: 1px solid var(--border-color);
            font-size: 14px;
            line-height: 1.6;
            color: var(--text-main);
        }

        .review-card.collapsed .content-area {
            display: block;
        }

        .review-card:not(.collapsed) .content-area {
            display: none;
        }

        .review-card.open .content-area {
            display: block;
        }

        .review-card.open .toggle-icon {
            transform: rotate(180deg);
        }

        /* Utility Classes for content */
        .highlight-good {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 20px;
            height: 20px;
            color: var(--success);
            font-weight: bold;
            margin-right: 8px;
            font-size: 13px;
        }

        .highlight-issue {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 20px;
            height: 20px;
            color: var(--danger);
            font-weight: bold;
            margin-right: 8px;
            font-size: 13px;
            
        }

        /* Compact severity badges */
        .severity-badge {
            display: inline-flex;
            align-items: center;
            padding: 2px 8px;
            border-radius: 4px;
            font-size: 0.7rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.025em;
            margin-left: 6px;
            vertical-align: middle;
        }

        .severity-critical {
            background-color: rgba(220, 38, 38, 0.12);
            color: #dc2626;
            border: 1px solid rgba(220, 38, 38, 0.25);
        }

        .severity-high {
            background-color: rgba(234, 88, 12, 0.12);
            color: #ea580c;
            border: 1px solid rgba(234, 88, 12, 0.25);
        }

        .severity-moderate {
            background-color: rgba(202, 138, 4, 0.12);
            color: #ca8a04;
            border: 1px solid rgba(202, 138, 4, 0.25);
        }

        .severity-low {
            background-color: rgba(100, 116, 139, 0.12);
            color: #64748b;
            border: 1px solid rgba(100, 116, 139, 0.25);
        }

        /* Feedback section labels */
        .feedback-label {
            display: block;
            margin: 16px 0 8px 0;
            font-size: 0.95rem;
            font-weight: 700;
            color: var(--primary);
            border-bottom: 1px solid rgba(59, 130, 246, 0.2);
            padding-bottom: 4px;
        }

        /* Improved content readability - bullet points */
        .feedback-bullet {
            display: block;
            padding-left: 1.5rem;
            position: relative;
            margin: 0.5rem 0;
            line-height: 1.6;
        }

        .feedback-bullet::before {
            content: "•";
            position: absolute;
            left: 0.5rem;
            color: black;
            font-weight: bold;
        }

        /* Numbered items - similar style but no pseudo-element */
        .feedback-numbered {
            display: block;
            margin: 0.5rem 0;
            padding-left: 1.25rem;
            line-height: 1.6;
        }

        /* Content area improvements */
        .content-area p {
            margin: 0.5rem 0;
            line-height: 1.6;
        }

        .content-area > p:first-child {
            margin-top: 0;
        }

        .reviewer-footer {
            margin-top: 40px;
            padding-top: 20px;
            border-top: 1px solid var(--border-color);
            text-align: center;
            display: flex;
            justify-content: center;
            gap: 12px;
        }

        /* Leaderboard/History */
        .history-item {
            padding: 12px;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            margin-bottom: 8px;
            background: #fff;
            cursor: pointer;
            transition: all 0.1s;
        }

        .history-item:hover {
            border-color: var(--primary);
            transform: translateY(-1px);
            box-shadow: var(--shadow-sm);
        }

        /* Tailwind Utilities needed */
        .text-center {
            text-align: center;
        }

        .text-danger {
            color: var(--danger);
        }

        .p-4 {
            padding: 16px;
        }

        .mb-2 {
            margin-bottom: 8px;
        }

        .font-semibold {
            font-weight: 600;
        }

        .text-sm {
            font-size: 13px;
        }

        .text-xs {
            font-size: 11px;
        }

        .bg-gray-200 {
            background: #e2e8f0;
        }

        .rounded {
            border-radius: 4px;
        }

        .px-1 {
            padding-left: 4px;
            padding-right: 4px;
        }

        .flex {
            display: flex;
        }

        .justify-between {
            justify-content: space-between;
        }

        .items-center {
            align-items: center;
        }

        .space-y-3>*+* {
            margin-top: 12px;
        }

        .list-decimal {
            list-style-type: decimal;
        }

        .list-inside {
            list-style-position: inside;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(5px);
            }

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

        /* --- RESPONSIVE --- */
        
        /* Large Tablet / Small Desktop (1024px - 1200px) */
        @media (max-width: 1200px) {
            .editor {
                flex: 0 0 480px;
            }
        }
        
        /* Tablet Landscape (769px - 1024px) */
        @media (max-width: 1024px) {
            .editor {
                flex: 0 0 420px;
                min-width: 360px;
            }
            
            .editor-header {
                padding: 16px 20px 12px;
            }
            
            .brand-row {
                margin-bottom: 12px;
            }
            
            .app-logo {
                font-size: 14px;
            }
            
            .app-logo svg {
                width: 24px;
                height: 24px;
            }
            .app-logo img {
                height: 37px;
                width: auto;
                max-width: 190px;
            }
            .beta-badge {
                display: none;
            }
            
            .btn-icon {
                padding: 6px 10px;
                font-size: 11px;
            }
            
            .form-control {
                font-size: 13px;
            }
            
            .section-expand-btn {
                padding: 12px 16px;
                font-size: 13px;
            }
        }

        /* Small Tablet (769px - 900px) */
        @media (max-width: 900px) {
            .editor {
                flex: 0 0 380px;
                min-width: 320px;
            }
            
            .editor-header {
                padding: 14px 16px 10px;
            }
            
            .beta-badge {
                display: none;
            }
            
            .action-bar {
                gap: 4px;
            }
            
            .btn-icon span:not(.btn-text-always) {
                display: none;
            }
            
            .btn-icon {
                padding: 8px;
            }
        }

        /* Mobile (max-width: 768px) - Full screen panels with tab switching */
        @media (max-width: 768px) {
            .mobile-nav {
                display: flex;
            }

            .beta-badge {
                display: inline-flex;
                align-items: center;
                padding: 2px 7px;
                font-size: 9px;
                line-height: 1;
            }

            .editor {
                width: 100%;
                height: calc(100% - 60px);
                position: fixed;
                top: 0;
                left: 0;
                border: none;
                flex: none;
                min-width: unset;
                max-width: unset;
            }

            .preview {
                width: 100%;
                height: calc(100% - 60px);
                position: fixed;
                top: 0;
                left: 0;
                padding: 12px;
                z-index: 15;
            }

            body.view-editor .preview {
                transform: translateX(100%);
                display: none;
            }

            body.view-preview .editor {
                transform: translateX(-20%);
                display: none;
            }

            body.view-preview .preview {
                transform: translateX(0);
                display: flex;
            }

            .template-floater {
                width: 100%;
                max-width: 100%;
                justify-content: flex-start;
                flex-wrap: nowrap;
                gap: 6px;
                padding: 8px 10px;
                border-radius: 8px;
                overflow-x: auto;
                -webkit-overflow-scrolling: touch;
                scrollbar-width: none;
            }

            .template-floater::-webkit-scrollbar {
                display: none;
            }

            .floater-pill {
                padding: 6px 7px;
                gap: 6px;
                flex-shrink: 0;
            }

            .undo-redo-pill .template-label {
                display: none;
            }

            .undo-redo-pill {
                display: none;
            }

            .undo-redo-group {
                gap: 8px;
            }

            .undo-redo-btn {
                width: 28px;
                height: 28px;
            }

            .mobile-history-controls {
                position: fixed;
                right: 14px;
                bottom: 76px;
                z-index: 65;
                display: none;
                align-items: center;
                gap: 8px;
                padding: 8px;
                border-radius: 999px;
                background: rgba(255, 255, 255, 0.96);
                border: 1px solid rgba(203, 213, 225, 0.9);
                box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
                backdrop-filter: blur(8px);
            }

            body.view-preview .mobile-history-controls {
                display: inline-flex;
            }

            .mobile-history-btn {
                width: 34px;
                height: 34px;
                border-radius: 999px;
                border: 1px solid #d1d5db;
                background: #ffffff;
                color: var(--text-main);
                display: inline-flex;
                align-items: center;
                justify-content: center;
                cursor: pointer;
                transition: all 0.18s ease;
            }

            .mobile-history-btn:disabled {
                opacity: 0.45;
                cursor: not-allowed;
                background: #f1f5f9;
            }

            .reorder-drawer {
                width: min(360px, 92vw);
                max-width: 92vw;
                height: 100vh;
                top: 0;
                bottom: auto;
                right: 0;
                border-top-left-radius: 0;
                border-top-right-radius: 0;
                transform: translateX(100%);
            }

            .reorder-drawer.open {
                transform: translateX(0);
            }

            .editor-content {
                padding: 12px 16px 80px;
            }
            
            .editor-header {
                padding: 12px 16px 10px;
            }

            .action-bar {
                gap: 4px;
                padding-bottom: 4px;
                margin-bottom: 8px;
            }

            .btn-icon {
                font-size: 11px;
                padding: 8px 10px;
            }
            
            .btn-icon svg {
                width: 14px;
                height: 14px;
            }
            
            .brand-row {
                margin-bottom: 10px;
            }
            
            .app-logo {
                font-size: 13px;
                gap: 8px;
            }
            
            .section-expand-btn {
                padding: 12px 14px;
                font-size: 13px;
            }
            
            .list-item {
                padding: 12px;
            }
            
            .form-group label {
                font-size: 11px;
            }
            
            .form-control {
                font-size: 14px;
                padding: 10px 12px;
            }

            #toast.show {
                bottom: 80px;
            }
            
            .resize-handle {
                display: none;
            }
        }
        
        /* Small Mobile (max-width: 480px) */
        @media (max-width: 480px) {
            .editor-content {
                padding: 10px 12px 90px;
            }
            
            .editor-header {
                padding: 10px 12px 8px;
            }
            
            .action-bar {
                gap: 3px;
            }
            
            .btn-icon {
                padding: 7px 8px;
                font-size: 10px;
            }
            
            .btn-icon svg {
                width: 12px;
                height: 12px;
            }
            
            .app-logo {
                font-size: 12px;
                gap: 6px;
            }
            
            .app-logo svg {
                width: 20px;
                height: 20px;
            }
            .app-logo img {
                height: 31px;
                width: auto;
                max-width: 160px;
            }

            .beta-badge {
                padding: 2px 6px;
                font-size: 8px;
            }
            
            .section-expand-btn {
                padding: 10px 12px;
                font-size: 12px;
            }
            
            .form-control {
                padding: 8px 10px;
            }
            
            .list-item {
                padding: 10px;
            }
            
            .item-actions {
                gap: 4px;
            }
            
            .action-btn {
                width: 22px;
                height: 22px;
                font-size: 12px;
            }
            
            .template-floater {
                padding: 6px 10px;
                justify-content: flex-start;
                flex-wrap: nowrap;
                gap: 6px;
            }

            .mobile-history-controls {
                right: 10px;
                bottom: 72px;
                padding: 7px;
                gap: 6px;
            }

            .mobile-history-btn {
                width: 32px;
                height: 32px;
            }
            
            .template-floater select {
                font-size: 11px;
            }
            
            .preview {
                padding: 8px;
            }
        }
        
        /* Extra Small Mobile (max-width: 360px) */
        @media (max-width: 360px) {
            .editor-header {
                padding: 8px 10px 6px;
            }
            
            .btn-icon {
                padding: 6px;
            }
            
            .brand-row .btn-icon span {
                display: none;
            }
        }
