/* OpenHeritage.online — Modern Civic Archive
   Companion styles for OpenHeritageTheme.cs / MudBlazor 9.9. */

.oh-theme {
    color-scheme: light;

    --oh-surface-raised: #FFFFFF;
    --oh-focus-ring: #0877A5;
    --oh-focus-inner: #FFFDF8;
    --oh-selected-bg: #DCEBF1;
    --oh-selected-fg: #163E4F;
    --oh-table-header: #E8E3D9;
    --oh-photo-frame: #ECE6DB;
    --oh-photo-caption-scrim: rgba(12, 18, 21, .76);
    --oh-info-subtle-bg: #E3F0F5;
    --oh-info-subtle-fg: #164B62;
    --oh-success-subtle-bg: #E4F0E8;
    --oh-success-subtle-fg: #24563A;
    --oh-warning-subtle-bg: #F6E9CF;
    --oh-warning-subtle-fg: #684100;
    --oh-error-subtle-bg: #F5E5E2;
    --oh-error-subtle-fg: #812920;
    --oh-border-strong: #948F85;
    --oh-link: #1F5D78;
    --oh-scrim-control-bg: rgba(12, 18, 21, .82);
    --oh-scrim-control-fg: #FFFFFF;

    --oh-radius-sm: 6px;
    --oh-radius-md: 10px;
    --oh-radius-lg: 16px;
    --oh-radius-pill: 999px;
    --oh-target-size: 44px;
    --oh-content-max: 1440px;
    --oh-reading-max: 72ch;
    --oh-card-shadow: 0 2px 5px rgba(16, 33, 40, .09),
                      0 1px 2px rgba(16, 33, 40, .06);
    --oh-card-shadow-hover: 0 8px 18px rgba(16, 33, 40, .12),
                            0 3px 5px rgba(16, 33, 40, .07);

    min-height: 100%;
    color: var(--mud-palette-text-primary);
    background: var(--mud-palette-background);
    accent-color: var(--mud-palette-primary);
}

.oh-theme.oh-theme-dark,
[data-oh-theme="dark"] .oh-theme {
    color-scheme: dark;

    --oh-surface-raised: #202B30;
    --oh-focus-ring: #8FC8E0;
    --oh-focus-inner: #11171B;
    --oh-selected-bg: #294451;
    --oh-selected-fg: #D4EDF6;
    --oh-table-header: #222D32;
    --oh-photo-frame: #202A2F;
    --oh-photo-caption-scrim: rgba(4, 8, 10, .82);
    --oh-info-subtle-bg: #183643;
    --oh-info-subtle-fg: #A9D8EA;
    --oh-success-subtle-bg: #19382A;
    --oh-success-subtle-fg: #A6DCB9;
    --oh-warning-subtle-bg: #3B2D12;
    --oh-warning-subtle-fg: #F2D58C;
    --oh-error-subtle-bg: #40221F;
    --oh-error-subtle-fg: #F4B3AD;
    --oh-border-strong: #607076;
    --oh-link: #7AB6CF;
    --oh-scrim-control-bg: rgba(4, 8, 10, .88);
    --oh-scrim-control-fg: #FFFFFF;
    --oh-card-shadow: 0 2px 8px rgba(0, 0, 0, .28),
                      0 1px 2px rgba(0, 0, 0, .24);
    --oh-card-shadow-hover: 0 10px 24px rgba(0, 0, 0, .34),
                            0 3px 7px rgba(0, 0, 0, .28);
}

/* Layout and readable measure */
.oh-theme .oh-page-shell {
    width: min(100% - 2rem, var(--oh-content-max));
    margin-inline: auto;
}

.oh-theme .oh-prose {
    max-width: var(--oh-reading-max);
}

.oh-theme .oh-section {
    padding-block: clamp(1.5rem, 1rem + 2vw, 3.5rem);
}

.oh-theme .oh-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
    gap: clamp(1rem, .75rem + 1vw, 1.5rem);
}

/* Links remain recognizable without relying on color alone. */
.oh-theme a:not(.mud-button-root):not(.mud-icon-button):not(.mud-nav-link) {
    color: var(--oh-link);
    text-decoration-line: underline;
    text-decoration-thickness: .08em;
    text-underline-offset: .18em;
}

.oh-theme a:not(.mud-button-root):not(.mud-icon-button):not(.mud-nav-link):hover {
    text-decoration-thickness: .14em;
}

/* Keyboard focus: an inner separator plus a high-contrast outer ring. */
.oh-theme :where(
    a[href],
    button,
    [role="button"],
    [role="menuitem"],
    [role="option"],
    [role="tab"],
    [tabindex]:not([tabindex="-1"])
):focus-visible {
    outline: 2px solid var(--oh-focus-ring);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px var(--oh-focus-inner);
}

.oh-theme .mud-input-control:has(input:focus-visible, textarea:focus-visible, select:focus-visible) {
    border-radius: var(--oh-radius-md);
    outline: 2px solid var(--oh-focus-ring);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px var(--oh-focus-inner);
}

.oh-theme .mud-input-control :where(input, textarea, select):focus-visible {
    outline: none;
}

/* Baseline 44px target. Use .oh-density-compact only for expert desktop tools. */
.oh-theme :where(
    .mud-button-root,
    .mud-icon-button,
    .mud-checkbox,
    .mud-radio,
    .oh-interactive
) {
    min-block-size: var(--oh-target-size);
}

.oh-theme :where(.mud-icon-button, .oh-square-action) {
    min-inline-size: var(--oh-target-size);
}

.oh-theme .oh-density-compact :where(.mud-button-root, .mud-icon-button) {
    min-block-size: 36px;
}

.oh-theme .oh-density-compact .mud-icon-button {
    min-inline-size: 36px;
}

/* Surfaces: border carries structure; shadow only carries elevation. */
.oh-theme .mud-card {
    overflow: clip;
    border: 1px solid var(--mud-palette-divider);
    border-radius: var(--oh-radius-lg);
    background: var(--mud-palette-surface);
    box-shadow: var(--oh-card-shadow);
}

.oh-theme .oh-card-interactive {
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.oh-theme .oh-card-interactive:hover {
    transform: translateY(-2px);
    border-color: var(--oh-border-strong);
    box-shadow: var(--oh-card-shadow-hover);
}

.oh-theme .mud-appbar {
    border-bottom: 1px solid color-mix(in srgb, var(--mud-palette-appbar-text) 22%, transparent);
    box-shadow: none;
}

/* Existing shell accents use Primary, which matches the modern light app bar. */
.oh-theme .mud-appbar .oh-appbar-contrast {
    color: var(--mud-palette-appbar-text) !important;
}

.oh-theme .mud-appbar .oh-appbar-avatar {
    border: 1px solid color-mix(in srgb, var(--mud-palette-appbar-text) 72%, transparent);
    background: var(--mud-palette-secondary);
}

.oh-theme .mud-drawer {
    border-inline-end: 1px solid var(--mud-palette-divider);
}

/* Inputs must keep a visible outline even outside focus. */
.oh-theme .mud-input.mud-input-outlined:not(.mud-disabled):not(.mud-input-error)
    > .mud-input-outlined-border {
    border-color: var(--mud-palette-lines-inputs);
}

.oh-theme .mud-input.mud-input-outlined:not(.mud-disabled):focus-within
    > .mud-input-outlined-border {
    border-width: 2px;
    border-color: var(--mud-palette-primary);
}

/* Selected and active states pair color with weight, border, or indicator. */
.oh-theme .mud-nav-link.active:not(.mud-nav-link-disabled),
.oh-theme .mud-list-item.mud-selected-item {
    color: var(--oh-selected-fg);
    background: var(--oh-selected-bg);
    box-shadow: inset 3px 0 0 var(--mud-palette-primary);
}

[dir="rtl"] .oh-theme .mud-nav-link.active:not(.mud-nav-link-disabled),
[dir="rtl"] .oh-theme .mud-list-item.mud-selected-item {
    box-shadow: inset -3px 0 0 var(--mud-palette-primary);
}

.oh-theme .mud-tab.mud-tab-active {
    color: var(--oh-selected-fg);
    font-weight: 650;
}

.oh-theme .mud-tab-slider {
    block-size: 3px;
    border-radius: var(--oh-radius-pill);
}

/* Data-heavy screens */
.oh-theme .mud-table-head {
    background: var(--oh-table-header);
}

.oh-theme .mud-table-head .mud-table-cell {
    color: var(--mud-palette-text-primary);
    font-weight: 650;
    letter-spacing: .01em;
}

.oh-theme .mud-table-row:focus-within {
    outline: 2px solid var(--oh-focus-ring);
    outline-offset: -2px;
}

.oh-theme .oh-metadata {
    color: var(--mud-palette-text-secondary);
    font-size: .875rem;
    line-height: 1.55;
}

/* Statuses use icon/text in markup; these colors are not the sole signal. */
.oh-theme .oh-status {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    min-block-size: 32px;
    padding: .25rem .65rem;
    border: 1px solid currentColor;
    border-radius: var(--oh-radius-pill);
    font-size: .8125rem;
    font-weight: 650;
}

.oh-theme .oh-status--info {
    color: var(--oh-info-subtle-fg);
    background: var(--oh-info-subtle-bg);
}

.oh-theme .oh-status--success {
    color: var(--oh-success-subtle-fg);
    background: var(--oh-success-subtle-bg);
}

.oh-theme .oh-status--warning {
    color: var(--oh-warning-subtle-fg);
    background: var(--oh-warning-subtle-bg);
}

.oh-theme .oh-status--error {
    color: var(--oh-error-subtle-fg);
    background: var(--oh-error-subtle-bg);
}

/* Photos and maps have unpredictable backgrounds, so controls get a scrim. */
.oh-theme .oh-photo {
    position: relative;
    overflow: clip;
    border: 1px solid var(--mud-palette-divider);
    border-radius: var(--oh-radius-lg);
    background: var(--oh-photo-frame);
}

.oh-theme .oh-photo > img {
    display: block;
    inline-size: 100%;
    block-size: 100%;
    object-fit: cover;
}

.oh-theme .oh-photo__caption {
    position: absolute;
    inset-inline: 0;
    inset-block-end: 0;
    padding: 1rem;
    color: #FFFFFF;
    background: var(--oh-photo-caption-scrim);
}

.oh-theme .oh-photo-control,
.oh-theme .oh-map-control {
    color: var(--oh-scrim-control-fg);
    background: var(--oh-scrim-control-bg);
    border: 1px solid rgba(255, 255, 255, .38);
    border-radius: var(--oh-radius-md);
    backdrop-filter: blur(6px);
}

.oh-theme .oh-map-fallback {
    display: grid;
    min-block-size: 18rem;
    place-items: center;
    padding: 2rem;
    border: 1px dashed var(--oh-border-strong);
    border-radius: var(--oh-radius-lg);
    color: var(--mud-palette-text-secondary);
    background: var(--mud-palette-background-gray);
    text-align: center;
}

.oh-theme .oh-sr-only {
    position: absolute !important;
    inline-size: 1px !important;
    block-size: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

@media (max-width: 899px) {
    .oh-theme .oh-page-shell {
        width: min(100% - 1rem, var(--oh-content-max));
    }

    .oh-theme .oh-desktop-nav {
        display: none !important;
    }

    .oh-theme .oh-mobile-actions {
        display: flex;
    }

    .oh-theme .mud-table.oh-responsive-table {
        overflow-x: auto;
        overscroll-behavior-inline: contain;
    }
}

@media (min-width: 900px) {
    .oh-theme .oh-mobile-actions {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .oh-theme *,
    .oh-theme *::before,
    .oh-theme *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }

    .oh-theme .oh-card-interactive:hover {
        transform: none;
    }
}

@media (forced-colors: active) {
    .oh-theme :where(
        a[href],
        button,
        [role="button"],
        [role="menuitem"],
        [role="option"],
        [role="tab"],
        [tabindex]:not([tabindex="-1"])
    ):focus-visible,
    .oh-theme .mud-input-control:has(input:focus-visible, textarea:focus-visible, select:focus-visible) {
        outline: 3px solid Highlight;
        box-shadow: none;
    }

    .oh-theme .oh-status,
    .oh-theme .oh-photo-control,
    .oh-theme .oh-map-control {
        border: 1px solid ButtonText;
    }
}
