:root {
    --bg: #0e0f13;
    --surface: #171922;
    --surface-2: #21242f;
    --border: #262a36;

    --text: #f2f3f7;
    --text-muted: #9aa0b0;
    --accent: #e5a00d;

    --radius: 12px;
    --content-max: 1100px;
    --nav-height: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);

    --z-header: 90;
    --z-bottom-nav: 100;
    --z-overlay: 200;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    overscroll-behavior-y: none;
}

h1, h2, h3 {
    margin: 0 0 8px;
    line-height: 1.2;
}

h1 {
    font-size: 22px;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Touch targets stay finger-sized on the phone, which is the primary device. */
button, a.btn {
    min-height: 44px;
    min-width: 44px;
    font: inherit;
    cursor: pointer;
}

.app-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.app-content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}

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

.error {
    color: #ff6b6b;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
}

.btn--accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #1a1200;
    font-weight: 600;
}

.btn:disabled {
    opacity: .55;
}

/* Bottom nav — thumb reach beats a top bar on a phone, which is the primary device here. */
.bottom-nav {
    position: sticky;
    bottom: 0;
    z-index: var(--z-bottom-nav);
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
}

.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--nav-height);
    color: var(--text-muted);
    font-size: 12px;
}

.bottom-nav__item.active {
    color: var(--accent);
}

.bottom-nav__icon {
    font-size: 20px;
    line-height: 1;
}

.search-form {
    display: flex;
    gap: 8px;
    margin: 12px 0 20px;
}

.search-form__input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

/* Two columns on a phone, more as the screen allows. */
.card-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.card {
    position: relative;
    display: block;
    padding: 0;
    border: none;
    background: none;
    text-align: left;
    color: inherit;
}

.card__badge {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .6);
    border-radius: var(--radius);
    font-size: 14px;
}

.poster {
    position: relative;
    aspect-ratio: 2 / 3;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-2);
}

.poster__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.poster__img--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--text-muted);
}

.poster__year {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(0, 0, 0, .7);
    font-size: 12px;
}

.poster-caption {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 2px 0;
}

.poster-caption__title {
    font-size: 14px;
    line-height: 1.25;
}

.poster-caption__sub {
    font-size: 12px;
}

.title-head {
    display: flex;
    gap: 14px;
    margin-bottom: 16px;
}

.title-head__poster {
    width: 120px;
    border-radius: var(--radius);
}

.title-overview {
    margin-bottom: 24px;
}

.source-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.playlist-url {
    word-break: break-all;
    font-size: 12px;
    color: var(--text-muted);
}

.btn--danger {
    border-color: #ff6b6b;
    color: #ff6b6b;
    background: none;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

/* Form fields: full width on a phone, labels above the input. */
.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.field__label {
    font-size: 14px;
    color: var(--text-muted);
}

.field__input {
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.field__input--code {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 13px;
    resize: vertical;
}

.field-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.field--check {
    flex-direction: row;
    align-items: center;
    min-height: 44px;
    flex: 0 0 auto;
}

.field--check input {
    width: 22px;
    height: 22px;
}

.code-block {
    margin: 8px 0 0;
    padding: 12px;
    max-height: 60vh;
    overflow: auto;
    border-radius: var(--radius);
    background: var(--surface);
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
    white-space: pre;
}

.realty-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 56px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.realty-row__main {
    min-width: 0;
}

.realty-row__link {
    flex: 1;
}

.realty-row__sub {
    font-size: 13px;
    overflow-wrap: anywhere;
}

.realty-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 12px 0 24px;
}

.realty-section {
    margin-bottom: 24px;
}

.realty-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}

.realty-listing {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.listing-card {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.listing-card__photo {
    flex: 0 0 96px;
    width: 96px;
    height: 72px;
    border-radius: var(--radius);
    object-fit: cover;
    background: var(--surface-2);
}

.listing-card__main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.listing-card__price {
    font-weight: 600;
}

.listing-card__old-price {
    margin-left: 6px;
    font-weight: 400;
    text-decoration: line-through;
    color: var(--text-muted);
}

.listing-card__sub {
    font-size: 13px;
    overflow-wrap: anywhere;
}

.listing-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.listing-badge {
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    font-size: 12px;
}

.listing-badge--accent {
    background: var(--accent);
    color: #1a1200;
}

/* Label column stays narrow so values keep most of a phone's width. */
.realty-fields {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 12px;
    margin: 8px 0 0;
    font-size: 14px;
}

.realty-fields dd {
    margin: 0;
    white-space: pre-wrap;
}

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

.realty-listing summary {
    min-height: 44px;
    cursor: pointer;
}

/* Realty module tabs: scroll sideways on a narrow phone instead of wrapping. */
.realty-tabs {
    display: flex;
    gap: 4px;
    margin: 0 -16px 16px;
    padding: 0 16px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
}

.realty-tabs__item {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 12px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
}

.realty-tabs__item.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.listings-view {
    max-width: 55%;
}

.filter-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.field--narrow {
    flex: 0 0 110px;
}

.route-point {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.generation-status {
    margin: 8px 0 12px;
    padding: 12px;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: var(--surface);
}

.generation-status__step {
    font-weight: 600;
}

.listings-more {
    width: 100%;
    margin-top: 12px;
}

.pipeline-banner {
    padding: 12px;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
}

.danger-zone {
    margin-top: 24px;
    padding: 12px;
    border: 1px solid #ff6b6b;
    border-radius: var(--radius);
}

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

.stage-card--running {
    border-color: var(--accent);
}

.stage-card--error {
    border-color: #ff6b6b;
}

.stage-card__head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.stage-card__state {
    font-size: 13px;
    color: var(--text-muted);
}

.stage-card__desc {
    margin: 4px 0 8px;
    font-size: 13px;
}

.stage-card__numbers {
    display: flex;
    gap: 24px;
    margin-bottom: 8px;
}

.stage-card__num {
    font-size: 22px;
    font-weight: 600;
}

.stage-card__label {
    font-size: 12px;
    overflow-wrap: anywhere;
}

.listing-head {
    display: flex;
    gap: 12px;
    margin: 8px 0 16px;
}

.listing-head__photo {
    width: 120px;
    height: 90px;
    object-fit: cover;
    border-radius: var(--radius);
}

.listing-head .btn {
    margin-top: 8px;
}

/* Vertical timeline: one step per pipeline stage, the marker colour tells how it went. */
.stage-timeline {
    list-style: none;
    margin: 0;
    padding: 0 0 0 20px;
    border-left: 2px solid var(--border);
}

.stage-step {
    position: relative;
    padding: 0 0 20px 12px;
    overflow-wrap: anywhere;
}

.stage-step::before {
    content: "";
    position: absolute;
    left: -28px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 2px solid var(--border);
}

.stage-step--done::before {
    background: var(--accent);
    border-color: var(--accent);
}

.stage-step--failed::before {
    background: #ff6b6b;
    border-color: #ff6b6b;
}

.stage-step__title {
    font-weight: 600;
}

.stage-step__text {
    font-size: 14px;
    margin-top: 2px;
}

/* Shown by index.html until the app has started. */
.app-loading {
    padding: 24px 16px;
    color: var(--text-muted);
}

/* Blazor's own "something broke" bar — hidden until the framework shows it. */
#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-overlay);
    padding: 12px 16px calc(12px + var(--safe-bottom));
    background: #5c1a1a;
    color: var(--text);
}

#blazor-error-ui .reload {
    margin-left: 8px;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    float: right;
    cursor: pointer;
}

@media (min-width: 768px) {
    h1 {
        font-size: 28px;
    }

    .app-content {
        padding: 24px;
    }
}
