/*
    VisionSO2Web - mobile-first stylesheet.

    Sizing rules that matter on a phone in the field:
      - every tappable target is at least 44px tall (glove-friendly, matches platform guidance)
      - inputs use 16px font, below which iOS Safari zooms the viewport on focus
      - the layout is single-column up to 640px and centres in a readable column above that,
        so a tablet does not stretch text to the full width
*/

:root {
    --so2-bg: #f4f6f8;
    --so2-surface: #ffffff;
    --so2-border: #d8dee6;
    --so2-text: #1a2230;
    --so2-text-muted: #5d6b7f;
    --so2-primary: #1f3a5f;
    --so2-primary-text: #ffffff;
    --so2-accent: #2f6fb5;
    --so2-danger: #b4232c;
    --so2-success: #1d6f42;
    --so2-warning-bg: #fff6e0;
    --so2-warning-border: #e8c164;

    --so2-radius: 10px;
    --so2-tap: 44px;
    --so2-gutter: 12px;
    --so2-header-height: 56px;
    --so2-save-bar-height: 68px;

    /*
        The order list is virtualized, so cards must be a fixed, known height. These two values
        sum to the CardPitch constant in Home.razor (104px) - change one and you must change all
        three, or Virtualize's spacers and the scroll-to-today offset drift apart.
    */
    --so2-card-height: 96px;
    --so2-card-gap: 8px;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--so2-bg);
    color: var(--so2-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

.so2-shell {
    min-height: 100vh;
    min-height: 100dvh;
}

/* ---------------------------------------------------------------- header */

.so2-header {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--so2-gutter);
    height: var(--so2-header-height);
    padding: 0 var(--so2-gutter);
    padding-top: env(safe-area-inset-top);
    height: calc(var(--so2-header-height) + env(safe-area-inset-top));
    background: var(--so2-primary);
    color: var(--so2-primary-text);
}

.so2-header-title {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.so2-header-app {
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.2;
}

.so2-header-user {
    font-size: 0.78rem;
    opacity: 0.82;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.so2-logout-form {
    margin: 0;
    flex-shrink: 0;
}

.so2-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--so2-tap);
    height: var(--so2-tap);
    padding: 0;
    border: 0;
    border-radius: var(--so2-radius);
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.so2-icon-button:active {
    background: rgba(255, 255, 255, 0.16);
}

.so2-icon-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.so2-main {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 var(--so2-gutter) calc(var(--so2-gutter) + env(safe-area-inset-bottom));
}

/* --------------------------------------------------------------- filters */

.so2-filters {
    position: sticky;
    top: calc(var(--so2-header-height) + env(safe-area-inset-top));
    z-index: 20;
    display: flex;
    gap: 8px;
    padding: var(--so2-gutter) 0;
    background: var(--so2-bg);
    overflow-x: auto;
    scrollbar-width: none;
}

.so2-filters::-webkit-scrollbar {
    display: none;
}

/* VMS-5284: applied filters change colour for visual confirmation. */
.so2-chip {
    flex-shrink: 0;
    min-height: var(--so2-tap);
    padding: 0 16px;
    border: 1px solid var(--so2-border);
    border-radius: 999px;
    background: var(--so2-surface);
    color: var(--so2-text);
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
}

.so2-chip-active {
    background: var(--so2-accent);
    border-color: var(--so2-accent);
    color: #ffffff;
}

.so2-chip:active {
    transform: scale(0.97);
}

/* ------------------------------------------------------------ order list */

.so2-order-list {
    margin: 0;
    padding: 0;
}

/*
    Fixed height, not min-height: Virtualize positions rows arithmetically, so a card that grows
    to fit its content would desynchronise the scrollbar from the data. Every field inside is
    single-line and ellipsised, which is what keeps the height honest.
*/
.so2-order-card {
    display: block;
    width: 100%;
    height: var(--so2-card-height);
    margin-bottom: var(--so2-card-gap);
    padding: 12px 14px;
    overflow: hidden;
    border: 1px solid var(--so2-border);
    border-radius: var(--so2-radius);
    background: var(--so2-surface);
    text-align: left;
    cursor: pointer;
}

/*
    Service-date tint: overdue red, due today green, scheduled ahead grey. An order with no
    service date keeps the plain surface above.

    Colour is a redundant cue here - every card also prints its service date - so the list stays
    readable without colour vision. Tints are kept pale so the text keeps its contrast.
*/
.so2-order-card-past {
    background: #fdeceb;
    border-color: #f0b6b3;
}

.so2-order-card-today {
    background: #e7f4ec;
    border-color: #a8d4bb;
}

.so2-order-card-future {
    background: #f0f2f5;
    border-color: #d8dee6;
}

/*
    Press feedback as a brightness shift rather than a fixed background, so one rule works for
    every tint - a hardcoded colour here would wipe out the tint on tap.
*/
.so2-order-card:active {
    filter: brightness(0.94);
}

.so2-order-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.so2-order-type {
    font-weight: 600;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.so2-order-date {
    flex-shrink: 0;
    font-size: 0.86rem;
    color: var(--so2-text-muted);
    font-variant-numeric: tabular-nums;
}

.so2-order-date-today {
    color: var(--so2-accent);
    font-weight: 600;
}

/*
    VMS-5283: "Property (truncated to not wrap)". One line, ellipsis, never wraps -
    min-width:0 is what actually lets the ellipsis engage inside a flex context.
*/
.so2-order-property {
    margin: 2px 0 6px;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--so2-text);
}

.so2-order-meta {
    font-size: 0.78rem;
    color: var(--so2-text-muted);
}

.so2-order-number {
    font-variant-numeric: tabular-nums;
}

.so2-badges {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.so2-badge {
    padding: 2px 8px;
    border-radius: 999px;
    background: #e8edf3;
    color: var(--so2-text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.so2-badge-unassigned {
    background: var(--so2-warning-bg);
    color: #8a6100;
}

/* ---------------------------------------------------------- order detail */

.so2-order-detail {
    padding-bottom: var(--so2-save-bar-height);
}

.so2-detail-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--so2-gutter) 0 4px;
}

.so2-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: var(--so2-tap);
    padding: 0 8px 0 0;
    border: 0;
    background: transparent;
    color: var(--so2-accent);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
}

.so2-back svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.so2-unsaved {
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--so2-warning-bg);
    border: 1px solid var(--so2-warning-border);
    color: #8a6100;
    font-size: 0.74rem;
    font-weight: 600;
}

.so2-detail-title {
    margin: 0 0 12px;
    font-size: 1.35rem;
    font-variant-numeric: tabular-nums;
}

.so2-field {
    margin-bottom: 14px;
}

.so2-field-label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--so2-text-muted);
}

.so2-field-value {
    display: block;
    font-size: 1rem;
}

.so2-multiline {
    white-space: pre-wrap;
    padding: 10px 12px;
    border: 1px solid var(--so2-border);
    border-radius: var(--so2-radius);
    background: var(--so2-surface);
}

/* Preserves entered line breaks without the boxed treatment. */
.so2-prewrap {
    white-space: pre-wrap;
}

.so2-property-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.so2-property-text {
    min-width: 0;
    flex: 1;
}

.so2-map-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: var(--so2-tap);
    height: var(--so2-tap);
    border: 1px solid var(--so2-border);
    border-radius: var(--so2-radius);
    background: var(--so2-surface);
    color: var(--so2-accent);
}

.so2-map-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.so2-textarea,
.so2-select {
    width: 100%;
    min-height: var(--so2-tap);
    padding: 10px 12px;
    border: 1px solid var(--so2-border);
    border-radius: var(--so2-radius);
    background: var(--so2-surface);
    color: var(--so2-text);
    /* 16px minimum: anything smaller makes iOS Safari zoom the page on focus. */
    font-size: 16px;
    font-family: inherit;
}

.so2-textarea {
    resize: vertical;
}

/* DevExpress editors inherit the same 16px floor for the same reason. */
.so2-editor,
.so2-editor input {
    width: 100%;
    font-size: 16px;
}

.so2-documents {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* --------------------------------------------------------- photo capture */

/*
    The real input is hidden and driven by its <label>, because a bare file input cannot be
    styled to a touch-sized target. Not display:none — that stops some browsers forwarding the
    label's click and makes the button do nothing.
*/
.so2-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.so2-camera-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: var(--so2-tap);
    padding: 0 18px;
    border: 1px dashed var(--so2-border);
    border-radius: var(--so2-radius);
    background: var(--so2-surface);
    color: var(--so2-accent);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.so2-camera-button:active {
    background: #eef2f7;
}

.so2-camera-button svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.so2-pending-photos {
    margin-top: 8px;
}

/* Green rather than the navy of a stored document: this one is not saved yet. */
.so2-document-icon-pending {
    background: var(--so2-success);
}

.so2-remove-photo {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    color: var(--so2-text-muted);
}

.so2-remove-photo svg {
    width: 18px;
    height: 18px;
}

.so2-field-hint {
    margin: 6px 0 0;
    font-size: 0.82rem;
    color: var(--so2-text-muted);
}

.so2-document {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--so2-tap);
    padding: 8px 12px;
    border: 1px solid var(--so2-border);
    border-radius: var(--so2-radius);
    background: var(--so2-surface);
    color: var(--so2-text);
    text-decoration: none;
}

.so2-document-icon {
    flex-shrink: 0;
    min-width: 42px;
    padding: 3px 6px;
    border-radius: 4px;
    background: var(--so2-primary);
    color: #ffffff;
    font-size: 0.66rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.03em;
}

.so2-document-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.so2-document-size {
    flex-shrink: 0;
    font-size: 0.76rem;
    color: var(--so2-text-muted);
}

/* Save bar pinned above the home indicator on iOS. */
.so2-save-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    padding: 10px var(--so2-gutter) calc(10px + env(safe-area-inset-bottom));
    background: var(--so2-surface);
    border-top: 1px solid var(--so2-border);
}

.so2-save-bar > * {
    max-width: 640px;
    margin: 0 auto;
}

/* --------------------------------------------------------------- buttons */

.so2-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--so2-tap);
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: var(--so2-radius);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
}

.so2-button-block {
    display: flex;
    width: 100%;
}

.so2-button-primary {
    background: var(--so2-primary);
    color: var(--so2-primary-text);
}

.so2-button-primary:disabled {
    background: #b6bfcb;
    cursor: default;
}

.so2-button-secondary {
    background: var(--so2-surface);
    border-color: var(--so2-border);
    color: var(--so2-text);
}

.so2-button-danger {
    background: var(--so2-danger);
    color: #ffffff;
}

.so2-button-link {
    min-height: var(--so2-tap);
    padding: 0 8px;
    background: transparent;
    color: var(--so2-accent);
    font-weight: 500;
}

/* ---------------------------------------------------------------- sheets */

.so2-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(16, 22, 32, 0.45);
}

.so2-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 41;
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    max-height: 80dvh;
    border-radius: 16px 16px 0 0;
    background: var(--so2-surface);
    padding-bottom: env(safe-area-inset-bottom);
}

.so2-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 8px 8px 16px;
    border-bottom: 1px solid var(--so2-border);
}

.so2-sheet-header h2 {
    margin: 0;
    font-size: 1.05rem;
}

.so2-sheet-header .so2-icon-button {
    color: var(--so2-text-muted);
}

.so2-sheet-actions {
    display: flex;
    gap: 8px;
    padding: 4px 12px;
    border-bottom: 1px solid var(--so2-border);
}

.so2-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
}

.so2-sheet-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--so2-border);
}

.so2-check-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--so2-tap);
    padding: 0 16px;
    cursor: pointer;
}

.so2-check-row input {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    accent-color: var(--so2-accent);
}

.so2-confirm {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 41;
    width: calc(100% - 32px);
    max-width: 360px;
    padding: 20px;
    border-radius: var(--so2-radius);
    background: var(--so2-surface);
}

.so2-confirm h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.so2-confirm p {
    margin: 0 0 16px;
    color: var(--so2-text-muted);
}

.so2-confirm-actions {
    display: flex;
    gap: 8px;
}

.so2-confirm-actions .so2-button {
    flex: 1;
}

/* ----------------------------------------------------------------- login */

.so2-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--so2-gutter);
}

.so2-login-card {
    width: 100%;
    max-width: 420px;
    padding: 28px 22px;
    border: 1px solid var(--so2-border);
    border-radius: 14px;
    background: var(--so2-surface);
}

.so2-login-title {
    margin: 0 0 2px;
    font-size: 1.5rem;
}

.so2-login-subtitle {
    margin: 0 0 20px;
    color: var(--so2-text-muted);
}

.so2-login-help {
    margin: 14px 0 0;
    font-size: 0.86rem;
    color: var(--so2-text-muted);
}

.so2-login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.so2-ms-logo {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* --------------------------------------------------------- status states */

.so2-alert {
    margin: 0 0 14px;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: var(--so2-radius);
    font-size: 0.92rem;
}

.so2-alert-error {
    background: #fdeceb;
    border-color: #f0b6b3;
    color: #86201c;
}

.so2-alert-success {
    background: #e7f4ec;
    border-color: #a8d4bb;
    color: var(--so2-success);
}

.so2-alert-warning {
    background: var(--so2-warning-bg);
    border-color: var(--so2-warning-border);
    color: #7a5500;
}

.so2-empty {
    padding: 48px 16px;
    text-align: center;
    color: var(--so2-text-muted);
}

.so2-loading {
    display: flex;
    justify-content: center;
    padding: 48px 0;
}

.so2-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--so2-border);
    border-top-color: var(--so2-accent);
    border-radius: 50%;
    animation: so2-spin 0.8s linear infinite;
}

@keyframes so2-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .so2-spinner { animation-duration: 2s; }
    .so2-chip:active,
    .so2-order-card:active { transform: none; }
}

/* -------------------------------------------------- blazor error overlay */

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 12px 16px;
    background: #ffe9c9;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 12px;
    top: 10px;
    cursor: pointer;
}
