:root {
    color-scheme: light;
    --page: #f3f6fa;
    --surface: #fff;
    --text: #172b46;
    --muted: #64748b;
    --border: #dbe3ee;
    --primary: #2563eb;
    --header: #10233f;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--page);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.55;
}

button, input, select, textarea { font: inherit; }

h1, h2, h3 {
    line-height: 1.3;
    letter-spacing: -.025em;
}

h1 { font-size: 1.7rem; margin: 0 0 24px; }
h2 { font-size: 1.15rem; margin: 0 0 20px; }
h3 { font-size: .95rem; margin: 18px 0 12px; }

p { margin: 10px 0; }

[hidden] { display: none !important; }

#connection {
    padding: 7px 18px;
    background: #ecfdf3;
    color: #166534;
    text-align: center;
    font-size: .8rem;
    border-bottom: 1px solid #d1fadf;
}

#connection.disconnected {
    background: #fffbeb;
    color: #92400e;
    border-color: #fde68a;
}

#notice {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 13px 24px;
    border-bottom: 1px solid;
    white-space: pre-line;
}

#notice.success {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e40af;
}

#notice.error {
    background: #fff1f2;
    border-color: #fecdd3;
    color: #9f1239;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 22px max(24px, calc((100vw - 1120px) / 2));
    background: var(--header);
    color: #fff;
}

.brand {
    font-size: 1.2rem;
    letter-spacing: .16em;
}

.header-subtitle {
    margin-top: 3px;
    color: #cbd5e1;
    font-size: .8rem;
}

.page {
    width: min(1120px, 100%);
    margin: 30px auto;
    padding: 0 24px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    margin: 20px 0;
    box-shadow: 0 4px 18px rgb(15 23 42 / 4%);
}

.login-card {
    width: min(440px, calc(100% - 32px));
    margin: 10vh auto;
    padding: 32px;
}

.toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.toolbar > select {
    flex: 1 1 260px;
    width: auto;
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: .85rem;
    font-weight: 600;
    line-height: 1.3;
    transition: background 140ms, border-color 140ms;
}

.btn.primary {
    color: #fff;
    background: var(--primary);
}

.btn.primary:hover { background: #1d4ed8; }

.btn.secondary {
    color: #334155;
    background: #fff;
    border-color: #cbd5e1;
}

.btn.secondary:hover { background: #f1f5f9; }

.btn.danger {
    color: #b91c1c;
    background: #fff1f2;
    border-color: #fecdd3;
}

.btn.danger:hover { background: #ffe4e6; }

.btn.header-button {
    color: #e2e8f0;
    background: rgb(255 255 255 / 7%);
    border-color: rgb(255 255 255 / 15%);
}

.btn.header-button:hover {
    background: rgb(255 255 255 / 15%);
}

.btn:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.btn.full { width: 100%; }

.icon {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.btn.loading::before {
    content: "";
    width: 15px;
    height: 15px;
    border: 2px solid rgb(255 255 255 / 40%);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

.btn.loading > .icon { display: none; }

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
    margin-bottom: 18px;
}

.field > span {
    color: #475569;
    font-size: .85rem;
    font-weight: 600;
}

.field > .btn {
    align-self: flex-start;
}

input:not([type="checkbox"]):not([type="range"]),
select,
textarea {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
    border: 1px solid #cbd5e1;
    border-radius: 8px;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 12%);
}

button:focus-visible, a:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 3px;
}

.columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.device-fields {
    margin: 0 0 24px;
    padding: 0;
    border: 0;
    min-width: 0;
}

.property-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 10px;
    margin-bottom: 10px;
}

.section-title {
    margin-top: 26px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid #e8edf4;
    vertical-align: middle;
}

th {
    background: #f8fafc;
    color: #64748b;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }

td .toolbar { min-width: 180px; }

.muted { color: var(--muted); }
.warning-text { color: #92400e; }
.form-error { color: #b91c1c; white-space: pre-line; }

.choice-group {
    margin: 14px 0 20px;
    padding: 14px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.check {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
}

.check input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

dialog {
    width: min(600px, calc(100% - 24px));
    max-height: 90dvh;
    overflow: auto;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    background: #fff;
    box-shadow: 0 24px 70px rgb(15 23 42 / 25%);
}

dialog::backdrop {
    background: rgb(15 23 42 / 55%);
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.section-heading h2 { margin: 0; }

#reader {
    min-height: 240px;
    overflow: hidden;
    margin-bottom: 18px;
    border-radius: 10px;
    background: #0f172a;
    touch-action: none;
}

#zoom-label {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

#scanner-zoom { width: 100%; }

.photo-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 14px 0;
}

.photo-grid img {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: 9px;
}

.photo-preview .btn {
    width: 100%;
    margin-top: 6px;
}

.history-item {
    margin-top: 14px;
    padding: 18px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 680px) {
    .app-header {
        align-items: flex-start;
        flex-direction: column;
        padding: 20px 16px;
    }

    .page {
        padding: 0 12px;
        margin-top: 22px;
    }

    .card { padding: 18px; }

    .columns { grid-template-columns: 1fr; gap: 0; }

    .property-row { grid-template-columns: 1fr 1fr; }

    .property-row .btn {
        grid-column: 1 / -1;
        justify-self: end;
    }

    .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

    th, td { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}



#connection.disconnected::before {
    content: "● ";
    color: #d97706;
}

.download-status {
    display: flex;
    align-items: center;
    gap: .5rem;
}

/* display:flex overschrijft het hidden-attribuut; dit herstelt dat. */
.download-status[hidden] {
    display: none;
}

.download-status::before {
    content: "";
    width: 1rem;
    height: 1rem;
    flex: none;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, .2);
    border-top-color: currentColor;
    animation: ericom-spin .8s linear infinite;
}

@keyframes ericom-spin {
    to { transform: rotate(360deg); }
}