/* App additions on top of base.css (copied from the v2 Early Exercise Boundary Visualizer). */

.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: 1679px) and (min-height: 501px), (min-width: 761px) and (max-width: 1679px) 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%;
    }
}


/* ── Dividend editor ───────────────────────────────────────────────────────── */
.dividend-field {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    flex-basis: 100%;
    order: 10;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.dividend-legend {
    float: left;   /* keeps the legend inside the flex row */
    margin-right: 4px;
    padding: 0;
    white-space: nowrap;
}

.dividend-unit {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
    opacity: 0.75;
}

.dividend-list {
    display: contents;
}

.dividend-row {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 2px 2px 8px;
    border: 1px solid rgba(255, 122, 217, 0.35);
    border-radius: 6px;
    background: rgba(255, 122, 217, 0.05);
}

.dividend-index {
    color: #ff7ad9;
    font: 700 10px/1 "Roboto Mono", monospace;
}

.dividend-row input {
    /* 8 monospace characters ("$ amount", "0.3077") plus padding and border; one spare
       character because browsers round the content box down to whole pixels. */
    width: calc(9ch + 14px);
    min-height: 28px;
    padding: 2px 6px;
    border: 1px solid rgba(59, 73, 75, 0.8);
    border-radius: 2px;
    background: #0d1515;
    color: #dce4e5;
    font: 500 13px/1 "Roboto Mono", monospace;
    outline: none;
}

.dividend-row input:focus {
    border-color: #ff7ad9;
    box-shadow: 0 0 10px rgba(255, 122, 217, 0.25);
}

.dividend-row input[aria-invalid="true"] {
    border-color: #ffb4ab;
}

.dividend-remove,
.dividend-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    background: transparent;
    color: #b9cacb;
    cursor: pointer;
}

.dividend-remove {
    width: 26px;
    height: 26px;
    border-radius: 4px;
}

.dividend-remove .material-symbols-outlined,
.dividend-add .material-symbols-outlined {
    font-size: 16px;
}

.dividend-remove:hover {
    color: #ffb4ab;
    background: rgba(255, 180, 171, 0.08);
}

.dividend-add {
    gap: 4px;
    min-height: 30px;
    padding: 0 10px;
    border-color: rgba(255, 122, 217, 0.55);
    border-radius: 2px;
    color: #ff7ad9;
}

.dividend-add:hover {
    background: rgba(255, 122, 217, 0.1);
}

/* Full: still clickable so the 13th dividend is blocked with a message, not ignored. */
.dividend-add.is-full {
    opacity: 0.45;
}

.dividend-count {
    font-family: "Roboto Mono", monospace;
    opacity: 0.8;
}

.dividend-help {
    flex-basis: 100%;
    margin: 0;
    color: #849495;
    font-size: 11px;
    line-height: 1.4;
}

.legend-dividend {
    width: 0;
    height: 12px;
    border-left: 2px dashed #ff7ad9;
}

/* Mobile-only row summary (see the mobile block below). */
.dividend-summary {
    display: none;
}

@media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
    /* The sheet is taller with the dividend editor; keep the tree from showing through
       (the Tailwind /70 background utility would otherwise win). */
    #parameter-panel {
        background-color: #080f10;
    }

    /* Fill in dividends before reaching CSV / CALCULATE. */
    #pricing-form .form-actions {
        order: 6;
    }

    .dividend-field {
        order: 5;
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .dividend-legend {
        float: none;
    }

    .dividend-list {
        display: grid;
        gap: 8px;
    }

    /* Each dividend is a tappable summary; editing happens in #dividend-dialog. */
    .dividend-row {
        display: grid;
        grid-template-columns: 28px minmax(0, 1fr);
        gap: 6px;
        padding: 0 0 0 10px;
    }

    .dividend-row input,
    .dividend-row .dividend-remove {
        display: none;
    }

    .dividend-summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        min-height: 44px;
        padding: 0 12px 0 4px;
        border: 0;
        background: transparent;
        color: #dce4e5;
        font: 500 15px/1.2 "Roboto Mono", monospace;
        text-align: left;
        cursor: pointer;
    }

    .dividend-summary .material-symbols-outlined {
        color: #ff7ad9;
        font-size: 18px;
    }

    .dividend-row.is-invalid {
        border-color: #ffb4ab;
    }

    .dividend-add {
        min-height: 44px;
    }
}

/* ── Mobile dividend dialog (opened only in the mobile layout) ─────────────── */
.dividend-dialog {
    position: fixed;
    inset: 0;
    z-index: 90;   /* above the parameter sheet (80) */
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 18vh 16px 16px;   /* stays above the on-screen keyboard */
    background: rgba(0, 0, 0, 0.6);
}

.dividend-dialog[hidden] {
    display: none;
}

.dividend-dialog-card {
    display: grid;
    gap: 12px;
    width: min(100%, 360px);
    padding: 16px;
    border: 1px solid rgba(255, 122, 217, 0.55);
    border-radius: 8px;
    background: #0d1515;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.dividend-dialog-title {
    margin: 0;
    color: #ff7ad9;
}

.dividend-dialog-field {
    display: grid;
    gap: 4px;
    color: #b9cacb;
    font-size: 12px;
}

.dividend-dialog-field input {
    min-height: 44px;
    padding: 0 10px;
    border: 1px solid rgba(59, 73, 75, 0.8);
    border-radius: 2px;
    background: #080f10;
    color: #dce4e5;
    font: 500 16px/1 "Roboto Mono", monospace;   /* no iOS zoom on focus */
    outline: none;
}

.dividend-dialog-field input:focus {
    border-color: #ff7ad9;
    box-shadow: 0 0 10px rgba(255, 122, 217, 0.25);
}

.dividend-dialog-field input[aria-invalid="true"] {
    border-color: #ffb4ab;
}

.dividend-dialog-error {
    margin: 0;
    color: #ffb4ab;
    font-size: 12px;
    line-height: 1.4;
}

.dividend-dialog-actions {
    display: flex;
    gap: 8px;
}

.dividend-dialog-btn {
    flex: 1;
    min-height: 44px;
    border: 1px solid rgba(59, 73, 75, 0.8);
    border-radius: 2px;
    background: transparent;
    color: #dce4e5;
    font: 700 13px/1 "Roboto Mono", monospace;
    text-transform: uppercase;
    cursor: pointer;
}

.dividend-dialog-btn.is-delete {
    border-color: rgba(255, 180, 171, 0.5);
    color: #ffb4ab;
}

.dividend-dialog-btn.is-save {
    border-color: #ff7ad9;
    background: #ff7ad9;
    color: #080f10;
}

/* ── Ex-date node convention (Ex-div / Cum-div) ────────────────────────────── */
.exdate-toggle {
    display: inline-flex;
    padding: 2px;
    border: 1px solid rgba(59, 73, 75, 0.8);
    border-radius: 2px;
    background: #0d1515;
}

.exdate-btn {
    min-height: 28px;
    padding: 0 8px;
    border: 0;
    border-radius: 1px;
    background: transparent;
    color: #b9cacb;
    font: 700 11px/1 "Roboto Mono", monospace;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 200ms, color 200ms;
}

/* With the Ex-date toggle and the Maturity legend item the row is wider: keep it on one line. */
@media (min-width: 761px) and (min-height: 501px), (min-width: 761px) and (pointer: fine) {
    #pricing-form .legend-row {
        column-gap: 12px;
        padding-right: 16px;
    }
}

.exdate-btn:hover {
    color: #dce4e5;
}

.exdate-btn[aria-pressed="true"] {
    background: #00f0ff;
    color: #00363a;
}

.exdate-note {
    flex-basis: 100%;
    margin: 0;
    color: #ff7ad9;
    font-size: 11px;
    line-height: 1.4;
}

@media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
    .exdate-field {
        grid-column: 1 / -1;
    }

    .exdate-toggle {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .exdate-btn {
        min-height: 40px;
        font-size: 13px;
    }
}
