/*
 * Terenski zapisnik design system.
 *
 * Field tool: one hand, sunlight, gloves. Big targets (min 48px), high
 * contrast, primary actions in the thumb zone. The accent color is the
 * tenant's brand color (set inline as --brand in base.html).
 *
 * Type scale (4 sizes, 2 weights): 13 / 15 / 20 / 28px, 400 / 650.
 * Spacing: 4-point grid (4, 8, 12, 16, 24, 32, 48).
 */

@font-face {
    font-family: "Inter";
    src: url("../fonts/InterVariable.2bf3d951bf9d.woff2") format("woff2");
    font-weight: 100 900;
    font-display: swap;
}

/* ---- Tokens -------------------------------------------------------------- */

:root {
    --brand: #0b568e;
    --on-brand: #ffffff;
    --bg: #f3f5f7;
    --surface: #ffffff;
    --surface-2: #eef1f4;
    --text: #13202b;
    --text-2: rgb(19 32 43 / 0.72);
    --text-3: rgb(19 32 43 / 0.52);
    --line: rgb(19 32 43 / 0.1);
    --brand-soft: color-mix(in srgb, var(--brand) 10%, transparent);
    --brand-line: color-mix(in srgb, var(--brand) 22%, transparent);
    --success: #1b7a4a;
    --success-soft: #e3f3ea;
    --warning: #8a5a00;
    --warning-soft: #fff3d1;
    --danger: #b42318;
    --danger-soft: #fdeceb;
    --on-danger: #fff;
    --record: #d92d20;
    --shadow: 0 1px 2px rgb(19 32 43 / 0.05), 0 8px 24px rgb(19 32 43 / 0.06);
    --shadow-up: 0 -8px 24px rgb(19 32 43 / 0.08);
    --radius: 16px;
    --radius-sm: 10px;
    --fs-s: 13px;
    --fs-m: 15px;
    --fs-l: 20px;
    --fs-xl: 28px;
    --bold: 650;
    --tap: 48px;
    --bar-h: 56px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --on-brand: #ffffff;
    --bg: #0d1318;
    --surface: #151d24;
    --surface-2: #1d2730;
    --text: #e7edf2;
    --text-2: rgb(231 237 242 / 0.76);
    --text-3: rgb(231 237 242 / 0.54);
    --line: rgb(231 237 242 / 0.11);
    --brand-soft: color-mix(in srgb, var(--brand) 26%, transparent);
    --brand-line: color-mix(in srgb, var(--brand) 45%, transparent);
    --success: #5fd197;
    --success-soft: rgb(95 209 151 / 0.14);
    --warning: #f2c14e;
    --warning-soft: rgb(242 193 78 / 0.14);
    --danger: #ff8a80;
    --danger-soft: rgb(255 138 128 / 0.14);
    --on-danger: #2a0d0a;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
    --shadow-up: 0 -8px 24px rgb(0 0 0 / 0.35);
    color-scheme: dark;
}

/* ---- Base ---------------------------------------------------------------- */

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

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font: 400 var(--fs-m) / 1.5 "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    font-feature-settings: "cv11", "ss01";
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: var(--fs-l);
    font-weight: var(--bold);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 17px;
    font-weight: var(--bold);
    line-height: 1.3;
    letter-spacing: -0.01em;
}

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

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

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

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

.small {
    font-size: var(--fs-s);
}

.mono {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.icon {
    width: 20px;
    height: 20px;
    flex: none;
}

/* ---- Layout -------------------------------------------------------------- */

.page {
    width: min(760px, 100%);
    margin: 0 auto;
    padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
}

.page-wide {
    width: min(960px, 100%);
}

.stack {
    display: grid;
    gap: 12px;
}

.stack-lg {
    display: grid;
    gap: 24px;
}

.row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.spread {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

/* ---- App bar ------------------------------------------------------------- */

.appbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
    height: calc(var(--bar-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 8px 0;
    /* Solid, not frosted: in the installed app on iPhone, Safari draws everything inside an
       element with backdrop-filter at lower resolution, so the logo and text looked blurred. */
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.appbar-title {
    flex: 1;
    min-width: 0;
    display: grid;
    line-height: 1.2;
}

.appbar-title strong {
    overflow: hidden;
    font-size: var(--fs-m);
    font-weight: var(--bold);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.appbar-title small {
    color: var(--text-3);
    font-size: var(--fs-s);
}

.brand {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 8px;
    color: var(--text);
    text-decoration: none;
}

.brand img {
    height: 32px;
    width: auto;
}

.brand-logo-dark,
:root[data-theme="dark"] .brand-logo-light {
    display: none;
}

:root[data-theme="dark"] .brand-logo-dark {
    display: block;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--brand);
    color: var(--on-brand);
    font-weight: var(--bold);
}

.brand-name {
    overflow: hidden;
    font-weight: var(--bold);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: var(--tap);
    height: var(--tap);
    flex: none;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
}

.icon-button:hover {
    background: var(--surface-2);
}

/* User menu (details/summary dropdown) */

.menu {
    position: relative;
}

.menu > summary {
    list-style: none;
}

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

.avatar {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: var(--fs-s);
    font-weight: var(--bold);
    text-transform: uppercase;
}

:root[data-theme="dark"] .avatar {
    color: var(--text);
}

.menu-panel {
    position: absolute;
    right: 4px;
    top: calc(100% + 4px);
    min-width: 240px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.menu-panel .menu-user {
    padding: 8px 12px 12px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 4px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: var(--tap);
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.menu-item:hover {
    background: var(--surface-2);
}

/* ---- Buttons ------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 0 20px;
    border: 1px solid transparent;
    border-radius: 12px;
    font-family: inherit;
    font-size: var(--fs-m);
    font-weight: var(--bold);
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.1s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--brand);
    color: var(--on-brand);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.18), 0 4px 12px color-mix(in srgb, var(--brand) 30%, transparent);
}

.btn-primary:hover {
    background: color-mix(in srgb, var(--brand) 88%, black);
}

.btn-secondary {
    background: var(--brand-soft);
    color: var(--brand);
    border-color: var(--brand-line);
}

:root[data-theme="dark"] .btn-secondary {
    color: var(--text);
}

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

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

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

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

/* The one irreversible action, in its confirmation sheet. */
.btn-danger-solid {
    background: var(--danger);
    color: var(--on-danger);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.18), 0 4px 12px color-mix(in srgb, var(--danger) 30%, transparent);
}

.btn-danger-solid:hover {
    background: color-mix(in srgb, var(--danger) 88%, black);
}

.btn-lg {
    min-height: 48px;
    padding: 0 20px;
    border-radius: 14px;
}

.btn-block {
    width: 100%;
}

.bottom-bar {
    position: fixed;
    inset: auto 0 0;
    z-index: 25;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
    background: var(--surface);
    box-shadow: var(--shadow-up);
}

.bottom-bar-inner {
    display: flex;
    gap: 12px;
    width: min(728px, 100%);
    margin: 0 auto;
}

.bottom-bar-inner .btn-primary {
    flex: 1;
}

/* A bar with nothing to tap is not shown, and the page doesn't keep room for it. */
.bottom-bar:not(:has(:is(a, button):not([hidden]))) {
    display: none;
}

.page:has(~ .bottom-bar:not(:has(:is(a, button):not([hidden])))) {
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
}

/* ---- Cards and lists ----------------------------------------------------- */

.card {
    padding: 16px;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-label {
    margin: 4px 4px 6px;
    color: var(--text-3);
    font-size: var(--fs-s);
    font-weight: var(--bold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Osnutki: the whole label row is the tap target. */
.drafts > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--tap);
    padding-right: 12px;
    color: var(--text-3);
    cursor: pointer;
    list-style: none;
}

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

.drafts > summary::after {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
}

.drafts[open] > summary::after {
    transform: rotate(-135deg) translateY(-2px);
}

.drafts-count {
    margin-left: 6px;
    font-variant-numeric: tabular-nums;
}

.order-list + .section-label {
    margin-top: 16px;
}

.order-list {
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.order-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 12px;
    padding: 12px 16px;
    color: inherit;
    text-decoration: none;
}

.order-row + .order-row {
    border-top: 1px solid var(--line);
}

.order-row:hover {
    background: var(--surface-2);
}

.order-row-title {
    overflow: hidden;
    font-weight: var(--bold);
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Always one line: what doesn't fit ends in "…". */
.order-row-meta {
    grid-column: 1 / -1;
    overflow: hidden;
    color: var(--text-2);
    font-size: var(--fs-s);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.order-row-meta span + span::before {
    content: "·";
    margin: 0 8px;
    color: var(--text-3);
}

.order-row-date {
    color: var(--text-2);
    font-size: var(--fs-s);
    white-space: nowrap;
}

.load-more {
    display: flex;
    width: 100%;
    margin-top: 12px;
}

.load-more[aria-busy] {
    opacity: 0.6;
    pointer-events: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 26px;
    padding: 0 10px;
    border-radius: 13px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: var(--fs-s);
    font-weight: var(--bold);
    white-space: nowrap;
}

.chip::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.chip-success {
    background: var(--success-soft);
    color: var(--success);
}

.chip-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

/* Processing: nothing to do but wait, so no words. */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin: 3px 4px;
    border: 2px solid var(--line);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.order-row-status {
    display: inline-flex;
    align-items: center;
}

.unsent {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border: 1px solid var(--warning);
    color: inherit;
    text-decoration: none;
}

.unsent-text {
    flex: 1;
    font-size: var(--fs-s);
}

.chip-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.chip-brand {
    background: var(--brand-soft);
    color: var(--brand);
}

:root[data-theme="dark"] .chip-brand {
    color: var(--text);
}

/* Search */

.search {
    position: relative;
}

.search .icon {
    position: absolute;
    left: 16px;
    top: 50%;
    color: var(--text-3);
    transform: translateY(-50%);
}

.search input[type="search"] {
    padding-left: 48px;
}

.search-status {
    margin: 12px 4px 0;
    color: var(--text-3);
    font-size: var(--fs-s);
}

/* Empty state */

.empty {
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 32px 16px;
    text-align: center;
}

.empty p {
    max-width: 32ch;
}


/* ---- Forms --------------------------------------------------------------- */

.field {
    display: grid;
    gap: 4px;
}

.field label {
    color: var(--text-2);
    font-size: var(--fs-s);
    font-weight: var(--bold);
}

.field small {
    color: var(--text-3);
    font-size: var(--fs-s);
}

input[type="text"],
input[type="search"],
input[type="password"],
input[type="date"],
input[type="number"],
textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px; /* 16px stops iOS from zooming on focus */
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* iOS Safari draws date fields natively: wider than their column, taller, text centred.
   Make them look like the other fields. The picker that opens stays the native one. */
input[type="date"] {
    display: block;
    min-width: 0;
    max-width: 100%;
    -webkit-appearance: none;
    appearance: none;
    line-height: normal;
    text-align: left;
}

input[type="date"]::-webkit-date-and-time-value {
    margin: 0;
    text-align: left;
}

input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: 0.6;
}

input:focus,
textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-soft);
    outline: none;
}

textarea {
    min-height: 128px;
    line-height: 1.5;
    resize: vertical;
}

.field-grid {
    display: grid;
    gap: 12px;
}

@media (min-width: 640px) {
    .field-grid {
        grid-template-columns: 1fr 1fr;
    }

    .field-grid .field-wide {
        grid-column: 1 / -1;
    }
}

.errorlist {
    margin: 0;
    padding: 0;
    color: var(--danger);
    font-size: var(--fs-s);
    list-style: none;
}

.has-error input,
.has-error textarea {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px var(--danger-soft);
}

/* ---- Toasts -------------------------------------------------------------- */

.toasts {
    position: fixed;
    top: calc(var(--bar-h) + env(safe-area-inset-top) + 8px);
    left: 50%;
    z-index: 40;
    display: grid;
    gap: 8px;
    width: min(440px, calc(100% - 32px));
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--text);
    color: var(--bg);
    box-shadow: var(--shadow);
    font-weight: var(--bold);
    animation: toast-in 0.25s ease-out;
    pointer-events: auto;
}

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

.toast.is-leaving {
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

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

/* ---- Step indicator ------------------------------------------------------ */

.steps {
    display: flex;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.steps li {
    width: 24px;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
}

.steps li.is-done {
    background: var(--brand-line);
}

.steps li.is-current {
    width: 32px;
    background: var(--brand);
}

/* ---- Recorder ------------------------------------------------------------ */

.recorder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 32px 16px;
    text-align: center;
}

/* On phones the card fills the screen so the record button sits in the thumb zone. */
@media (max-width: 640px) {
    .recorder {
        min-height: calc(100dvh - var(--bar-h) - 108px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }

    .recorder .record-button {
        margin-top: auto;
    }

    /* After a dictation is saved the progress matters more: shrink the recorder. */
    .recorder.has-recording:not(.is-recording):not(.is-paused) {
        min-height: 0;
    }

    .recorder.has-recording .record-button {
        margin-top: 0;
    }
}

/* With a saved dictation and no recording running, the page fits one screen:
   the timer and the pause row only matter while recording. */
.recorder.has-recording:not(.is-recording):not(.is-paused) {
    gap: 16px;
    padding: 24px 16px;
}

.recorder.has-recording:not(.is-recording):not(.is-paused) :is(.recorder-timer, .recorder-controls) {
    display: none;
}

.recorder.has-recording:not(.is-recording):not(.is-paused) .record-button {
    width: 80px;
    height: 80px;
}

.recorder.has-recording:not(.is-recording):not(.is-paused) .record-button .icon {
    width: 32px;
    height: 32px;
}

.recorder-timer {
    font-size: 56px;
    font-weight: 300;
    line-height: 1;
}

.recorder-status {
    min-height: 24px;
    color: var(--text-2);
}

.record-button {
    --level: 0;
    position: relative;
    display: grid;
    place-items: center;
    width: 112px;
    height: 112px;
    border: 0;
    border-radius: 50%;
    background: var(--record);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 12px 32px rgb(217 45 32 / 0.35), inset 0 1px 0 rgb(255 255 255 / 0.25);
    transition: transform 0.15s ease;
}

.record-button:active {
    transform: scale(0.96);
}

/* While recording, a ring grows with the microphone level: proof the mic hears you. */
.recorder.is-recording .record-button {
    box-shadow:
        0 0 0 calc(8px + var(--level) * 28px) rgb(217 45 32 / 0.22),
        0 12px 32px rgb(217 45 32 / 0.35);
    transition: box-shadow 0.08s linear;
}

.record-button .icon {
    width: 44px;
    height: 44px;
}

.recorder.is-recording .recorder-timer {
    color: var(--record);
}

.recorder.is-paused .record-button {
    opacity: 0.7;
}

.recorder-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    min-height: var(--tap);
}

.prompt-chips {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: 440px;
}

.prompt-chips span {
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    color: var(--text-2);
    font-size: var(--fs-s);
}

audio {
    width: 100%;
    height: 44px;
}

.pending {
    border: 1px solid var(--warning);
    background: var(--warning-soft);
}

.pending ul {
    display: grid;
    gap: 8px;
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}

.pending li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.pending li span {
    flex: 1 1 160px;
}

/* ---- Processing timeline ------------------------------------------------- */

.timeline {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.timeline li {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 40px;
    color: var(--text-3);
}

.timeline li:not(:last-child)::after {
    content: "";
    position: absolute;
    left: 11px;
    top: 30px;
    width: 2px;
    height: 20px;
    background: var(--line);
}

.timeline .dot {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    flex: none;
    border: 2px solid var(--line);
    border-radius: 50%;
}

.timeline li.is-done {
    color: var(--text);
}

.timeline li.is-done .dot {
    border-color: var(--success);
    background: var(--success);
    color: #fff;
}

.timeline li.is-done .dot::after {
    content: "✓";
    font-size: 13px;
    font-weight: 700;
}

.timeline li.is-active {
    color: var(--text);
    font-weight: var(--bold);
}

.timeline li.is-active .dot {
    border-color: var(--brand);
    border-top-color: transparent;
    animation: spin 0.9s linear infinite;
}

.timeline li.is-failed {
    color: var(--danger);
    font-weight: var(--bold);
}

.timeline li.is-failed .dot {
    border-color: var(--danger);
    background: var(--danger);
}

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

.disclosure > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap);
    color: var(--brand);
    font-weight: var(--bold);
    cursor: pointer;
    list-style: none;
}

:root[data-theme="dark"] .disclosure > summary {
    color: var(--text);
}

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

.disclosure > summary::after {
    content: "";
    width: 8px;
    height: 8px;
    margin-left: 4px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    transition: transform 0.15s ease;
}

.disclosure[open] > summary::after {
    transform: rotate(-135deg) translateY(-2px);
}

.quote {
    padding: 12px 16px;
    border-left: 3px solid var(--brand-line);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--surface-2);
    color: var(--text-2);
    white-space: pre-wrap;
}

/* AI provenance badge above the work text. */
.ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--brand);
    font-size: var(--fs-s);
    font-weight: var(--bold);
}

:root[data-theme="dark"] .ai-badge {
    color: var(--text-2);
}

/* ---- Photos -------------------------------------------------------------- */

/* Uploading or deleting: dimmed until the server answers. */
.photo-tile[aria-busy] {
    opacity: 0.5;
    pointer-events: none;
}

/* While recording, picking a photo could interrupt the microphone on a phone. */
main:has(.recorder.is-recording, .recorder.is-paused) [data-photo-panel] .photo-add {
    opacity: 0.5;
    pointer-events: none;
}

/* Back here after adding a photo: not hidden under the sticky app bar. */
#photos {
    scroll-margin-top: calc(var(--bar-h) + env(safe-area-inset-top) + 12px);
}

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

.photo-tile {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 12px;
    background: var(--surface-2);
}

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

.photo-tile .photo-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: rgb(0 0 0 / 0.55);
    color: #fff;
    cursor: pointer;
}

.photo-add {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 4px;
    border: 2px dashed var(--brand-line);
    background: var(--brand-soft);
    color: var(--brand);
    font-size: var(--fs-s);
    font-weight: var(--bold);
    cursor: pointer;
}

:root[data-theme="dark"] .photo-add {
    color: var(--text);
}

/* Destructive action, kept away from the primary buttons. */
/* ---- Dialog -------------------------------------------------------------- */

dialog {
    width: min(440px, calc(100% - 32px));
    padding: 20px 16px;
    border: 0;
    border-radius: 20px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

/* Phones: a bottom sheet, so the confirm button is under the thumb. */
@media (max-width: 640px) {
    dialog {
        width: 100%;
        max-width: 100%;
        margin: auto 0 0;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
        border-radius: 20px 20px 0 0;
        animation: sheet-up 0.25s ease-out;
    }
}

@keyframes sheet-up {
    from {
        transform: translateY(40px);
        opacity: 0;
    }
}

dialog::backdrop {
    background: rgb(13 19 24 / 0.5);
    backdrop-filter: blur(2px);
}

.checklist {
    display: grid;
    gap: 6px;
    margin: 12px 0 16px;
    padding: 0;
    list-style: none;
}

.checklist li {
    display: flex;
    gap: 12px;
}

.checklist li::before {
    content: "✓";
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    flex: none;
    border-radius: 50%;
    background: var(--success-soft);
    color: var(--success);
    font-size: 12px;
    font-weight: 700;
}

abbr.required {
    color: var(--danger);
    text-decoration: none;
    cursor: help;
}

.checklist li.is-missing::before {
    content: "!";
    background: var(--warning-soft);
    color: var(--warning);
}

.dialog-actions {
    display: grid;
    gap: 8px;
}

/* A confirmation sheet: icon, question, what it's about, then the actions. */
.confirm-dialog {
    text-align: center;
}

.confirm-dialog > p {
    margin-top: 4px;
}

.confirm-dialog .dialog-actions {
    margin-top: 20px;
}

.dialog-icon {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    border-radius: 50%;
}

.dialog-icon .icon {
    width: 24px;
    height: 24px;
}

.dialog-icon-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.dialog-subject {
    font-weight: var(--bold);
}

/* ---- Document / success -------------------------------------------------- */

.success-hero {
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 16px 16px 0;
    text-align: center;
}

.success-mark {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--success);
    color: #fff;
    box-shadow: 0 0 0 8px var(--success-soft);
    animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.success-mark svg {
    width: 32px;
    height: 32px;
}

.success-mark path {
    stroke-dasharray: 30;
    stroke-dashoffset: 30;
    animation: draw 0.4s 0.3s ease-out forwards;
}

@keyframes pop {
    from {
        opacity: 0;
        transform: scale(0.4);
    }
}

@keyframes draw {
    to {
        stroke-dashoffset: 0;
    }
}

.doc-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
    gap: 8px 12px;
    margin: 0;
}

.doc-meta dt {
    color: var(--text-3);
    font-size: var(--fs-s);
}

.doc-meta dd {
    margin: 2px 0 0;
    font-weight: var(--bold);
}

.doc-text {
    line-height: 1.55;
    white-space: pre-wrap;
}

/* The PDF is the thing you open; the bottom bar has the one action. */
.pdf-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: inherit;
    text-decoration: none;
}

.pdf-row:hover {
    background: var(--surface-2);
}

.pdf-row-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-weight: var(--bold);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pdf-row-open {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-2);
    font-size: var(--fs-s);
}

/* The PDF under the app bar, filling the rest of the screen. */
.page-pdf {
    width: min(960px, 100%);
    padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
}

/* Pages as images: pinch-zoom works like on any page. White, like paper, also in dark mode. */
.pdf-pages {
    display: grid;
    gap: 12px;
}

.pdf-pages img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 4px;
    background: #fff;
    box-shadow: var(--shadow);
}

.bottom-bar-status {
    width: min(728px, 100%);
    margin: 0 auto;
    color: var(--text-2);
    font-size: var(--fs-s);
    text-align: center;
}

.bottom-bar-status:not(:empty) {
    margin-bottom: 8px;
}

/* share.js sets .can-share on phones and tablets that can share files; otherwise: download. */
.pdf-share,
.can-share .pdf-download {
    display: none;
}

.can-share .pdf-share {
    display: inline-flex;
}

/* ---- Auth ---------------------------------------------------------------- */

.auth {
    display: grid;
    place-items: center;
    min-height: calc(100dvh - 120px);
}

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

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