:root {
    --brand-primary: #1A365D;
    --brand-accent: #C53030;
    --bg: #FFFFFF;
    --fg: #1A1A1A;
    --muted: #555;
    --border: #D1D5DB;
    --tap-target: 44px;   /* iOS HIG minimum interactive element size */
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    /* Native-app feel: no tap highlight, no long-press image-save menu,
       no accidental text selection on chrome. Form inputs override below. */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Form inputs and read-only artifact text (extracted nameplate values
   the salesperson may want to copy) keep normal selection behavior. */
input,
textarea,
select,
[contenteditable],
.selectable {
    user-select: text;
    -webkit-user-select: text;
}

main#app {
    max-width: 720px;
    margin: 0 auto;
    padding:
        env(safe-area-inset-top)
        max(env(safe-area-inset-right), 1rem)
        env(safe-area-inset-bottom)
        max(env(safe-area-inset-left), 1rem);
}

/* ─── Header / branding ─── */

.brand-header {
    border-bottom: 4px solid var(--brand-primary);
    padding: 0.75rem 0 1rem;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-text {
    flex: 1;
    min-width: 0;
}

.brand-header h1 {
    margin: 0;
    color: var(--brand-primary);
    font-size: 1.4rem;
    line-height: 1.2;
}

.brand-header p {
    margin: 0.15rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.back-btn {
    appearance: none;
    background: transparent;
    border: 0;
    color: var(--brand-primary);
    font-size: 1rem;
    font-weight: 500;
    min-width: var(--tap-target);
    min-height: var(--tap-target);
    padding: 0 0.5rem;
    cursor: pointer;
}

.back-btn:active {
    opacity: 0.6;
}

/* ─── Step indicator ─── */

.step-indicator {
    margin-top: 0.75rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.step-indicator ol {
    display: flex;
    gap: 0.4rem;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.78rem;
    white-space: nowrap;
}

.step-indicator li {
    color: var(--muted);
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.04);
    flex-shrink: 0;
}

.step-indicator li.completed {
    color: var(--brand-primary);
    background: rgba(26, 54, 93, 0.08);
}

.step-indicator li.active {
    color: #FFFFFF;
    background: var(--brand-primary);
    font-weight: 600;
}

/* ─── Screen container + buttons ─── */

.screen {
    padding: 1.25rem 0 2rem;
}

.btn {
    appearance: none;
    border: 0;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    min-height: var(--tap-target);
    padding: 0.7rem 1.2rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Inherits user-select: none + -webkit-touch-callout: none from
       the global rule, which is exactly what we want on buttons. */
}

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

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--brand-primary);
    color: #FFFFFF;
}

.btn-secondary {
    background: transparent;
    color: var(--brand-primary);
    border: 1.5px solid var(--brand-primary);
}

/* ─── Welcome screen ─── */

.welcome h2 {
    color: var(--brand-primary);
    font-size: 1.5rem;
    margin: 0 0 0.6rem;
}

.welcome p {
    color: var(--fg);
    line-height: 1.5;
    margin: 0 0 1.4rem;
}

.welcome .btn {
    width: 100%;
    max-width: 320px;
}

.welcome-resume {
    margin-top: 1.5rem;
    color: var(--muted);
    font-size: 0.92rem;
}

.welcome-resume code {
    background: rgba(0, 0, 0, 0.06);
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
    font-size: 0.86em;
}

/* ─── Placeholder screens (Phase 4b–4e fill these in) ─── */

.placeholder-screen h2 {
    color: var(--brand-primary);
    font-size: 1.4rem;
    margin: 0 0 0.5rem;
}

.placeholder-note {
    color: var(--muted);
    line-height: 1.5;
    margin: 0 0 1.25rem;
}

.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 1rem;
    margin: 0 0 1.5rem;
    font-size: 0.95rem;
}

.kv dt {
    font-weight: 600;
    color: var(--muted);
}

.kv dd {
    margin: 0;
    color: var(--fg);
}

.kv code {
    background: rgba(0, 0, 0, 0.06);
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
    font-size: 0.88em;
}

.actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

/* ─── Error screen ─── */

.error-screen h2 {
    color: var(--brand-accent);
    margin: 0 0 0.5rem;
}

.error-screen p {
    color: var(--fg);
    line-height: 1.5;
    margin: 0 0 1.25rem;
}

/* ─── Forms (Phase 4b) ─── */

.form h2 {
    color: var(--brand-primary);
    font-size: 1.4rem;
    margin: 0 0 0.4rem;
}

.form-hint {
    color: var(--muted);
    font-size: 0.92rem;
    margin: 0 0 1.25rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin: 0 0 1rem;
    cursor: pointer;
}

.field-label {
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--fg);
}

.field-label em {
    color: var(--brand-accent);
    font-style: normal;
    margin-left: 0.15rem;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="tel"],
.field select,
.field textarea {
    appearance: none;
    border: 1.5px solid var(--border);
    border-radius: 0.4rem;
    padding: 0.65rem 0.75rem;
    font-size: 1rem;
    /* iOS form-zoom mitigation: any input < 16 px text size triggers an
       auto-zoom on focus, breaking the layout. 1rem ≈ 16 px keeps Safari
       calm. */
    font-family: inherit;
    background: #FFFFFF;
    color: var(--fg);
    /* iOS HIG minimum tap target — input height ends up at ~46 px with
       0.65 rem vertical padding + line-height. */
    min-height: var(--tap-target);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.15);
}

.field textarea {
    resize: vertical;
    line-height: 1.4;
}

.fieldset {
    border: 0;
    padding: 0;
    margin: 0 0 1rem;
}

.fieldset > legend {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--brand-primary);
    padding: 0;
    margin: 0 0 0.5rem;
}

/* Three-up VFD population row — collapses to stacked on narrow screens */
.vfd-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.vfd-row .field {
    margin: 0;
}

.vfd-row .field input {
    text-align: center;
}

@media (max-width: 360px) {
    .vfd-row {
        grid-template-columns: 1fr;
    }
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0;
    cursor: pointer;
    /* Make the whole row tappable, not just the small checkbox box —
       gloved-thumb friendly. */
    min-height: var(--tap-target);
}

.checkbox input[type="checkbox"] {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.checkbox span {
    font-size: 0.96rem;
}

.form-error {
    color: var(--brand-accent);
    background: rgba(197, 48, 48, 0.08);
    border-left: 3px solid var(--brand-accent);
    padding: 0.6rem 0.75rem;
    border-radius: 0.3rem;
    margin: 0 0 1rem;
    font-size: 0.92rem;
}

/* ─── Equipment screen (Phase 4c) ─── */

.equipment-screen h2 {
    color: var(--brand-primary);
    font-size: 1.4rem;
    margin: 0 0 1rem;
}

.photo-card {
    border: 1.5px solid var(--border);
    border-radius: 0.6rem;
    padding: 1rem;
    margin: 0 0 1.25rem;
    background: rgba(0, 0, 0, 0.015);
}

.photo-card-header h3 {
    color: var(--brand-primary);
    font-size: 1.1rem;
    margin: 0 0 0.3rem;
}

.photo-card-hint {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.4;
    margin: 0 0 0.85rem;
}

.photo-preview {
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 0.4rem;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 0 0.85rem;
}

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

.photo-empty {
    color: var(--muted);
    font-size: 0.95rem;
}

/* The capture button is a styled <label> wrapping a hidden <input file> —
   tapping anywhere on the label opens the iOS native camera. Width 100%
   gives a proper full-width tap target. */
.photo-capture-btn {
    width: 100%;
    cursor: pointer;
}

.photo-capture-btn input {
    display: none;
}

.photo-status {
    margin: 0.6rem 0 0;
    font-size: 0.9rem;
    color: var(--muted);
}

.photo-status.error {
    color: var(--brand-accent);
}

/* ─── Saved flash indicator (Phase 4b) ─── */

.saved-flash {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom) + 1rem);
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    background: var(--brand-primary);
    color: #FFFFFF;
    padding: 0.55rem 1rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: transform 220ms ease, opacity 220ms ease;
    z-index: 100;
}

.saved-flash.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ─── Status pill (Phase 4d) ─── */

.status-pill {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom) + 0.6rem);
    right: max(env(safe-area-inset-right), 0.75rem);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.95);
    color: var(--fg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 99;
    transition: background 200ms ease, color 200ms ease, box-shadow 200ms ease;
    max-width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-pill.clickable {
    cursor: pointer;
}

.status-pill-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #16A34A;       /* green: idle / all synced */
    transition: background 200ms ease;
}

/* State transitions via data-state. */
.status-pill[data-state="pending"] {
    background: rgba(254, 243, 199, 0.96);
    color: #92400E;
}
.status-pill[data-state="pending"] .status-pill-dot {
    background: #F59E0B;       /* amber */
    animation: status-pulse 1.4s ease-in-out infinite;
}

.status-pill[data-state="syncing"] {
    background: rgba(219, 234, 254, 0.96);
    color: #1E40AF;
}
.status-pill[data-state="syncing"] .status-pill-dot {
    background: #2563EB;       /* blue */
    animation: status-pulse 0.7s ease-in-out infinite;
}

.status-pill[data-state="analyzing"] {
    background: var(--brand-primary);
    color: #FFFFFF;
}
.status-pill[data-state="analyzing"] .status-pill-dot {
    background: #FFFFFF;
    animation: status-pulse 0.5s ease-in-out infinite;
}

.status-pill[data-state="failed"] {
    background: rgba(254, 226, 226, 0.96);
    color: #991B1B;
}
.status-pill[data-state="failed"] .status-pill-dot {
    background: var(--brand-accent);
}

/* Phase 5b-5 — auth-paused state. Visually distinct from "failed"
   (which is red and connotes "something is broken") because the
   recovery action is different: paused needs the salesperson to
   sign in again; failed is a transient that retries on its own.
   Field-safe amber; tap target routes to #/login. */
.status-pill[data-state="auth_paused"] {
    background: rgba(255, 248, 230, 0.98);
    color: #92400E;
    border: 1px solid #F59E0B;
}
.status-pill[data-state="auth_paused"] .status-pill-dot {
    background: #F59E0B;
}

/* Phase 5b post-deploy fix #2/#3 — needs-attention state. Same amber
   palette as auth_paused since both are "salesperson, you have
   something to do" actions; differentiated by copy + a slightly
   deeper amber dot (no border) so the two states are not visually
   identical. Tap target routes to #/recovery. */
.status-pill[data-state="needs_attention"] {
    background: rgba(255, 243, 215, 0.98);
    color: #92400E;
}
.status-pill[data-state="needs_attention"] .status-pill-dot {
    background: #D97706;
}

@keyframes status-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.7); }
}

/* ─── Audio screen (Phase 4d) ─── */

.audio-screen h2 {
    color: var(--brand-primary);
    font-size: 1.4rem;
    margin: 0 0 1rem;
}

.audio-slot {
    border: 1.5px solid var(--border);
    border-radius: 0.6rem;
    padding: 1rem;
    margin: 0 0 1rem;
    background: rgba(0, 0, 0, 0.015);
}

.audio-slot-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0 0 0.5rem;
}

.audio-slot-header h3 {
    color: var(--brand-primary);
    font-size: 1.05rem;
    margin: 0;
}

.audio-meta {
    color: var(--muted);
    font-size: 0.85rem;
}

.audio-warning {
    color: var(--brand-accent);
    background: rgba(197, 48, 48, 0.08);
    border-left: 3px solid var(--brand-accent);
    padding: 0.45rem 0.6rem;
    border-radius: 0.3rem;
    margin: 0 0 0.6rem;
    font-size: 0.88rem;
}

.audio-recording {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    min-height: 60px;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 0.4rem;
    margin: 0 0 0.75rem;
}

.record-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--brand-accent);
    animation: status-pulse 1s ease-in-out infinite;
}

.countdown {
    color: var(--fg);
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

.audio-playback {
    width: 100%;
}

.audio-meta-line {
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0.4rem 0 0;
    text-align: center;
}

.audio-actions {
    margin: 0 0 0;
}

.audio-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
}

.audio-status {
    margin: 0.6rem 0 0;
    font-size: 0.88rem;
    color: var(--muted);
}

.audio-status.error {
    color: var(--brand-accent);
}

/* ─── Welcome pending UI (Phase 4d) ─── */

.welcome-pending {
    margin-top: 1.5rem;
    padding: 0.85rem 1rem;
    background: rgba(254, 243, 199, 0.7);
    border-left: 3px solid #F59E0B;
    border-radius: 0.4rem;
}

.welcome-pending p {
    margin: 0 0 0.6rem;
    color: var(--fg);
    font-size: 0.92rem;
}

.welcome-pending .btn {
    width: 100%;
    max-width: 240px;
}

/* Phase 5b post-deploy fix #3 — welcome screen needs-attention block.
   Same amber-on-cream visual register as welcome-pending; renders
   ABOVE the pending block when both are present (most-actionable
   first). Copy distinguishes; color does not. */
.welcome-needs-attention {
    margin-top: 1.5rem;
    padding: 0.85rem 1rem;
    background: rgba(254, 243, 199, 0.7);
    border-left: 3px solid #D97706;
    border-radius: 0.4rem;
}

.welcome-needs-attention p {
    margin: 0 0 0.6rem;
    color: var(--fg);
    font-size: 0.92rem;
}

.welcome-needs-attention .btn {
    width: 100%;
    max-width: 240px;
}

/* Phase 5b post-deploy fix #3 — recovery screen.
   Lists items the drain classified as permanent_failed. Field-safe
   labels via friendlyKindLabel; per-item Discard with two-tap inline
   confirm (the inline confirm reuses the .recovery-item-detail span
   for the prompt + appends a Cancel button to .recovery-item-actions). */
.recovery-screen h2 {
    color: var(--brand-primary);
    font-size: 1.4rem;
    margin: 0 0 0.5rem;
}

.recovery-screen > p {
    color: var(--fg);
    line-height: 1.5;
    margin: 0 0 1.2rem;
}

.recovery-list {
    list-style: none;
    margin: 0 0 1.5rem;
    padding: 0;
}

.recovery-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    margin: 0 0 0.6rem;
    background: rgba(254, 243, 199, 0.5);
    border-left: 3px solid #D97706;
    border-radius: 0.4rem;
}

.recovery-item-text {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1 1 auto;
    min-width: 0;
}

.recovery-item-label {
    font-weight: 600;
    color: var(--fg);
}

.recovery-item-detail {
    color: var(--muted);
    font-size: 0.9rem;
}

.recovery-item-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    flex: 0 0 auto;
}

.recovery-item-actions .btn {
    min-width: 6rem;
}

/* ─── Submit screen (Phase 4d minimal) ─── */

.submit-screen h2 {
    color: var(--brand-primary);
    font-size: 1.4rem;
    margin: 0 0 0.5rem;
}

.submit-status {
    margin: 1rem 0 0;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.5;
}

/* ─── Review & Submit screen (Phase 4e) ─── */

.review-screen h2 {
    color: var(--brand-primary);
    font-size: 1.4rem;
    margin: 0 0 0.75rem;
}

.review-cache-banner {
    background: #FFF8E6;
    border-left: 3px solid #C8941F;
    padding: 0.5rem 0.75rem;
    margin: 0 0 1rem;
    font-size: 0.88rem;
    color: var(--text);
    border-radius: 4px;
}

.review-section {
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    padding: 0.75rem 0.9rem;
    margin: 0 0 0.85rem;
}

.review-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0 0 0.5rem;
}

.review-section-header h3 {
    margin: 0;
    font-size: 1.02rem;
    color: var(--brand-primary);
}

.review-section-header .btn-link {
    font-size: 0.88rem;
    padding: 0.25rem 0.5rem;
    background: transparent;
    color: var(--brand-primary);
    text-decoration: underline;
    border: none;
    min-height: 32px;
}

.review-rows {
    margin: 0;
    display: grid;
    grid-template-columns: minmax(8rem, 35%) 1fr;
    gap: 0.3rem 0.6rem;
    font-size: 0.92rem;
}

.review-rows dt {
    font-weight: 600;
    color: var(--muted);
}

.review-rows dd {
    margin: 0;
    word-break: break-word;
}

.review-blank {
    color: #94A3B8;
    font-style: italic;
}

/* Nameplate-edit section + in-place editable fields */

.nameplate-edit-section .form-hint {
    margin: 0 0 0.6rem;
    font-size: 0.88rem;
}

.nameplate-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 0.75rem;
}

@media (max-width: 480px) {
    .nameplate-fields {
        grid-template-columns: 1fr;
    }
}

.nameplate-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.nameplate-field-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 600;
}

.nameplate-field input {
    padding: 0.5rem 0.6rem;
    font-size: 1rem;
    border: 1px solid #CBD5E1;
    border-radius: 6px;
    background: #fff;
    min-height: 40px;
    user-select: text;
    -webkit-user-select: text;
}

.nameplate-field input.field-low-confidence {
    background: #FFF8E6;
    border-color: #E0B86A;
}

/* Mutually-exclusive pills — Edited (gray) replaces Verify (amber) once
   a human touches the field. Same physical slot in the layout. */

.pill {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 12px;
    line-height: 1.2;
    letter-spacing: 0.02em;
}

.pill-edited {
    background: #E2E8F0;
    color: #475569;
}

.pill-verify {
    background: #FBE5B5;
    color: #7C5615;
}

/* Run Analysis "analyzing" pulse — visual affordance during the 30-60s
   Opus wait. Subtle opacity pulse so the disabled state doesn't read
   as "frozen." */

.btn.analyzing {
    animation: pulse-analyzing 1.4s ease-in-out infinite;
}

@keyframes pulse-analyzing {
    0%, 100% { opacity: 0.6; }
    50%      { opacity: 1.0; }
}

.review-submit {
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    padding: 0.75rem 0.9rem;
    margin: 1rem 0 0.5rem;
}

.review-submit .gate-hint {
    color: #B7791F;
    font-size: 0.92rem;
    margin: 0.5rem 0;
    padding: 0.5rem 0.6rem;
    background: #FFF8E6;
    border-left: 3px solid #C8941F;
    border-radius: 4px;
}

.review-submit .actions {
    margin: 0.5rem 0 0;
}

.share-error {
    margin: 0.6rem 0 0;
    padding: 0.5rem 0.6rem;
    background: #FEE2E2;
    border-left: 3px solid #B91C1C;
    border-radius: 4px;
    color: #7F1D1D;
    font-size: 0.9rem;
}
