/* Light theme */
:root {
    color-scheme: light;
    --background: #f6f7f5;
    --surface: #ffffff;
    --text: #24382d;
    --muted: #5c6f65;
    --border: #d0d9d1;
    --selected: #e7f0e8;
}

/* Dark theme */
:root[data-theme="dark"] {
    color-scheme: dark;
    --background: #121a16;
    --surface: #1d2922;
    --text: #e5eee8;
    --muted: #afc1b5;
    --border: #52665a;
    --selected: #365a43;
}

/* Page colors */
body {
    background-color: var(--background);
    color: var(--text);
}

/* Theme bar */
.theme-bar {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    padding: 12px 20px;
    box-sizing: border-box;
}

/* Theme button */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 10px;
    background-color: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
}

/* Icon size */
.theme-toggle svg {
    width: 22px;
    height: 22px;
}

/* Hide sun */
.sun-icon {
    display: none;
}

/* Dark icons */
:root[data-theme="dark"] .moon-icon {
    display: none;
}

:root[data-theme="dark"] .sun-icon {
    display: block;
}

/* Button hover */
.theme-toggle:hover {
    background-color: var(--selected);
}

/* Keyboard focus */
.theme-toggle:focus-visible {
    outline: 2px solid #6c957c;
    outline-offset: 3px;
}
/* Shared header */
header.site-app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 76px;
    padding: 16px 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

/* Brand title */
header.site-app-header .brand {
    position: relative;
    min-width: 0;
    max-width: 100%;
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding-left: 44px;
    color: var(--text);
    font-size: clamp(20px, 1.7vw, 24px);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.4px;
    text-decoration: none;
}

/* Moving leaf */
header.site-app-header .brand-mark {
    position: absolute;
    left: 0;
    top: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--selected);
    color: var(--text);
    transform: translate(var(--leaf-shift, 0px), -50%);
    pointer-events: auto;
    cursor: pointer;
    transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

header.site-app-header .brand-mark svg {
    width: 20px;
    height: 20px;
}

/* Fading title */
header.site-app-header .brand-title {
    min-width: 0;
    opacity: 1;
    transition: opacity 140ms ease 420ms;
}

/* Header controls */
header.site-app-header .header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 18px;
    color: var(--muted);
    font-size: 13px;
}

header.site-app-header .header-actions a {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    color: var(--text);
    text-underline-offset: 3px;
}

header.site-app-header .theme-bar {
    width: auto;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
}

header.site-app-header .theme-toggle {
    position: static;
}

/* Compact header */
header.site-app-header.is-scrolled {
    min-height: 48px;
    padding-top: 8px;
    padding-bottom: 8px;
}

header.site-app-header.is-scrolled .brand-title {
    opacity: 0;
    transition-delay: 0ms;
}
header.site-app-header.is-scrolled .brand-mark {
    transition-delay: 140ms;
}
header.site-app-header.is-scrolled .brand-mark svg {
    width: 22px;
    height: 22px;
}

/* Compact controls */
header.site-app-header.is-scrolled .header-actions > span,
header.site-app-header.is-scrolled .header-actions > .theme-bar {
    display: none;
}

/* Mobile header */
@media (max-width: 600px) {
    header.site-app-header {
        flex-direction: column;
        align-items: flex-start;
        min-height: 116px;
        padding: 16px;
        gap: 12px;
    }

    header.site-app-header .header-actions {
        width: 100%;
        justify-content: flex-end;
        gap: 12px;
    }

    /* Compact layout */
    header.site-app-header.is-scrolled {
        flex-direction: row;
        align-items: center;
        min-height: 44px;
        height: 44px;
        padding: 6px 16px;
        gap: 12px;
    }

    header.site-app-header.is-scrolled .brand {
        flex: 0 0 32px;
        width: 32px;
        padding-left: 0;
    }

    header.site-app-header.is-scrolled .brand-title {
        position: absolute;
        pointer-events: none;
        width: calc(100vw - 76px);
    }

    header.site-app-header.is-scrolled .header-actions {
        width: auto;
        margin-left: auto;
        flex-wrap: nowrap;
        font-size: 12px;
    }
}

/* Shared navigation */
.app-navigation {
    display: flex;
    flex-wrap: wrap;
    gap: 28px;
    padding: 0 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.app-navigation a {
    display: inline-flex;
    align-items: center;
    min-height: 48px;
    padding: 12px 0;
    border-bottom: 3px solid transparent;
    color: var(--muted);
    font-size: 14px;
    text-decoration: none;
}
.app-navigation a[aria-current="page"] {
    color: var(--text);
    border-bottom-color: var(--text);
    font-weight: 700;
}
.app-navigation a:hover {
    color: var(--text);
}

/* Keyboard access */
.skip-link {
    position: fixed;
    top: 8px;
    left: 16px;
    z-index: 100;
    padding: 12px 16px;
    transform: translateY(-200%);
    background: var(--surface);
    color: var(--text);
    border: 2px solid var(--text);
    border-radius: 5px;
}
.skip-link:focus {
    transform: translateY(0);
}
.app-navigation a:focus-visible {
    outline: 2px solid #6c957c;
    outline-offset: 3px;
}

/* Mobile navigation */
@media (max-width: 600px) {
    .app-navigation {
        gap: 20px;
        padding: 0 16px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    header.site-app-header .brand-mark,
    header.site-app-header .brand-title {
        transition: none;
    }
}

/* Network status */
.network-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font:
        12px/1.5 Arial,
        sans-serif;
    white-space: nowrap;
}
.network-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #43864a;
    flex-shrink: 0;
}
.network-status[data-online="false"] .network-dot {
    background: #b7812a;
}
:root[data-theme="dark"] .network-dot {
    background: #86ba8b;
}
:root[data-theme="dark"] .network-status[data-online="false"] .network-dot {
    background: #e0b66a;
}
.login-header .network-status {
    margin-left: auto;
    margin-right: 18px;
}

/* Header button */
header.site-app-header button.brand {
    padding-top: 0;
    padding-right: 0;
    padding-bottom: 0;
    border: 0;
    background: transparent;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}
header.site-app-header button.brand:focus-visible {
    outline: none;
}
header.site-app-header button.brand:focus-visible .brand-mark {
    outline: 2px solid #6c957c;
    outline-offset: 3px;
}

/* Small tooltips */
.control-tooltip {
    position: fixed;
    inset: auto;
    z-index: 1000;
    width: max-content;
    max-width: min(220px, calc(100vw - 16px));
    margin: 0;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 3px 12px rgb(0 0 0 / 10%);
    font:
        12px/1.45 Arial,
        sans-serif;
    text-align: left;
    overflow-wrap: anywhere;
    pointer-events: auto;
}
.control-tooltip[hidden] {
    display: none;
}

/* Theme fade */
:where(html.theme-ready, html.theme-ready *) {
    transition:
        background-color 300ms ease,
        border-color 300ms ease,
        box-shadow 300ms ease;
}

@media (prefers-reduced-motion: reduce) {
    :where(html.theme-ready, html.theme-ready *) {
        transition: none;
    }
}

/* FAQ launcher */
.faq-launcher {
    position: fixed;
    right: max(20px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    z-index: 30;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 4px 18px rgb(0 0 0 / 12%);
    font:
        600 13px/1.4 Arial,
        sans-serif;
    cursor: pointer;
}
.faq-launcher:hover,
.faq-dialog .faq-close:hover {
    background: var(--selected);
}
.faq-question {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: 12px;
}
body:has(.faq-launcher) {
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

body:has(.faq-dialog[open]) {
    overflow: hidden;
}

/* FAQ panel */
.faq-dialog {
    position: fixed;
    inset: auto max(20px, env(safe-area-inset-right))
        calc(76px + env(safe-area-inset-bottom)) auto;
    box-sizing: border-box;
    width: min(420px, calc(100vw - 32px));
    max-width: none;
    max-height: min(680px, calc(100dvh - 108px));
    margin: 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 20px 60px rgb(0 0 0 / 20%);
    overflow-y: auto;
    overscroll-behavior: contain;
    font:
        14px/1.6 Arial,
        sans-serif;
}
.faq-dialog::backdrop {
    background: rgb(0 0 0 / 18%);
}
.faq-dialog .faq-heading {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 22px 16px 20px 22px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.faq-dialog h2 {
    margin: 0;
    font:
        600 19px/1.35 Arial,
        sans-serif;
}
.faq-dialog .faq-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font:
        26px/1 Arial,
        sans-serif;
    cursor: pointer;
}
.faq-eyebrow {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.4px;
}
.faq-introduction p {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 12px;
}
.faq-list {
    padding: 0 18px 18px;
}
.faq-group h3 {
    margin: 18px 4px 9px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.4px;
}
.faq-list details {
    margin-top: 7px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}
.faq-list details[open] {
    background: var(--background);
}
.faq-list summary::marker {
    content: "";
}
.faq-list summary::-webkit-details-marker {
    display: none;
}
.faq-list summary::after {
    content: "+";
    flex: 0 0 18px;
    text-align: center;
    color: var(--muted);
    font-size: 19px;
    font-weight: 400;
}
.faq-list details[open] summary::after {
    content: "−";
}
.faq-list summary:hover {
    background: var(--selected);
    border-radius: 10px;
}
.faq-list summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    list-style: none;
    min-height: 48px;
    padding: 13px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
}
.faq-list p {
    margin: 0;
    padding: 0 14px 15px;
    color: var(--muted);
    font:
        13px/1.65 Arial,
        sans-serif;
}
.faq-launcher:focus-visible,
.faq-close:focus-visible,
.faq-list summary:focus-visible {
    outline: 2px solid #6c957c;
    outline-offset: -3px;
}
@media (max-width: 600px) {
    .faq-launcher {
        right: max(16px, env(safe-area-inset-right));
        bottom: max(16px, env(safe-area-inset-bottom));
    }
    .faq-dialog {
        right: max(16px, env(safe-area-inset-right));
        bottom: calc(72px + env(safe-area-inset-bottom));
    }
}

/* FAQ assistant */
.faq-modes {
    display: flex;
    gap: 4px;
    margin: 16px 18px 4px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--background);
}
.faq-modes button,
.faq-suggestions button {
    min-height: 38px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font:
        12px/1.5 Arial,
        sans-serif;
    cursor: pointer;
}
.faq-modes button {
    flex: 1;
    border-color: transparent;
    background: transparent;
    border-radius: 7px;
}
.faq-modes button[aria-pressed="true"] {
    background: var(--surface);
    border-color: var(--border);
    box-shadow: 0 1px 3px rgb(0 0 0 / 6%);
    font-weight: 600;
}
.faq-chat[hidden],
.faq-list[hidden] {
    display: none;
}
.faq-chat {
    padding: 0 16px 16px;
}
.faq-dialog .faq-assistant-note {
    margin: 10px 0;
    color: var(--muted);
    font:
        12px/1.5 Arial,
        sans-serif;
}
.faq-messages {
    max-height: clamp(100px, 22dvh, 180px);
    overflow-y: auto;
    overscroll-behavior: contain;
}
.faq-message {
    margin: 8px 0;
    padding: 10px 12px;
    border-radius: 12px 12px 12px 3px;
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--text);
    overflow-wrap: anywhere;
}
.faq-message-user {
    margin-left: 36px;
    border-radius: 12px 12px 3px 12px;
    background: var(--selected);
}
.faq-message strong {
    display: block;
    margin-bottom: 5px;
    font-size: 12px;
}
.faq-dialog .faq-message p {
    margin: 0;
    padding: 0;
    color: inherit;
    font:
        13px/1.6 Arial,
        sans-serif;
}
.faq-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 12px 0;
}
.faq-compose label {
    display: block;
    margin: 0 0 6px;
    font:
        600 12px/1.5 Arial,
        sans-serif;
}
.faq-compose-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.faq-compose input {
    flex: 1;
    min-width: 0;
    width: 100%;
    min-height: 44px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font:
        16px/1.4 Arial,
        sans-serif;
}
.faq-compose input::placeholder {
    color: var(--muted);
    font-size: 12px;
}
.faq-compose button {
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #315e43;
    border-radius: 6px;
    background: #315e43;
    color: #fff;
    font:
        600 13px/1.5 Arial,
        sans-serif;
    cursor: pointer;
}
.faq-modes button:focus-visible,
.faq-suggestions button:focus-visible,
.faq-compose input:focus-visible,
.faq-compose button:focus-visible {
    outline: 2px solid #6c957c;
    outline-offset: 2px;
}

/* Conversation feedback */
.faq-message-enter {
    animation: faq-message-in 240ms ease-out 180ms backwards;
}
.faq-message-user.faq-message-enter {
    animation-delay: 0ms;
}
@keyframes faq-message-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@media (prefers-reduced-motion: reduce) {
    .faq-message-enter {
        animation: none;
    }
}

/* Help panel interactions */
.faq-dialog[open] {
    animation: faq-panel-in 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.faq-dialog[open]::backdrop {
    animation: faq-backdrop-in 200ms ease-out;
}
.faq-chat:not([hidden]),
.faq-list:not([hidden]) {
    animation: faq-content-in 220ms ease-out;
}
.faq-list details[open] p {
    animation: faq-content-in 200ms ease-out;
}
.faq-launcher {
    transition:
        transform 180ms ease,
        box-shadow 180ms ease;
}
.faq-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 22px rgb(0 0 0 / 16%);
}
.faq-modes button,
.faq-suggestions button,
.faq-compose button,
.faq-close {
    transition:
        background-color 180ms ease,
        transform 180ms ease,
        box-shadow 180ms ease;
}
.faq-suggestions button:hover {
    background: var(--selected);
    transform: translateY(-2px);
}
.faq-compose button:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 9px rgb(0 0 0 / 14%);
}
.faq-compose button:active,
.faq-suggestions button:active {
    transform: scale(0.97);
}
.faq-chat {
    padding: 4px 18px 18px;
}
.faq-chat-welcome {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0 10px;
}
.faq-chat-symbol {
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    height: 42px;
    border-radius: 13px;
    background: var(--selected);
    color: var(--text);
}
.faq-chat-welcome h3 {
    margin: 0;
    font:
        600 16px/1.4 Arial,
        sans-serif;
}
.faq-dialog .faq-chat-welcome .faq-assistant-note {
    margin: 3px 0 0;
    font-size: 11px;
}
.faq-suggestions button {
    border-radius: 18px;
    font-size: 11px;
    padding: 6px 11px;
}
.faq-compose {
    border-top: 1px solid var(--border);
    padding-top: 14px;
    margin-top: 14px;
}
.faq-compose-row {
    gap: 6px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface);
    transition:
        border-color 180ms ease,
        box-shadow 180ms ease;
}
.faq-compose-row:focus-within {
    border-color: #6c957c;
    box-shadow: 0 0 0 3px rgb(108 149 124 / 14%);
}
.faq-compose input {
    border: 0;
    background: transparent;
    padding: 9px 7px;
}
.faq-compose input:focus-visible {
    outline: none;
}
.faq-compose button {
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    padding: 0;
    border-radius: 9px;
}
@keyframes faq-panel-in {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
@keyframes faq-backdrop-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
@keyframes faq-content-in {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@media (prefers-reduced-motion: reduce) {
    .faq-dialog[open],
    .faq-dialog[open]::backdrop,
    .faq-chat:not([hidden]),
    .faq-list:not([hidden]),
    .faq-list details[open] p {
        animation: none;
    }
    .faq-launcher,
    .faq-modes button,
    .faq-suggestions button,
    .faq-compose button,
    .faq-close,
    .faq-compose-row {
        transition: none;
    }
    .faq-launcher:hover,
    .faq-suggestions button:hover,
    .faq-compose button:hover,
    .faq-compose button:active,
    .faq-suggestions button:active {
        transform: none;
    }
}

/* Shared motion: brief feedback without delaying actions. */
@media (prefers-reduced-motion: no-preference) {
    main {
        animation: app-content-in 300ms ease-out;
    }
    :where(button, a[href], summary, input, select, textarea) {
        transition:
            background-color 200ms ease,
            color 200ms ease,
            border-color 200ms ease,
            box-shadow 200ms ease,
            opacity 180ms ease,
            translate 180ms ease,
            scale 140ms ease;
    }
    :where(button:not(.brand):enabled, a[href]:not(.skip-link)):active {
        scale: 0.98;
    }
    :where(input, select, textarea):focus-visible {
        animation: app-focus-in 220ms ease-out;
    }
    .theme-toggle svg {
        animation: app-icon-in 240ms ease-out;
    }
    .export-dialog[open] {
        animation: faq-panel-in 260ms ease-out;
    }
    .export-dialog[open]::backdrop {
        animation: faq-backdrop-in 200ms ease-out;
    }
    .control-tooltip:not([hidden]) {
        animation: app-content-in 160ms ease-out;
    }
    .entry-readiness[open] ul {
        animation: faq-content-in 200ms ease-out;
    }
    @media (hover: hover) {
        :where(
            button:not(.brand):not(.faq-launcher):enabled,
            a[href]:not(.skip-link)
        ):hover {
            translate: 0 -1px;
        }
    }
}
@keyframes app-content-in {
    from {
        opacity: 0;
        translate: 0 5px;
    }
    to {
        opacity: 1;
        translate: 0 0;
    }
}
@keyframes app-focus-in {
    from {
        box-shadow: 0 0 0 0 rgb(108 149 124 / 0%);
    }
    to {
        box-shadow: 0 0 0 3px rgb(108 149 124 / 14%);
    }
}
@keyframes app-icon-in {
    from {
        opacity: 0;
        rotate: -18deg;
        scale: 0.85;
    }
    to {
        opacity: 1;
        rotate: 0deg;
        scale: 1;
    }
}

/* Crossfade the complete theme so nested text remains stable. */
html.theme-switching *,
html.theme-switching {
    transition: none !important;
}
html.theme-switching::view-transition-old(root),
html.theme-switching::view-transition-new(root) {
    animation-duration: 260ms;
    animation-timing-function: ease-in-out;
    mix-blend-mode: normal;
}
@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation: none;
    }
}
