/* ─── IBKR Execution Panel — Dark Theme v3 ─── */

:root {
    --bg-primary: #131722;
    --bg-secondary: #1e222d;
    --bg-tertiary: #2a2e39;
    --bg-hover: #363a45;
    --bg-input: #1a1e2b;
    --border: #2a2e39;
    --border-focus: #4a90d9;
    --text-primary: #d1d4dc;
    --text-secondary: #787b86;
    --text-muted: #4a4e59;
    --text-bright: #e0e3eb;
    --green: #26a69a;
    --green-bg: rgba(38, 166, 154, 0.12);
    --red: #ef5350;
    --red-bg: rgba(239, 83, 80, 0.12);
    --blue: #4a90d9;
    --blue-bg: rgba(74, 144, 217, 0.12);
    --yellow: #f0b90b;
    --yellow-bg: rgba(240, 185, 11, 0.12);
    --header-height: 52px;
    --radius: 4px;
    --radius-lg: 6px;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.4;
}

/* ─── Header ─────────────────────────────────────────────── */

#app-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-left h1 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--text-bright);
}

.header-tag {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--blue);
    background: var(--blue-bg);
    padding: 2px 8px;
    border-radius: 3px;
}

.header-center {
    display: flex;
    align-items: center;
    gap: 12px;
}

.account-select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 5px 28px 5px 10px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23787b86'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    outline: none;
}

.account-select:focus { border-color: var(--border-focus); }

.header-right {
    display: flex;
    gap: 20px;
}

.account-block {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.account-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.account-value {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-bright);
}

/* Warning: AvailableFunds bajo (< 10% NetLiq) */
.account-value-warning {
    color: var(--red) !important;
    font-weight: 700;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.status-badge.connected { background: var(--green-bg); color: var(--green); }
.status-badge.disconnected { background: var(--red-bg); color: var(--red); }

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.status-badge.connected .status-dot { animation: pulse 2s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ─── Main Layout ────────────────────────────────────────── */

#app-main {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 1px;
    background: var(--border);
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

#panel-left, #panel-right {
    background: var(--bg-primary);
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ─── Panel Cards ────────────────────────────────────────── */

.panel-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.card-header h2 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.header-hint {
    font-size: 10px;
    color: var(--text-muted);
    font-style: italic;
    margin-left: auto;
}

.card-body { padding: 12px 14px; }

.badge {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-primary);
    color: var(--text-secondary);
    padding: 1px 8px;
    border-radius: 10px;
}

/* ─── Tables ─────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; }

th {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 6px 8px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th:first-child { text-align: left; }

td {
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 7px 8px;
    text-align: right;
    border-bottom: 1px solid rgba(42, 46, 57, 0.5);
    white-space: nowrap;
}

td:first-child {
    text-align: left;
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--text-bright);
}

tr:hover { background: var(--bg-hover); }

/* Fila de posición clicable */
.position-row {
    cursor: pointer;
    transition: background 0.1s;
}

.position-row:hover {
    background: var(--bg-hover);
}

.empty-row td {
    text-align: center;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-style: italic;
    padding: 16px;
}

.empty-row:hover { background: transparent; }

.pnl-positive { color: var(--green); }
.pnl-negative { color: var(--red); }
.pnl-muted { color: var(--text-muted); }

.account-tag {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    font-family: var(--font-mono);
    background: var(--bg-primary);
    color: var(--text-muted);
}

/* ─── Watchlist ──────────────────────────────────────────── */

.watchlist-add {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.watchlist-add input {
    width: 110px;
    font-size: 12px;
    padding: 4px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font-mono);
    text-transform: uppercase;
    outline: none;
}

.watchlist-add input:focus { border-color: var(--border-focus); }

.watchlist-body { padding: 0; }
.watchlist-body table { margin: 0; }

.btn-remove-watch {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    padding: 2px 6px;
    opacity: 0.5;
}

.btn-remove-watch:hover { opacity: 1; color: var(--red); }

.watch-symbol {
    cursor: pointer;
}

.watch-symbol:hover {
    color: var(--blue);
}

/* ─── Forms ──────────────────────────────────────────────── */

.form-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    align-items: flex-end;
}

.form-row.triple { gap: 6px; }

.input-group {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.input-group label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.input-hint {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
    font-style: italic;
}

input[type="text"],
input[type="number"],
select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 8px 10px;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}

input:focus, select:focus { border-color: var(--border-focus); }

.input-symbol {
    text-transform: uppercase;
    font-weight: 600;
    max-width: 120px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23787b86'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

.select-sm { max-width: 120px; }

/* ─── Buttons ────────────────────────────────────────────── */

.btn {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #5a9de5; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }

.btn-execute {
    background: var(--green);
    color: #fff;
    width: 100%;
    padding: 10px;
    font-size: 13px;
    margin-top: 4px;
}

.btn-execute:hover:not(:disabled) { background: #2eb8aa; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #f06e6b; }
.btn-sm { padding: 4px 10px; font-size: 11px; }

.btn-cancel-order {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    opacity: 0.6;
}

.btn-cancel-order:hover { opacity: 1; }

.btn-close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 10px;
}

.btn-close-modal:hover { color: var(--text-primary); }

/* ─── Tabs ───────────────────────────────────────────────── */

.tab-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.tab-btn:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Quote Display ──────────────────────────────────────── */

.quote-input-row { display: flex; gap: 8px; }

.quote-display {
    margin-top: 12px;
    padding: 10px;
    background: var(--bg-primary);
    border-radius: var(--radius);
}

.quote-main {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 6px;
}

.quote-symbol { font-size: 16px; font-weight: 700; color: var(--text-bright); }
.quote-price { font-family: var(--font-mono); font-size: 20px; font-weight: 700; color: var(--text-bright); }

.quote-change {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
}

.quote-details {
    display: flex;
    gap: 14px;
    font-size: 12px;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.quote-details b { font-family: var(--font-mono); color: var(--text-primary); }

/* ─── Risk Calculator ────────────────────────────────────── */

.risk-calc {
    display: flex;
    gap: 16px;
    padding: 8px 10px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.risk-calc b { font-family: var(--font-mono); color: var(--yellow); }

/* ─── Option Chain ───────────────────────────────────────── */

.chain-header-calls { text-align: center !important; color: var(--green) !important; }
.chain-header-puts { text-align: center !important; color: var(--red) !important; }
.chain-header-strike { text-align: center !important; color: var(--yellow) !important; background: var(--yellow-bg); }

#chain-table td { font-size: 11px; padding: 4px 6px; }

.chain-strike-cell {
    text-align: center !important;
    font-weight: 700;
    color: var(--yellow) !important;
    background: var(--yellow-bg);
}

.chain-itm { background: rgba(255, 255, 255, 0.02); }
#chain-table-container { max-height: 400px; overflow-y: auto; }

/* ─── Toasts ─────────────────────────────────────────────── */

#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 500;
    animation: toast-in 0.3s ease;
    max-width: 360px;
    border-left: 3px solid;
}

.toast-success { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.toast-error { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.toast-info { background: var(--blue-bg); color: var(--blue); border-color: var(--blue); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Modal ──────────────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    min-width: 360px;
    max-width: 480px;
}

.modal-content h3 { font-size: 14px; margin-bottom: 12px; color: var(--text-bright); }

#confirm-body { font-size: 13px; color: var(--text-primary); margin-bottom: 16px; line-height: 1.6; }

#confirm-body .confirm-line {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}

#confirm-body .confirm-label { color: var(--text-secondary); }
#confirm-body .confirm-value { font-family: var(--font-mono); font-weight: 600; }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ─── Position Modal ─────────────────────────────────────── */

.modal-position {
    min-width: 440px;
    max-width: 540px;
    padding: 0;
}

.position-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.position-modal-header h3 {
    margin: 0;
    font-size: 14px;
    color: var(--text-bright);
}

.warning-banner {
    margin: 12px 18px 0 18px;
    padding: 10px 12px;
    background: var(--yellow-bg);
    border-left: 3px solid var(--yellow);
    border-radius: var(--radius);
    font-size: 11.5px;
    color: var(--text-primary);
    line-height: 1.5;
}

.warning-banner strong { color: var(--yellow); }
.warning-banner b { color: var(--text-bright); }

.position-detail {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 20px;
}

.detail-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    border-bottom: 1px solid rgba(42, 46, 57, 0.4);
    font-size: 12px;
}

.detail-line-highlight {
    grid-column: 1 / -1;
    margin-top: 4px;
    padding-top: 10px;
    border-bottom: none;
    border-top: 1px solid var(--border);
    font-size: 14px;
}

.detail-line-highlight .detail-label {
    font-weight: 600;
    color: var(--text-primary);
}

.detail-line-highlight .detail-value {
    font-size: 16px;
    font-weight: 700;
}

.detail-label {
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.detail-value {
    font-family: var(--font-mono);
    color: var(--text-bright);
    font-weight: 600;
}

.loader-dot {
    color: var(--text-muted);
    font-style: italic;
    animation: pulse 1.5s infinite;
}

.position-actions {
    padding: 14px 18px 18px 18px;
}

.position-actions h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.close-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.close-tab-btn {
    padding: 8px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.close-tab-btn:hover { color: var(--text-primary); }
.close-tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

.close-tab-content { display: none; }
.close-tab-content.active { display: block; }

.close-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    line-height: 1.5;
}

/* ─── Utility ────────────────────────────────────────────── */

.hidden { display: none !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }

@media (max-width: 900px) {
    #app-main { grid-template-columns: 1fr; overflow-y: auto; height: auto; }
    #panel-left, #panel-right { overflow: visible; }
    .header-right { display: none; }
    .modal-position { min-width: 90vw; max-width: 95vw; }
    .detail-grid { grid-template-columns: 1fr; }
}
