/* Layout primitives: large touch targets, generous spacing, genuine reflow between a
   single-column mobile layout and a wider desktop layout. */

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

html, body {
    margin: 0;
    padding: 0;
    background: var(--surface-sunken);
    color: var(--text);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
}

body {
    min-height: 100vh;
}

h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.25;
    margin: 0 0 var(--space-2) 0;
}

h1 { font-size: var(--font-size-xxl); }
h2 { font-size: var(--font-size-xl); }
h3 { font-size: var(--font-size-lg); }

p { margin: 0 0 var(--space-3) 0; }

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

a:hover {
    color: var(--accent-hover);
}

/* Skip link — visible only on keyboard focus */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--accent);
    color: var(--accent-contrast);
    padding: var(--space-2) var(--space-3);
    z-index: 1000;
    border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
    left: 0;
}

/* Visible focus rings everywhere — never remove outline without a replacement */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

button, .btn {
    font: inherit;
    font-size: var(--font-size-base);
    min-height: 44px;
    min-width: 44px;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius);
    border: 2px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-contrast);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--accent);
    border-color: var(--accent);
}

.btn-large {
    font-size: var(--font-size-lg);
    padding: var(--space-4) var(--space-5);
    min-height: 64px;
    width: 100%;
}

input[type="text"], input[type="search"], input[type="tel"], input[type="url"], select {
    font: inherit;
    font-size: var(--font-size-base);
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    border: 2px solid var(--border);
    background: var(--surface);
    color: var(--text);
    width: 100%;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
}

.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

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

/* App shell: responsive grid that reflows from a single mobile column to a side-rail
   desktop layout — pure CSS, no JS layout hack. */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.app-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.app-main {
    flex: 1;
    padding: var(--space-4);
    padding-bottom: calc(var(--space-6) + 64px); /* clears the fixed bottom tab bar on mobile */
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

/* Bottom tab bar — narrow/mobile viewports */
.app-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: var(--space-1) var(--space-1) env(safe-area-inset-bottom);
    z-index: 100;
}

.app-nav a, .app-nav .nav-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-2);
    color: var(--text-muted);
    text-decoration: none;
    font-size: var(--font-size-sm);
    border-radius: var(--radius);
}

.app-nav a.active, .app-nav .nav-link.active {
    color: var(--accent);
    font-weight: 600;
}

.app-nav .nav-icon {
    width: 24px;
    height: 24px;
}

/* Wide/desktop viewport: side rail instead of bottom bar, content grid alongside it */
@media (min-width: 900px) {
    .app-body {
        flex-direction: row;
    }

    .app-nav {
        position: sticky;
        top: 0;
        bottom: auto;
        left: auto;
        right: auto;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        width: 220px;
        min-width: 220px;
        height: 100vh;
        border-top: none;
        border-right: 1px solid var(--border);
        padding: var(--space-4) var(--space-2);
        gap: var(--space-1);
    }

    .app-nav a, .app-nav .nav-link {
        flex-direction: row;
        justify-content: flex-start;
        gap: var(--space-2);
        font-size: var(--font-size-base);
    }

    .app-main {
        padding-bottom: var(--space-6);
        max-width: 720px;
        margin: 0;
    }
}

/* Reduced motion: minimal, no flashy transitions per design doc */
.fade-in {
    animation: fade-in 150ms ease-out;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

#blazor-error-ui {
    display: none;
    background: var(--verdict-red-bg);
    border-top: 2px solid var(--verdict-red);
    color: var(--text);
    padding: var(--space-3) var(--space-4);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

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

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: var(--space-3);
    color: var(--text-muted);
}
