/* ============================================================================
   StampSync — shared design system
   Tokens, base styles and UI components used by index.html, login.html and
   license.html. Page-specific rules stay in each page's own <style> block.
   ========================================================================== */

:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --secondary: #10B981;
    --secondary-hover: #059669;
    --bg-body: #F9FAFB;
    --bg-card: #FFFFFF;
    --text-main: #111827;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
    --sidebar-bg: #1F2937;
    --sidebar-hover: #374151;
    --radius-lg: 16px;
    --radius-md: 8px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --danger: #EF4444;
    --danger-hover: #DC2626;
    --warning: #F59E0B;
    --info: #3B82F6;
    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* App shell: sidebar + topbar + scrolling content (index.html) */
body.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: white;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 100;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-main);
}

.brand-logo {
    height: 115px;
    width: auto;
}

.sidebar-menu {
    flex: 1;
    padding: 1.5rem 0;
    overflow-y: auto;
}

.menu-item {
    padding: 0.875rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.95rem;
    border-left: 3px solid transparent;
}

.menu-item:hover {
    background: var(--bg-body);
    color: var(--text-main);
}

.menu-item.active {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary);
    border-left-color: var(--primary);
}

.menu-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Topbar */
.topbar {
    background: white;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.topbar-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-email {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Content Area */
.content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

/* Page Sections */
.page-section {
    display: none;
}

.page-section.active {
    display: block;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.card-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: #F9FAFB;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body {
    padding: 1.5rem;
}

/* Buttons */
.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(1px);
}

.btn-success {
    background: var(--secondary);
}

.btn-success:hover {
    background: var(--secondary-hover);
}

.btn-secondary {
    background: #6B7280;
}

.btn-secondary:hover {
    background: #4B5563;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-outline {
    background: #FFFFFF;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    box-shadow: none;
}

.btn-outline:hover {
    background: var(--bg-body);
    color: var(--primary);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.read-only-banner {
    background: #FEF3C7;
    border: 1px solid #FCD34D;
    color: #92400E;
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.btn:disabled, input:disabled, select:disabled, textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed !important;
}

/* Grid Layout */
.grid {
    display: grid;
    gap: 1.5rem;
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

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

/* Preview Box */
.preview-box {
    border: 2px dashed #D1D5DB;
    border-radius: var(--radius-lg);
    padding: 2rem;
    background: #FFFFFF;
    min-height: 500px;
}

/* Table */
.tenant-table {
    width: 100%;
    border-collapse: collapse;
}

.tenant-table thead {
    background: #F9FAFB;
    border-bottom: 2px solid var(--border-color);
}

.tenant-table th {
    padding: 0.65rem 0.85rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tenant-table td {
    padding: 0.85rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.tenant-table tbody tr {
    transition: background 0.2s;
}

.tenant-table tbody tr:hover {
    background: #F9FAFB;
}

.tenant-table tbody tr:last-child td {
    border-bottom: none;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.status-active {
    background: #D1FAE5;
    color: #065F46;
}

.status-pending {
    background: #FEF3C7;
    color: #92400E;
}

.status-warning {
    background: #FED7AA;
    color: #9A3412;
}

.status-inactive {
    background: #FEE2E2;
    color: #991B1B;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

/* Toast */
#toast {
    visibility: hidden;
    min-width: 300px;
    background-color: #111827;
    color: #fff;
    text-align: center;
    border-radius: var(--radius-md);
    padding: 1rem;
    position: fixed;
    z-index: var(--z-toast);
    left: 50%;
    bottom: 40px;
    transform: translateX(-50%);
    box-shadow: var(--shadow-lg);
    font-weight: 500;
}

#toast.show {
    visibility: visible;
    animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@keyframes fadein {
    from {
        bottom: 0;
        opacity: 0;
    }
    to {
        bottom: 30px;
        opacity: 1;
    }
}

@keyframes fadeout {
    from {
        bottom: 30px;
        opacity: 1;
    }
    to {
        bottom: 0;
        opacity: 0;
    }
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
}

.modal-card {
    background: white;
    width: 90%;
    max-width: 700px;
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-height: 90vh;
    overflow-y: auto;
}

.coming-soon-badge {
    display: inline-block;
    background: #FEF3C7;
    color: #92400E;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 999px;
    margin-left: 8px;
}

/* Wizard Styles */
.wizard-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
}

.wizard-step-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.wizard-step.active .wizard-step-circle {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.wizard-step.completed .wizard-step-circle {
    background: var(--secondary);
    border-color: var(--secondary);
    color: white;
}

.wizard-step-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-align: center;
}

.wizard-step.active .wizard-step-label {
    color: var(--primary);
}

/* Setup Wizard Specific Styles */
.setup-wizard-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
}

.setup-wizard-step-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.setup-wizard-step.active .setup-wizard-step-circle {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.setup-wizard-step.completed .setup-wizard-step-circle {
    background: var(--secondary);
    border-color: var(--secondary);
    color: white;
}

.setup-wizard-step-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.setup-wizard-step.active .setup-wizard-step-label {
    color: var(--primary);
}

.setup-wizard-step.completed .setup-wizard-step-label {
    color: var(--secondary);
}

.rule-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    background: #F9FAFB;
}

.rule-item-text {
    flex: 1;
    font-size: 0.9rem;
}

.rule-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-right: 8px;
    background: #E0E7FF;
    color: #4338CA;
}

/* ── Mobile / narrow screens ── */
@media (max-width: 768px) {
    body.app-shell {
        flex-direction: column;
    }

    /* Sidebar becomes a compact top bar with a horizontal menu */
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        box-shadow: var(--shadow-sm);
        border-right: 0;
        border-bottom: 1px solid var(--border-color);
    }

    .sidebar-header {
        padding: 0.5rem 0.75rem;
        border-bottom: 0;
        flex-shrink: 0;
    }

    .brand-logo {
        height: 44px;
    }

    .sidebar-menu {
        display: flex;
        padding: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .menu-item {
        padding: 0.9rem 0.9rem;
        border-left: 0;
        border-bottom: 3px solid transparent;
        white-space: nowrap;
        font-size: 0.85rem;
    }

    .menu-item.active {
        border-bottom-color: var(--primary);
    }

    .menu-item .coming-soon-badge {
        display: none;
    }

    .sidebar-footer {
        display: none;
    }

    .topbar {
        padding: 0.75rem 1rem;
    }

    .topbar-title {
        font-size: 1.1rem;
    }

    .user-email {
        display: none;
    }

    .content {
        padding: 1rem;
    }

    .card-header {
        padding: 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .card-body {
        padding: 1rem;
    }

    .grid-cols-2 {
        grid-template-columns: 1fr;
    }

    .sig-grid {
        grid-template-columns: 1fr;
        padding: 1rem;
    }

    /* Modals go edge-to-edge */
    .modal-card {
        width: 100%;
        max-width: 100% !important;
        max-height: 100vh;
        border-radius: 0;
        padding: 1.25rem;
    }

    .wizard-step-label,
    .setup-wizard-step-label {
        display: none;
    }

    .tpl-card {
        width: 200px;
    }

    .tpl-card__thumb {
        width: 200px;
        height: 100px;
    }

    .tpl-card__thumb iframe {
        width: 400px;
        height: 200px;
    }

    .design-preview {
        min-height: 360px;
    }

    .design-preview__frame iframe {
        min-height: 300px;
    }
}

/* Fix TinyMCE dropdown z-index appearing behind modal */
.tox-tinymce-aux {
    z-index: 3000 !important;
}

/* License Management Styles */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.info-item {
    background: #F9FAFB;
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--primary);
}

.info-item label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.info-item .value {
    font-size: 1.5rem;
    color: var(--text-main);
    font-weight: 700;
}

.progress-bar {
    width: 100%;
    height: 30px;
    background: #E5E7EB;
    border-radius: 15px;
    overflow: hidden;
    margin: 10px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, #7C3AED 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    transition: width 0.3s ease;
}

.progress-fill.warning {
    background: linear-gradient(90deg, #F59E0B 0%, #D97706 100%);
}

.progress-fill.danger {
    background: linear-gradient(90deg, #EF4444 0%, #DC2626 100%);
}

.alert {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin: 1rem 0;
    font-weight: 500;
}

.alert-info {
    background: #DBEAFE;
    color: #1E40AF;
    border-left: 4px solid #3B82F6;
}

.alert-warning {
    background: #FEF3C7;
    color: #92400E;
    border-left: 4px solid #F59E0B;
}

.alert-danger {
    background: #FEE2E2;
    color: #991B1B;
    border-left: 4px solid #EF4444;
}

.alert-success {
    background: #D1FAE5;
    color: #065F46;
    border-left: 4px solid #10B981;
}

.status-trial {
    background: #FEF3C7;
    color: #92400E;
}

.status-grace {
    background: #FED7AA;
    color: #9A3412;
}

.license-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
}

.license-table thead {
    background: #F9FAFB;
    border-bottom: 2px solid var(--border-color);
}

.license-table th {
    padding: 0.875rem 1rem;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.license-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
}

.license-table tbody tr:hover {
    background: #F9FAFB;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Small inline spinner */
.spinner {
    border: 3px solid #f3f4f6;
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

/* License status badges shared with license.html */
.status-expired {
    background: #FEE2E2;
    color: #991B1B;
}

.status-past_due {
    background: #FDE68A;
    color: #92400E;
}

/* Forms (class-based so existing inline-styled inputs are untouched) */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    background: #FFFFFF;
    color: var(--text-main);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* ── Signature wizard modal sizing (index.html) ── */




/* ── Confirm dialog ── */
.confirm-card {
    max-width: 440px;
}

.confirm-card__title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.confirm-card__message {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

.confirm-card__actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ── Design step: gallery + editor/preview split ── */







.tpl-gallery__strip {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding: 0.25rem 0.25rem 0.75rem;
}

.tpl-card {
    flex: 0 0 auto;
    width: 240px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: #FFFFFF;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.tpl-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.tpl-card.is-active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.tpl-card__thumb {
    width: 240px;
    height: 120px;
    overflow: hidden;
    background: #FFFFFF;
    pointer-events: none;
}

.tpl-card__thumb iframe {
    width: 480px;
    height: 240px;
    border: 0;
    display: block;
    transform: scale(0.5);
    transform-origin: 0 0;
    pointer-events: none;
}

.tpl-card__name {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-top: 1px solid var(--border-color);
    color: var(--text-main);
}

.design-split {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: stretch;
}

.design-editor .form-hint {
    margin-top: 0.5rem;
}

.design-tabs {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.6rem;
}

.design-tab {
    background: #FFFFFF;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 0.4rem 0.9rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

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

.design-tab.is-active {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary);
    border-color: var(--primary);
}

.design-preview {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-body);
    display: flex;
    flex-direction: column;
    min-height: 500px;
}

.design-preview__bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background: #FFFFFF;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.design-preview__title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-right: auto;
}

.form-control--sm {
    width: auto;
    max-width: 260px;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

.design-preview__frame {
    flex: 1;
    padding: 0.75rem;
    display: flex;
}

.design-preview__frame iframe {
    flex: 1;
    width: 100%;
    min-height: 420px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #FFFFFF;
    display: block;
}

.design-preview__note {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0 0.75rem 0.6rem;
    min-height: 1.6em;
}

@media (max-width: 1100px) {
    .design-split {
        grid-template-columns: 1fr;
    }

    .design-step__conv {
        min-width: 0;
        width: 100%;
    }
}

/* ── Sidebar links (menu items that navigate to another page) ── */
a.menu-item {
    text-decoration: none;
}

.count-badge {
    display: inline-block;
    min-width: 1.5em;
    padding: 0 0.5em;
    border-radius: 999px;
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.6;
    text-align: center;
    vertical-align: middle;
}

.count-badge:empty {
    display: none;
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state svg {
    margin: 0 auto 1rem;
    opacity: 0.3;
    display: block;
}

.empty-state__title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.35rem;
}

.empty-state__text {
    font-size: 0.9rem;
    max-width: 420px;
    margin: 0 auto 1.25rem;
}

/* ── Signature rule cards ── */
.sig-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
    padding: 1.5rem;
}

.sig-card {
    display: flex;
    flex-direction: column;
    background: #FFFFFF;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}

.sig-card:hover {
    border-color: #C7D2FE;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.sig-card__thumb {
    position: relative;
    height: 150px;
    background: #FFFFFF;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    cursor: pointer;
}

.sig-card__thumb iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 200%;
    border: 0;
    transform: scale(0.5);
    transform-origin: 0 0;
    pointer-events: none;
}

.sig-card--draft .sig-card__thumb::after,
.sig-card--inactive .sig-card__thumb::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(249, 250, 251, 0.45);
    pointer-events: none;
}

.sig-card__nodesign {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    background: repeating-linear-gradient(45deg, #FAFAFB 0 10px, #F3F4F6 10px 20px);
}

.sig-card__body {
    padding: 1rem 1.25rem 0.75rem;
    flex: 1;
}

.sig-card__title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

.sig-card__title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.3;
}

.sig-card__desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.sig-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.sig-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: #EEF2FF;
    color: #4338CA;
    font-size: 0.75rem;
    font-weight: 600;
}

.sig-chip--muted {
    background: var(--bg-body);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.sig-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-body);
}

.sig-card__date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sig-card__delete:hover {
    color: var(--danger);
    border-color: var(--danger);
}

/* ═══════════════ v2 tokens (additive) ═══════════════ */
:root {
    --primary-50: #EEF2FF;
    --primary-100: #E0E7FF;
    --primary-200: #C7D2FE;
    --primary-ring: rgba(79, 70, 229, 0.15);
    --success-50: #D1FAE5;
    --success-200: #A7F3D0;
    --success-700: #047857;
    --warning-50: #FEF3C7;
    --warning-200: #FDE68A;
    --warning-700: #92400E;
    --danger-50: #FEE2E2;
    --danger-200: #FECACA;
    --danger-700: #B91C1C;
    --gray-100: #F3F4F6;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --radius-sm: 6px;
    --focus-ring: 0 0 0 3px rgba(79, 70, 229, 0.12);
    --z-modal: 2000;
    --z-designer: 2050;
    --z-modal-nested: 2100;
    --z-confirm: 2300;
    --z-toast: 2400;
    --z-tox: 3000;
    --dur-fast: 0.15s;
    --dur-base: 0.2s;
    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

#confirmModal { backdrop-filter: none; }

/* ── Buttons ── */
.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; padding: 0;
    border: 1px solid transparent; border-radius: var(--radius-md);
    background: transparent; color: var(--text-muted);
    cursor: pointer; font-family: inherit;
    transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.btn-icon:hover { background: var(--bg-body); color: var(--text-main); }
.btn-icon:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn-icon:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon svg { width: 16px; height: 16px; }

.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
    content: ''; position: absolute; width: 16px; height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.5); border-top-color: #fff; border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.btn-outline.is-loading::after { border-color: var(--primary-200); border-top-color: var(--primary); }
.spinner--sm { width: 14px; height: 14px; border-width: 2px; }

/* ── Forms ── */
.form-control--textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15); }
.form-error { font-size: 0.8rem; color: var(--danger-hover); margin-top: 0.4rem; }
.form-error[hidden] { display: none; }
.form-required { color: var(--danger); font-weight: 700; }
.form-optional { font-weight: 400; color: var(--text-muted); font-size: 0.85em; }
.checkbox-row { display: flex; align-items: flex-start; gap: 0.6rem; font-size: 0.9rem; cursor: pointer; user-select: none; margin-bottom: 1.25rem; }
.checkbox-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex-shrink: 0; }

/* ── Info boxes / placeholders ── */
.info-box {
    padding: 0.85rem 1rem; border-radius: var(--radius-md);
    background: var(--primary-50); border-left: 4px solid var(--primary);
    color: var(--text-main); font-size: 0.85rem; line-height: 1.5;
}
.info-box--warning { background: var(--warning-50); border-left-color: var(--warning); color: var(--warning-700); }
.info-box--danger { background: var(--danger-50); border-left-color: var(--danger); color: var(--danger-700); }
.placeholder-box {
    color: var(--text-muted); font-size: 0.85rem; padding: 1rem;
    border: 1px dashed var(--gray-300); border-radius: var(--radius-md); background: #FFFFFF;
    text-align: center; display: flex; align-items: center; justify-content: center; gap: 0.5rem; flex-wrap: wrap;
}
.placeholder-box--quiet { padding: 0.65rem 1rem; }
.placeholder-box--loading { border-style: solid; }

/* ── Segmented control ── */
.segmented { display: inline-flex; background: var(--bg-body); border: 1px solid var(--border-color); border-radius: 999px; padding: 2px; }
.segmented[hidden] { display: none; }
.segmented__btn {
    border: 0; background: transparent; padding: 0.35rem 0.8rem; border-radius: 999px;
    font: inherit; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); cursor: pointer;
    transition: background var(--dur-fast), color var(--dur-fast);
}
.segmented__btn:hover { color: var(--text-main); }
.segmented__btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.segmented__btn.is-active { background: #FFFFFF; color: var(--primary); box-shadow: var(--shadow-sm); }
.segmented__btn[data-status="active"].is-active { color: var(--success-700); }
.segmented__btn[data-status="inactive"].is-active { color: var(--text-main); }
.segmented--sm .segmented__btn { padding: 0.25rem 0.65rem; font-size: 0.72rem; }

/* ── Modal building blocks ── */
.modal-card--sm { max-width: 520px; }
.modal-header { margin-bottom: 1.25rem; }
.modal-title { font-size: 1.15rem; font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.5rem; }
.modal-actions--start { justify-content: flex-start; margin-top: 1rem; }

/* ── Searchable check list ── */
.scroll-box { max-height: 280px; overflow-y: auto; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: #FFFFFF; margin-top: 0.6rem; }
.check-list { padding: 0.25rem; }
.check-list__item { display: flex; align-items: center; gap: 0.65rem; padding: 0.5rem 0.6rem; border-radius: var(--radius-sm); cursor: pointer; transition: background var(--dur-fast); }
.check-list__item:hover { background: var(--bg-body); }
.check-list__item input { width: 18px; height: 18px; accent-color: var(--primary); flex-shrink: 0; }
.check-list__item:has(input:checked) { background: var(--primary-50); }
.check-list__avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-100); color: var(--primary-hover); font-size: 0.7rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.check-list__avatar--group { background: var(--bg-body); color: var(--text-muted); }
.check-list__text { display: flex; flex-direction: column; min-width: 0; }
.check-list__primary { font-size: 0.9rem; font-weight: 500; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check-list__secondary { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check-list__count { margin-top: 0.5rem; }

/* ═══════════════ Wizard shell ═══════════════ */
.wizard-modal-card {
    display: flex; flex-direction: column;
    padding: 0; overflow: hidden;
    max-width: 1000px; height: min(88vh, 840px); max-height: none;
    border-radius: var(--radius-lg);
}
.wizard__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.25rem 1.5rem 1rem 2rem; border-bottom: 1px solid var(--border-color); background: #FFFFFF; }
.wizard__title { font-size: 1.2rem; font-weight: 700; margin: 0; line-height: 1.3; }
.wizard__subtitle { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.25rem; min-height: 1.5rem; flex-wrap: wrap; }
.wizard__name { font-size: 0.9rem; color: var(--text-muted); max-width: 520px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wizard__name.is-empty { font-style: italic; }
.wizard__dirty { font-size: 0.72rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--warning-50); color: var(--warning-700); border: 1px solid var(--warning-200); }
.wizard__dirty[hidden] { display: none; }
.wizard__close { margin-top: -0.25rem; margin-right: -0.25rem; }

/* Step rail — keeps .wizard-step / -circle / -label */
.wizard-rail {
    --rail-pad: 2rem;
    --wizard-progress: 0;
    list-style: none; display: grid; grid-template-columns: repeat(6, 1fr); position: relative;
    padding: 1rem var(--rail-pad) 0.75rem; margin: 0;
    background: var(--bg-body); border-bottom: 1px solid var(--border-color);
}
.wizard-rail::before, .wizard-rail::after {
    content: ''; position: absolute; top: calc(1rem + 14px);
    left: calc(var(--rail-pad) + 8.33%); right: calc(var(--rail-pad) + 8.33%);
    height: 2px; background: var(--border-color); z-index: 0;
}
.wizard-rail::after {
    right: auto; background: var(--secondary);
    width: calc((100% - 2 * var(--rail-pad) - 16.66%) * var(--wizard-progress));
    transition: width var(--dur-base) var(--ease);
}
.wizard-rail .wizard-step { z-index: 1; }
.wizard-step__btn { display: flex; flex-direction: column; align-items: center; background: transparent; border: 0; padding: 0; font: inherit; cursor: pointer; border-radius: var(--radius-md); }
.wizard-step__btn:disabled { cursor: default; }
.wizard-step__btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.wizard-rail .wizard-step-circle { width: 28px; height: 28px; font-size: 0.8rem; margin-bottom: 6px; transition: background var(--dur-fast), border-color var(--dur-fast), box-shadow var(--dur-fast); }
.wizard-rail .wizard-step.active .wizard-step-circle { box-shadow: 0 0 0 4px var(--primary-ring); }
.wizard-rail .wizard-step.completed .wizard-step-circle { font-size: 0; }
.wizard-rail .wizard-step.completed .wizard-step-circle::after { content: '\2713'; font-size: 0.8rem; font-weight: 700; }
.wizard-rail .wizard-step.completed .wizard-step__btn:hover .wizard-step-circle { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.18); }
.wizard-rail .wizard-step.has-error .wizard-step-circle { border-color: var(--danger); color: var(--danger); }
.wizard-rail .wizard-step-label { font-size: 0.72rem; }
.wizard-rail .wizard-step.completed .wizard-step-label { color: var(--text-main); }
.wizard-rail__mobile { display: none; }

/* Body: the only scrolling region */
.wizard-modal-card .wizard-content { flex: 1 1 auto; min-height: 0; max-height: none; margin: 0; padding: 1.5rem 2rem 2rem; overflow-y: auto; overscroll-behavior: contain; }

/* Sticky footer */
.wizard__footer { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 1rem 2rem; border-top: 1px solid var(--border-color); background: #FFFFFF; flex-wrap: wrap; }
.wizard__footer-group { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }

/* ═══════════════ Step content ═══════════════ */
.step { max-width: 860px; }
.step__header { margin-bottom: 1.5rem; }
.step__title { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.3rem; }
.step__lead { font-size: 0.9rem; color: var(--text-muted); line-height: 1.55; }
.step__section { margin-bottom: 1.75rem; }
.step__section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.step__section-title { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-main); margin: 0 0 0.75rem; }
.step__section-head .step__section-title { margin-bottom: 0; }
.step__section-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.15rem; }
.step__section--exceptions .step__section-title { color: var(--text-muted); }
.step__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* Rule lists (steps 2–4) */
.rule-list { display: flex; flex-direction: column; gap: 0.5rem; }
.rule-list .rule-item { margin-bottom: 0; gap: 0.75rem; background: #FFFFFF; padding: 0.6rem 0.6rem 0.6rem 0.9rem; transition: border-color var(--dur-fast), box-shadow var(--dur-fast); }
.rule-list .rule-item:hover { border-color: var(--primary-200); box-shadow: var(--shadow-sm); }
.rule-list--exceptions .rule-item { background: var(--bg-body); }
.rule-list--exceptions .rule-type-badge { background: var(--danger-50); color: var(--danger-700); }
.rule-item__value { flex: 1; font-size: 0.9rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rule-item__value--muted { color: var(--text-muted); }
.rule-item__value--loading { color: var(--text-muted); font-style: italic; }
.rule-item__phrase { flex: 1; font-weight: 600; font-size: 0.9rem; }
.rule-item--keyword { flex-wrap: wrap; }
.rule-item__remove { margin-left: auto; color: var(--text-muted); }
.rule-item__remove:hover { color: var(--danger); background: var(--danger-50); }

/* Scheduler */
.scheduler-details { display: flex; flex-direction: column; gap: 1rem; margin-top: 0.5rem; }
.day-picker { border: 0; padding: 0; margin: 0; }
.day-picker[hidden] { display: none; }
.day-picker__days { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.day-picker__day { position: relative; }
.day-picker__day input { position: absolute; opacity: 0; width: 0; height: 0; }
.day-picker__day span { display: inline-block; min-width: 52px; text-align: center; padding: 0.45rem 0.6rem; border: 1px solid var(--border-color); border-radius: 999px; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); background: #FFFFFF; cursor: pointer; user-select: none; transition: all var(--dur-fast); }
.day-picker__day input:checked + span { background: var(--primary-50); border-color: var(--primary); color: var(--primary); }
.day-picker__day input:focus-visible + span { box-shadow: var(--focus-ring); }

/* Step 6: design card */
.design-card__conv { max-width: 560px; }
.design-card { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 1.5rem; padding: 1.25rem; border: 1px solid var(--border-color); border-radius: var(--radius-lg); background: var(--bg-body); margin-bottom: 1.75rem; }
.design-card__thumbs { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.design-card[data-conversation="different"] .design-card__thumbs { grid-template-columns: 1fr 1fr; }
.thumb-frame { margin: 0; position: relative; }
.thumb-frame__body { position: relative; height: 180px; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: #FFFFFF; overflow: hidden; cursor: pointer; transition: border-color var(--dur-fast), box-shadow var(--dur-fast); }
.thumb-frame__body:hover, .thumb-frame__body:focus-visible { border-color: var(--primary); box-shadow: var(--shadow-md); outline: none; }
.thumb-frame__body iframe { position: absolute; top: 0; left: 0; width: 200%; height: 200%; border: 0; transform: scale(0.5); transform-origin: 0 0; pointer-events: none; }
.thumb-frame__empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); font-size: 0.85rem; background: repeating-linear-gradient(45deg, #FAFAFB 0 10px, var(--gray-100) 10px 20px); }
.thumb-frame__caption { display: flex; align-items: center; justify-content: center; gap: 0.35rem; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-top: 0.4rem; }
.thumb-frame__clear { width: 28px; height: 28px; }
.design-card__side { display: flex; flex-direction: column; justify-content: center; gap: 0.75rem; }
.design-card__stats { font-size: 0.85rem; color: var(--text-muted); }
.design-card__open { justify-content: center; }

/* Step 6: review summary + status */
.review { border: 1px solid var(--border-color); border-radius: var(--radius-lg); background: #FFFFFF; overflow: hidden; margin-bottom: 1rem; }
.review__row { display: grid; grid-template-columns: 120px minmax(0, 1fr) auto; align-items: center; gap: 1rem; padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; }
.review__row:last-child { border-bottom: 0; }
.review__label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.review__value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review__value--muted { color: var(--text-muted); }
.review__edit { background: none; border: 0; padding: 0.25rem 0.5rem; font: inherit; font-size: 0.8rem; font-weight: 600; color: var(--primary); cursor: pointer; border-radius: var(--radius-sm); }
.review__edit:hover { background: var(--primary-50); }
.review__edit:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.review__status { display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.25rem; background: var(--bg-body); flex-wrap: wrap; }
.review__status .form-hint { margin-top: 0; }
.review__warnings { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.review__warnings:empty { display: none; }

/* ═══════════════ Full-screen signature designer ═══════════════ */
html.designer-open, html.designer-open body { overflow: hidden; }

.designer {
    position: fixed; inset: 0; z-index: var(--z-designer);
    display: flex; flex-direction: column; height: 100dvh;
    background: var(--bg-body); overscroll-behavior: contain;
    animation: designer-in var(--dur-base) var(--ease);
}
.designer[hidden] { display: none; }
@keyframes designer-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.designer__bar {
    flex: 0 0 auto; min-height: 56px;
    display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 1rem;
    padding: 0.5rem 1rem; background: #FFFFFF; border-bottom: 1px solid var(--border-color); box-shadow: var(--shadow-sm);
    position: relative; z-index: 2;
}
.designer__bar-left { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.designer__bar-center { display: flex; justify-content: center; }
.designer:not([data-variants="on"]) .designer__bar-center { display: none; }
.designer__bar-right { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; min-width: 0; flex-wrap: wrap; }
.designer__heading { display: flex; flex-direction: column; min-width: 0; }
.designer__eyebrow { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.designer__title { font-size: 0.98rem; font-weight: 700; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.design-tabs[hidden] { display: none; }
.design-tab[aria-disabled="true"] { opacity: 0.5; cursor: progress; }

.designer__status { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0.7rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; background: var(--bg-body); color: var(--text-muted); border: 1px solid var(--border-color); }
.designer__status[data-state="dirty"]  { background: var(--warning-50); color: var(--warning-700); border-color: var(--warning-200); }
.designer__status[data-state="ready"]  { background: var(--success-50); color: var(--success-700); border-color: var(--success-200); }
.designer__status[data-state="saving"] { background: var(--primary-50); color: var(--primary-hover); border-color: var(--primary-200); }
.designer__status[data-state="error"]  { background: var(--danger-50); color: var(--danger-700); border-color: var(--danger-200); }
.designer__status[data-state="source"] { background: var(--primary-50); color: var(--primary-hover); border-color: var(--primary-200); }
.designer__status .spinner { display: none; }
.designer__status[data-state="loading"] .spinner { display: inline-block; }

.designer__body { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 296px minmax(480px, 1fr) clamp(360px, 30vw, 420px); gap: 1rem; padding: 1rem; }

/* Left rail */
.designer__rail { display: flex; flex-direction: column; min-height: 0; background: #FFFFFF; border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
.designer__rail-tabs { display: flex; border-bottom: 1px solid var(--border-color); background: var(--bg-body); }
.designer__rail-tab { flex: 1; border: 0; background: transparent; padding: 0.7rem 0.5rem; font: inherit; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color var(--dur-fast), border-color var(--dur-fast); }
.designer__rail-tab:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }
.designer__rail-tab.is-active { color: var(--primary); border-bottom-color: var(--primary); background: #FFFFFF; }
.designer__panel { display: none; flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0.75rem; }
.designer__panel.is-active { display: flex; flex-direction: column; gap: 0.75rem; }
.designer__panel-hint { font-size: 0.75rem; color: var(--text-muted); line-height: 1.45; }

.designer__tpl-list { display: flex; flex-direction: column; overflow-x: visible; padding: 0; gap: 0.75rem; }
.designer__tpl-list .tpl-card { width: 100%; }
.designer__tpl-list .tpl-card__thumb { width: 100%; height: 124px; }
.designer__tpl-list .tpl-card__thumb iframe { width: 200%; height: 248px; }
.tpl-card:focus-visible { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.tpl-card[aria-disabled="true"] { opacity: 0.55; cursor: progress; }
.tpl-card--blank .tpl-card__thumb { display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 0.8rem; background: repeating-linear-gradient(45deg, #FAFAFB 0 10px, var(--gray-100) 10px 20px); }
.designer[data-empty="true"] .designer__tpl-list .tpl-card:nth-child(2) { animation: tpl-pulse 1.6s ease-in-out 2; }
@keyframes tpl-pulse { 0%, 100% { box-shadow: none; } 50% { box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.2); } }

.var-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.var-list__group { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); padding: 0.5rem 0.25rem 0.15rem; }
.var-list__group[hidden], .var-list__item[hidden] { display: none; }
.var-list__btn { width: 100%; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "label token" "sample sample"; gap: 0 0.5rem; text-align: left; padding: 0.5rem 0.6rem; border: 1px solid transparent; border-radius: var(--radius-md); background: transparent; font: inherit; cursor: pointer; transition: background var(--dur-fast), border-color var(--dur-fast); }
.var-list__btn:hover { background: var(--primary-50); border-color: var(--primary-200); }
.var-list__btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.var-list__btn[aria-disabled="true"] { opacity: 0.6; cursor: progress; }
.var-list__label { grid-area: label; font-size: 0.85rem; font-weight: 600; color: var(--text-main); }
.var-list__token { grid-area: token; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.7rem; color: var(--primary-hover); background: var(--primary-100); padding: 1px 6px; border-radius: 4px; }
.var-list__sample { grid-area: sample; font-size: 0.75rem; color: var(--text-muted); }

.drop-zone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.25rem; padding: 1.5rem 1rem; border: 2px dashed var(--gray-300); border-radius: var(--radius-md); background: var(--bg-body); text-align: center; cursor: pointer; transition: border-color var(--dur-fast), background var(--dur-fast); }
.drop-zone:hover, .drop-zone.is-over { border-color: var(--primary); background: var(--primary-50); }
.drop-zone.is-busy { opacity: 0.6; pointer-events: none; }
.drop-zone__title { font-size: 0.85rem; font-weight: 600; color: var(--text-main); }
.drop-zone__hint { font-size: 0.72rem; color: var(--text-muted); }
.upload-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.upload-list__item { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem; border: 1px solid var(--border-color); border-radius: var(--radius-md); }
.upload-list__item img { width: 40px; height: 40px; object-fit: contain; background: var(--gray-100); border-radius: 4px; }
.upload-list__name { flex: 1; font-size: 0.78rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Editor column */
.designer__editor { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.designer__editor-host { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; background: #FFFFFF; border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
.designer__editor-host .tox-tinymce { flex: 1 1 auto; min-height: 0; border: 0 !important; border-radius: 0 !important; }
.designer__editor-host .tox .tox-toolbar-overlord, .designer__editor-host .tox .tox-toolbar__primary { background: #FFFFFF; border-bottom: 1px solid var(--border-color); }
.designer__editor-host .tox .tox-edit-area__iframe { background: var(--gray-100); }
.designer__source { flex: 1 1 auto; width: 100%; border: 0; padding: 1rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; line-height: 1.5; resize: none; outline: none; }
.designer__source[hidden] { display: none; }

.designer__skeleton { position: absolute; inset: 0; background: #FFFFFF; display: none; flex-direction: column; }
.designer[data-editor-state="loading"] .designer__skeleton { display: flex; }
.designer__skeleton-bar { height: 46px; border-bottom: 1px solid var(--border-color); background: linear-gradient(90deg, var(--gray-100) 25%, var(--border-color) 50%, var(--gray-100) 75%); background-size: 400% 100%; animation: shimmer 1.4s infinite; }
.designer__skeleton-line { height: 14px; margin: 18px 24px 0; border-radius: 999px; background: linear-gradient(90deg, var(--gray-100) 25%, var(--border-color) 50%, var(--gray-100) 75%); background-size: 400% 100%; animation: shimmer 1.4s infinite; }
.designer__skeleton-line:nth-child(2) { width: 38%; } .designer__skeleton-line:nth-child(3) { width: 62%; } .designer__skeleton-line:nth-child(4) { width: 48%; } .designer__skeleton-line:nth-child(5) { width: 70%; } .designer__skeleton-line:nth-child(6) { width: 30%; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.designer__error { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 2rem; background: #FFFFFF; z-index: 1; }
.designer__error[hidden] { display: none; }
.designer__error-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.4rem; }
.designer__error-text { font-size: 0.9rem; color: var(--text-muted); max-width: 420px; }

/* Preview column (extends .design-preview) */
.designer__preview { min-height: 0; border-radius: var(--radius-lg); background: #FFFFFF; display: flex; flex-direction: column; }
.designer__preview .design-preview__bar { border-radius: var(--radius-lg) var(--radius-lg) 0 0; flex-wrap: wrap; }
.designer__preview .form-control--sm { max-width: 190px; }
.design-preview__toggles { display: flex; gap: 0.5rem; flex-wrap: wrap; padding: 0.5rem 0.75rem 0; }
.designer__preview .design-preview__frame { flex: 1 1 auto; min-height: 0; background: var(--bg-body); overflow: auto; display: flex; align-items: stretch; justify-content: center; }
.designer__preview .design-preview__frame iframe { width: 100%; min-height: 100%; flex: 1 1 auto; transition: width var(--dur-base) var(--ease); }
.design-preview__frame[data-device="mobile"] iframe { flex: 0 0 auto; width: 375px; box-shadow: var(--shadow-md); }
.design-preview__note[data-loading="true"] { color: var(--primary-hover); }

/* ═══════════════ Responsive ═══════════════ */
@media (max-width: 1100px) {
    .designer__body { display: flex; flex-direction: column; overflow-y: auto; gap: 0.75rem; }
    .designer__rail { flex: 0 0 auto; max-height: 240px; }
    .designer__tpl-list { flex-direction: row; overflow-x: auto; padding-bottom: 0.25rem; }
    .designer__tpl-list .tpl-card { width: 200px; flex: 0 0 auto; }
    .designer__tpl-list .tpl-card__thumb { width: 200px; height: 100px; }
    .designer__tpl-list .tpl-card__thumb iframe { width: 400px; height: 200px; }
    .designer__editor { flex: 0 0 auto; height: 62vh; }
    .designer__preview { flex: 0 0 auto; min-height: 420px; }
    .design-preview__frame[data-device="mobile"] iframe { width: 100%; max-width: 375px; }
}

@media (max-width: 768px) {
    .wizard-modal-card { height: 100dvh; max-width: 100% !important; border-radius: 0; padding: 0; }
    .wizard__header { padding: 1rem 1rem 0.75rem 1.25rem; }
    .wizard__name { max-width: 200px; }
    .wizard-rail { --rail-pad: 1.25rem; padding-top: 0.75rem; padding-bottom: 0.5rem; border-bottom: 0; }
    .wizard-rail::before, .wizard-rail::after { top: calc(0.75rem + 14px); }
    .wizard-rail__mobile { display: block; padding: 0 1.25rem 0.6rem; font-size: 0.8rem; font-weight: 600; color: var(--primary); background: var(--bg-body); border-bottom: 1px solid var(--border-color); }
    .wizard-modal-card .wizard-content { padding: 1.25rem; }
    .wizard__footer { padding: 0.75rem 1rem; }
    .wizard__footer .btn { padding: 0.65rem 0.9rem; font-size: 0.85rem; }
    .step__section-head { flex-direction: column; align-items: stretch; }
    .step__section-head .btn { align-self: flex-start; }
    .step__grid { grid-template-columns: 1fr; }
    .design-card { grid-template-columns: 1fr; }
    .design-card[data-conversation="different"] .design-card__thumbs { grid-template-columns: 1fr; }
    .review__row { grid-template-columns: 1fr auto; }
    .review__label { grid-column: 1 / -1; }
    .btn-icon, .rule-item__remove { width: 40px; height: 40px; }

    .designer__bar { grid-template-columns: 1fr auto; grid-template-areas: "left right" "center center"; padding: 0.5rem 0.75rem; row-gap: 0.4rem; }
    .designer__bar-left { grid-area: left; }
    .designer__bar-right { grid-area: right; }
    .designer__bar-center { grid-area: center; }
    .designer__heading { display: none; }
    .designer__status { display: none; }
    .designer__status[data-state="dirty"] { display: inline-flex; }
    #designerCleanBtn, #designerSourceBtn { display: none; }
    .designer__body { padding: 0.5rem; }
    .designer__editor { height: 58vh; }
    .designer__preview .design-preview__bar .form-control--sm { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .designer, .wizard-rail::after, .designer__skeleton-line, .designer__skeleton-bar, .tpl-card, .design-preview__frame iframe { animation: none; transition: none; }
}
