/* Theme and shared controls. */
:root {
    color-scheme: light;
    --bg: #f6f7fa;
    --panel: #fff;
    --text: #253046;
    --muted: #697487;
    --line: #e2e6ed;
    --brand: #243651;
    --mobile-nav-height: calc(64px + env(safe-area-inset-bottom, 0px));
    --mobile-actions-height: 0px;
}
* {
    box-sizing: border-box;
}
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font:
        14px/1.5 system-ui,
        sans-serif;
}
button,
input,
select,
textarea {
    font: inherit;
}
button,
a.button {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 15px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    min-height: 44px;
}
button.primary {
    background: var(--brand);
    color: white;
    border-color: var(--brand);
}
button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
input,
select {
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    color: var(--text);
    max-width: 100%;
}
input {
    width: 100%;
}
label {
    display: block;
    font-weight: 600;
    margin: 16px 0 6px;
}
/* Page layout and reusable panels. */
header {
    background: white;
    border-bottom: 1px solid var(--line);
    padding: 20px 30px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.brand {
    font-size: 21px;
    letter-spacing: -0.8px;
    font-weight: 700;
}
.badge {
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 12px;
    color: var(--muted);
}
header .right {
    margin-left: auto;
}
main {
    max-width: 1500px;
    margin: auto;
    padding: 30px;
}
h1 {
    font-size: 28px;
    letter-spacing: -0.8px;
    margin: 0 0 8px;
}
h2 {
    font-size: 18px;
    margin: 0 0 8px;
}
p {
    color: var(--muted);
    margin: 0;
}
small {
    color: var(--muted);
    font-size: 12px;
}
.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.box {
    background: white;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 22px;
    margin-top: 20px;
}
.empty {
    text-align: center;
    padding: 70px 20px;
}
.empty button {
    margin-top: 20px;
}
.wizard {
    max-width: 600px;
    margin: 25px auto;
}
/* HTML editor and media library. */
.editorgrid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    gap: 18px;
    margin-top: 18px;
}
.pane {
    background: white;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    min-width: 0;
}
.panehead {
    padding: 12px 15px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
textarea {
    width: 100%;
    display: block;
    padding: 18px;
    border: 0;
    background: #f8fafc;
    color: #23334c;
    font:
        13px/1.7 ui-monospace,
        monospace;
    min-height: 440px;
    resize: vertical;
}
iframe {
    width: 100%;
    height: 440px;
    border: 0;
    background: white;
    display: block;
}
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(205px, 1fr));
    gap: 16px;
    margin-top: 20px;
}
.asset {
    background: var(--bg);
    border: 1px solid var(--line);
    padding: 12px;
    border-radius: 9px;
    min-width: 0;
}
.asset img {
    width: 100%;
    height: 130px;
    object-fit: contain;
    background: white;
    border-radius: 6px;
}
.asset strong {
    display: block;
    overflow-wrap: anywhere;
    margin-top: 8px;
}
.asset button {
    padding: 8px 10px;
}
.asset .group {
    gap: 5px;
    margin-top: 10px;
}
.site-row {
    padding: 20px 0;
    border-bottom: 1px solid var(--line);
}
.site-row:last-child {
    border: 0;
}
.site-row strong {
    display: block;
    font-size: 16px;
}
.notice {
    padding: 12px 16px;
    border-radius: 8px;
    background: #eaf0f8;
    color: #294260;
    margin: 18px 0;
    overflow-wrap: anywhere;
}
.notice.error {
    background: #fff0ed;
    color: #9b3029;
}
.foot {
    border-top: 1px solid var(--line);
    padding-top: 18px;
    margin-top: 24px;
}
.warn {
    background: #fff5e6;
    border: 1px solid #eedab7;
    padding: 16px;
    border-radius: 8px;
    margin-top: 14px;
}
.success {
    text-align: center;
    padding: 32px;
}
.success .url {
    display: block;
    margin: 22px 0;
    overflow-wrap: anywhere;
}
/* Deployment result and saved-file previews. */
.steps {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin: 20px 0;
    text-align: left;
}
.steps > div {
    padding: 18px;
    border-radius: 9px;
    background: var(--bg);
}
.steps small {
    display: block;
}
.back {
    border: 0;
    background: transparent;
    padding-left: 0;
    color: var(--muted);
}
.preview-stage {
    position: relative;
    overflow: hidden;
    background: #eef1f5;
}
.preview-stage iframe {
    position: absolute;
    top: 0;
    left: 0;
    max-width: none;
    transform-origin: top left;
}
.preview-meta {
    padding: 8px 15px;
    background: #f8fafc;
    border-top: 1px solid var(--line);
}
[hidden] {
    display: none !important;
}
#storage {
    overflow-wrap: anywhere;
}
.login {
    max-width: 450px;
    margin: 70px auto;
}
.actions {
    margin-top: 16px;
}
.fit {
    max-width: 200px;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 3px solid #83a9d7;
    outline-offset: 3px;
}
summary {
    cursor: pointer;
    font-weight: 600;
}
/* Site and connection controls. */
.connection-toolbar {
    display: flex;
    gap: 16px;
    align-items: end;
    flex-wrap: wrap;
}
.connection-toolbar > div {
    flex: 1;
    min-width: 220px;
}
.connection-toolbar select {
    width: 100%;
}
.editor-toolbar {
    position: sticky;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    top: 0;
    padding: 12px 0;
    z-index: 5;
}
#message {
    position: relative;
    z-index: 1;
    box-shadow: 0 3px 12px #25304608;
}
#site-title,
#site-address {
    overflow-wrap: anywhere;
}
#save-state {
    display: inline-block;
    margin-top: 5px;
    color: #35674b;
}
#save-state.unsaved {
    color: #9b6318;
}
#sync-state {
    display: inline-block;
    border-radius: 6px;
    padding: 5px 8px;
    background: #edf4ef;
}
#sync-state.attention {
    background: #fff5e6;
    color: #895912;
}
.site-row small {
    display: block;
    margin-top: 4px;
}
#code {
    tab-size: 2;
    font-size: 14px;
    height: 560px;
    min-height: 400px;
}
#connection-summary {
    overflow-wrap: anywhere;
}
.asset .badge {
    display: inline-block;
    margin-top: 6px;
    white-space: normal;
}
.site-row .group {
    justify-content: flex-end;
}

/* Cloudflare connection settings. */
.connections-page {
    max-width: 1100px;
    margin: auto;
}
.eyebrow {
    display: block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.4px;
    color: var(--muted);
    margin-bottom: 6px;
}
.connection-layout {
    display: grid;
    grid-template-columns: 270px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}
.connection-sidebar {
    position: sticky;
    top: 20px;
}
.connection-sidebar > label {
    margin-top: 0;
}
.connection-sidebar select {
    width: 100%;
}
.connection-sidebar small {
    display: block;
}
.connection-settings {
    border-top: 1px solid var(--line);
    padding-top: 18px;
    margin-top: 22px;
}
.connection-note {
    border-radius: 8px;
    background: #f3f6fa;
    padding: 16px;
    margin-top: 24px;
}
.connection-note p {
    font-size: 13px;
    margin-top: 6px;
}
.connection-overview h2 {
    font-size: 22px;
    margin: 0;
}
.connection-badge,
.connection-overview .badge {
    white-space: nowrap;
}
.badge.verified {
    background: #eaf5ed;
    color: #27653a;
    border-color: #c6e4ce;
}
.badge.pending {
    background: #fff6e7;
    color: #895912;
    border-color: #eedab7;
}
.connection-feedback {
    margin-top: 12px;
    overflow-wrap: anywhere;
}
.connection-feedback:empty {
    display: none;
}
.connection-feedback.error {
    color: #9b3029;
    background: #fff0ed;
    padding: 12px;
    border-radius: 8px;
}
.connection-feedback.good {
    color: #27653a;
}
.connection-methods {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 0;
    border: 0;
    margin: 24px 0 0;
}
.connection-methods legend,
.oauth-permissions legend {
    font-weight: 600;
    margin-bottom: 10px;
}
.method-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 15px;
    margin: 0;
    cursor: pointer;
}
.method-option:has(input:checked) {
    background: #f0f5fc;
    border-color: #7392bb;
    box-shadow: 0 0 0 1px #7392bb;
}
.method-option input {
    width: auto;
    margin: 4px 0 0;
    accent-color: var(--brand);
}
.method-option small {
    display: block;
    font-weight: 400;
    margin-top: 5px;
}
.recommended {
    font-size: 10px;
    background: #e5edf8;
    color: #34557b;
    border-radius: 4px;
    padding: 3px 5px;
    margin-left: 5px;
}
.method-panel {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}
.method-panel h3 {
    font-size: 16px;
    margin: 0 0 8px;
}
.copy-field {
    display: flex;
    gap: 8px;
}
.copy-field input {
    min-width: 0;
}
.copy-field button {
    flex-shrink: 0;
}
.oauth-explainer {
    background: #f4f6fa;
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 20px;
}
.oauth-permissions {
    padding: 0;
    border: 0;
    margin-top: 20px;
}
.oauth-permissions label {
    font-weight: 400;
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 8px 0;
}
.oauth-permissions input {
    width: auto;
    accent-color: var(--brand);
}
.oauth-authorize {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}
.connection-footnote {
    font-size: 12px;
    padding: 16px 2px;
}
.connection-main {
    min-width: 0;
}
.connection-setup > summary {
    font-size: 18px;
}

/* Access-token permissions use compact checkboxes beside their labels. */
#mcp-token-form input[type='checkbox'] {
    width: auto;
}

/* Shared navigation keeps the primary task separate from settings and recovery. */
.tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px 0;
    margin-top: 12px;
    border-bottom: 1px solid var(--line);
}
.tabs > button {
    background: transparent;
    border-color: transparent;
}
.tabs > button[aria-current='page'] {
    background: white;
    border-color: var(--line);
    box-shadow: 0 2px 5px #2530460a;
    font-weight: 700;
}
.action-menu {
    position: relative;
}
.action-menu > summary {
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    min-height: 44px;
}
.menu-items {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 8;
    min-width: 210px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: white;
    box-shadow: 0 8px 25px #25304620;
}
.menu-items > button,
.menu-items > a {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
}
button.danger {
    color: #9b3029;
}
button.danger:hover {
    background: #fff0ed;
}
.danger-panel {
    border-color: #dfb6b0;
}
.danger-panel h2 {
    color: #9b3029;
}
.badge.failed {
    background: #fff0ed;
    border-color: #dfb6b0;
    color: #9b3029;
}
.search-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}
.search-toolbar input {
    flex: 1 1 240px;
    width: auto;
    margin: 0;
}
.search-toolbar select {
    flex: 0 1 210px;
}
.field-help {
    margin: 8px 0;
    font-size: 13px;
}

/* Feedback floats above the page instead of moving the editor when text changes. */
.feedback-stack {
    position: fixed;
    top: 96px;
    right: 18px;
    z-index: 20;
    width: min(480px, calc(100vw - 36px));
    pointer-events: none;
}
.feedback-stack .notice {
    margin: 0 0 8px;
    box-shadow: 0 4px 18px #25304624;
}
.feedback-message {
    position: relative;
}
.feedback-message .notice {
    padding-right: 42px;
}
#dismiss-message {
    position: absolute;
    z-index: 2;
    right: 4px;
    top: 0;
    min-height: 44px;
    background: transparent;
    border: 0;
    font-size: 22px;
    pointer-events: auto;
}
#request-status {
    background: var(--brand);
    color: white;
}
.editor-toolbar h1 {
    font-size: 24px;
}
.editor-toolbar > div:first-child {
    min-width: 0;
    flex: 1 1 250px;
}
.editor-toolbar #site-address {
    font-size: 13px;
}
.editor-tabs {
    margin-top: 0;
}
#editor-workspace > .box {
    margin-top: 12px;
    padding: 14px 18px;
}
.workspace-switch {
    display: none;
}
#mcp-token-form fieldset {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 16px;
    margin-top: 20px;
}
#mcp-token-form fieldset label {
    font-weight: 400;
    margin: 10px 0;
}
#mcp-token-form fieldset input {
    margin-right: 8px;
}
#settings-mcp-panel,
#settings-account-panel {
    max-width: 760px;
}
#history .group select {
    max-width: 100%;
}

/* Headings receive programmatic focus after navigation, without a control outline. */
h1[tabindex='-1']:focus {
    outline: none;
}
/* Account-limit explanations are optional; the current usage stays visible. */
.usage-help {
    margin-top: 14px;
    border-top: 1px solid var(--line);
    padding-top: 12px;
}
.usage-help p,
.usage-help small {
    display: block;
    margin-top: 10px;
}
/* Shared heading and page controls avoid wrapping secondary actions around the editor. */
.site-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.site-heading h1 {
    min-width: 0;
}
.page-toolbar > .group {
    flex: 1;
    min-width: 0;
}
.page-toolbar select {
    min-width: 0;
}
.mobile-nav {
    display: none;
}
.feedback-stack .notice {
    max-height: min(220px, 35dvh);
    overflow-y: auto;
    pointer-events: auto;
}

/* Phone layouts keep actions visible and show one editor pane at a time. */
@media (max-width: 900px) {
    main {
        padding: 16px max(14px, env(safe-area-inset-right, 0px)) 24px
            max(14px, env(safe-area-inset-left, 0px));
    }
    .workspace-user main {
        padding-bottom: calc(var(--mobile-nav-height) + var(--mobile-actions-height) + 24px);
    }
    html:has(body.workspace-user) {
        scroll-padding-bottom: calc(var(--mobile-nav-height) + var(--mobile-actions-height) + 16px);
    }
    :root:has(body[data-screen='editor']) {
        --mobile-actions-height: 64px;
    }
    header {
        padding: calc(10px + env(safe-area-inset-top, 0px))
            max(14px, env(safe-area-inset-right, 0px)) 10px
            max(14px, env(safe-area-inset-left, 0px));
    }
    header .badge {
        display: none;
    }
    .editorgrid {
        grid-template-columns: 1fr;
    }
    .steps {
        grid-template-columns: 1fr;
    }
    input,
    select {
        font-size: 16px;
    }
    select {
        width: 100%;
    }
    .login {
        margin: 24px auto;
    }
    .login button[type='submit'] {
        width: 100%;
    }
    .brand {
        font-size: 19px;
    }
    h1 {
        font-size: 24px;
    }
    .editor-toolbar {
        position: static;
        padding-top: 0;
    }
    .editor-toolbar > div:first-child {
        flex-basis: 100%;
    }
    .editor-toolbar > .group {
        position: fixed;
        left: 0;
        right: 0;
        bottom: var(--mobile-nav-height);
        z-index: 9;
        display: grid;
        grid-template-columns: 52px minmax(76px, 0.8fr) minmax(0, 1.2fr);
        height: var(--mobile-actions-height);
        padding: 8px max(12px, env(safe-area-inset-right, 0px)) 8px
            max(12px, env(safe-area-inset-left, 0px));
        gap: 6px;
        background: white;
        border-top: 1px solid var(--line);
        box-shadow: 0 -4px 16px #25304608;
    }
    .editor-toolbar > .group button {
        padding: 8px 6px;
        min-width: 0;
        font-size: 13px;
        line-height: 1.2;
    }
    #message {
        position: static;
    }
    .connection-toolbar {
        align-items: stretch;
    }
    #code {
        font-size: 16px;
        min-height: 280px;
        height: clamp(280px, 54dvh, 520px);
    }
    .site-row {
        align-items: flex-start;
    }
    .site-row .group {
        justify-content: flex-start;
    }
    .panehead .group {
        gap: 5px;
    }
    .panehead button,
    .panehead a.button {
        padding: 8px;
    }
    .connection-layout {
        grid-template-columns: 1fr;
        gap: 0;
    }
    .connection-sidebar {
        position: static;
    }
    .connection-note {
        display: none;
    }
    .connection-methods {
        grid-template-columns: 1fr;
    }
    .copy-field {
        flex-wrap: wrap;
    }
    .copy-field input {
        flex: 1 1 100%;
    }
    .connection-overview .group button {
        flex: 1;
    }
    .box {
        padding: 18px;
    }
    .editor-toolbar h1 {
        font-size: 20px;
        overflow-wrap: anywhere;
    }
    .tabs {
        position: sticky;
        top: env(safe-area-inset-top, 0px);
        z-index: 6;
        gap: 4px;
        flex-wrap: nowrap;
        overflow-x: auto;
        background: var(--bg);
        scrollbar-width: thin;
    }
    .tabs > button {
        flex: 0 0 auto;
        padding: 10px;
        white-space: nowrap;
    }
    .search-toolbar select {
        flex: 1 1 160px;
    }
    .workspace-switch {
        display: flex;
        gap: 8px;
        margin-top: 14px;
    }
    .workspace-switch button {
        flex: 1;
    }
    .workspace-switch button[aria-pressed='true'] {
        background: var(--brand);
        border-color: var(--brand);
        color: white;
    }
    #editor-grid[data-view='source'] > .pane:last-child,
    #editor-grid[data-view='preview'] > .pane:first-child {
        display: none;
    }
    .feedback-stack {
        top: auto;
        bottom: calc(var(--mobile-nav-height) + var(--mobile-actions-height) + 10px);
    }
    .site-row > div:first-child {
        min-width: 0;
        width: 100%;
        overflow-wrap: anywhere;
    }
    #history .group {
        align-items: stretch;
    }
    #history .group select {
        width: 100%;
    }
    .menu-items {
        right: auto;
        left: 0;
    }
    .site-row .menu-items {
        left: auto;
        right: 0;
    }
    #home > .row > .group,
    #back,
    #cancel-create,
    #connections-back {
        display: none;
    }
    .wizard {
        margin: 0 auto;
    }
    .wizard .foot,
    .wizard .foot button {
        width: 100%;
    }
    .group > input:not([type='checkbox']):not([type='radio']),
    .group > select {
        flex: 1 1 100%;
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }
    .page-toolbar > .group {
        flex-wrap: nowrap;
    }
    .page-toolbar select {
        flex: 1 1 auto;
        width: auto;
    }
    .page-toolbar > .action-menu .menu-items,
    .site-heading .menu-items {
        left: auto;
        right: 0;
    }
    .search-toolbar {
        position: sticky;
        top: env(safe-area-inset-top, 0px);
        z-index: 6;
        padding: 10px 0;
        background: var(--bg);
    }
    #sites {
        padding: 0;
        border: 0;
        background: transparent;
    }
    #sites .site-row,
    #sites .site-row:last-child {
        padding: 16px;
        margin-bottom: 12px;
        border: 1px solid var(--line);
        border-radius: 12px;
        background: white;
    }
    #sites .site-row .group {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        width: 100%;
        gap: 10px;
    }
    #sites .site-row .badge {
        grid-column: 1 / -1;
        justify-self: start;
    }
    #sites .action-menu > summary {
        text-align: center;
    }
    /* The footer reserves the device safe area and never overlaps the editor action row. */
    .mobile-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
        display: flex;
        gap: 8px;
        height: var(--mobile-nav-height);
        padding: 6px max(12px, env(safe-area-inset-right, 0px))
            calc(6px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
        border-top: 1px solid var(--line);
        background: white;
    }
    .mobile-nav button {
        display: flex;
        flex: 1;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 3px;
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: var(--muted);
        font-size: 12px;
        line-height: 1.2;
    }
    .mobile-nav button[aria-current='page'] {
        background: #edf2f8;
        color: var(--brand);
        font-weight: 700;
    }
    .mobile-nav svg {
        width: 22px;
        height: 22px;
        fill: white;
        stroke: currentColor;
        stroke-width: 1.7;
        stroke-linecap: round;
        stroke-linejoin: round;
    }
    .usage-card > .row {
        flex-wrap: nowrap;
        align-items: flex-start;
    }
    .usage-card > .row h2 {
        min-width: 0;
    }
    .usage-card > .row button {
        flex-shrink: 0;
    }
}

/* Readiness stays compact on phones; findings scroll independently of the editor. */
.quality-status {
    display: block;
    margin-top: 8px;
    padding: 4px 0;
    background: transparent;
    border: 0;
    font-size: 13px;
    text-align: left;
    text-decoration: underline;
}
.quality-status.attention {
    color: #895912;
}
.quality-panel select {
    min-width: 0;
    width: 100%;
    flex: 1 1 240px;
}
.quality-panel details {
    margin-top: 16px;
}
.quality-issues {
    max-height: 320px;
    overflow: auto;
    padding-left: 24px;
    overflow-wrap: anywhere;
}
.quality-issues li {
    margin: 8px 0;
}

/* Sharing controls fit the same single-column layout on desktop and mobile. */
#share-panel {
    max-width: 900px;
}
#share-panel p + p {
    margin-top: 12px;
}
#share-panel input:not([type='checkbox']),
#share-panel select {
    width: 100%;
}
#share-remove-password,
#share-show-topbar {
    width: auto;
    margin-right: 8px;
}
.share-note {
    margin-top: 20px;
}
