* { box-sizing: border-box; }

:root {
    font-family: "Space Grotesk", "Segoe UI", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 0.94rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.mud-typography, .mud-button-root, .mud-input, .mud-input-label, .mud-snackbar, .mud-dialog { font-family: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}
/* FocusOnNavigate moves focus to h1 for screen readers; it must not show a frame. */
h1:focus { outline: none; }
button:disabled, select:disabled { opacity: 0.5; cursor: default; }

.app-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
    background: var(--shell-bg);
    color: var(--text);
}

.app-sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-self: start;
    height: 100vh;
    padding: 0.9rem 0.7rem 0.75rem;
    overflow-y: auto;
    background: var(--bg-sidebar);
    border-right: 1px solid color-mix(in srgb, var(--nav-accent) 24%, transparent);
    color: var(--text-on-dark);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 2.75rem;
    margin: 0 0 1rem;
    padding: 0 0.25rem;
    color: var(--text-on-dark);
    text-decoration: none;
}
.brand:hover { color: var(--text-on-dark); text-decoration: none; }
.brand-icon {
    display: grid;
    flex: 0 0 auto;
    width: 2.3rem;
    height: 2.3rem;
    place-items: center;
    border: 1px solid color-mix(in srgb, var(--nav-accent) 45%, transparent);
    border-radius: 50%;
    background: color-mix(in srgb, var(--text-on-dark) 8%, transparent);
    color: var(--nav-accent);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-size: 0.9rem; font-weight: 700; line-height: 1.1; white-space: nowrap; }
.brand-subtitle {
    margin-top: 0.15rem;
    color: color-mix(in srgb, var(--text-on-dark) 55%, transparent);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    line-height: 1;
    text-transform: uppercase;
}

.side-nav { display: flex; flex-direction: column; align-items: stretch; gap: 0.1rem; }
.nav-item {
    display: flex;
    align-items: center;
    min-height: 2.4rem;
    padding: 0.5rem 0.65rem 0.5rem 1.1rem;
    border-left: 3px solid transparent;
    border-radius: 0 var(--radius) var(--radius) 0;
    color: color-mix(in srgb, var(--text-on-dark) 76%, transparent);
    font-size: 0.86rem;
    font-weight: 500;
    text-decoration: none;
}
.side-nav > .nav-item:first-child { padding-left: 0.65rem; }
.nav-item:hover { background: color-mix(in srgb, var(--text-on-dark) 7%, transparent); color: var(--text-on-dark); text-decoration: none; }
.nav-item.active { border-left-color: var(--nav-accent); background: color-mix(in srgb, var(--nav-accent) 14%, transparent); color: var(--text-on-dark); font-weight: 700; }
.nav-item:focus-visible { outline: 3px solid var(--nav-accent); outline-offset: -2px; }

.app-body { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.6rem 1rem;
    min-height: 3.5rem;
    padding: 0.45rem clamp(1rem, 2vw, 2rem);
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(16px);
}
.workspace-label { color: var(--heading, var(--primary)); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; }
.mobile-menu-btn, .sidebar-scrim { display: none; }
.app-content { flex: 1 1 auto; width: min(100%, 1440px); min-width: 0; margin: 0 auto; }
.workarea { min-width: 0; padding: clamp(1.1rem, 2vw, 2rem) clamp(1rem, 2.25vw, 2.5rem) 2.75rem; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin: 0 0 1.5rem; }
.page-heading h1 { margin: 0; color: var(--heading, var(--primary)); font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.2; }
.eyebrow { margin: 0 0 0.3rem; color: var(--eyebrow); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; }
.hint { color: var(--muted); }
.error-message { padding: 0.75rem 0.9rem; margin-bottom: 1.25rem; border: 1px solid var(--error-border); border-radius: var(--radius); background: var(--error-bg); color: var(--error-text); overflow-wrap: anywhere; }
.settings-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 1rem; max-width: 42rem; }
.select-label { display: grid; gap: 0.4rem; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.select-label select { width: 100%; min-height: 2.65rem; padding: 0.45rem 0.65rem; border: 1px solid var(--input-border); border-radius: var(--radius); background: var(--surface); color: var(--text); }

#blazor-error-ui {
    display: none;
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 100;
    max-width: min(40rem, calc(100vw - 2rem));
    padding: 0.8rem 1rem;
    border: 1px solid var(--error-border);
    border-radius: var(--radius);
    background: var(--error-bg);
    color: var(--error-text);
}
#blazor-error-ui a { margin: 0 0.25rem; font-weight: 700; }
#blazor-error-ui .dismiss { cursor: pointer; }

@media (max-width: 760px) {
    .app-shell { display: block; }
    .app-sidebar { position: fixed; inset: 0 auto 0 0; width: min(280px, 85vw); height: 100dvh; transform: translateX(-105%); transition: transform 0.2s ease; }
    .app-shell.nav-open .app-sidebar { transform: translateX(0); }
    .app-shell.nav-open .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: 15; border: 0; background: rgb(0 0 0 / 45%); }
    .mobile-menu-btn { display: inline-flex; min-height: 2.25rem; padding: 0.3rem 0.65rem; border: 1px solid var(--border-strong, var(--input-border)); border-radius: var(--radius); background: var(--surface); color: var(--text); }
    .app-header { min-height: 3.25rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
