/* v2-only additions on top of /v2/base.css (v2's copy of /styles.css, which stays the v1 file). */

.calculation-status {
    max-width: 1600px;
    margin: 8px auto 0;
    color: #ffb4ab;
    font-size: 13px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

#pricing-form input[aria-invalid="true"] {
    border-color: #ffb4ab;
}

.kpi-label-short,
.boundary-toggle {
    display: none;
}

.hint-touch {
    display: none;
}

/* Top bar: title + KPI results always fully visible on desktop widths. */
@media (min-width: 761px) and (min-height: 501px), (min-width: 761px) and (pointer: fine) {
    body .app-title {
        font-size: clamp(16px, 1.55vw, 24px);
    }

    #prices-panel {
        gap: 8px;
    }

    #prices-panel .kpi-chip {
        gap: 8px;
        padding: 4px 10px;
    }
}

/* Narrow desktop: one row cannot hold title + results, so the results get their own row. */
@media (min-width: 761px) and (max-width: 1023px) and (min-height: 501px), (min-width: 761px) and (max-width: 1023px) and (pointer: fine) {
    body .app-topbar {
        height: 92px;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        gap: 6px;
    }

    body .app-main {
        padding-top: 92px;
    }

    .kpi-chip-wide .kpi-chip-label {
        display: inline;
    }
}

/* Parameter bar: one compact row on desktop/tablet widths (mobile keeps its bottom sheet). */
@media (min-width: 761px) and (min-height: 501px), (min-width: 761px) and (pointer: fine) {
    #parameter-panel {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    #pricing-form .control-field input {
        min-height: 30px;
        padding-top: 4px;
        padding-bottom: 4px;
    }

    #calculate-btn {
        min-height: 34px;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    /* One row whenever it fits; on very narrow windows the button wraps instead of overlapping. */
    #pricing-form {
        flex-wrap: wrap;
    }

    #pricing-form .control-field label {
        white-space: nowrap;
    }

    /* A field may shrink, but never below its (single-line) label. */
    #pricing-form .control-field {
        flex: 0 1 auto;
        min-width: min-content;
    }

    #pricing-form .form-actions {
        flex: 1 0 auto;
        min-width: 0;
        justify-content: flex-end;
    }
}

/* Too narrow for fields + legend + button in one row: tighten gaps and drop the legend
   (the boundary panes show the put/call colours). */
@media (min-width: 761px) and (max-width: 1439px) and (min-height: 501px), (min-width: 761px) and (max-width: 1439px) and (pointer: fine) {
    #pricing-form {
        column-gap: 12px;
    }

    #pricing-form .legend-row {
        display: none;
    }
}

/* Right-hand column: Boundary Overview on top of Boundary Detail. */
.boundary-panes {
    position: absolute;
    top: 72px;
    right: 22px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: clamp(280px, 24vw, 360px);
    max-height: calc(100% - 72px - 92px);
    overflow-y: auto;
    scrollbar-width: none;
}

/* Credit cards (advisor, developer): same text and position, lifted off the tree with a card
   backdrop (padding is offset by the left/right/bottom shift so the text stays where it was). */
@media (min-width: 761px) and (min-height: 501px), (min-width: 761px) and (pointer: fine) {
    #canvas-container .canvas-credit-left,
    #canvas-container .canvas-credit-right {
        bottom: 12px;
        padding: 10px 14px 12px;
        border: 1px solid rgba(59, 73, 75, 0.88);
        border-radius: 10px;
        background: rgba(8, 15, 16, 0.88);
        box-shadow: 0 0 22px rgba(0, 0, 0, 0.45);
        backdrop-filter: blur(6px);
    }

    #canvas-container .canvas-credit-left {
        left: 10px;
    }

    #canvas-container .canvas-credit-right {
        right: 10px;
    }
}

.boundary-panes[hidden] {
    display: none;
}

.bpane {
    flex: 0 0 auto;
    border: 1px solid rgba(59, 73, 75, 0.88);
    border-radius: 10px;
    background: rgba(8, 15, 16, 0.9);
    box-shadow: 0 0 22px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.bpane-canvas {
    display: block;
    width: 100%;
}

.bpane-canvas-overview {
    height: 200px;
    cursor: crosshair;
    touch-action: none;
}

.bpane-canvas-detail {
    height: 235px;
}

@media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
    .boundary-panes {
        top: 56px;
        right: 12px;
        width: min(270px, calc(100vw - 24px));
        gap: 8px;
        max-height: calc(100% - 56px - 80px);
    }

    .bpane-canvas-overview {
        height: 130px;
    }

    .bpane-canvas-detail {
        height: 166px;
    }
}

/* Desktop: the scale toggle sits close to the top, and the two panes share all the height
   between it and the developer card (no scrolling unless the window is very short). */
@media (min-width: 761px) and (min-height: 501px), (min-width: 761px) and (pointer: fine) {
    #canvas-container .scale-toggle {
        top: 12px;
        right: 22px;
    }

    .boundary-panes {
        top: 60px;
        bottom: 86px;
        gap: 10px;
        max-height: none;
    }

    .bpane {
        flex: 4 1 0;
        min-height: 140px;
    }

    .bpane + .bpane {
        flex-grow: 5;
        min-height: 170px;
    }

    .bpane-canvas-overview,
    .bpane-canvas-detail {
        height: 100%;
    }
}

/* Secondary "CSV" download button next to CALCULATE (outlined, same height). */
.csv-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    padding: 6px 14px;
    border: 1px solid rgba(0, 240, 255, 0.55);
    border-radius: 0.125rem;
    background: transparent;
    color: #00f0ff;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 200ms, box-shadow 200ms, opacity 200ms;
}

.csv-btn .material-symbols-outlined {
    font-size: 16px;
}

.csv-btn:hover:not(:disabled) {
    background: rgba(0, 240, 255, 0.1);
    box-shadow: 0 0 12px rgba(0, 240, 255, 0.25);
}

.csv-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

@media (min-width: 761px) and (min-height: 501px), (min-width: 761px) and (pointer: fine) {
    #pricing-form .form-actions {
        column-gap: 12px;
    }
}

@media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
    .csv-btn {
        width: 100%;
        min-height: 44px;
    }
}

@media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
    :root {
        --topbar-h: 92px;
    }

    body .app-topbar {
        height: var(--topbar-h);
    }

    body .app-main {
        padding-top: var(--topbar-h);
    }

    body .app-title {
        font-size: clamp(12px, 4vw, 15px);
    }

    #prices-panel {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        width: 100%;
        overflow: visible;
    }

    #prices-panel .kpi-chip-wide {
        display: contents;
    }

    #prices-panel .kpi-divider,
    #prices-panel .kpi-chip-wide > .kpi-chip-label,
    #prices-panel > .kpi-chip:first-child > .kpi-chip-label:not(.kpi-label-short) {
        display: none;
    }

    #prices-panel > .kpi-chip:first-child .kpi-label-short {
        display: inline;
    }

    #prices-panel > .kpi-chip:first-child,
    #prices-panel .kpi-chip-wide > div:not(.kpi-divider) {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 3px;
        min-height: 0;
        padding: 5px 8px;
        border: 1px solid #3b494b;
        border-radius: 8px;
        background: #0d1515;
        box-shadow: none;
    }

    #prices-panel .ml-2,
    #prices-panel .ml-1\.5 {
        margin-left: 0;
    }

    .boundary-toggle {
        position: absolute;
        top: 12px;
        left: 12px;
        z-index: 20;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        min-height: 36px;
        padding: 0 12px;
        border: 1px solid #3b494b;
        border-radius: 999px;
        background: #151d1e;
        color: #b9cacb;
        font: 700 10px/1 "Inter", sans-serif;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
    }

    .boundary-toggle .material-symbols-outlined {
        font-size: 16px;
    }

    body.panes-open .boundary-toggle {
        background: #00f0ff;
        color: #00363a;
    }

    body:not(.panes-open) .boundary-panes {
        display: none;
    }

    body #canvas-tooltip.is-visible {
        display: block !important;
    }

    body .parameters-fab {
        bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    }

    #canvas-container .canvas-hints {
        bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    }

    #parameter-panel {
        padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    }

    #pricing-form .form-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        width: 100%;
        flex-basis: 100%;
    }

    #pricing-form .legend-row {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        gap: 8px 14px;
        border-right: 0;
        padding-right: 0;
    }
}

@media (min-width: 761px) and (min-height: 501px) and (pointer: coarse) {
    body .hint-mouse {
        display: none;
    }

    body .hint-touch {
        display: inline;
    }
}

@media (min-width: 761px) and (max-width: 1023px) and (min-height: 501px) and (pointer: coarse) {
    body .hint-copy,
    body .hint-separator {
        display: none;
    }

    #canvas-container .canvas-hints {
        top: 12px;
        left: 12px;
        bottom: auto;
        transform: none;
        align-items: flex-start;
    }
}

@media (min-width: 761px) and (max-height: 500px) and (pointer: coarse) {
    :root {
        --topbar-h: 60px;
    }

    body .app-topbar {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 6px max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px));
    }

    body .brand-lockup {
        width: auto;
        flex: 1 1 auto;
        min-width: 0;
    }

    #prices-panel {
        width: min(440px, 55vw);
        flex: 0 0 auto;
    }

    #prices-panel > .kpi-chip:first-child,
    #prices-panel .kpi-chip-wide > div:not(.kpi-divider) {
        padding: 3px 8px;
    }

    .boundary-toggle {
        left: max(12px, env(safe-area-inset-left, 0px));
    }

    #canvas-container .scale-toggle {
        right: max(12px, env(safe-area-inset-right, 0px));
    }

    body .parameters-fab {
        right: max(14px, env(safe-area-inset-right, 0px));
    }

    #canvas-container .canvas-hints {
        left: max(14px, env(safe-area-inset-left, 0px)) !important;
    }

    .boundary-panes {
        top: 56px;
        bottom: 72px;
        right: max(12px, env(safe-area-inset-right, 0px));
        width: min(560px, calc(100vw - 24px));
        max-height: none;
        flex-direction: row;
    }

    .bpane {
        flex: 1 1 0;
        min-height: 0;
    }

    .bpane-canvas-overview,
    .bpane-canvas-detail {
        height: 100%;
    }
}

