/* =============================================
   SchoolTools Survey - Public Form Styles
   Mobile-first responsive design
   ============================================= */

/* --- Survey Layout --- */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--gray-50);
}

/* --- Header --- */
.survey-header {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.survey-header-inner {
    max-width: var(--container-sm);
    margin: 0 auto;
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.survey-logo {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--primary-500);
    letter-spacing: -0.01em;
}

/* --- Progress Bar --- */
.survey-progress {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 49px; /* below header */
    z-index: 99;
}

.survey-progress-bar {
    height: 4px;
    background: var(--gray-200);
    overflow: hidden;
}

.survey-progress-fill {
    height: 100%;
    background: hsl(0, 70%, 55%);
    border-radius: 0 2px 2px 0;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.4s ease;
    min-width: 2%;
}

.survey-progress-meta {
    max-width: var(--container-sm);
    margin: 0 auto;
    padding: var(--space-1) var(--space-4);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.survey-progress-text {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.survey-timer-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.survey-est-time {
    opacity: 0.7;
}

.survey-stopwatch {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text-light);
    background: var(--gray-100);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    font-size: 11px;
    letter-spacing: 0.02em;
}

/* --- Collapsible Remark Toggle --- */
.remark-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: var(--space-1);
    width: 100%;
    justify-content: center;
}

.remark-toggle-btn:hover {
    color: var(--primary-500);
    border-color: var(--primary-300);
    background: var(--primary-50, #eff6ff);
}

.remark-toggle-btn .remark-plus {
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    transition: transform 0.2s ease;
}

.remark-toggle-btn.open .remark-plus {
    transform: rotate(45deg);
}

.remark-body-collapsible {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.2s ease, margin 0.3s ease;
    margin-top: 0;
}

.remark-body-collapsible.open {
    max-height: 120px;
    opacity: 1;
    margin-top: var(--space-2);
}

/* Hide question number and required star for remark questions */
.survey-question.is-collapsible-remark {
    padding: var(--space-3);
    margin-bottom: var(--space-1);
    background: var(--gray-50);
    border: 1px dashed var(--gray-200);
    box-shadow: none;
}

.survey-question.is-collapsible-remark .survey-question-header {
    display: none;
}

.survey-question.is-collapsible-remark .survey-question-body {
    margin-top: 0;
}

/* --- Main Container --- */
.survey-container {
    flex: 1;
    max-width: var(--container-sm);
    width: 100%;
    margin: 0 auto;
    padding: var(--space-4);
}

@media (min-width: 768px) {
    .survey-container {
        padding: var(--space-8) var(--space-4);
    }
}

/* --- Loading State --- */
.survey-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    gap: var(--space-4);
    color: var(--text-muted);
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

/* --- Access Gate --- */
.survey-access-gate {
    max-width: 440px;
    margin: var(--space-8) auto;
}

.survey-access-gate .card {
    border: none;
    box-shadow: var(--shadow-md);
}

.survey-access-gate h2 {
    font-size: var(--text-xl);
    margin-bottom: var(--space-2);
}

/* --- Error State --- */
.survey-error {
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Survey Intro --- */
.survey-intro {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-sm);
}

.survey-intro h1 {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-2);
    line-height: 1.3;
}

.survey-description {
    color: var(--text-muted);
    font-size: var(--text-base);
    line-height: 1.6;
    margin: 0;
}

@media (max-width: 480px) {
    .survey-intro {
        padding: var(--space-4);
    }
    .survey-intro h1 {
        font-size: var(--text-xl);
    }
}

/* --- Question Cards --- */
.survey-page {
    display: none;
}

.survey-page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

.survey-question {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    margin-bottom: var(--space-3);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.survey-question:hover {
    border-color: var(--gray-300);
}

.survey-question.has-error {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px var(--danger-light);
}

.survey-question-header {
    margin-bottom: var(--space-3);
}

.survey-question-text {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text);
    margin: 0;
    line-height: 1.4;
}

.survey-question-number {
    display: inline-block;
    font-size: var(--text-xs);
    color: var(--text-light);
    font-weight: 600;
    margin-bottom: var(--space-1);
}

.survey-question-required {
    color: var(--danger);
    font-weight: 700;
    margin-left: 2px;
}

.survey-question-description {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-top: var(--space-1);
    line-height: 1.5;
}

.survey-question-body {
    margin-top: var(--space-3);
}

.survey-question-error {
    color: var(--danger);
    font-size: var(--text-sm);
    margin-top: var(--space-2);
    display: none;
    align-items: center;
    gap: var(--space-1);
}

.survey-question-error.visible {
    display: flex;
}

.survey-question-error::before {
    content: '!';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 50%;
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .survey-question {
        padding: var(--space-4);
        border-radius: var(--radius);
    }
}

/* --- Section Titles (page dividers) --- */
.survey-section-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text);
    padding: var(--space-4) 0 var(--space-2);
    border-bottom: 2px solid var(--primary-100);
    margin-bottom: var(--space-3);
}

/* --- Navigation Buttons --- */
.survey-nav {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-6) 0;
    margin-top: var(--space-2);
}

.survey-nav-spacer {
    flex: 1;
}

#btn-submit {
    min-width: 160px;
}

@media (max-width: 480px) {
    .survey-nav {
        padding: var(--space-4) 0;
    }
    .survey-nav .btn {
        flex: 1;
    }
    #btn-submit {
        min-width: auto;
    }
}

/* --- Thank You Page --- */
.survey-thankyou {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    animation: fadeIn 0.5s ease;
}

.thankyou-card {
    text-align: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-10);
    box-shadow: var(--shadow-md);
    max-width: 480px;
    width: 100%;
}

.thankyou-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto var(--space-4);
    background: var(--success-light);
    color: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    animation: scaleIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scaleIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

.thankyou-card h2 {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-2);
}

.thankyou-card p {
    color: var(--text-muted);
    font-size: var(--text-base);
    line-height: 1.6;
}

/* --- Footer --- */
.survey-footer {
    background: var(--bg);
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.survey-footer-inner {
    max-width: var(--container-sm);
    margin: 0 auto;
    padding: var(--space-4);
    text-align: center;
    font-size: var(--text-xs);
    color: var(--text-light);
}

.survey-footer a {
    color: var(--text-muted);
    font-weight: 500;
}

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

/* --- Draft saved indicator --- */
.draft-indicator {
    position: fixed;
    bottom: var(--space-4);
    right: var(--space-4);
    background: var(--gray-800);
    color: #fff;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 200;
    pointer-events: none;
}

.draft-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

/* --- Submit loading overlay --- */
.survey-submitting {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.survey-submitting .spinner {
    width: 40px;
    height: 40px;
    border-width: 3px;
}

.survey-submitting p {
    font-size: var(--text-base);
    color: var(--text-muted);
    font-weight: 500;
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    bottom: var(--space-4);
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.toast {
    background: var(--gray-800);
    color: #fff;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    max-width: 400px;
}

.toast-error {
    background: var(--danger);
}

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

/* --- Print styles --- */
@media print {
    .survey-header,
    .survey-progress,
    .survey-footer,
    .survey-nav,
    .draft-indicator {
        display: none !important;
    }

    .survey-container {
        max-width: 100%;
    }

    .survey-page {
        display: block !important;
        page-break-inside: avoid;
    }

    .survey-question {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }
}
