/*
    The app shell only — header, footer, theme toggle, boot spinner and page container. The wizard's
    components are styled by Convert.Core's stylesheet (_content/Convert.Core/convert.css), and Morph's
    viewer by Morph.Blazor's (_content/Morph.Blazor/morph.css), both linked ahead of this file.
*/

:root {
    --primary-color: #2b579a;
    --accent-color: #f0a500;
    --success-color: #28a745;
    --background-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #333;
    --muted-color: #6c757d;
    --border-color: #dee2e6;
}

[data-theme="dark"] {
    --primary-color: #5b8dd6;
    --accent-color: #f0a500;
    --success-color: #4caf50;
    --background-color: #1e1e1e;
    --surface-color: #2a2a2a;
    --text-color: #e0e0e0;
    --muted-color: #999999;
    --border-color: #404040;
}

/* Hands this app's palette to the Convert and Morph components. They declare no colours of their own —
   every rule reads a --convert-* / --morph-* property with a literal fallback — so this mapping is the
   whole of their theming, and it follows the light/dark switch above for free. */
:root {
    --convert-primary: var(--primary-color);
    --convert-background: var(--background-color);
    --convert-surface: var(--surface-color);
    --convert-text: var(--text-color);
    --convert-muted: var(--muted-color);
    --convert-border: var(--border-color);
    --morph-primary: var(--primary-color);
    --morph-background: var(--background-color);
    --morph-surface: var(--surface-color);
    --morph-text: var(--text-color);
    --morph-muted: var(--muted-color);
    --morph-border: var(--border-color);
}

* {
    box-sizing: border-box;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: var(--primary-color);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-message {
    margin-bottom: 0;
}

.loading-version {
    margin-top: 0.25rem;
    color: var(--muted-color);
    font-size: 0.8rem;
}

.loading-error {
    max-width: min(40rem, calc(100vw - 2rem));
    margin: 0;
    color: var(--text-color);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    text-align: center;
    user-select: text;
}

.loading.failed .spinner {
    display: none;
}

#blazor-error-ui {
    background: #fff3cd;
    color: #856404;
    padding: 1rem;
    text-align: center;
    display: none;
}

#blazor-error-ui.show,
#blazor-error-ui[style*="display: block"] {
    display: block;
}

#blazor-error-ui a {
    color: #856404;
    margin-left: 0.5rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

header {
    background: var(--primary-color);
    color: white;
    padding: 1.5rem;
    text-align: center;
    margin-bottom: 1.5rem;
    position: relative;
    /* The title and the mode links share a row; the tagline wraps under both. */
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: center;
    column-gap: 1.25rem;
}

header h1 {
    margin: 0;
    font-size: 1.75rem;
    outline: none;
}

/* The title starts over, like the wizard's Start over button. */
header h1 a {
    color: inherit;
    text-decoration: none;
}

header h1 a:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

header p {
    margin: 0.5rem 0 0;
    flex-basis: 100%;
    order: 1;
    text-align: left;
    opacity: 0.9;
    font-size: 0.9rem;
}

.theme-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
}

/* Convert | View: the two components the app shows, one per page. */
.app-nav {
    display: inline-flex;
    gap: 0.25rem;
    padding: 0.2rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
}

.app-nav a {
    padding: 0.3rem 0.9rem;
    border-radius: 4px;
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
}

.app-nav a:hover {
    background: rgba(255, 255, 255, 0.15);
}

.app-nav a.active {
    background: white;
    color: var(--primary-color);
}

/* The viewer wants the width of the window and the height left between the header and the footer. */
.container:has(.viewer) {
    max-width: none;
}

/* Above it, only the container's own padding, so the gap matches the one at its side. */
header:has(+ .container .viewer) {
    margin-bottom: 0;
}

/* And below it the same, the footer giving up its own margin and top padding. */
.container:has(.viewer) + footer {
    margin-top: 0;
    padding-top: 0;
}

.container .viewer {
    height: calc(100vh - 8.5rem);
    min-height: 420px;
}

.theme-toggle-btn {
    padding: 0.5rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.theme-toggle-btn .icon {
    width: 1rem;
    height: 1rem;
}

.theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

/* The wizard lays its preview and choices side by side; on a wide screen the container relaxes to give the
   preview room. :has() scopes that to when a file is open, so the empty state keeps its narrower column. */
@media (min-width: 1200px) {
    .container:has(.wizard) {
        max-width: 2400px;
        padding-inline: 1.5rem;
    }
}

/* Text with a render of its own: narrow, the tabs show the editor or the render; wide, both side by side,
   and the tab pair collapses into one "Edit and preview" tab. */
.split.show-edit .split-preview,
.split.show-preview .split-edit,
.wide-only {
    display: none;
}

@media (min-width: 1100px) {
    .split {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 1rem;
        align-items: start;
    }

    .split.show-edit .split-preview,
    .split.show-preview .split-edit {
        display: block;
    }

    .split .text-editor textarea {
        min-height: 70vh;
    }

    /* The render stays in view while a long text scrolls past it. */
    .split-preview {
        position: sticky;
        top: 1rem;
    }

    .wide-only {
        display: inline;
    }

    .narrow-only,
    .tabs.narrow-only {
        display: none;
    }

    .tabs button.wide-active {
        background: var(--convert-primary, #2b579a);
        color: #fff;
    }
}

footer {
    text-align: center;
    /* The container's own bottom padding already separates it from the page above. */
    padding: 0.5rem 1rem 1rem;
    color: var(--muted-color);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

.footer-version,
.footer-size,
.footer-ram {
    margin-left: 0.5rem;
    opacity: 0.7;
}

@media (max-width: 768px) {
    header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem;
        /* One row on a phone: the tagline is hidden, and the margins below space the items, so the
           wide layout's wrap and gap would only push the theme toggle onto a line of its own. */
        flex-wrap: nowrap;
        column-gap: 0;
    }

    header h1 {
        font-size: 1.25rem;
        text-align: left;
        flex: 1;
        margin-right: 0.5rem;
    }

    header p {
        display: none;
    }

    .app-nav {
        margin: 0 0.5rem 0 0;
    }

    .theme-toggle {
        position: static;
        flex-shrink: 0;
    }

    .theme-toggle-btn {
        padding: 0.5rem;
        min-width: 36px;
    }

    .theme-toggle-btn .text {
        display: none;
    }

    .theme-toggle-btn .icon {
        font-size: 1.25rem;
    }

    /* The footer row is tight on a phone; drop the payload-size figure to keep it readable. */
    .footer-size {
        display: none;
    }
}
