/* AIBAL design system - one stylesheet for the whole app.
   No inline styles are allowed by the CSP, so every layout need has a class here. */

/* ---------- font ---------- */
/* Plus Jakarta Sans (SIL OFL, see fonts/OFL-PlusJakartaSans.txt), variable weight 200-800,
   self-hosted because the CSP allows fonts only from this site */
@font-face {
    font-family: "Plus Jakarta Sans";
    font-style: normal;
    font-display: swap;
    font-weight: 200 800;
    src: url("fonts/plus-jakarta-sans-latin-ext-wght-normal.woff2") format("woff2-variations");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
        U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: "Plus Jakarta Sans";
    font-style: normal;
    font-display: swap;
    font-weight: 200 800;
    src: url("fonts/plus-jakarta-sans-latin-wght-normal.woff2") format("woff2-variations");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
        U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- tokens ---------- */
/* Look: clean and friendly - light neutral surfaces, thin borders with a soft shadow,
   moderate radii, one deep petrol accent (the logo's teal, darkened). */
:root {
    --brand: #0e6e68;
    --brand-hover: #0b5c57;
    --brand-strong: #084a46;
    --brand-tint: #e7f1f0;

    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --border: #e1e4e8;
    --border-strong: #c7cdd4;
    --text: #161b21;
    --text-2: #525c67;
    --text-muted: #838d98;
    --ink: #1c2229; /* dark panels: selection bar, partner logos */

    --success: #167a4f;
    --success-tint: #eaf5ef;
    --warning: #95600d;
    --warning-tint: #fcf4e6;
    --danger: #b42a2f;
    --danger-hover: #962226;
    --danger-tint: #fcefef;
    --info: #2160c4;
    --info-tint: #edf3fc;

    /* segmentation masks: bitumen blue, aggregate red, background green - the same colours as
       REPORT_COLORS in app_report_exporter.py (a deep blue, distinct from the light blue paper) */
    --mask-bitumen: #1f4fff;
    --mask-aggregate: #e8323c;
    --mask-background: #1fa64a;

    --radius-sm: 4px;
    --radius: 6px;
    --radius-lg: 8px;
    --shadow-sm: 0 1px 2px rgba(22, 27, 33, 0.05);
    --shadow: 0 4px 12px rgba(22, 27, 33, 0.08);
    --shadow-lg: 0 12px 28px rgba(22, 27, 33, 0.14);
    --focus: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);

    --font: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    --header-h: 60px;
    --container: 1280px;
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    font-variant-numeric: tabular-nums;
    word-spacing: 0.04em; /* the typeface sets words quite close together */
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
    margin: 0;
    line-height: 1.25;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}

h1 {
    font-size: 1.6rem;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.08rem;
}

h3 {
    font-size: 1rem;
}

p {
    margin: 0 0 0.75rem;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img,
canvas,
video {
    max-width: 100%;
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.icon {
    width: 1.15em;
    height: 1.15em;
    flex: none;
    vertical-align: -0.2em;
}

.muted {
    color: var(--text-2);
}

.small {
    font-size: 0.85rem;
}

.mono {
    font-family: var(--font-mono);
}

/* ---------- app shell ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.app-header-inner {
    max-width: var(--container);
    margin: 0 auto;
    height: var(--header-h);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 8px;
    color: var(--text);
    font-weight: 800;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.brand:hover {
    text-decoration: none;
}

.brand img {
    width: 30px;
    height: 30px;
}

.brand-sub {
    display: block;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0;
    color: var(--text-2);
}

.app-nav {
    display: flex;
    align-items: stretch;
    align-self: stretch;
    gap: 2px;
    flex: 1;
}

/* the active page is underlined along the bottom edge of the header */
.app-nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    color: var(--text-2);
    font-weight: 600;
    font-size: 0.93rem;
}

.app-nav a:hover {
    color: var(--text);
    border-bottom-color: var(--border-strong);
    text-decoration: none;
}

.app-nav a.is-active {
    color: var(--brand-strong);
    border-bottom-color: var(--brand);
}

.header-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.app-header .nav-toggle {
    display: none;
}

.app-main {
    flex: 1;
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 24px 20px 48px;
}

.app-main.is-narrow {
    max-width: 880px;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}

.page-header p {
    margin: 4px 0 0;
    color: var(--text-2);
    font-size: 0.92rem;
}

.page-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.app-footer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    font-size: 0.8rem;
}

.app-footer-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.app-footer-inner p {
    margin: 0;
}

.app-footer a {
    color: var(--text-2);
    text-decoration: underline;
}

.app-footer .footer-paper {
    margin-top: 6px;
}

.app-footer .footer-paper a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--brand);
    font-weight: 600;
    text-decoration: none;
}

.app-footer .footer-paper a:hover {
    text-decoration: underline;
}

.footer-logos {
    display: flex;
    gap: 16px;
    margin-left: auto;
    align-items: center;
}

.footer-logos {
    padding: 8px 12px;
    border-radius: var(--radius);
    background: var(--ink);
}

.footer-logos img {
    /* the partner logos are white, so they sit on a dark chip */
    height: 30px;
    width: auto;
}

/* ---------- dropdown menus (user, language) ---------- */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 200px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 60;
}

.dropdown-menu a,
.dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.dropdown-menu a:hover,
.dropdown-menu button:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.dropdown-menu .menu-label {
    padding: 6px 10px 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    color: var(--text-2);
    font-size: 0.85rem;
}

.dropdown-menu .menu-label strong {
    display: block;
    color: var(--text);
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
}

/* the SVG flags have their own proportions - cropped to a circle; the ring keeps white parts visible */
.flag {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 0 0 1px var(--border-strong);
}

/* ---------- buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 36px;
    padding: 7px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}

.btn:hover {
    background: var(--surface-2);
    border-color: var(--text-muted);
    text-decoration: none;
}

.btn:disabled,
.btn.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

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

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

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

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

.btn-ghost {
    border-color: transparent;
    background: transparent;
    color: var(--text-2);
}

.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}

.btn-link {
    border: 0;
    background: none;
    padding: 0;
    min-height: 0;
    color: var(--brand);
    font-weight: 600;
}

.btn-link:hover {
    background: none;
    text-decoration: underline;
}

.btn-sm {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 0.85rem;
}

.btn-lg {
    min-height: 42px;
    padding: 9px 20px;
    font-size: 0.98rem;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: 6px;
    min-width: 36px;
}

/* ---------- cards ---------- */
/* panels with a title strip, like the windows of measurement software */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px 11px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 1rem;
}

.card-header p {
    margin: 2px 0 0;
    color: var(--text-2);
    font-size: 0.82rem;
}

.card-body {
    padding: 16px 18px 18px;
}

.card-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.card + .card {
    margin-top: 16px;
}

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

.stack > * + * {
    margin-top: 16px;
}

/* key-value lists (profile, company) */
.kv {
    display: grid;
    grid-template-columns: minmax(120px, 34%) 1fr;
    gap: 10px 16px;
    margin: 0;
}

.kv dt {
    color: var(--text-2);
}

.kv dd {
    margin: 0;
    font-weight: 550;
    overflow-wrap: anywhere;
}

/* ---------- forms ---------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.field > label,
.field-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-2);
}

.field-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.field-error {
    font-size: 0.85rem;
    color: var(--danger);
    margin: 0;
}

.input,
.field input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="submit"]):not([type="file"]),
.field select,
.field textarea {
    width: 100%;
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    transition: border-color 0.12s, box-shadow 0.12s;
}

.input:hover,
.field input:hover,
.field select:hover,
.field textarea:hover {
    border-color: var(--text-muted);
}

.field textarea {
    min-height: 120px;
    resize: vertical;
}

::placeholder {
    color: #9aa3ac;
    opacity: 1;
}

.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: var(--focus);
}

.field input:disabled,
.field select:disabled,
.field textarea:disabled {
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: not-allowed;
}

.field.has-error input,
.field.has-error select,
.field.has-error textarea {
    border-color: var(--danger);
}

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

.form-grid .span-2 {
    grid-column: 1 / -1;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.input-with-icon {
    position: relative;
}

.input-with-icon .icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.input-with-icon > input {
    /* beats the generic .field input rule */
    padding-left: 36px !important;
}

.nowrap {
    white-space: nowrap;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.check input {
    width: 16px;
    height: 16px;
    accent-color: var(--brand);
}

input[type="range"] {
    accent-color: var(--brand);
}

details.disclosure > summary {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: var(--brand);
    font-weight: 600;
    list-style: none;
}

details.disclosure > summary::-webkit-details-marker {
    display: none;
}

details.disclosure > summary .icon {
    transition: transform 0.15s;
}

details.disclosure[open] > summary .icon {
    transform: rotate(180deg);
}

/* ---------- notices and badges ---------- */
/* notices: a lightly tinted box with a coloured icon */
.notice {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 11px 14px;
    border: 1px solid color-mix(in srgb, var(--info) 18%, transparent);
    border-radius: var(--radius);
    background: var(--info-tint);
    color: var(--text);
    font-size: 0.9rem;
}

.notice > .icon {
    color: var(--info);
}

.notice p:last-child {
    margin-bottom: 0;
}

.notice-warning {
    border-color: color-mix(in srgb, var(--warning) 22%, transparent);
    background: var(--warning-tint);
}

.notice-warning > .icon {
    color: var(--warning);
}

.notice-danger {
    border-color: color-mix(in srgb, var(--danger) 20%, transparent);
    background: var(--danger-tint);
}

.notice-danger > .icon {
    color: var(--danger);
}

.notice-success {
    border-color: color-mix(in srgb, var(--success) 20%, transparent);
    background: var(--success-tint);
}

.notice-success > .icon {
    color: var(--success);
}

/* badges: small status labels */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success {
    border-color: color-mix(in srgb, var(--success) 25%, transparent);
    background: var(--success-tint);
    color: var(--success);
}

.badge-warning {
    border-color: color-mix(in srgb, var(--warning) 25%, transparent);
    background: var(--warning-tint);
    color: var(--warning);
}

.badge-danger {
    border-color: color-mix(in srgb, var(--danger) 25%, transparent);
    background: var(--danger-tint);
    color: var(--danger);
}

.badge-brand {
    border-color: color-mix(in srgb, var(--brand) 25%, transparent);
    background: var(--brand-tint);
    color: var(--brand-strong);
}

/* ---------- tables ---------- */
.toolbar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.toolbar .field {
    min-width: 140px;
}

.toolbar .grow {
    flex: 1 1 260px;
}

.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

.table th,
.table td {
    padding: 9px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table th {
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

.table tbody tr:hover {
    background: var(--surface-2);
}

.table tbody tr.is-selected {
    background: var(--brand-tint);
}

/* numbers right-aligned; the font's tabular figures (body) keep the decimals in line */
.table .num {
    text-align: right;
}

.table .col-check {
    width: 44px;
}

.table .col-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.th-sort {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: inherit;
}

.th-sort:hover {
    color: var(--text);
    text-decoration: none;
}

.th-sort .icon {
    opacity: 0.35;
}

.th-sort.is-sorted {
    color: var(--brand-strong);
}

.th-sort.is-sorted .icon {
    opacity: 1;
}

.cell-truncate {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cell-strong {
    font-weight: 600;
}

.table-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-2);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    color: var(--text-2);
    font-size: 0.9rem;
}

.pagination-buttons {
    display: flex;
    gap: 8px;
}

/* bar that slides in when table rows are selected */
.selection-bar {
    position: sticky;
    bottom: 16px;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
    padding: 10px 14px;
    background: var(--ink);
    color: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.selection-bar .count {
    font-weight: 650;
    margin-right: auto;
}

.selection-bar .btn {
    border-color: rgba(255, 255, 255, 0.35);
    background: transparent;
    color: #fff;
}

.selection-bar .btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.selection-bar .btn-danger {
    background: var(--danger);
    border-color: var(--danger);
}

/* ---------- loading, toasts, dialogs ---------- */
.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid color-mix(in srgb, var(--brand) 20%, transparent);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-lg {
    width: 40px;
    height: 40px;
    border-width: 4px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.busy-overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(242, 243, 245, 0.8);
}

.busy-overlay .busy-box {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-weight: 600;
}

.toast-region {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(420px, calc(100vw - 40px));
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 14px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--info);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    animation: toast-in 0.15s ease-out;
}

.toast p {
    margin: 0;
    flex: 1;
}

.toast-success {
    border-left-color: var(--success);
}

.toast-error {
    border-left-color: var(--danger);
}

.toast-warning {
    border-left-color: var(--warning);
}

.toast-close {
    border: 0;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 1.1rem;
    line-height: 1;
}

@keyframes toast-in {
    from {
        transform: translateY(8px);
        opacity: 0;
    }
}

dialog.ui-dialog {
    width: min(480px, calc(100vw - 32px));
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    color: var(--text);
}

dialog.ui-dialog::backdrop {
    background: rgba(20, 25, 30, 0.5);
}

.ui-dialog-body {
    padding: 20px 20px 6px;
}

.ui-dialog-body h2 {
    margin-bottom: 8px;
}

.ui-dialog-body p {
    color: var(--text-2);
    white-space: pre-line;
}

.ui-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    margin-top: 10px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

/* ---------- auth and simple form pages ---------- */
.auth-wrap {
    display: flex;
    justify-content: center;
    padding: 24px 0 40px;
}

.auth-card {
    width: min(460px, 100%);
}

.auth-card .card-body {
    padding: 28px;
}

.auth-card h1 {
    font-size: 1.4rem;
    margin-bottom: 20px;
}

.auth-card .lead {
    color: var(--text-2);
    margin: -14px 0 20px;
}

.auth-links {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 18px;
    font-size: 0.9rem;
}

.form-card {
    width: min(640px, 100%);
    margin: 0 auto;
}

.auth-wrap.has-aside {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 20px;
}

.auth-aside {
    width: min(340px, 100%);
    padding: 22px;
    border-radius: var(--radius-lg);
    background: var(--brand-tint);
}

.auth-aside h2 {
    margin-bottom: 8px;
}

.auth-aside p {
    color: var(--text-2);
    font-size: 0.9rem;
}

/* profile, company, company key, employees */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    align-items: start;
}

.profile-grid .card + .card {
    margin-top: 0;
}

.card-footer-wrap {
    flex-wrap: wrap;
    justify-content: flex-start;
}

.card-header h2 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.key-display {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--surface-2);
}

.key-display code {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--brand-strong);
}

.steps-list {
    margin: 0;
    padding-left: 20px;
    color: var(--text-2);
}

.steps-list li + li {
    margin-top: 6px;
}

.invite-card {
    margin-top: 20px;
}

.invite-card h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

@media (max-width: 900px) {
    .profile-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ---------- error page ---------- */
.error-page {
    text-align: center;
    padding: 56px 20px;
}

.error-page img {
    width: 88px;
    height: 88px;
    margin-bottom: 16px;
}

.error-page .code {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--brand);
    letter-spacing: 0.08em;
}

.error-page p {
    color: var(--text-2);
    max-width: 520px;
    margin: 8px auto 20px;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
    .app-header .nav-toggle {
        display: inline-flex;
    }

    .app-nav {
        display: none;
        position: absolute;
        top: var(--header-h);
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        padding: 8px 12px 12px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow);
    }

    .app-nav.is-open {
        display: flex;
    }

    /* in the opened menu the active page is marked on the left instead of underlined */
    .app-nav a {
        padding: 10px 12px;
        margin: 0;
        border-bottom: 0;
        border-left: 3px solid transparent;
    }

    .app-nav a:hover {
        background: var(--surface-2);
    }

    .app-nav a.is-active {
        background: var(--brand-tint);
        border-left-color: var(--brand);
    }

    .app-header-inner {
        gap: 12px;
    }

    .user-name {
        display: none;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 14.5px;
    }

    .app-main {
        padding: 16px 12px 40px;
    }

    .form-grid,
    .grid-2 {
        grid-template-columns: minmax(0, 1fr);
    }

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

    .kv dd {
        margin-bottom: 8px;
    }

    .card-body,
    .auth-card .card-body {
        padding: 16px;
    }

    .footer-logos {
        margin-left: 0;
    }

    .brand-sub {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* =====================================================================
   Home page (landing, demo, contact)
   ===================================================================== */
html {
    scroll-behavior: smooth;
}

.page-home .app-main {
    padding-top: 8px;
}

.hero {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.6fr);
    gap: 32px;
    align-items: center;
    padding: 40px 0 32px;
}

.hero h1 {
    font-size: clamp(2rem, 4vw, 2.8rem);
    margin: 12px 0 14px;
    letter-spacing: -0.01em;
}

.hero-lead {
    font-size: 1.08rem;
    color: var(--text);
}

.hero-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.hero-visual {
    display: flex;
    justify-content: center;
}

.hero-visual img {
    width: min(260px, 100%);
    height: auto;
    padding: 40px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.landing-section {
    padding: 32px 0;
    scroll-margin-top: calc(var(--header-h) + 12px);
}

.section-title {
    font-size: 1.5rem;
    margin-bottom: 6px;
}

.section-lead {
    margin-bottom: 18px;
}

.feature-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 18px 0 0;
    padding: 0;
    list-style: none;
    counter-reset: step;
}

.feature-steps .card {
    margin: 0;
    padding: 20px;
    counter-increment: step;
}

.feature-steps h3 {
    margin: 12px 0 6px;
}

.feature-steps h3::before {
    content: counter(step) ". ";
    color: var(--brand);
}

.feature-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-lg);
    background: var(--brand-tint);
    color: var(--brand);
}

.feature-icon .icon {
    width: 22px;
    height: 22px;
}

.demo-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(260px, 0.8fr);
    gap: 20px;
    align-items: start;
}

.demo-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.demo-side .result-tile {
    background: var(--surface);
}

.demo-cta h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 14px;
    line-height: 1.45;
}

.contact-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    gap: 24px;
    align-items: start;
}

@media (max-width: 900px) {
    .hero,
    .demo-grid,
    .contact-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .hero {
        padding-top: 20px;
    }

    .hero-visual {
        display: none;
    }

    .feature-steps {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* =====================================================================
   Sample records, export
   ===================================================================== */
.designation-cell .btn-link {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.designation-fallback {
    color: var(--text-2);
    font-style: italic;
    font-weight: 400;
}

.export-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.export-grid .card + .card {
    margin-top: 0;
}

.sample-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.sample-list li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 2px 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.sample-list li:last-child {
    border-bottom: 0;
}

.sample-list li > .small {
    grid-column: 2;
}

.sample-list-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notice .icon {
    margin-top: 2px;
}

.notice + .sample-list {
    margin-top: 12px;
}

@media (max-width: 900px) {
    .export-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* tables become stacked cards on phones (cells carry data-label) */
@media (max-width: 640px) {
    .table-cards thead {
        display: none;
    }

    .table-cards,
    .table-cards tbody,
    .table-cards tr,
    .table-cards td {
        display: block;
        width: 100%;
    }

    .table-cards tbody tr {
        position: relative;
        display: flex;
        flex-direction: column;
        padding: 12px 56px 12px 46px;
        border-bottom: 1px solid var(--border);
    }

    .table-cards td.card-title-cell {
        order: -1;
    }

    .table-cards tbody tr:last-child {
        border-bottom: 0;
    }

    .table-cards td {
        padding: 1px 0;
        border: 0;
        text-align: left;
    }

    .table-cards td.num {
        text-align: left;
    }

    .table-cards td[data-label]::before {
        content: attr(data-label) ": ";
        color: var(--text-2);
        font-family: var(--font);
        font-size: 0.8rem;
    }

    .table-cards td[data-label] > div {
        display: inline;
    }

    .table-cards td.card-title-cell {
        max-width: none;
        font-size: 1rem;
        margin-bottom: 2px;
    }

    .table-cards td.col-check {
        position: absolute;
        left: 14px;
        top: 14px;
        width: auto;
    }

    .table-cards td.col-actions {
        position: absolute;
        right: 6px;
        top: 6px;
        width: auto;
        display: flex;
        flex-direction: column;
    }

    .table-cards td.table-empty {
        padding: 24px 0;
        text-align: center;
    }

    .table-cards tbody tr:has(.table-empty) {
        padding: 12px;
    }
}

/* =====================================================================
   Current Sample (workbench)
   ===================================================================== */
/* progress as one segmented control; the current step is highlighted */
.stepper {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin: 0;
    padding: 3px;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.step {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 8px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}

.step-num {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 700;
}

.step.is-current {
    color: var(--brand-strong);
    background: var(--brand-tint);
}

.step.is-current .step-num {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.step.is-done {
    color: var(--text-2);
}

.step.is-done .step-num {
    border-color: var(--success);
    background: var(--success);
    color: transparent;
}

.step.is-done .step-num::after {
    content: "\2713";
    position: absolute;
    color: #fff;
}

.workbench {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(340px, 1fr);
    gap: 20px;
    align-items: start;
}

.workbench.is-empty {
    grid-template-columns: minmax(0, 1fr);
}

.workbench-viewer {
    position: sticky;
    top: calc(var(--header-h) + 16px);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.workbench.is-empty .workbench-viewer {
    position: static;
}

.workbench-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.workbench-panel .card + .card {
    margin-top: 0;
}

/* upload area */
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    padding: 52px 24px;
    border: 2px dashed var(--border-strong);
    background: var(--surface);
    transition: border-color 0.12s, background-color 0.12s;
}

.dropzone.is-dragover,
.viewer-stage.is-dragover {
    border-color: var(--brand);
    background-color: var(--brand-tint);
}

.dropzone-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin-bottom: 4px;
    border-radius: 12px;
    background: var(--brand-tint);
    color: var(--brand);
}

.dropzone-icon .icon {
    width: 30px;
    height: 30px;
}

.dropzone-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 12px 0 8px;
}

.dropzone-note {
    max-width: 560px;
    margin: 8px 0 0;
}

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

.camera-frame {
    margin: 0;
}

.camera-frame video,
.camera-frame canvas {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: contain;
    background: #11171c;
    border-radius: var(--radius-sm);
}

.camera-frame figcaption {
    margin-top: 4px;
}

.camera-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 14px 0;
}

/* exposure: always visible under the camera buttons */
.exposure-control {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) 104px auto;
    align-items: center;
    gap: 6px 14px;
    margin-bottom: 14px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
}

.exposure-control > label:first-child {
    font-weight: 600;
    white-space: nowrap;
}

.exposure-control .slider {
    width: 100%;
}

.exposure-control .exposure-limit {
    grid-column: 1 / -1;
    margin: 0;
}

.camera-panel .notice {
    margin-bottom: 14px;
}

.camera-settings {
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.manual-rows {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.row-manual {
    display: grid;
    grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1.4fr) minmax(0, 1fr) 90px;
    gap: 10px;
    align-items: center;
    font-size: 0.85rem;
}

.row-manual label {
    font-weight: 600;
    color: var(--text-2);
}

.row-manual select,
.row-manual input[type="number"] {
    min-height: 30px;
    padding: 3px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font: inherit;
    width: 100%;
}


.row-manual input[type="range"] {
    width: 100%;
}

.row-manual .held {
    display: none;
}

/* photo + masks */
.viewer {
    overflow: hidden;
}

.viewer-stage {
    position: relative;
    line-height: 0;
    background: #11171c;
    border-bottom: 1px solid var(--border);
    cursor: crosshair;
}

.viewer-stage canvas {
    display: block;
    width: 100%;
    height: auto;
}

.viewer-stage .overlayCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.viewer-stage .loupe {
    position: absolute;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    z-index: 3;
    background: #11171c;
}

.viewer-busy {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 220px;
    background: rgba(17, 23, 28, 0.6);
    color: #fff;
    font-weight: 600;
    line-height: 1.4;
}

.viewer-busy .spinner {
    border-color: rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
}

.viewer-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px 16px;
}

.legend {
    display: flex;
    align-items: center;
    gap: 6px 10px;
    flex-wrap: wrap;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.legend-item input {
    accent-color: var(--brand);
}

.legend-item:has(input:not(:checked)) {
    color: var(--text-muted);
}

.swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.swatch-bitumen {
    background: var(--mask-bitumen);
}

.swatch-aggregate {
    background: var(--mask-aggregate);
}

.swatch-background {
    background: var(--mask-background);
}

.legend-hint {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.viewer-settings {
    display: flex;
    align-items: center;
    gap: 10px 18px;
    flex-wrap: wrap;
}

.field-inline {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.field-inline > label {
    white-space: nowrap;
}

.field .field-inline select,
.field-inline select {
    min-height: 32px;
    padding: 4px 8px;
    width: auto;
}

.field-inline output {
    min-width: 42px;
    color: var(--text-2);
    font-size: 0.85rem;
    font-weight: 600;
}

.viewer-replace {
    margin-left: auto;
}

/* assessment */
.assessment-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 16px;
    align-items: start;
}

.assessment-grid .span-2 {
    grid-column: 1 / -1;
}

.result-tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 16px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
}

.result-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-2);
}

.result-value {
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--brand-strong);
}

.result-class {
    font-size: 0.85rem;
    color: var(--text-2);
    min-height: 1.2em;
}

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

.result-dialog {
    width: min(640px, calc(100vw - 32px));
}

.result-dialog h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--success);
}

.result-dialog .ui-dialog-actions {
    flex-wrap: wrap;
}

/* sticky save / evaluate bar */
.action-bar {
    position: sticky;
    bottom: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 20px -20px -48px;
    padding: 10px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border-strong);
}

.action-bar-buttons {
    display: flex;
    gap: 8px;
    margin-left: auto;
    flex-wrap: wrap;
}

.save-status {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-2);
}

.save-status.saved {
    color: var(--success);
}

.save-status.error {
    color: var(--danger);
}

@media (max-width: 1024px) {
    .workbench {
        grid-template-columns: minmax(0, 1fr);
    }

    .workbench-viewer {
        position: static;
    }
}

@media (max-width: 640px) {
    .stepper {
        width: 100%;
    }

    .step {
        flex: 1;
        justify-content: center;
        padding: 6px;
        font-size: 0;
        gap: 0;
    }

    .step-num {
        font-size: 0.75rem;
    }

    .step.is-current {
        font-size: 0.8rem;
        gap: 6px;
        flex: 2.5;
    }

    .camera-grid,
    .assessment-grid,
    .result-compare {
        grid-template-columns: minmax(0, 1fr);
    }

    .row-manual {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .exposure-control {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .exposure-control > label:first-child,
    .exposure-control .slider {
        grid-column: 1 / -1;
    }

    .legend-hint {
        display: none;
    }

    .viewer-replace {
        margin-left: 0;
    }

    .action-bar {
        margin: 16px -12px -40px;
        padding: 10px 12px;
    }

    .action-bar-buttons {
        width: 100%;
        margin-left: 0;
    }

    .action-bar-buttons .btn {
        flex: 1;
    }
}
