/* =============================================================================
   Trade Modal — Unified BUY + CLOSE equity order component
   Extends .upgrade-modal-overlay / .upgrade-modal from upgrade-modal.css
   New .tm-* classes handle 2-column layout and CLOSE-mode specifics.
   All colors use design system tokens from 1-foundation.css.
   ============================================================================= */

/* ── Modal sizing: wider to fit 2-column layout ────────────────────────────── */
#trade-modal-overlay .upgrade-modal {
    max-width: 640px;
    width: 640px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}

/* ── Dense header (CLOSE mode: symbol + strategy + strikes + DTE + P&L) ─────── */
.tm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.tm-header-left {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}
.tm-symbol {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}
.tm-mode-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.tm-mode-badge.buy    { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.tm-mode-badge.sell   { background: rgba(239,68,68,0.15);  color: var(--accent-red); }
.tm-mode-badge.close  { background: rgba(245,158,11,0.12); color: var(--accent-yellow); }

/* Dense meta line: strategy · strike · DTE · P&L */
.tm-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tm-meta .dot { margin: 0 5px; color: var(--text-muted); }
.tm-meta .pnl-positive { color: var(--accent-green); }
.tm-meta .pnl-negative { color: var(--accent-red); }
.tm-price-display {
    font-size: 0.88rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ── 2-column body layout ──────────────────────────────────────────────────── */
.tm-two-col {
    display: grid;
    grid-template-columns: 55% 1fr;
    gap: 14px;
    margin-top: 4px;
}
.tm-col-left  { min-width: 0; overflow: hidden; }
.tm-col-right { min-width: 0; }

/* Collapse to 1 column on narrow viewports */
@media (max-width: 560px) {
    #trade-modal-overlay .upgrade-modal { width: 96vw; max-width: 96vw; }
    .tm-two-col { grid-template-columns: 1fr; }
}

/* ── Source context tag (BUY mode — shown when invoked from a module) ────────── */
.tm-source-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(99,102,241,0.08);
    border: 1px solid rgba(99,102,241,0.20);
    border-radius: 6px;
    padding: 3px 9px;
    font-size: 0.75rem;
    color: var(--accent-indigo, #818cf8);
    margin-bottom: 10px;
}

/* ── Impact panel (right column in INPUT state) ────────────────────────────── */
.tm-impact-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 16px;
    height: 100%;
    box-sizing: border-box;
}
.tm-impact-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.tm-impact-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.83rem;
}
.tm-impact-label { color: var(--text-secondary); }
.tm-impact-value { color: var(--text-primary); font-weight: 500; }
.tm-impact-value.positive { color: var(--accent-green); }
.tm-impact-value.negative { color: var(--accent-red); }
.tm-impact-value.warning  { color: var(--accent-yellow); }

/* ── CLOSE mode: impact grid (4-cell 2×2) ─────────────────────────────────── */
.tm-release-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.tm-release-cell {
    background: var(--bg-tertiary, var(--bg-secondary));
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
}
.tm-release-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.tm-release-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}
.tm-release-value.positive { color: var(--accent-green); }
.tm-release-value.negative { color: var(--accent-red); }

/* ── Order console (left column) ──────────────────────────────────────────── */
.tm-order-type-toggle {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}
.tm-order-type-toggle button {
    flex: 1;
    padding: 6px 0;
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}
.tm-order-type-toggle button.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}

/* Price stepper row */
.tm-price-row {
    margin-bottom: 10px;
    max-width: 100%;
    box-sizing: border-box;
}
.tm-price-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
/* ── Manual mode banner ──────────────────────────────────────────────────── */
.tm-manual-banner {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: 6px;
    color: var(--accent-yellow);
    font-size: 0.78rem;
    padding: 8px 12px;
    margin-bottom: 12px;
}

.tm-price-stepper {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    max-width: 100%;
    box-sizing: border-box;
}
.tm-stepper-btn {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    color: #fff;
    padding: 8px 0;
    min-width: 44px;
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tm-stepper-btn:first-child { border-left: none; border-right: 1px solid var(--border-color); }
.tm-stepper-btn:last-child  { border-right: none; border-left: 1px solid var(--border-color); }
.tm-stepper-btn:hover { background: var(--accent-blue); color: #fff; }
.tm-price-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    padding: 8px 4px;
    font-family: inherit;
    outline: none;
}
.tm-price-input::-webkit-inner-spin-button,
.tm-price-input::-webkit-outer-spin-button { -webkit-appearance: none; }

/* Quick price chips */
.tm-quick-prices {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}
.tm-chip {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 5px 6px;
    font-size: 0.75rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.12s;
    font-family: inherit;
}
.tm-chip:hover { border-color: var(--accent-blue); color: var(--accent-blue); }
.tm-chip.selected {
    background: rgba(74,108,247,0.12);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    font-weight: 600;
}
.tm-chip:disabled { opacity: 0.4; pointer-events: none; }

/* Price ladder dropdown (replaces stepper + chips for CLOSE mode) */
.tm-price-ladder {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    padding: 10px 12px;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23999' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}
.tm-price-ladder:hover { border-color: var(--accent-blue); }
.tm-price-ladder:focus { border-color: var(--accent-blue); box-shadow: 0 0 0 2px rgba(74,108,247,0.25); }
.tm-price-ladder option {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    padding: 4px 8px;
}

/* Estimated cost / CTA indicator */
.tm-estimated-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 3px;
}
.tm-estimated-value {
    font-size: 1.1rem;
    font-weight: 700;
}
.tm-estimated-value.credit { color: var(--accent-green); }
.tm-estimated-value.debit  { color: var(--accent-red); }

/* ── Chain history (CLOSE mode) ────────────────────────────────────────────── */
.tm-chain-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
    width: 100%;
    text-align: left;
    font-family: inherit;
    margin-top: 10px;
    transition: border-color 0.15s;
}
.tm-chain-toggle:hover { border-color: var(--accent-blue); color: var(--text-primary); }
.tm-chain-pnl { margin-left: auto; font-weight: 600; }
.tm-chain-body {
    display: none;
    padding: 8px 12px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}
.tm-chain-body.visible { display: block; }

/* ── Fat-finger warning ────────────────────────────────────────────────────── */
.tm-fat-finger {
    display: none;
    align-items: flex-start;
    gap: 8px;
    background: rgba(245,158,11,0.08);
    border: 1px solid rgba(245,158,11,0.25);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 0.8rem;
    color: var(--accent-yellow);
    margin-top: 8px;
}

/* ── Kill switch banner ─────────────────────────────────────────────────────── */
.tm-kill-switch-banner {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: rgba(239,68,68,0.1);
    border: 1px solid var(--accent-red);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.82rem;
    color: var(--accent-red);
    margin-bottom: 12px;
    font-weight: 500;
}

/* ── Preview state ─────────────────────────────────────────────────────────── */
.tm-preview-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 12px;
}
.tm-preview-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.tm-preview-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border-color);
}
.tm-preview-row:last-child { border-bottom: none; }
.tm-preview-label { color: var(--text-secondary); }
.tm-preview-value { color: var(--text-primary); font-weight: 500; }
.tm-preview-value.positive { color: var(--accent-green); }
.tm-preview-value.negative { color: var(--accent-red); }
.tm-divider { height: 1px; background: var(--border-color); margin: 12px 0; }

/* ── Result state ──────────────────────────────────────────────────────────── */
.tm-result-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    margin: 0 auto 14px;
    font-size: 1.5rem;
}
.tm-result-icon.success { background: rgba(16,185,129,0.15); }
.tm-result-icon.error   { background: rgba(239,68,68,0.15); }
.tm-result-icon.working { background: rgba(245,158,11,0.12); }

/* ── Result status rows (CLOSE mode: order working) ──────────────────────── */
.tm-status-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    padding: 4px 0;
    color: var(--text-secondary);
}
.tm-status-row-value { color: var(--text-primary); font-weight: 500; }
.tm-status-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.5;
    text-align: center;
}
.tm-result-details {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
    margin: 10px 0;
}

/* ── CTA button variants ───────────────────────────────────────────────────── */
.tm-btn-cta {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.15s;
    margin-top: 4px;
}
.tm-btn-cta:hover { opacity: 0.88; }
.tm-btn-cta.credit { background: var(--accent-green); color: #fff; }
.tm-btn-cta.debit  { background: var(--accent-red);   color: #fff; }
.tm-btn-cta.primary { background: var(--accent-blue);  color: #fff; }
.tm-btn-cta:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Roll Instead button ────────────────────────────────────────────────────── */
.tm-btn-roll {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    padding: 8px 14px;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.tm-btn-roll:hover { border-color: var(--accent-blue); color: var(--accent-blue); }

/* ── Freshness badge row ───────────────────────────────────────────────────── */
.tm-freshness-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.tm-freshness-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.tm-freshness-live {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
}
.tm-freshness-delayed {
    background: rgba(245, 158, 11, 0.12);
    color: var(--accent-yellow);
}
.tm-freshness-stale {
    background: rgba(239, 68, 68, 0.12);
    color: var(--accent-red);
    animation: tm-stale-pulse 1.5s ease-in-out infinite;
}
@keyframes tm-stale-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}

/* Refresh button (inline next to freshness badge) */
.tm-refresh-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 1px 6px;
    cursor: pointer;
    line-height: 1;
    transition: all 0.15s;
}
.tm-refresh-btn:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    background: rgba(74, 108, 247, 0.08);
}

/* Stale / unavailable banner */
.tm-stale-banner {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.78rem;
    color: var(--accent-red);
    margin-bottom: 8px;
    font-weight: 500;
}

/* ── Footer layout ──────────────────────────────────────────────────────────── */
.tm-footer-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
