:root {
    color-scheme: light;
    --bg: #f3f7f8;
    --panel: #ffffff;
    --text: #17242b;
    --muted: #5c6b73;
    --line: #d7e0e4;
    --brand: #164e63;
    --brand-dark: #0f3b4b;
    --warn: #9a6700;
    --ok: #0f6b3f;
    --danger: #a12222;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 16px;
}

button,
input,
textarea {
    font: inherit;
}

.app-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: 12px;
    padding-bottom: 88px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: -12px -12px 12px;
    padding: 12px;
    border-bottom: 1px solid #0d3544;
    background: var(--brand);
    color: #fff;
}

.app-header h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
}

.connection-state {
    margin: 3px 0 0;
    color: #d7eef5;
    font-size: 13px;
}

.user-state {
    margin: 3px 0 0;
    color: #d7eef5;
    font-size: 13px;
}

.user-state a {
    color: #fff;
    font-weight: 700;
}

.header-actions {
    display: inline-flex;
    flex: 0 0 auto;
    gap: 8px;
}

.icon-button {
    position: relative;
    display: inline-flex;
    width: 48px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

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

.icon-button .sync-icon {
    width: 25px;
    height: 25px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2.2;
}

.icon-button strong {
    position: absolute;
    right: -6px;
    top: -7px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: #e5484d;
    color: #fff;
    font-size: 12px;
    line-height: 20px;
}

.message-host {
    position: fixed;
    top: 108px;
    right: max(12px, calc((100vw - 1180px) / 2 + 12px));
    left: max(12px, calc((100vw - 1180px) / 2 + 12px));
    z-index: 5;
    display: grid;
    gap: 8px;
    margin: 0;
}

.message-host:empty {
    display: none;
}

.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: start center;
    padding: 134px 12px 24px;
    background: rgba(15, 36, 43, 0.34);
}

.confirm-overlay[hidden] {
    display: none;
}

.confirm-dialog {
    display: grid;
    width: min(520px, 100%);
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 12px;
    padding: 16px;
    border: 1px solid rgba(22, 78, 99, 0.24);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 18px 42px rgba(15, 59, 75, 0.24);
}

.confirm-icon {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 8px;
    background: #e7f3f6;
    color: var(--brand);
    font-size: 24px;
    font-weight: 800;
}

.confirm-content h2 {
    margin: 0 0 6px;
    color: var(--brand);
    font-size: 19px;
    line-height: 1.25;
}

.confirm-content p {
    margin: 0;
    color: var(--text);
    line-height: 1.4;
}

.confirm-detail {
    margin-top: 8px !important;
    color: var(--muted) !important;
    font-size: 14px;
}

.confirm-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
    margin-top: 16px;
}

.inspections-panel[hidden] {
    display: none;
}

body.inspections-open .unit-panel,
body.inspections-open .questions-panel,
body.inspections-open .photos-panel,
body.inspections-open .note-panel,
body.inspections-open .action-bar {
    display: none;
}

.inspections-list {
    display: grid;
    gap: 8px;
}

.inspection-item {
    display: grid;
    width: 100%;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    text-align: left;
}

.inspection-item strong,
.inspection-item span {
    display: block;
}

.inspection-item strong {
    overflow: hidden;
    color: var(--text);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inspection-item span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 400;
}

.inspection-status {
    align-self: start;
    padding: 3px 7px;
    border-radius: 999px;
    background: #eef3f5;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.inspection-status.pending {
    background: #fff3cd;
    color: var(--warn);
}

.inspection-status.synced {
    background: #dff3e9;
    color: var(--ok);
}

.panel {
    margin: 12px 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.panel h2 {
    margin: 0 0 10px;
    font-size: 18px;
    line-height: 1.25;
}

.unit-panel label,
.note-panel label {
    display: block;
    margin-bottom: 6px;
    color: #263840;
    font-weight: 700;
}

.unit-panel {
    position: sticky;
    top: 77px;
    z-index: 1;
    box-shadow: 0 8px 18px rgba(15, 59, 75, 0.08);
}

.unit-select-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 8px;
}

.refresh-units-button {
    display: inline-flex;
    width: 48px;
    min-width: 48px;
    padding: 0;
    align-items: center;
    justify-content: center;
}

.refresh-units-button span {
    font-size: 24px;
    line-height: 1;
}

input[type="search"],
textarea {
    width: 100%;
    border: 1px solid #b9c8cf;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
}

input[type="search"] {
    min-height: 44px;
    padding: 8px 10px;
}

input[type="search"]:disabled {
    border-color: #d7e0e4;
    background: #eef3f5;
    color: #5c6b73;
    cursor: not-allowed;
}

textarea {
    min-height: 190px;
    padding: 10px;
    resize: vertical;
}

button,
.file-button {
    min-height: 44px;
    border: 1px solid var(--brand);
    border-radius: 6px;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
}

button {
    padding: 0 14px;
}

button.secondary,
.file-button.secondary {
    background: #fff;
    color: var(--brand);
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.dictate-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #fff;
}

.dictate-icon {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    fill: currentColor;
}

.dictate-button .record-icon {
    display: none;
}

.dictate-button.recording {
    border-color: var(--danger);
    background: #fff;
    color: var(--danger);
}

.dictate-button span {
    color: inherit;
}

.dictate-button.recording .mic-icon {
    display: none;
}

.dictate-button.recording .record-icon {
    display: block;
}

.hint {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.section-heading > span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.question-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.question {
    min-width: 0;
    margin: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
}

.question legend {
    padding: 0 4px;
    color: #263840;
    font-weight: 700;
}

.question label {
    display: flex;
    min-height: 36px;
    align-items: center;
    gap: 8px;
}

.question input {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
}

.photo-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.file-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    text-align: center;
}

.file-button input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.photo-tile {
    position: relative;
    margin: 0;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #eef3f5;
}

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

.photo-tile button {
    position: absolute;
    right: 6px;
    top: 6px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border-color: rgba(0, 0, 0, 0.3);
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 22px;
    line-height: 1;
}

.action-bar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
    padding: 10px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -8px 22px rgba(15, 59, 75, 0.12);
}

.app-message {
    padding: 11px 13px;
    border: 1px solid rgba(15, 59, 75, 0.22);
    border-left: 5px solid var(--brand);
    border-radius: 8px;
    background: #eef7fa;
    color: #123745;
    font-weight: 700;
    line-height: 1.35;
}

.app-message.error {
    border-color: rgba(161, 34, 34, 0.25);
    border-left-color: var(--danger);
    background: #fff0f0;
    color: var(--danger);
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
    background:
        linear-gradient(180deg, rgba(22, 78, 99, 0.92) 0%, rgba(22, 78, 99, 0.78) 38%, rgba(243, 247, 248, 1) 38%),
        var(--bg);
}

.login-shell {
    width: min(440px, 100%);
}

.login-panel {
    padding: 24px;
    border: 1px solid rgba(215, 224, 228, 0.9);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 18px 46px rgba(15, 59, 75, 0.24);
}

.login-brand {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
    margin-bottom: 22px;
}

.login-icon {
    display: grid;
    width: 58px;
    height: 58px;
    place-items: center;
    border-radius: 8px;
    background: #e7f3f6;
    color: var(--brand);
}

.login-icon svg {
    width: 34px;
    height: 34px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.login-panel h1 {
    margin: 0 0 4px;
    color: var(--brand);
    font-size: 26px;
    line-height: 1.15;
}

.login-panel p {
    margin: 0;
    color: var(--muted);
}

.login-field {
    margin-top: 14px;
}

.login-field label {
    display: block;
    margin: 0 0 6px;
    color: #263840;
    font-weight: 700;
}

.login-field input {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid #c9d5da;
    border-radius: 7px;
    background: #fff;
    color: var(--text);
}

.login-field input:focus {
    border-color: var(--brand);
    outline: 3px solid rgba(22, 78, 99, 0.16);
}

.login-submit {
    width: 100%;
    min-height: 50px;
    margin-top: 18px;
    font-weight: 800;
}

.login-error {
    margin: 14px 0 0 !important;
    padding: 10px 12px;
    border: 1px solid rgba(161, 34, 34, 0.26);
    border-radius: 7px;
    background: #fff0f0;
    color: var(--danger) !important;
    font-weight: 700;
}

.login-note {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 14px;
    color: var(--muted);
    font-size: 14px;
}

.app-message.ok {
    border-color: rgba(15, 107, 63, 0.25);
    border-left-color: var(--ok);
    background: #e8f6ee;
    color: var(--ok);
}

@media (min-width: 1024px) {
    body {
        background:
            linear-gradient(180deg, rgba(22, 78, 99, 0.05), rgba(22, 78, 99, 0) 260px),
            var(--bg);
    }

    .app-shell {
        display: grid;
        grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
        gap: 14px 16px;
        align-items: start;
        padding: 16px;
        padding-bottom: 92px;
    }

    .app-header,
    .inspections-panel {
        grid-column: 1 / -1;
    }

    .app-header {
        margin: -16px -16px 0;
        padding: 14px 16px;
        border-radius: 0 0 8px 8px;
    }

    .app-header h1 {
        font-size: 24px;
    }

    .panel {
        margin: 0;
        padding: 16px;
        box-shadow: 0 8px 22px rgba(15, 59, 75, 0.06);
    }

    .unit-panel {
        grid-column: 1;
        top: 90px;
        z-index: 2;
    }

    .photos-panel {
        grid-column: 1;
    }

    .questions-panel,
    .note-panel {
        grid-column: 2;
    }

    .question-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .question {
        padding: 12px;
    }

    textarea {
        min-height: 300px;
    }

    .photo-actions {
        grid-template-columns: 1fr;
    }

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

    .action-bar {
        right: auto;
        left: 50%;
        width: min(1180px, calc(100% - 32px));
        grid-template-columns: 180px 220px;
        justify-content: end;
        transform: translateX(-50%);
        border: 1px solid var(--line);
        border-bottom: 0;
        border-radius: 8px 8px 0 0;
    }
}

@media (max-width: 680px) {
    .question-grid,
    .photo-actions {
        grid-template-columns: 1fr;
    }

    .confirm-overlay {
        align-items: start;
        padding-top: 116px;
    }

    .confirm-dialog {
        grid-template-columns: 1fr;
    }

    .confirm-actions {
        grid-template-columns: 1fr;
    }

    .action-bar {
        grid-template-columns: 1fr 1fr;
    }
}
