/* Aegis / DnA visual tokens — see .cursor/docs/06_aegis_design_standards.md */
:root {
    --font-family: "Noto Sans", sans-serif;

    --color-primary: #3F5BFF;
    --color-primary-dark: #3652F6;
    --color-success: #3FC380;
    --color-warning: #FF9800;
    --color-error: #FF5454;
    --color-error-alt: #DE326E;
    --color-info: #607D8B;
    --color-secondary-btn: #E4E4E4;
    --color-page-bg: #F5F5F5;
    --color-divider: #EEEEEE;
    --color-surface: #FFFFFF;

    --radius-xs: 2px;
    --radius-sm: 4px;
    --radius-md: 5px;
    --radius-lg: 8px;
    --radius-full: 100px;

    --space-8: 8px;
    --space-12: 12px;
    --space-16: 16px;
    --space-20: 20px;
    --space-24: 24px;
    --space-56: 56px;
    --space-72: 72px;

    /* Legacy aliases used across the app */
    --primary: var(--color-primary);
    --primary-dark: var(--color-primary-dark);
    --success: var(--color-success);
    --warning: var(--color-warning);
    --danger: var(--color-error);
    --info: var(--color-info);
    --background: var(--color-page-bg);
    --card: var(--color-surface);
    --border: var(--color-divider);
    --text-primary: rgba(0, 0, 0, 0.87);
    --text-secondary: rgba(0, 0, 0, 0.60);
    --text-muted: rgba(0, 0, 0, 0.38);
    --readonly-bg: #F5F5F5;
    /* Form controls — Aegis field readability scheme (see 06_aegis_design_standards.md) */
    --field-bg: #F0F0F0;
    --field-label: #707070;
    --field-value: #202020;
    --field-border: #000000;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--font-family);
    font-size: 16px;
    font-weight: 400;
    background: var(--background);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Header + nav: see assets/css/app.css */

#mainContent {
    padding: var(--space-24) var(--space-16) var(--space-24);
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

#surveyWrapper {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
}

.form-disclaimer {
    display: flex;
    align-items: flex-start;
    gap: var(--space-12);
    margin-bottom: var(--space-20);
    padding: 14px var(--space-16);
    background: rgba(63, 91, 255, 0.08);
    border: 1px solid rgba(63, 91, 255, 0.24);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
}

.form-disclaimer-icon {
    flex-shrink: 0;
    margin-top: 0.15rem;
    font-size: 1rem;
    color: var(--color-primary);
}

.form-disclaimer-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

/* Progress stepper */
#progressStepper {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-24);
    margin-bottom: var(--space-24);
}

.stepper-track {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 0.25rem;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 0 0 auto;
    min-width: 0;
}

.step-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    font-size: 0.875rem;
    font-weight: 700;
}

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

.step.inactive .step-circle {
    background: var(--color-secondary-btn);
    color: var(--text-muted);
}

.step-label {
    margin-top: var(--space-8);
    font-size: 12px;
    font-weight: 400;
    text-align: center;
}

.step.active .step-label {
    color: var(--text-primary);
    font-weight: 500;
}

.step.inactive .step-label {
    color: var(--text-muted);
}

.step-connector {
    flex: 1 1 auto;
    height: 2px;
    background: var(--color-divider);
    margin-top: 1rem;
    min-width: 0.5rem;
}

@media (max-width: 640px) {
    #progressStepper {
        padding: 1rem 0.75rem;
    }

    .stepper-track {
        gap: 0.15rem;
    }

    .step-connector {
        min-width: 0.35rem;
        margin-top: 0.9rem;
    }

    .step-label {
        font-size: 0.65rem;
    }

    .step-circle {
        width: 1.75rem;
        height: 1.75rem;
        font-size: 0.8rem;
    }
}

#languageBar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

#languageBar .lang-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-right: auto;
}

#languageBar button {
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}

#languageBar button:hover {
    border-color: var(--color-primary);
    background: rgba(63, 91, 255, 0.04);
}

#languageBar button.active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: #fff;
}

#surveyContainer {
    width: 100%;
}

/* ── SurveyJS typography (Aegis / Noto Sans) ─────────────────────────
   Roles from 06_aegis_design_standards.md:
   Body 16/400 · Body Small 14/400 · Caption 12/400 ·
   Subtitle 14/500 · Section Header 14/600 · Bold Labels 12/700
──────────────────────────────────────────────────────────────────── */
#surveyContainer .sv-root-modern,
#surveyContainer .sv-container-modern,
#surveyContainer .sv-body,
#surveyContainer .sv-page,
#surveyContainer .sv-question,
#surveyContainer .sv-panel {
    font-family: var(--font-family) !important;
    font-size: 16px;
    font-weight: 400;
    color: var(--text-primary);
}

#surveyContainer .sv-container-modern {
    max-width: 100% !important;
    width: 100% !important;
    background: transparent !important;
}

#surveyContainer .sv-root-modern {
    max-width: 100% !important;
    width: 100% !important;
    background: transparent !important;
}

/* Kill SurveyJS Raleway / Segoe title stack */
#surveyContainer .sv-title,
#surveyContainer .sv-string-viewer,
#surveyContainer .sv-string-editor {
    font-family: var(--font-family) !important;
}

/* Survey form header ("Create Observation" / observation no.) — Aegis dialog title */
#surveyContainer .sv-container-modern__title,
#surveyContainer .sv-container-modern__title h3,
#surveyContainer .sv-container-modern__title .sv-title,
#surveyContainer .sv-container-modern__title .sv-string-viewer {
    font-family: var(--font-family) !important;
    font-size: 20px !important;
    font-weight: 500 !important;
    color: var(--text-primary) !important;
    line-height: 1.4;
    letter-spacing: normal;
}

#surveyContainer .sv-container-modern__title {
    color: var(--text-primary) !important;
    padding: 0 0 var(--space-16) 0 !important;
    margin: 0 0 var(--space-8) 0 !important;
}

/* SurveyJS modern theme indents .sv-body__page (5% / 10px). Keep panels
   flush with the form header title (.sv-container-modern__title). */
#surveyContainer .sv-body,
#surveyContainer .sv-body__page,
#surveyContainer .sv-body__footer,
#surveyContainer .sv-page {
    margin-left: 0 !important;
    margin-right: 0 !important;
    max-width: 100%;
}

#surveyContainer .sv-container-modern__title h5,
#surveyContainer .sv-container-modern__title .sv-description {
    font-family: var(--font-family) !important;
    font-size: 14px !important;
    font-weight: 400 !important;
    color: var(--field-label) !important;
}

/* Section / panel headers — 14px SemiBold */
#surveyContainer .sv-panel__title,
#surveyContainer .sv_p_title,
#surveyContainer .sv-page__title {
    font-family: var(--font-family) !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    color: var(--text-primary) !important;
    line-height: 1.4;
    letter-spacing: normal;
}

#surveyContainer .sv-panel__description,
#surveyContainer .sv-page__description {
    font-size: 12px !important;
    font-weight: 400;
    color: var(--text-secondary) !important;
}

/* Question labels — Caption-size, medium gray (#707070) for readability */
#surveyContainer .sv-question__title,
#surveyContainer .sv_q_title,
#surveyContainer .sv-question .sv-title {
    font-family: var(--font-family) !important;
    font-size: 14px !important;
    font-weight: 400 !important;
    color: var(--field-label) !important;
    line-height: 1.4;
    letter-spacing: normal;
    background: transparent !important;
}

#surveyContainer .sv-question__title--answer,
#surveyContainer .sv-question__title--error,
#surveyContainer .sv-panel__title--error {
    background: transparent !important;
}

#surveyContainer .sv-question__required-text {
    font-size: 14px !important;
    font-weight: 500;
    color: var(--color-error) !important;
    line-height: 1;
}

#surveyContainer .sv-question__description,
#surveyContainer .sv-description {
    font-size: 12px !important;
    font-weight: 400;
    color: var(--text-secondary) !important;
}

#surveyContainer .sv-question__erbox {
    font-size: 12px !important;
    font-weight: 700;
    color: var(--color-error) !important;
}

#surveyContainer .sv-question--disabled .sv-question__header,
#surveyContainer .sv-question--disabled .sv-question__title,
#surveyContainer .sv-item--disabled .sv-item__control-label {
    color: var(--text-muted) !important;
}

/* Choice / boolean labels — Body Small 14px */
#surveyContainer .sv-selectbase__label,
#surveyContainer .sv-item__control-label,
#surveyContainer .sv-boolean__label,
#surveyContainer .sv-checkbox .sv-item__control-label,
#surveyContainer .sv-radiogroup .sv-item__control-label {
    font-family: var(--font-family) !important;
    font-size: 14px !important;
    font-weight: 400;
    color: var(--text-primary);
}

#surveyContainer .sv-file__no-file-chosen,
#surveyContainer .sv-file__sign a {
    font-family: var(--font-family) !important;
    font-size: 12px !important;
    font-weight: 400;
    color: var(--text-secondary);
}

#surveyContainer .sv-file__sign a {
    color: var(--color-info);
}

#surveyContainer .sv-btn,
#surveyContainer .sv-file__choose-btn,
#surveyContainer .sv-file__clean-btn {
    font-family: var(--font-family) !important;
    font-size: 14px !important;
    font-weight: 500 !important;
}

.panel-required-hint {
    margin: 0 0 1rem;
    font-family: var(--font-family);
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    text-align: right;
}

/* SurveyJS panel cards */
#surveyContainer .sv-body,
#surveyContainer .sv_p_root {
    max-width: 100%;
}

#surveyContainer .sv_p_container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-16) var(--space-20);
    margin-bottom: var(--space-16);
}

#surveyContainer .sv-panel {
    min-width: 0;
}

/* NOI Number: read-only prefix + running-number input (same height / baseline) */
#surveyContainer .noi-number-field {
    display: flex;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    min-height: 2.75rem;
    box-sizing: border-box;
}

#surveyContainer .noi-number-prefix {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    box-sizing: border-box;
    margin: 0;
    padding: 0 12px;
    min-height: 2.75rem;
    height: auto;
    font-family: var(--font-family);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.4;
    color: var(--field-label);
    background: var(--readonly-bg);
    border: 1px solid var(--field-border);
    border-right: none;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    white-space: nowrap;
}

#surveyContainer .noi-number-field input,
#surveyContainer .noi-number-field input.sv-text,
#surveyContainer .noi-number-field .sv-text {
    flex: 1 1 auto;
    align-self: stretch;
    box-sizing: border-box !important;
    width: auto !important;
    min-width: 0;
    min-height: 2.75rem !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 12px !important;
    font-size: 16px !important;
    line-height: 1.4 !important;
    border: 1px solid var(--field-border) !important;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0 !important;
}

/* Keep NOI Number + Revision No tops aligned in the shared row */
#surveyContainer .sv-question[name="NOINumber"],
#surveyContainer .sv-question[name="NOIRevNo"] {
    vertical-align: top;
}

#surveyContainer .sv-question[name="NOIRevNo"] input,
#surveyContainer .sv-question[name="NOIRevNo"] .sv-text {
    min-height: 2.75rem !important;
    box-sizing: border-box !important;
}

#surveyContainer input[type="text"],
#surveyContainer input[type="email"],
#surveyContainer input[type="date"],
#surveyContainer input[type="datetime-local"],
#surveyContainer select,
#surveyContainer textarea,
#surveyContainer .sv-text,
#surveyContainer .sv-comment {
    width: 100% !important;
    max-width: 100%;
    font-family: var(--font-family) !important;
    font-size: 16px !important;
    font-weight: 400;
    color: var(--field-value) !important;
    background-color: var(--field-bg) !important;
    border: 1px solid var(--field-border);
    border-radius: var(--radius-lg);
    padding: 10px 12px;
}

#surveyContainer .sv-text::placeholder,
#surveyContainer input::placeholder,
#surveyContainer textarea::placeholder {
    color: var(--field-label) !important;
    opacity: 1;
    font-weight: 400;
}

#surveyContainer input:focus,
#surveyContainer select:focus,
#surveyContainer textarea:focus,
#surveyContainer .sv-text:focus {
    outline: 2px solid rgba(63, 91, 255, 0.35);
    outline-offset: 1px;
    border-color: var(--color-primary);
    background-color: var(--color-surface) !important;
}

/* Dropdowns — SurveyJS modern theme fixes a short height that clips selected text */
#surveyContainer .sv-dropdown,
#surveyContainer select.sv-dropdown {
    height: auto !important;
    min-height: 2.75rem !important;
    line-height: 1.4 !important;
    padding: 0.5rem 2.5rem 0.5rem 0.75rem !important;
    background-color: var(--field-bg) !important;
    background-position: right 0.75rem center !important;
    background-size: 0.65em auto !important;
    border: 1px solid var(--field-border) !important;
    border-radius: var(--radius-lg) !important;
    font-family: var(--font-family) !important;
    font-size: 16px !important;
    font-weight: 400;
    color: var(--field-value) !important;
    overflow: visible !important;
    text-overflow: clip;
    white-space: nowrap;
}

#surveyContainer .sv-question__input {
    height: auto !important;
    min-height: 0;
}

#surveyContainer .sv-question__content,
#surveyContainer .sv-question__content--left {
    overflow: visible !important;
}

#surveyContainer .sv-question {
    overflow: visible;
}

#surveyContainer .sv_row > div,
#surveyContainer .sv-row > div {
    min-width: 0;
}

#surveyContainer input[readonly],
#surveyContainer .sv_q_text_root input[readonly],
#surveyContainer .sv-text[readonly] {
    background: var(--readonly-bg) !important;
    color: var(--field-value) !important;
    cursor: not-allowed;
}

#surveyContainer .sv_q,
#surveyContainer .sv_qstn {
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* Fixed-size image previews for file uploads (not scaled to original dimensions) */
#surveyContainer .sv_q_file .sv_q_file_preview,
#surveyContainer .sv_q_file_preview {
    max-width: 72px;
    max-height: 72px;
}

#surveyContainer .sv_q_file .sv_q_file_preview img,
#surveyContainer .sv_q_file_preview img {
    width: 72px !important;
    height: 72px !important;
    max-width: 72px !important;
    max-height: 72px !important;
    object-fit: cover;
}

.readonly-info-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-20) var(--space-24);
    margin-bottom: var(--space-20);
}

.readonly-info-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
    padding: 0;
    margin: 0;
}

.readonly-info-grid .info-label {
    display: block;
    font-family: var(--font-family);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.readonly-info-grid .info-value {
    display: block;
    font-family: var(--font-family);
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.35;
}

.readonly-info-grid .info-value-bold {
    font-size: 16px;
    font-weight: 700;
}

@media (max-width: 640px) {
    .readonly-info-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 641px) and (max-width: 900px) {
    .readonly-info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Sticky submit bar — SurveyJS footer pinned to viewport bottom */
#surveyContainer .sv-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 90;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    min-height: auto;
    margin: 0;
    padding: 0.75rem 1rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
}

@media (min-width: 768px) {
    #surveyContainer .sv-footer {
        padding-left: var(--space-56);
        padding-right: var(--space-56);
    }
}

#surveyContainer .sv_complete_btn,
#surveyContainer .sv-footer__complete-btn {
    background: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
    color: #fff !important;
    font-family: var(--font-family) !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    min-height: 40px;
    padding: 10px 16px;
    float: none !important;
    border-radius: var(--radius-lg);
    cursor: pointer;
}

#surveyContainer .sv_complete_btn:hover,
#surveyContainer .sv-footer__complete-btn:hover {
    background: var(--color-primary-dark) !important;
    border-color: var(--color-primary-dark) !important;
}

#surveyContainer .sv_nav_btn,
#surveyContainer button {
    min-height: 40px;
    padding: 10px 16px;
    font-family: var(--font-family) !important;
    font-size: 14px;
    font-weight: 500;
}

.form-actions-left {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-12);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-8);
    min-height: 40px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-family: inherit;
    line-height: 1.25;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-sm {
    min-height: 32px;
    padding: 8px 12px;
    font-size: 12px;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

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

.btn-secondary {
    background: var(--color-secondary-btn);
    color: var(--text-primary);
    border-color: var(--color-secondary-btn);
}

.btn-secondary:hover {
    background: #d6d6d6;
    border-color: #d6d6d6;
}

.btn-outline {
    background: var(--card);
    color: var(--text-primary);
    border-color: var(--border);
}

.btn-outline:hover {
    background: rgba(0, 0, 0, 0.04);
}

.btn-danger-text {
    background: transparent;
    color: var(--color-error);
    border-color: transparent;
}

.btn-danger-text:hover {
    background: rgba(255, 84, 84, 0.08);
}

/* Submit confirmation dialog */
.confirm-dialog {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.confirm-dialog[hidden] {
    display: none !important;
}

.confirm-dialog-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.confirm-dialog-panel {
    position: relative;
    width: 100%;
    max-width: 28rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-16) var(--space-12) var(--space-8);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.confirm-dialog-message {
    margin: 0 0 var(--space-24);
    padding: 0 var(--space-8);
    font-size: 20px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-primary);
}

.confirm-dialog-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-12);
    padding: var(--space-8);
}

@media (min-width: 768px) {
    #mainContent {
        padding: var(--space-24) var(--space-56) var(--space-24);
        padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    }
}

@media (min-width: 1024px) {
    #appHeader {
        padding: 8px 24px;
    }
}

#formActions[hidden],
#btnSaveDraft,
#btnCancel,
#btnSaveRectifyDraft {
    display: none !important;
}

#rectifyActions[hidden] {
    display: none !important;
}

#rectifyActions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 90;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: var(--space-12);
    padding: 0.75rem 1rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
}

.existing-attachments-list {
    margin: 0.5rem 0 1rem;
    padding: 0.75rem;
    background: var(--readonly-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.existing-attachments-list ul {
    margin: 0;
    padding-left: 1.25rem;
}

.existing-attachments-list a {
    color: var(--info);
    word-break: break-all;
}

/* Pending Closeout / Closed: no sticky footer or action bars */
body.survey-view-only #mainContent {
    padding-bottom: 2rem;
}

.survey-detail-mode.survey-view-only #surveyContainer .sv-footer {
    display: none !important;
}

@media (max-width: 640px) {
    #surveyContainer .sv_row .sv_qstn {
        width: 100% !important;
    }
}

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

.step.complete .step-label {
    color: var(--color-success);
    font-weight: 500;
}

.step-connector.complete {
    background: var(--success);
}
