/* TerenGIS — shared tokens and base elements. */

:root {
    /* The brand is petrol green, inherited from the edanoci.mk colour, with an amber accent for actions. */
    --brand-950: #04292a;
    --brand-900: #073b39;
    --brand-800: #0a5450;
    --brand-700: #0b675f;
    --brand-600: #0e8074;
    --brand-500: #12a08f;
    --brand-400: #2bbcaa;
    --brand-200: #a6e5db;
    --brand-100: #d7f2ee;
    --brand-50: #eefaf8;

    --amber-700: #b0700a;
    --amber-600: #d98a0b;
    --amber-500: #f2a41b;
    --amber-200: #fbdda0;
    --amber-100: #fdf0d8;

    --ink-950: #07121a;
    --ink-900: #0b1620;
    --ink-800: #132430;
    --ink-700: #1e3543;
    --ink-600: #33505f;
    --ink-500: #4a6273;
    --ink-400: #6d8494;
    --ink-300: #9aacb8;
    --ink-200: #c4d1d9;

    --paper: #ffffff;
    --paper-2: #f4f7f8;
    --paper-3: #e9eff2;
    --line: #dbe4e9;

    --danger: #d64545;
    --danger-bg: #fdeded;
    --ok: #2f9e6b;
    --ok-bg: #e8f6ef;
    --warn: #d98a0b;
    --warn-bg: #fdf3e0;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --radius-xl: 26px;

    --shadow-1: 0 1px 2px rgba(7, 18, 26, .08), 0 1px 3px rgba(7, 18, 26, .06);
    --shadow-2: 0 4px 12px rgba(7, 18, 26, .10), 0 2px 4px rgba(7, 18, 26, .06);
    --shadow-3: 0 18px 40px rgba(7, 18, 26, .18), 0 4px 12px rgba(7, 18, 26, .10);
    --shadow-brand: 0 10px 30px rgba(11, 103, 95, .28);

    --font: "Segoe UI", system-ui, -apple-system, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;

    /* Field use: with gloves, in sunlight. Nothing smaller than this is tappable. */
    --tap: 46px;
}

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

/*
 * Any author-declared `display` overrides the browser rule for [hidden]. Without
 * this, an element hidden from JS still shows up if it has display: flex.
 */
[hidden] {
    display: none !important;
}

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

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    color: var(--ink-800);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
    margin: 0 0 .5em;
    line-height: 1.2;
    font-weight: 700;
    letter-spacing: -.015em;
    color: var(--ink-900);
}

p {
    margin: 0 0 1em;
}

a {
    color: var(--brand-700);
    text-decoration-color: color-mix(in srgb, var(--brand-700) 35%, transparent);
    text-underline-offset: 3px;
}

a:hover {
    color: var(--brand-600);
}

img,
svg {
    max-width: 100%;
}

:focus-visible {
    outline: 3px solid var(--brand-400);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ── Brand (shared by the landing page and the login page) ─────────────── */
.brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    text-decoration: none;
    color: #fff;
    font-weight: 750;
    letter-spacing: -.02em;
    font-size: 1.12rem;
}

.brand img {
    width: 36px;
    height: 36px;
    border-radius: 9px;
}

.brand small {
    display: block;
    font-size: .68rem;
    font-weight: 500;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--brand-200);
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .55em;
    min-height: var(--tap);
    padding: .68em 1.35em;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font: inherit;
    font-weight: 650;
    letter-spacing: .01em;
    cursor: pointer;
    transition: background-color .16s, border-color .16s, color .16s, transform .08s, box-shadow .16s;
    text-decoration: none;
    white-space: nowrap;
}

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

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: .55;
    cursor: not-allowed;
    transform: none;
}

.btn--primary {
    background: linear-gradient(180deg, var(--brand-600), var(--brand-700));
    color: #fff;
    box-shadow: var(--shadow-brand);
}

.btn--primary:hover:not(:disabled) {
    background: linear-gradient(180deg, var(--brand-500), var(--brand-600));
}

.btn--amber {
    background: linear-gradient(180deg, var(--amber-500), var(--amber-600));
    color: #2a1b02;
    box-shadow: 0 10px 26px rgba(217, 138, 11, .3);
}

.btn--amber:hover:not(:disabled) {
    background: linear-gradient(180deg, #f7b43c, var(--amber-500));
}

.btn--ghost {
    background: transparent;
    color: var(--ink-700);
    border-color: var(--line);
}

.btn--ghost:hover:not(:disabled) {
    background: var(--paper-2);
    border-color: var(--ink-200);
}

.btn--onDark {
    background: rgba(255, 255, 255, .1);
    color: #fff;
    border-color: rgba(255, 255, 255, .28);
    backdrop-filter: blur(6px);
}

.btn--onDark:hover:not(:disabled) {
    background: rgba(255, 255, 255, .18);
}

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

.btn--block {
    width: 100%;
}

/* A control inside a row or a heading — small, and shared by the console and the field screen. */
.btn--slim { min-height: 34px; padding: .2em .8em; font-size: .82rem; }

.btn--lg {
    min-height: 56px;
    padding: .8em 1.8em;
    font-size: 1.05rem;
}

/* ── Icon button (map, admin, review) ──────────────────────────────────── */
.icon-btn {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex: none;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--paper);
    color: var(--ink-600);
    cursor: pointer;
}

.icon-btn:hover { background: var(--paper-2); color: var(--ink-900); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn svg { width: 20px; height: 20px; }

.icon-btn--danger:hover {
    background: var(--danger-bg);
    color: #a12b2b;
    border-color: #f3c9c9;
}

/*
 * „Mark this one on the map“, standing in a row beside a badge and a button — 42px would make
 * the row about the button. Pressed, it wears the colour the mark is drawn in, which is the
 * whole point: the crimson in the list and the crimson on the map are the same record.
 */
.icon-btn--mark {
    width: 34px;
    height: 34px;
    border-radius: 9px;
}

.icon-btn--mark svg { width: 17px; height: 17px; }

.icon-btn--mark[aria-pressed="true"] {
    background: #e11d48;
    border-color: #e11d48;
    color: #fff;
}

.icon-btn--mark[aria-pressed="true"]:hover {
    background: #be123c;
    border-color: #be123c;
    color: #fff;
}

/* ── Forms ────────────────────────────────────────────────────────────── */
.field {
    display: block;
    margin-bottom: 14px;
}

.field__label {
    display: block;
    margin-bottom: 6px;
    font-size: .82rem;
    font-weight: 650;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ink-500);
}

.field__label .req {
    color: var(--danger);
}

.input,
.select,
.textarea {
    width: 100%;
    min-height: var(--tap);
    padding: .6em .8em;
    font: inherit;
    color: var(--ink-900);
    background: var(--paper);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}

.select {
    padding-right: 2.2em;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234a6273' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .6em center;
    background-size: 1.1em;
    -webkit-appearance: none;
    appearance: none;
}

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

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--brand-100);
}

.input[readonly] {
    background: var(--paper-2);
    color: var(--ink-500);
}

/* A control that cannot be used yet — the second step of a purpose before its first, a name the
   register keeps — reads as such rather than as an empty field waiting to be filled. The colour
   alone, so a select keeps its arrow. */
.input:disabled,
.select:disabled,
.textarea:disabled {
    background-color: var(--paper-2);
    color: var(--ink-400);
    cursor: not-allowed;
}

.check {
    display: flex;
    align-items: center;
    gap: .6em;
    min-height: var(--tap);
    cursor: pointer;
    user-select: none;
}

.check input {
    width: 22px;
    height: 22px;
    accent-color: var(--brand-600);
    flex: none;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 14px;
}

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

/* ── Small parts ──────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .4em;
    padding: .22em .7em;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 650;
    letter-spacing: .02em;
}

.badge--ok { background: var(--ok-bg); color: #1c6b47; }
.badge--warn { background: var(--warn-bg); color: var(--amber-700); }
.badge--danger { background: var(--danger-bg); color: #a12b2b; }
.badge--info { background: var(--brand-50); color: var(--brand-800); }
.badge--muted { background: var(--paper-3); color: var(--ink-500); }

.alert {
    display: flex;
    gap: .7em;
    padding: .8em 1em;
    border-radius: var(--radius-sm);
    font-size: .92rem;
    border: 1px solid transparent;
}

.alert--error { background: var(--danger-bg); border-color: #f3c9c9; color: #8f2626; }
.alert--ok { background: var(--ok-bg); border-color: #bfe4d2; color: #1c6b47; }
.alert--info { background: var(--brand-50); border-color: var(--brand-200); color: var(--brand-900); }
.alert--warn { background: var(--warn-bg); border-color: var(--amber-200); color: var(--amber-700); }
.alert[hidden] { display: none; }

/* An alert that carries more than one fact. Flex in a row would lay them out side by side. */
.alert--stack {
    display: grid;
    gap: .45em;
}

/* ── Toasts ───────────────────────────────────────────────────────────── */
.toasts {
    position: fixed;
    left: 50%;
    bottom: 1.4rem;
    transform: translateX(-50%);
    z-index: 700;
    display: grid;
    gap: .5rem;
    width: min(440px, calc(100vw - 2rem));
    pointer-events: none;
}

.toast {
    padding: .7rem 1rem;
    border-radius: var(--radius);
    background: var(--ink-900);
    color: #fff;
    font-size: .92rem;
    box-shadow: var(--shadow-3);
    animation: toast-in .22s ease;
}

.toast--ok { background: #1c6b47; }
.toast--error { background: #a12b2b; }
.toast--warn { background: var(--amber-700); color: #fff; }
.toast.is-leaving { opacity: 0; transition: opacity .25s; }

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

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

.spinner {
    width: 1.05em;
    height: 1.05em;
    border: 2.5px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex: none;
}

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

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

/* ── Comparison: register value beside field value ────────────────────── */
/*
 * Shared by the inspection screen and the appraiser console. The two ends of the
 * workflow have to write a change the same way, otherwise the operator and the
 * appraiser end up reading the same record differently.
 */
.cmp-was {
    color: var(--ink-500);
    font-weight: 400;
}

.cmp-now {
    font-style: normal;
    text-transform: none;
    letter-spacing: 0;
    color: var(--ink-900);
}

/* ── Dialog over a dialog ─────────────────────────────────────────────── */
/* A special part opened from inside the field record, and a part's history — see
   js/core/dialog.js. Above the record (560) and below the action sheet (600), so a question can
   still be asked from inside one. Here and not in app.css: the appraiser console opens the same
   history. */
.dlg {
    position: fixed;
    inset: 0;
    z-index: 590;
    display: grid;
    place-items: center;
    padding: max(env(safe-area-inset-top), 1rem) 1rem max(env(safe-area-inset-bottom), 1rem);
    background: rgba(4, 18, 22, .55);
    opacity: 0;
    transition: opacity .18s;
}

.dlg.is-open { opacity: 1; }

.dlg__card {
    width: min(560px, 100%);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    overflow: hidden;
    transform: translateY(12px);
    transition: transform .18s;
}

.dlg.is-open .dlg__card { transform: none; }

/* Only the body may give way — the header and the buttons stay whole however long the body. */
.dlg__head {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: .7rem;
    padding: .85rem 1rem;
    background: linear-gradient(180deg, var(--brand-600), var(--brand-700));
    color: #fff;
}

.dlg__head h2 {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 1rem;
    color: #fff;
    overflow-wrap: anywhere;
}

.dlg__head .icon-btn {
    flex: 0 0 auto;
    background: rgba(255, 255, 255, .14);
    border-color: rgba(255, 255, 255, .24);
    color: #fff;
}

.dlg__head .icon-btn:hover {
    background: rgba(255, 255, 255, .24);
    color: #fff;
}

.dlg__body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
    background: var(--paper-2);
}

.dlg__foot {
    display: flex;
    flex: 0 0 auto;
    gap: .6rem;
    justify-content: flex-end;
    padding: .8rem 1rem calc(env(safe-area-inset-bottom) + .8rem);
    border-top: 1px solid var(--line);
    background: var(--paper);
}

/* Three buttons do not fit across a phone; „Откажи“ goes, since the × in the header also closes. */
@media (max-width: 520px) {
    .dlg__foot .btn--optional { display: none; }
    .dlg__foot .btn { flex: 1 1 0; min-width: 0; padding-inline: .6em; }
}

/* ── A special part's history ─────────────────────────────────────────── */
.hist__lead {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem .6rem;
    margin: 0 0 .8rem;
    font-size: .9rem;
    color: var(--ink-600);
}

.hist__block {
    margin: 0 0 .8rem;
    padding: .8rem .9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
}

.hist__block h3 {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: .2rem .6rem;
    margin: 0 0 .6rem;
    font-size: .74rem;
    font-weight: 750;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--brand-700);
}

.hist__block h3 small {
    font-size: .78rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--ink-400);
}

.hist__kv {
    display: grid;
    grid-template-columns: minmax(7.5rem, auto) minmax(0, 1fr);
    gap: .3rem .9rem;
    margin: 0;
    font-size: .88rem;
}

.hist__kv dt { font-size: .82rem; color: var(--ink-400); }
.hist__kv dd { margin: 0; font-weight: 600; color: var(--ink-800); overflow-wrap: anywhere; }

.hist__note,
.hist__empty {
    margin: 0;
    font-size: .86rem;
    color: var(--ink-400);
}

.hist__empty { padding: 1.5rem .5rem; text-align: center; }

.hist__visits {
    display: grid;
    gap: .7rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.hist__visit { padding-top: .7rem; border-top: 1px solid var(--line); }
.hist__visit:first-child { padding-top: 0; border-top: 0; }

.hist__visit-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .3rem .5rem;
    margin-bottom: .45rem;
}

/* Who and when is a sentence, so it takes a line of its own under the number and the state. */
.hist__when { flex-basis: 100%; font-size: .8rem; color: var(--ink-400); }

.hist__quote {
    margin: .5rem 0 0;
    padding: .45rem .7rem;
    border-left: 3px solid var(--brand-200);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--paper-2);
    font-size: .88rem;
    color: var(--ink-700);
    white-space: pre-wrap;
}

.hist__review { margin: .45rem 0 0; font-size: .82rem; color: var(--ink-500); }

/* The photos a record carries of the part: small, and each one opens the shared viewer. */
.hist__photos {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-top: .5rem;
}

.hist__photo {
    padding: 0;
    border: 0;
    background: none;
    cursor: zoom-in;
    line-height: 0;
}

.hist__photo img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 8px;
}

/* ── Photo viewer ─────────────────────────────────────────────────────── */
/* Sits above every dialog of the application (the highest is 620) and below the
   toasts, which have to stay readable while a photo is open. */
.lbx {
    position: fixed;
    inset: 0;
    z-index: 680;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: rgba(4, 18, 22, .92);
    color: #eaf3f1;
    padding: max(env(safe-area-inset-top), .5rem) .5rem max(env(safe-area-inset-bottom), .5rem);
}

.lbx__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .7rem;
    padding: .2rem .3rem;
    min-height: 46px;
}

.lbx__count {
    font-size: .9rem;
    font-variant-numeric: tabular-nums;
    color: #b9cdc9;
}

.lbx__tools {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.lbx__close,
.lbx__toggle,
.lbx__nav {
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    cursor: pointer;
    line-height: 1;
}

.lbx__close {
    width: 44px;
    height: 44px;
    font-size: 1.6rem;
}

/* The 360° switch. It stays visible on a flat photo as well — the shape of the file is
   only a hint, and the operator is the one who knows what was taken. */
.lbx__toggle {
    height: 44px;
    padding: 0 .9rem;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 700;
    letter-spacing: .04em;
}

.lbx__toggle.is-on {
    background: var(--brand-600, #157a6e);
    border-color: transparent;
}

.lbx__pano {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: var(--radius);
    /* The renderer handles the gestures itself; the browser must not scroll or zoom. */
    touch-action: none;
    cursor: grab;
}

.lbx__pano.is-dragging { cursor: grabbing; }

.lbx__stage {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 0;
}

.lbx__img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius);
}

.lbx__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 46px;
    height: 46px;
    font-size: 2rem;
    /* The glyph sits high in its box; nudging it back keeps the arrow centred. */
    padding-bottom: .25rem;
}

.lbx__nav--prev { left: .25rem; }
.lbx__nav--next { right: .25rem; }

.lbx__foot {
    display: grid;
    gap: .5rem;
    justify-items: center;
    padding: .4rem .2rem 0;
}

.lbx__caption {
    margin: 0;
    max-width: min(52rem, 100%);
    text-align: center;
    font-size: .86rem;
    color: #cfe0dc;
}

.lbx__strip {
    display: flex;
    gap: .4rem;
    max-width: 100%;
    padding: .15rem;
    overflow-x: auto;
    scrollbar-width: thin;
}

.lbx__thumb {
    flex: 0 0 auto;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 8px;
    background: none;
    cursor: pointer;
    opacity: .6;
    transition: opacity .15s;
}

.lbx__thumb img {
    display: block;
    width: 54px;
    height: 54px;
    object-fit: cover;
    border-radius: 6px;
}

.lbx__thumb.is-active,
.lbx__thumb:hover { opacity: 1; }
.lbx__thumb.is-active { border-color: #fff; }

/* Nothing behind the viewer may scroll while it is open. */
body.has-viewer { overflow: hidden; }
