/* Simplicity programme — the shared page frame.
   See docs/plans/SIMPLICITY_PROGRAMME.md (SP2). Loaded after the theme so
   these rules win; keep element ids intact because page scripts use them. */

/* ---- Header menu ------------------------------------------------------- */
.app-menu {
    position: relative;
}

.app-menu-button {
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.6);
    color: #e2e8f0;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.app-menu-button::-webkit-details-marker {
    display: none;
}

.app-menu[open] .app-menu-button,
.app-menu-button:hover {
    border-color: rgba(96, 165, 250, 0.6);
}

.app-menu-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 10050;
    display: grid;
    min-width: 190px;
    padding: 6px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
    background: #0f1726;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.app-menu-item {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #e2e8f0 !important;
    font: inherit;
    font-size: 14px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.app-menu-item:hover,
.app-menu-item:focus-visible {
    background: rgba(59, 130, 246, 0.18);
}

.app-menu-item.auth-logout {
    color: #fca5a5 !important;
}

/* Feedback is in the menu for signed-in users; the floating bubble covered
   page controls. Pages that dock the launcher into their own toolbar move it
   out of <body>, so only the floating copy is hidden. */
body > .feedback-floating-launcher--in-menu {
    display: none !important;
}

.app-header .header-auth {
    order: 7;
}

/* ---- Level bar: one slim row with the project name -------------------- */
@media (min-width: 721px) {
    .building-level-bar,
    .building-level-bar--single {
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 0;
        padding: 4px 16px;
        border-bottom-width: 1px;
        box-shadow: none;
        background: rgba(17, 35, 60, 0.96);
    }

    .building-level-bar .building-level-summary {
        display: flex;
        align-items: center;
        gap: 8px;
        min-width: 0;
    }

    .building-level-project {
        max-width: 320px;
        overflow: hidden;
        color: #f8fafc;
        font-size: 14px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .building-level-bar .building-level-kicker {
        color: #93c5fd;
        font-size: 11px;
        letter-spacing: 0.06em;
    }

    /* The tabs already show which level is current. */
    .building-level-bar:not(.building-level-bar--single) .building-level-current,
    .building-level-bar .building-level-count {
        display: none;
    }

    .building-level-bar .building-level-tabs {
        gap: 4px;
        padding: 0;
    }

    .building-level-bar .building-level-tab {
        flex: 0 0 auto;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        min-height: 30px;
        max-width: none;
        padding: 3px 12px;
    }

    .building-level-bar .building-level-tab-elevation,
    .building-level-bar .building-level-tab:not(.is-current) .building-level-tab-reference {
        display: none;
    }

    .building-level-bar .building-level-actions {
        margin-left: auto;
        gap: 6px;
    }

    .building-level-bar .btn-edit-walls,
    .building-level-bar .btn-edit-storey,
    .building-level-bar .btn-redraw-storey,
    .building-level-bar .btn-align-storey {
        min-height: 28px;
        padding: 3px 10px;
        font-size: 12px;
    }
}

/* ---- Bottom action bar: Back / Next always in the same place ---------- */
@media (min-width: 721px) {
    .app-action-bar {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 9000;
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        align-items: center;
        gap: 12px;
        height: 56px;
        padding: 0 16px;
        border-top: 1px solid rgba(148, 163, 184, 0.22);
        background: rgba(10, 16, 28, 0.96);
        box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.35);
    }

    .app-action-bar .ag-prev-action {
        grid-column: 1;
        grid-row: 1;
        justify-self: start;
    }

    .app-action-bar .app-action-bar-step {
        grid-column: 2;
        grid-row: 1;
        color: #94a3b8;
        font-size: 13px;
        white-space: nowrap;
    }

    .app-action-bar .ag-next-action {
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
        min-height: 40px;
        padding: 0 18px;
        font-size: 14px;
    }

    .app-action-bar .ag-next-action strong,
    .app-action-bar .ag-prev-action strong {
        font-size: 14px;
    }

    body:has(.app-action-bar) {
        padding-bottom: 56px;
    }

    /* Anything else pinned to the bottom of the screen moves above the bar. */
    body:has(.app-action-bar) .assistant-guide {
        bottom: 74px;
    }

    body:has(.app-action-bar) #submit_opening_btn,
    body:has(.app-action-bar) #bulk-height-apply {
        bottom: 68px;
    }
}

@media (max-width: 720px) {
    .app-action-bar {
        display: contents;
    }

    .app-action-bar-step {
        display: none;
    }
}

/* ---- Six steps + sub-page tabs (SP3) ----------------------------------- */
.ag-stage-nav-single .app-step .stage-label {
    font-size: 13px;
}

.app-step-tabs {
    display: flex;
    gap: 4px;
    padding: 6px 16px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
    background: rgba(2, 6, 23, 0.35);
}

.app-step-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #cbd5e1;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.app-step-tab:hover {
    background: rgba(59, 130, 246, 0.12);
}

.app-step-tab.active {
    border-color: rgba(96, 165, 250, 0.55);
    background: rgba(37, 99, 235, 0.22);
    color: #f8fafc;
}

.app-menu-heading {
    padding: 6px 12px 2px;
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.app-menu-form {
    margin: 0;
}

/* ---- Messages (SP4): top-right, readable, never over the frame -------- */
.global-flashes {
    top: 72px;
    right: 16px;
    left: auto;
    transform: none;
    width: min(420px, calc(100% - 32px));
}

.global-flash {
    background: #122033;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.global-flash--success { background: #0f2a24; }
.global-flash--warning { background: #2e2410; }
.global-flash--error { background: #2e1418; }

.global-flash.is-fading {
    opacity: 0;
    transform: translateX(12px);
}

/* Standalone page headers share the base header's links and menu. */
.app-header .project-shortcuts {
    display: flex;
    gap: 6px;
}

.app-header .header-auth {
    margin-left: 12px;
}

.app-header .project-shortcut {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 11px;
    border: 1px solid rgba(96, 165, 250, 0.38);
    border-radius: 9px;
    background: rgba(30, 64, 175, 0.12);
    color: #bfdbfe;
    font-size: 13px;
    font-weight: 650;
    text-decoration: none;
    white-space: nowrap;
}

/* The brand is a project setting, not something to read on every screen. */
.app-header .brand-logo {
    display: none;
}

.app-header .header-auth {
    margin-left: auto;
}

.app-header #saveStatus + .header-auth,
.app-header #wasteTicker ~ .header-auth {
    margin-left: 12px;
}

/* ---- Phones: keep the work reachable ---------------------------------- */
@media (max-width: 760px) {
    /* The header wraps to three rows on a phone; pinned, it hid ~150px of
       an 844px screen on every scroll. */
    .app-header {
        position: relative;
    }

    /* Pages that pin their main action to the bottom (Add Opening, Apply
       height): the assistant button sat on top of it. */
    body:has(#submit_opening_btn) .assistant-guide,
    body:has(#bulk-height-apply) .assistant-guide {
        bottom: 76px;
    }
}

/* ---- Phones: one header row (logo left, Menu right) ------------------- */
@media (max-width: 767px) {
    .app-header {
        flex-wrap: nowrap !important;
        row-gap: 0;
        gap: 8px;
    }

    /* The two project links move into the Menu (partials/app_menu.html). */
    .app-header .project-shortcuts,
    .app-header .ma-header-link {
        display: none !important;
    }

    /* manual_adjustment writes display:flex inline once north is saved; the
       phone frame already has the compass on the plan, so keep the duplicate
       header indicator from overriding this responsive hide. */
    .app-header .ma-north-indicator {
        display: none !important;
    }

    .app-header .app-tools-button {
        margin-right: 0;
    }

    .app-header .header-auth,
    .app-header #saveStatus + .header-auth,
    .app-header #wasteTicker ~ .header-auth {
        margin-left: auto;
        flex: 0 0 auto;
    }

    .app-menu-panel {
        min-width: min(240px, calc(100vw - 24px));
    }
}

@media (max-width: 480px) {
    /* Keep the All pages and My account labels readable at 320px without
       wrapping the work header: remove decorative duplicates and tighten it. */
    .app-header {
        gap: 4px;
        padding: 8px;
    }

    .app-header .app-logo {
        display: none;
    }

    .app-header .app-tools-button {
        min-height: 32px;
        gap: 3px;
        padding: 0 6px;
        font-size: 12px;
    }

    .app-header .ma-cost-ticker {
        padding: 5px !important;
    }

    .app-header .ma-cost-ticker__value {
        font-size: 12px;
    }

    .app-header #saveStatus {
        gap: 0 !important;
        padding: 5px 6px !important;
    }

    .app-header #saveStatus .save-icon,
    .app-header .app-menu-button > span[aria-hidden="true"] {
        display: none;
    }

    .app-header .app-menu-button {
        min-height: 32px;
        gap: 0;
        padding: 0 6px;
        font-size: 12px;
    }
}

/* Navigation option B: one quiet line on each optional tool's landing page. */
.optional-tool-note {
    margin: 4px 0 0;
    color: var(--color-text-secondary, #94a3b8);
    font-size: 13px;
    font-weight: 500;
}

/* ---- Tools panel (navigation option B) -------------------------------- */
/* Opened from the left of the header. It overlays the page and never pushes
   or shrinks it, so plan canvases keep their size whether it is open or not. */
.app-tools-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    order: -1;
    flex: 0 0 auto;
    min-height: 34px;
    margin-right: 6px;
    padding: 0 12px;
    border: 1px solid #60a5fa;
    border-radius: 8px;
    background: #2563eb;
    color: #ffffff;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.app-tools-button:hover,
.app-tools-button[aria-expanded="true"] {
    border-color: #bfdbfe;
    background: #1d4ed8;
}

.app-tools-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10039;
    background: rgba(2, 6, 23, 0.45);
}

.app-tools-backdrop[hidden],
.app-tools-panel[hidden] {
    display: none;
}

.app-tools-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10040;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    width: min(320px, 100vw);
    padding: 12px 12px 16px;
    overflow: hidden;
    border-right: 1px solid rgba(148, 163, 184, 0.25);
    background: #0f1726;
    box-shadow: 16px 0 40px rgba(0, 0, 0, 0.45);
    color: #e2e8f0;
    font-size: 14px;
    animation: app-tools-in 0.16s ease-out;
}

@keyframes app-tools-in {
    from { transform: translateX(-24px); opacity: 0; }
    to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .app-tools-panel { animation: none; }
}

.app-tools-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-tools-title {
    margin: 0 auto 0 0;
    color: #f8fafc;
    font-size: 17px;
}

.app-tools-keep {
    display: none;
    align-items: center;
    gap: 5px;
    color: #94a3b8;
    font-size: 12px;
    cursor: pointer;
}

@media (min-width: 1280px) {
    .app-tools-keep { display: inline-flex; }
}

.app-tools-close {
    width: 32px;
    height: 32px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 8px;
    background: transparent;
    color: #e2e8f0;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.app-tools-intro {
    margin: 6px 0 10px;
    color: #94a3b8;
    font-size: 12px;
}

.app-tools-search-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.app-tools-search {
    box-sizing: border-box;
    width: 100%;
    min-height: 38px;
    margin-bottom: 8px;
    padding: 0 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 8px;
    background: #0b1220;
    color: #f8fafc;
    font: inherit;
}

.app-tools-search:focus {
    outline: 2px solid rgba(96, 165, 250, 0.7);
    outline-offset: 1px;
}

.app-tools-list {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.app-tools-group[hidden],
.app-tools-list li[hidden] {
    display: none;
}

.app-tools-heading {
    margin: 12px 4px 4px;
    color: #93c5fd;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.app-tools-group ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-tools-link {
    display: block;
    padding: 8px 10px;
    border-radius: 6px;
    color: #e2e8f0 !important;
    text-decoration: none;
}

/* Hover is a faint tint; the current page is a solid highlight with an accent bar. */
.app-tools-link:hover,
.app-tools-child-link:hover {
    background: rgba(148, 163, 184, 0.12);
}

.app-tools-link.is-current,
.app-tools-child-link.is-current {
    background: #1d4ed8;
    box-shadow: inset 4px 0 0 #93c5fd;
    color: #ffffff !important;
    font-weight: 700;
}

.app-tools-link:focus-visible,
.app-tools-child-link:focus-visible,
.app-tools-expand:focus-visible,
.app-tools-close:focus-visible,
.app-tools-keep input:focus-visible {
    outline: 2px solid #bfdbfe;
    outline-offset: -2px;
}

.app-tools-here {
    margin: 0 4px 8px;
    color: #cbd5e1;
    font-size: 12px;
    font-weight: 600;
}

.app-tools-here[hidden] { display: none; }

.app-tools-empty {
    margin: 12px 4px;
    color: #94a3b8;
}

/* Phones: a full-height, full-width drawer. */
@media (max-width: 767px) {
    .app-tools-panel {
        width: 100vw;
        border-right: 0;
    }

    /* Keep the word: an icon alone looked like a second Menu. */
    .app-tools-button {
        margin-right: 0;
        padding: 0 10px;
    }
}

/* Phones: "Go to" floats while the header is scrolled away (owner, 20 Oct 2026: "the go to tab
   needs to float"). app_tools.js sets body.app-tools-floating; the same button is pinned at the
   top left, compact, with its word kept. Ask ICF Assistant sits bottom right, so nothing is
   covered; where the step row is pinned (641-760px) it makes room on its left. */
@media (max-width: 760px) {
    /* The header's blur makes it the containing block for fixed children; it is off
       screen while the button floats, so it drops the blur then. */
    body.app-tools-floating .app-header {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        filter: none;
        transform: none;
        /* The button can only rise as high as the header's own layer: above the pinned steps. */
        z-index: 950;
    }

    body.app-tools-floating .app-header .app-tools-button {
        position: fixed;
        top: 8px;
        left: 8px;
        z-index: 950;
        min-height: 32px;
        padding: 0 9px;
        font-size: 13px;
        box-shadow: 0 6px 18px rgba(2, 6, 23, 0.45);
    }
}

@media (min-width: 641px) and (max-width: 760px) {
    body.app-tools-floating .ag-stage-nav-row {
        padding-left: 96px;
    }
}

/* ---- Breadcrumb on Tools pages (navigation option B) ------------------ */
/* One quiet line: "Tools › <group> › <page>". "Tools" reopens the panel. */
.tools-breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 8px 16px 0;
    color: #94a3b8;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
}

.tools-breadcrumb-root {
    padding: 0;
    border: 0;
    background: none;
    color: #93c5fd;
    font: inherit;
    cursor: pointer;
}

.tools-breadcrumb-root:hover,
.tools-breadcrumb-root:focus-visible {
    text-decoration: underline;
}

.tools-breadcrumb-sep {
    color: #64748b;
}

.tools-breadcrumb-page {
    color: #e2e8f0;
}

/* The existing assistant is the question destination for Go to. */
.app-tools-actions { display: flex; gap: 8px; padding: 0 16px 8px; flex-wrap: wrap; }
.app-tools-actions button { width: auto; border: 1px solid #475569; background: #17263e; font: inherit; cursor: pointer; }
#app-tools-suggestions { padding: 0 16px; }
#app-tools-suggestions .app-tools-link { display: block; }
#app-tools-status { margin: 4px 16px 12px; }

.app-tools-actions button[hidden], #app-tools-status[hidden], #app-tools-suggestions[hidden] { display: none; }

.app-tools-row { display: flex; align-items: stretch; }
.app-tools-row > .app-tools-link { flex: 1; min-width: 0; }
.app-tools-expand { flex: 0 0 38px; border: 0; border-radius: 6px; background: transparent; color: #93c5fd; cursor: pointer; font-size: 24px; transition: transform 0.15s ease; }
.app-tools-expand:hover { background: rgba(148, 163, 184, 0.12); }
.app-tools-expand[aria-expanded="true"] { transform: rotate(90deg); }
.app-tools-list .app-tools-children { margin: 0 0 8px 14px; padding-left: 9px; overflow: hidden; border-left: 2px solid #334a69; transition: height 0.15s ease; }
.app-tools-children[hidden] { display: none; }
.app-tools-child-link { display: block; padding: 9px 10px; border-radius: 6px; color: #cbd5e1; text-decoration: none; font-size: 13px; }
.app-tools-child-link:hover { color: white; }

@media (prefers-reduced-motion: reduce) {
    .app-tools-expand,
    .app-tools-list .app-tools-children { transition: none; }
}
