:root {
    --primary: #0b6cb8;
    --on-primary: #ffffff;
    --primary-dark: #095591;
    --primary-soft: #e7f1fa;
    --link: #0b6cb8;
    --accent: #e8590c;
    --on-accent: #ffffff;
    --bg: #f5f7fa;
    --surface: #ffffff;
    --text: #1b2733;
    --muted: #5b6774;
    --border: #d5dbe2;
    --danger: #b42318;
    --ok: #1a7f37;
    --radius: 12px;
    --tap: 48px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; font-weight: 800; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 .75rem; }
a { color: var(--link); }

.app-header {
    position: relative;
    background: var(--primary);
    color: var(--on-primary);
    padding: .6rem 1rem .9rem;
    padding-top: calc(.6rem + env(safe-area-inset-top, 0px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    min-height: 60px;
    margin-bottom: 1rem;
}
/* roller shutter slats along the bottom edge */
.app-header::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: -8px; height: 8px;
    background: repeating-linear-gradient( to bottom, var(--primary-dark) 0 2px, transparent 2px 4px );
    -webkit-mask: linear-gradient( to bottom, #000, transparent ); mask: linear-gradient( to bottom, #000, transparent );
}
.app-header .brand { display: flex; align-items: center; gap: .6rem; color: inherit; text-decoration: none; min-width: 0; }
.app-header img { max-height: 36px; max-width: 55vw; object-fit: contain; }
.app-header .brand-name { font-weight: 800; font-size: 1.15rem; letter-spacing: .01em; }
.app-header .header-link { color: inherit; font-size: .875rem; font-weight: 600; text-decoration: none; padding: .4rem .8rem; border: 1px solid color-mix( in srgb, currentColor 45%, transparent ); border-radius: 999px; white-space: nowrap; }

main { padding: 0 1rem 1rem; padding-bottom: calc(100px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; }

.progress { display: flex; margin: 0 0 1.25rem; padding: 0; list-style: none; counter-reset: step; }
.progress li { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem; position: relative; font-size: .75rem; color: var(--muted); text-align: center; }
.progress li::before { content: ""; position: absolute; top: 13px; right: 50%; width: 100%; height: 3px; background: var(--border); }
.progress li:first-child::before { display: none; }
.progress li.done::before, .progress li.current::before { background: var(--primary); }
.progress .dot { position: relative; z-index: 1; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .8rem; background: var(--surface); border: 2px solid var(--border); color: var(--muted); }
.progress li.done .dot { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.progress li.current .dot { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.progress li.current { color: var(--text); font-weight: 700; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: .75rem; }

label { display: block; font-weight: 600; margin: .75rem 0 .25rem; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], input[type=search], select, textarea {
    width: 100%;
    min-height: var(--tap);
    padding: .6rem .75rem;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}
input[aria-invalid=true] { border-color: var(--danger); background: #fff5f4; }
.field-error { color: var(--danger); font-size: .875rem; margin-top: .2rem; }
.hint { color: var(--muted); font-size: .875rem; }

.check { display: flex; gap: .75rem; align-items: flex-start; font-weight: 400; margin: 1rem 0; }
.check input { width: 24px; height: 24px; flex: none; margin-top: .1rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    min-height: var(--tap); padding: .6rem 1.1rem;
    border: 1px solid transparent; border-radius: 999px;
    font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
    background: var(--primary); color: var(--on-primary);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--link); border-color: var(--border); }
.btn.accent { background: var(--accent); color: var(--on-accent); }
.btn.block { width: 100%; }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.chip {
    min-height: 40px; padding: .35rem .9rem; border-radius: 999px; font: inherit;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.chip[aria-pressed=true] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

.segmented { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: .5rem 0 1rem; }
.segmented button { flex: 1; min-height: var(--tap); border: 0; background: var(--surface); font: inherit; color: var(--text); cursor: pointer; }
.segmented button[aria-pressed=true] { background: var(--primary); color: var(--on-primary); font-weight: 700; }

.unit-card {
    display: flex; align-items: center; gap: .85rem; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: .6rem;
    transition: border-color .15s, box-shadow .15s, transform .1s;
}
.unit-card:active { transform: scale( .985 ); }
.unit-card[aria-pressed=true] { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); background: var(--primary-soft); }
.unit-card .door { width: 64px; height: 58px; flex: none; }
.unit-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.unit-card .title { font-weight: 800; font-size: 1.15rem; display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.unit-no { font-size: .8rem; font-weight: 600; color: var(--muted); }
.unit-card .meta { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; }
.unit-card .price { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.unit-card .price strong { display: block; font-size: 1.15rem; }
.list-head { display: flex; justify-content: space-between; align-items: baseline; margin: 1rem 0 .5rem; }

.size-guide { display: grid; grid-template-columns: repeat( 2, 1fr ); gap: .6rem; margin: .5rem 0 .5rem; }
.size-tile {
    display: flex; flex-direction: column; align-items: flex-start; gap: .15rem; text-align: left; font: inherit; color: inherit; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem;
}
.size-tile .door { width: 56px; height: 50px; margin-bottom: .2rem; }
.size-tile .size-title { font-weight: 800; }
.size-tile .size-text { font-size: .78rem; color: var(--muted); line-height: 1.3; }
.size-tile .size-count { margin-top: .3rem; font-size: .75rem; font-weight: 700; color: var(--link); }
.size-tile[aria-pressed=true] { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); background: var(--primary-soft); }
.size-tile:disabled { opacity: .5; cursor: default; }
.size-tile:disabled .size-count { color: var(--muted); }

/* door illustration, colours follow the tenant theme */
.door .frame { fill: none; stroke: var(--text); stroke-opacity: .55; stroke-width: 1.6; }
.door .recess { fill: var(--text); fill-opacity: .8; }
.door .shutter { fill: var(--primary); }
.door .slat { stroke: #000; stroke-opacity: .2; stroke-width: .8; }
.door .handle { fill: var(--accent); }
.door .ground { fill: var(--border); }
.door .plate { fill: var(--surface); stroke: var(--text); stroke-opacity: .5; stroke-width: .8; }
.door .plate-text { fill: var(--text); font-weight: 800; text-anchor: middle; dominant-baseline: central; font-family: inherit; }
.door.open .panel { transform-box: fill-box; transform-origin: top; animation: door-lift 1.4s .3s cubic-bezier( .5, 0, .2, 1 ) forwards; }
@keyframes door-lift { to { transform: scaleY( .12 ); } }

.hero { background: var(--primary); color: var(--on-primary); border-radius: var(--radius); padding: 1.25rem 1.25rem 0; margin-bottom: 1.25rem; overflow: hidden; }
.hero h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: -.01em; }
.hero p { opacity: .92; max-width: 28em; }
.door-row { display: block; width: 100%; height: auto; margin-top: .5rem; }
.hero .shutter { fill: var(--on-primary); fill-opacity: .16; }
.hero .hero-door.d1 .shutter { fill-opacity: .26; }
.hero .hero-door.d2 .shutter { fill-opacity: .1; }
.hero .slat { stroke: var(--primary-dark); stroke-opacity: .45; stroke-width: .7; }
.hero .handle { fill: var(--accent); }
.hero .ground { fill: var(--on-primary); fill-opacity: .35; }

.ticket { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .75rem; overflow: hidden; }
.ticket-top { display: flex; align-items: center; gap: 1rem; padding: 1rem; background: var(--primary-soft); }
.ticket-top .door { width: 76px; height: 69px; flex: none; }
.ticket-title { font-size: 1.3rem; font-weight: 800; }
.ticket-body { padding: .5rem 1rem; border-bottom: 2px dashed var(--border); position: relative; }
.ticket-body::before, .ticket-body::after { content: ""; position: absolute; bottom: -9px; width: 16px; height: 16px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border); }
.ticket-body::before { left: -9px; } .ticket-body::after { right: -9px; }
.ticket .row { display: flex; justify-content: space-between; padding: .4rem 0; }
.ticket-total { display: flex; justify-content: space-between; align-items: baseline; padding: .9rem 1rem; }
.ticket-total strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }

.result-page { text-align: center; padding-top: 1.5rem; }
.result-page .door { width: 140px; height: 127px; margin: 0 auto 1rem; display: block; }
.result-page .alert { text-align: left; }
.result-page .btn { margin: .25rem; }

.action-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: .75rem 1rem calc(.75rem + var(--safe-bottom));
    display: flex; gap: .75rem; align-items: center; justify-content: space-between;
}
.action-bar .summary { font-size: .875rem; color: var(--muted); line-height: 1.25; }
.action-bar .summary strong { display: block; color: var(--text); font-size: 1.1rem; }

.alert { border-radius: 8px; padding: .75rem 1rem; margin: .75rem 0; border: 1px solid; }
.alert.error { background: #fff5f4; border-color: #f1b7b1; color: #7a1a12; }
.alert.info { background: var(--primary-soft); border-color: var(--border); }
.alert.success { background: #effaf1; border-color: #a7dbb1; color: #0f4d1f; }

dl.summary-list { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; }
dl.summary-list dt { color: var(--muted); }
dl.summary-list dd { margin: 0; text-align: right; font-weight: 600; }

.map-wrap { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; touch-action: none; height: 60vh; min-height: 320px; }
.map-wrap svg { width: 100%; height: 100%; display: block; }
.map-wrap rect.unit { stroke: #fff; stroke-width: 1; cursor: pointer; }
.map-wrap rect.unit.free { fill: var(--primary); fill-opacity: .55; }
.map-wrap rect.unit.taken { fill: #888; fill-opacity: .35; cursor: default; }
.map-wrap rect.unit.selected { fill: var(--accent); fill-opacity: .85; stroke: var(--text); stroke-width: 2; }
.map-wrap .unit-label { text-anchor: middle; dominant-baseline: central; fill: var(--text); pointer-events: none; font-weight: 600; paint-order: stroke; stroke: #fff; stroke-width: 2px; }
.map-wrap .route { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 8 6; animation: route-flow 1s linear infinite; pointer-events: none; }
.map-wrap .route-end { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; pointer-events: none; }
.map-wrap .entrance circle { fill: var(--text); }
.map-wrap .entrance text { fill: var(--text); font-size: 11px; font-weight: 700; text-anchor: middle; paint-order: stroke; stroke: #fff; stroke-width: 3px; pointer-events: none; }
.map-wrap .pin circle { fill: var(--accent); stroke: #fff; stroke-width: 2; pointer-events: none; }
.map-wrap .pin .pulse { fill: var(--accent); fill-opacity: .35; stroke: none; animation: pin-pulse 1.6s ease-out infinite; transform-box: fill-box; transform-origin: center; }
.map-wrap.static { height: 42vh; min-height: 260px; }
@keyframes route-flow { to { stroke-dashoffset: -14; } }
@keyframes pin-pulse { from { transform: scale(.6); opacity: 1; } to { transform: scale(2.2); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .map-wrap .route, .map-wrap .pin .pulse { animation: none; } }
.map-legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin: .5rem 0; }
.map-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }
.map-zoom { position: absolute; right: .5rem; top: .5rem; display: flex; flex-direction: column; gap: .4rem; }
.map-zoom button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); font-size: 1.3rem; cursor: pointer; }

.splash { min-height: 60vh; display: grid; place-items: center; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate( 360deg ); } }

.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

.result { text-align: center; padding: 2rem 1rem; }
.result .icon { font-size: 3rem; line-height: 1; margin-bottom: .5rem; }

@media ( prefers-reduced-motion: reduce ) { .spinner { animation-duration: 3s; } }

.rental-head { display: flex; align-items: center; gap: .85rem; margin-bottom: .75rem; }
.rental-head .door { width: 56px; height: 51px; flex: none; }
.rental-info { flex: 1; min-width: 0; }
.rental-info .ticket-title { font-size: 1.1rem; }
.status { font-size: .75rem; font-weight: 700; padding: .25rem .6rem; border-radius: 999px; white-space: nowrap; display: inline-block; margin-top: .35rem; }
.status.ok { background: #e3f4e7; color: #14562a; }
.status.soon { background: #fff1d6; color: #7a4a00; }
.status.expired { background: #fde4e1; color: #8a1c12; }
.price-line { background: var(--primary-soft); border-radius: 8px; padding: .6rem .8rem; margin-top: .75rem; }
.rental-card label { margin-top: 1rem; }
.action-bar ~ .footer { padding-bottom: 6rem; }
.link-card { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; padding: .75rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius, 12px); }
.link-card .btn { width: auto; }
.text-btn { background: none; border: 0; padding: .5rem 0; min-height: var(--tap); font: inherit; color: var(--link); text-decoration: underline; cursor: pointer; }
.card form > .btn, form.card > .btn { margin-top: 1rem; }
form.card .alert, form.card .text-btn { margin-top: .75rem; }
form.card .text-btn { display: block; margin-left: auto; margin-right: auto; }
form.card > .btn { margin-top: 1rem; }
