/* =====================================================================
   SnapFile app — Notion-inspired redesign
   All IDs and class names preserved for JS compatibility.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* -------- Design tokens -------- */
:root {
    /* Palette */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --danger-soft: #fef2f2;
    --warning: #f59e0b;

    /* Neutrals (Notion-style: warm grays, high contrast) */
    --bg: #fafaf9;
    --surface: #ffffff;
    --surface-alt: #f7f7f5;
    --border: #e7e5e4;
    --border-strong: #d6d3d1;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;

    /* Spacing (4px scale) */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-7: 32px;
    --sp-8: 40px;

    /* Radius */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 20px;
    --r-full: 999px;

    /* Shadows (subtle, Notion-like) */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 16px 32px rgba(15, 23, 42, 0.12);
    --shadow-ring: 0 0 0 3px rgba(37, 99, 235, 0.12);

    /* Typography */
    --fs-xs: 11px;
    --fs-sm: 13px;
    --fs-base: 14px;
    --fs-md: 15px;
    --fs-lg: 17px;
    --fs-xl: 20px;
    --fs-2xl: 24px;

    /* Transitions */
    --ease: 0.18s ease;
    --ease-slow: 0.25s ease;
}

/* -------- Reset & base -------- */
*, *::before, *::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: var(--fs-base);
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font-family: inherit;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--ease);
}

a:hover {
    color: var(--primary-hover);
}

h1, h2, h3 {
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

h1 { font-size: var(--fs-2xl); line-height: 1.2; }
h2 { font-size: var(--fs-xl); line-height: 1.3; }
h3 { font-size: var(--fs-lg); line-height: 1.35; }

/* -------- Layout primitives -------- */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: var(--sp-5);
}

/* -------- Header -------- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: none;
    min-height: 64px;
    gap: var(--sp-3);
}

.header .logo {
    display: flex;
    align-items: center;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.logo-img {
    height: 40px;
    width: auto;
    display: block;
}

#statusText {
    font-weight: 600;
    font-size: var(--fs-sm);
    color: var(--success);
    white-space: nowrap;
}

.flag-select-compact {
    height: 40px;
    width: 52px;
    padding: 0;
    font-size: 18px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface);
    cursor: pointer;
    appearance: none;
    transition: border-color var(--ease);
}

.flag-select-compact:hover {
    border-color: var(--border-strong);
}

.flag-select-compact:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-ring);
}

/* -------- Main form card -------- */
.main-form {
    background: var(--surface);
    padding: var(--sp-7);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
    box-shadow: var(--shadow-sm);
}

/* -------- Form elements -------- */
.form-group {
    margin-bottom: var(--sp-5);
}

.form-group:last-child {
    margin-bottom: 0;
}

label {
    display: block;
    font-weight: 500;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin-bottom: var(--sp-2);
    letter-spacing: 0.01em;
}

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 11px 14px;
    font-family: inherit;
    font-size: var(--fs-md);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
    outline: none;
}

input[type="text"]:hover,
input[type="tel"]:hover,
input[type="email"]:hover,
textarea:hover,
select:hover {
    border-color: var(--border-strong);
}

input[type="text"]:focus,
input[type="tel"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-ring);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}

/* Custom select chevron */
select:not(.flag-select-compact):not(.flag-select) {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

/* -------- Buttons (base) -------- */
.btn-primary,
.btn-secondary,
#generateBtn,
#saveBrandingBtn,
#newReportBtn,
.btn-settings,
.reg-start-btn,
.btn-run {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 12px 18px;
    font-family: inherit;
    font-size: var(--fs-md);
    font-weight: 600;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    cursor: pointer;
    transition: background var(--ease), border-color var(--ease), color var(--ease), transform 0.08s, box-shadow var(--ease);
    white-space: nowrap;
    user-select: none;
}

.btn-primary:active,
#generateBtn:active,
#saveBrandingBtn:active,
.reg-start-btn:active {
    transform: translateY(1px);
}

/* Primary — blue */
.btn-primary,
#generateBtn,
.reg-start-btn,
.btn-run {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: var(--shadow-xs);
}

.btn-primary:hover,
#generateBtn:hover,
.reg-start-btn:hover,
.btn-run:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: var(--shadow-sm);
}

.btn-primary:disabled,
.reg-start-btn:disabled {
    background: #93c5fd;
    border-color: #93c5fd;
    cursor: not-allowed;
    box-shadow: none;
}

/* Success — green (branding save) */
#saveBrandingBtn {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
    box-shadow: var(--shadow-xs);
}

#saveBrandingBtn:hover {
    background: var(--success-hover);
    border-color: var(--success-hover);
    box-shadow: var(--shadow-sm);
}

/* Secondary — neutral outline */
.btn-secondary,
.btn-settings {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover,
.btn-settings:hover {
    background: var(--surface-alt);
    border-color: var(--border-strong);
}

/* Danger-ghost — New Report */
#newReportBtn {
    background: transparent;
    color: var(--danger);
    border-color: transparent;
}

#newReportBtn:hover {
    background: var(--danger-soft);
    border-color: transparent;
}

/* Size: full-width stack buttons in action area */
#generateBtn,
#saveBrandingBtn,
#newReportBtn,
.btn-settings {
    width: 100%;
    padding: 14px 20px;
    font-size: var(--fs-md);
}

#generateBtn {
    font-size: var(--fs-lg);
    margin-top: var(--sp-6);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    font-size: 16px;
    line-height: 1;
}

.btn-icon i { line-height: 1; }

/* -------- Action buttons block -------- */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    margin-top: var(--sp-5);
}

/* -------- Checklist -------- */
.checklist-wrapper {
    margin: var(--sp-5) 0;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    overflow: hidden;
}

.checklist-header {
    display: flex;
    gap: var(--sp-2);
    align-items: center;
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
}

.checklist-selector-dropdown {
    flex: 1;
    height: 38px;
    padding: 0 12px;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    cursor: pointer;
    outline: none;
    transition: border-color var(--ease), box-shadow var(--ease);
}

.checklist-selector-dropdown:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-ring);
}

.btn-edit-checklist {
    padding: 8px 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--ease);
}

.btn-edit-checklist:hover {
    background: var(--surface-alt);
    border-color: var(--primary);
    color: var(--primary);
}

.checklist {
    margin: 0;
}

.checklist h3 {
    display: none;
}

.checklist-item {
    display: flex;
    align-items: center;
    padding: 12px var(--sp-4);
    border-bottom: 1px solid var(--border);
    font-size: var(--fs-md);
    transition: background var(--ease);
}

.checklist-item:last-child {
    border-bottom: none;
}

.checklist-item:hover {
    background: var(--surface-alt);
}

.checklist-item input[type="checkbox"] {
    margin-right: var(--sp-3);
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.checklist-item label {
    margin: 0;
    font-size: var(--fs-md);
    font-weight: 400;
    color: var(--text);
    cursor: pointer;
}

.checklist-empty {
    padding: var(--sp-6) var(--sp-4);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    text-align: center;
}

/* -------- Photo section -------- */
.photo-section {
    background: var(--surface-alt);
    padding: var(--sp-4);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin: var(--sp-5) 0;
}

.photo-section h3 {
    margin: 0;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.photo-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-3);
    padding-bottom: var(--sp-2);
    border-bottom: 1px solid var(--border);
    gap: var(--sp-3);
}

.photo-per-page {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.photo-per-page label {
    margin: 0;
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    white-space: nowrap;
}

.photo-section h3 #photoCounter {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
    margin-left: var(--sp-1);
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: var(--sp-2);
    margin: var(--sp-3) 0;
}

.photo-preview {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: var(--r-sm);
    overflow: hidden;
    box-shadow: var(--shadow-xs);
}

.photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

#addPhotoBtn {
    width: 100%;
    padding: 12px;
    font-size: var(--fs-md);
    font-weight: 500;
    color: var(--primary);
    background: var(--surface);
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--r-md);
    cursor: pointer;
    transition: all var(--ease);
    margin-top: var(--sp-2);
}

#addPhotoBtn:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
    border-style: solid;
}

#photosPerPage {
    padding: 4px 8px;
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    cursor: pointer;
    width: auto;
}

/* -------- Report language selector -------- */
.report-language-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin: var(--sp-5) 0 0;
}

.report-language-selector label {
    margin: 0;
    font-weight: 500;
    white-space: nowrap;
}

.flag-select {
    width: auto;
    min-width: 140px;
    padding: 8px 12px;
    font-size: var(--fs-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    cursor: pointer;
}

/* -------- Settings (details/summary) -------- */
.settings-section {
    margin-top: var(--sp-5);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    background: var(--surface);
}

.settings-toggle {
    width: 100%;
    background: var(--surface);
    color: var(--text);
    border: none;
    border-radius: 0;
    font-family: inherit;
    font-weight: 500;
    font-size: var(--fs-md);
    padding: 14px var(--sp-4);
    cursor: pointer;
    list-style: none;
    text-align: center;
    transition: background var(--ease);
}

.settings-toggle .btn-icon {
    margin-right: var(--sp-2);
    vertical-align: middle;
}

.settings-toggle .btn-text {
    vertical-align: middle;
}

.settings-toggle::-webkit-details-marker,
.settings-toggle::marker {
    display: none;
}

.settings-toggle:hover {
    background: var(--surface-alt);
}

.settings-section[open] .settings-toggle {
    border-bottom: 1px solid var(--border);
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface-alt);
}

.btn-settings {
    width: 100%;
    padding: 10px var(--sp-4);
    font-size: var(--fs-sm);
    font-weight: 500;
    justify-content: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
}

.btn-settings:hover {
    background: var(--surface);
    border-color: var(--primary);
    color: var(--primary);
}

/* -------- Footer -------- */
.footer {
    margin-top: var(--sp-8);
    padding: var(--sp-5);
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
}

.footer p {
    margin: 0;
}

.footer a {
    display: inline-block;
    margin-top: var(--sp-2);
    color: var(--text-secondary);
}

.footer a:hover {
    color: var(--primary);
}

/* -------- Expired banner -------- */
#expiredBanner {
    display: none;
    background: var(--danger-soft);
    border: 1px solid #fecaca;
    border-radius: var(--r-md);
    padding: 10px var(--sp-4);
    margin-bottom: var(--sp-3);
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
}

#expiredBannerText {
    font-size: var(--fs-sm);
    color: #b91c1c;
    font-weight: 500;
}

.expired-banner-link {
    font-size: var(--fs-sm);
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
    text-decoration: none;
}

.expired-banner-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* -------- Modal base -------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    z-index: 1000;
    animation: fadeIn 0.15s ease;
}

.modal-content {
    background: var(--surface);
    padding: var(--sp-7);
    border-radius: var(--r-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.2s ease;
}

.modal-content h3 {
    margin: 0;
    font-size: var(--fs-lg);
    font-weight: 600;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-3);
    gap: var(--sp-3);
}

.modal-subtitle {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin-bottom: var(--sp-4);
    line-height: 1.5;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--r-sm);
    transition: background var(--ease), color var(--ease);
}

.modal-close-btn:hover {
    background: var(--surface-alt);
    color: var(--text);
}

.modal-skip-btn {
    background: none;
    border: none;
    font-size: var(--fs-sm);
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
    padding: 4px 8px;
    transition: color var(--ease);
}

.modal-skip-btn:hover {
    color: var(--text-secondary);
}

.modal-input-flush {
    margin: 0 !important;
}

.file-input-block {
    display: block;
    width: 100%;
    margin-top: var(--sp-2);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.label-hint {
    font-weight: 400;
    color: var(--text-muted);
}

.accent-blue {
    color: var(--primary);
}

.branding-save-btn {
    width: 100%;
    margin-top: var(--sp-3);
}

.modal-input,
.modal-textarea {
    width: 100%;
    padding: 11px 14px;
    margin: var(--sp-2) 0 var(--sp-4);
    font-family: inherit;
    font-size: var(--fs-md);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    outline: none;
    transition: border-color var(--ease), box-shadow var(--ease);
}

.modal-input:focus,
.modal-textarea:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-ring);
}

.modal-textarea {
    min-height: 160px;
    resize: vertical;
    line-height: 1.5;
}

.modal-buttons {
    display: flex;
    gap: var(--sp-3);
    justify-content: flex-end;
    margin-top: var(--sp-4);
}

.modal-buttons .btn-primary,
.modal-buttons .btn-secondary {
    width: auto;
    padding: 10px var(--sp-5);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* -------- Checklist editor modal -------- */
.editor-items-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    margin: var(--sp-2) 0 var(--sp-3);
    max-height: 260px;
    overflow-y: auto;
    padding-right: 2px;
}

.editor-item {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.editor-item-input {
    flex: 1;
    height: 40px;
    padding: 0 12px;
    font-size: var(--fs-sm);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    outline: none;
    transition: border-color var(--ease);
}

.editor-item-input:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-ring);
}

.editor-item-delete {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color var(--ease), background var(--ease);
}

.editor-item-delete:hover {
    color: var(--danger);
    background: var(--danger-soft);
}

.editor-add-row {
    display: flex;
    gap: var(--sp-2);
    align-items: center;
    margin-bottom: var(--sp-3);
}

.editor-new-input {
    flex: 1;
    margin: 0 !important;
}

.editor-add-btn {
    height: 42px;
    padding: 0 var(--sp-4);
    white-space: nowrap;
    flex-shrink: 0;
}

/* -------- Registration overlay -------- */
#registrationOverlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-5);
}

.reg-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    padding: var(--sp-7) var(--sp-6) var(--sp-6);
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.reg-logo {
    max-height: 48px;
    margin-bottom: var(--sp-3);
}

.reg-lang {
    align-self: flex-end;
    margin-bottom: var(--sp-6) !important;
}

.reg-field {
    width: 100%;
    margin-bottom: var(--sp-4);
}

.reg-field-label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--sp-2);
}

.reg-input-block {
    display: block;
    width: 100%;
    height: 44px;
    padding: 0 14px;
    font-family: inherit;
    font-size: var(--fs-md);
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    outline: none;
    transition: border-color var(--ease), box-shadow var(--ease);
}

.reg-input-block:hover {
    border-color: var(--border-strong);
}

.reg-input-block:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-ring);
}

.reg-input-key {
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: var(--fs-sm);
}

.reg-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-sm);
    color: var(--primary);
    cursor: pointer;
    user-select: none;
    padding: var(--sp-1) 0;
}

.reg-toggle:hover {
    color: var(--primary-hover);
}

.reg-toggle-caret {
    font-size: 9px;
    display: inline-block;
    transition: transform var(--ease);
    line-height: 1;
}

.reg-toggle-caret.open {
    transform: rotate(90deg);
}

.reg-collapse {
    overflow: hidden;
    max-height: 0;
    transition: max-height var(--ease-slow), margin-top var(--ease);
    margin-top: 0;
}

.reg-collapse.open {
    max-height: 64px;
    margin-top: var(--sp-2);
}

.reg-start-btn {
    width: 100%;
    padding: 14px;
    margin-top: var(--sp-1);
    font-size: var(--fs-md);
    font-weight: 600;
    letter-spacing: 0.01em;
}

.reg-link {
    display: block;
    margin-top: var(--sp-4);
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--text-muted);
}

.reg-link:hover {
    color: var(--primary);
}

/* -------- Onboarding overlay -------- */
#onboardingOverlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: var(--sp-6) var(--sp-5);
    overflow-y: auto;
}

.onboarding-title {
    font-size: var(--fs-xl);
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--sp-2);
    text-align: center;
}

#onboardingSubtitle {
    color: var(--text-secondary) !important;
    font-size: var(--fs-sm) !important;
    margin: 0 0 var(--sp-4) !important;
    text-align: center;
}

.industry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--sp-2);
    padding: var(--sp-3) 0;
    width: 100%;
    max-width: 640px;
    margin-bottom: var(--sp-7);
}

.industry-card {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 52px;
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: all var(--ease);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.industry-card:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

#skipOnboardingBtn {
    margin-top: var(--sp-4) !important;
    background: none !important;
    border: none !important;
    color: var(--text-muted) !important;
    font-size: var(--fs-sm) !important;
    cursor: pointer !important;
    text-decoration: underline !important;
    text-underline-offset: 3px !important;
}

#skipOnboardingBtn:hover {
    color: var(--text-secondary) !important;
}

/* Preset preview tooltip */
.preset-preview {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: #f9fafb;
    font-size: var(--fs-xs);
    font-weight: 400;
    border-radius: var(--r-sm);
    padding: 8px 10px;
    min-width: 160px;
    max-width: 220px;
    z-index: 100;
    pointer-events: none;
    white-space: normal;
    line-height: 1.5;
    box-shadow: var(--shadow-md);
}

.preset-preview::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0 5px 5px;
    border-style: solid;
    border-color: transparent transparent #1f2937;
}

.industry-card:hover .preset-preview {
    display: block;
}

/* -------- Library modal -------- */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: var(--sp-2);
    max-height: 380px;
    overflow-y: auto;
    padding-right: 2px;
}

.library-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-1);
    padding: var(--sp-3) var(--sp-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    cursor: pointer;
    transition: border-color var(--ease), background var(--ease);
    text-align: center;
    position: relative;
}

.library-card:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.library-card.active {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.lib-check {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 20px;
    height: 20px;
    background: var(--border);
    color: var(--text-muted);
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--ease), color var(--ease);
}

.library-card.active .lib-check {
    background: var(--primary);
    color: #fff;
}

.lib-icon {
    font-size: 24px;
    line-height: 1;
}

.lib-name {
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text);
    line-height: 1.35;
}

.lib-status {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.library-card.active .lib-status {
    color: var(--primary);
}

/* -------- Toasts -------- */
#toastContainer {
    position: fixed;
    bottom: var(--sp-6);
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.toast {
    min-width: 260px;
    max-width: 90vw;
    padding: 12px 18px;
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    font-weight: 500;
    color: #fff;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    opacity: 0;
    transform: translateY(16px);
    animation: toastIn 0.25s ease forwards;
}

.toast.toast-success { background: var(--success); }
.toast.toast-error   { background: var(--danger); }
.toast.toast-info    { background: var(--primary); }
.toast.toast-out     { animation: toastOut 0.25s ease forwards; }

@keyframes toastIn {
    to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
    to { opacity: 0; transform: translateY(16px); }
}

/* -------- PDF spinner -------- */
#pdfSpinnerOverlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pdf-spinner-box {
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: var(--sp-7) var(--sp-8);
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.pdf-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--sp-4);
}

#pdfSpinnerText {
    margin: 0;
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text);
}

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

/* -------- Form validation -------- */
.field-invalid {
    border-color: var(--danger) !important;
    background: var(--danger-soft) !important;
}

.field-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12) !important;
}

/* -------- Step indicator -------- */
.step-indicator {
    display: flex;
    align-items: center;
    gap: 0;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-1);
}

.step-circle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.step.done .step-circle {
    background: var(--success);
    color: #fff;
}

.step.active .step-circle {
    background: var(--primary);
    color: #fff;
}

.step span {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    font-weight: 500;
}

.step.done span,
.step.active span {
    color: var(--text);
}

.step-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    margin: 0 var(--sp-1) 18px;
}

.step-line.done {
    background: var(--success);
}

/* -------- Usage counter -------- */
#reportUsageCounter {
    display: block;
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    margin-top: var(--sp-1);
}

/* -------- Responsive -------- */
@media (max-width: 600px) {
    .container {
        padding: var(--sp-3);
    }

    .main-form {
        padding: var(--sp-5);
    }

    .header {
        flex-direction: column;
        align-items: center;
        gap: var(--sp-3);
        padding: var(--sp-3) var(--sp-4);
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
        min-width: 0;
    }

    #statusText {
        flex: 1;
        min-width: 0;
        white-space: normal;
        text-align: left;
        line-height: 1.35;
    }

    .logo-img {
        height: 36px;
    }

    #generateBtn,
    #saveBrandingBtn,
    #newReportBtn,
    .btn-settings {
        padding: 14px var(--sp-4);
        font-size: var(--fs-md);
        min-height: 48px;
    }

    .modal-content {
        padding: var(--sp-5);
    }

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

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

@media (max-width: 400px) {
    .flag-select-compact {
        width: 46px;
    }
}

/* -------- Utility: screen reader only -------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
