/* Trade entry prototype. Self-contained: the site build publishes this
 * file through its existing css project, so there is no import to wire. */

:root {
    --bg: #12161c;
    --panel: #1a2029;
    --panel-2: #212936;
    --line: #2d3748;
    --line-soft: #232c39;
    --ink: #e6ebf2;
    --ink-dim: #98a4b5;
    --ink-faint: #6b7688;
    --accent: #4da3ff;
    --accent-dim: #1f4a75;
    --ok: #3fbf7f;
    --warn: #e8b13a;
    --bad: #e2604f;
    --buy: #3fbf7f;
    --sell: #e2604f;
    --radius: 6px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 13px/1.45 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    display: block;
    padding: 0;
    align-items: unset;
}

a { color: var(--accent); }

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1500px;
    margin: 0 auto;
    padding: 16px;
    gap: 12px;
}

/* --- Structure header ---------------------------------------------- */

.struct-header {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
}

.struct-header .identity { flex: 1 1 320px; min-width: 260px; }
.struct-header h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.struct-header .sub { color: var(--ink-dim); font-size: 12px; margin-top: 2px; }

/* The structure is a trade too, so it carries a trade header in the same
 * shape as a component's. It never moves. */
.envelope-strip {
    flex: 1 1 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 24px;
    padding-top: 10px;
    border-top: 1px solid var(--line-soft);
}

.env-label {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-right: 6px;
    border-right: 1px solid var(--line-soft);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-dim);
}

.env-label .legend { font-size: 10px; text-transform: none; letter-spacing: 0; }

.env-pair { display: flex; flex-direction: column; gap: 1px; }

.env-key {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-faint);
}

.env-val { font-size: 12px; font-variant-numeric: tabular-nums; }

.badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
    border: 1px solid var(--line);
    background: var(--panel-2);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--ink-dim);
}

.chip.version { color: var(--accent); border-color: var(--accent-dim); }
.chip.mode { text-transform: none; letter-spacing: 0; }
.chip.auth-draft { color: var(--warn); border-color: #5a4620; background: #2a2214; }
.chip.auth-authorised { color: var(--ok); border-color: #24503a; background: #14261d; }
.chip.bump { animation: bump 0.5s ease-out; }

@keyframes bump {
    0% { transform: scale(1); box-shadow: 0 0 0 0 var(--accent-dim); }
    40% { transform: scale(1.14); box-shadow: 0 0 0 6px rgba(77, 163, 255, 0.16); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(77, 163, 255, 0); }
}

/* --- Buttons -------------------------------------------------------- */

button, a.btn {
    font: inherit;
    font-size: 12px;
    background: var(--panel-2);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 6px 12px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

button:hover, a.btn:hover { border-color: var(--accent-dim); background: #26303f; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #08121c; font-weight: 600; }
button.primary:hover { background: #6bb4ff; }
button.ghost, a.btn.ghost { background: transparent; }
button.danger:hover { border-color: var(--bad); color: var(--bad); }

/* --- Layout --------------------------------------------------------- */

.workspace {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) minmax(380px, 1.25fr);
    gap: 12px;
    align-items: start;
}

@media (max-width: 980px) {
    .workspace { grid-template-columns: 1fr; }
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.panel > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
}

.panel > header h2 {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-dim);
}

.panel .body { padding: 12px 14px; }

/* --- Validation banner ---------------------------------------------- */

.validation {
    border-radius: var(--radius);
    padding: 9px 12px;
    font-size: 12px;
    border: 1px solid;
    display: flex;
    gap: 8px;
    align-items: baseline;
}

.validation.ok { color: var(--ok); border-color: #24503a; background: #14261d; }
.validation.bad { color: var(--bad); border-color: #5a2a24; background: #2a1614; }
.validation .what { font-weight: 600; }

/* --- Structure tree -------------------------------------------------- */

.tree { padding: 8px; }

.node.depth-0 > .node-row {
    background: var(--panel-2);
    border-color: var(--line);
}

.node-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 9px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
}

.node-row:hover { background: #1f2733; }
.node-row.selected { border-color: var(--accent); background: #16293d; }

.node-row .twisty {
    width: 12px;
    color: var(--ink-faint);
    font-size: 10px;
    user-select: none;
    flex: none;
}

.node-row .label { flex: 1; min-width: 0; }
.node-row .label .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-row .label .meta { display: block; color: var(--ink-faint); font-size: 11px; }

.node-row .num { color: var(--ink-dim); font-variant-numeric: tabular-nums; font-size: 11px; }

.group-children { margin-left: 14px; border-left: 1px solid var(--line-soft); padding-left: 6px; }

.type-tag {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    border-radius: 3px;
    padding: 1px 5px;
    background: #24303f;
    color: var(--ink-dim);
    flex: none;
}

.side-buy { color: var(--buy); font-weight: 600; }
.side-sell { color: var(--sell); font-weight: 600; }

.tree-actions { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }

/* --- Widgets --------------------------------------------------------- */

.widget h3, .widget-head h3 { margin: 0 0 4px; font-size: 14px; }

.widget-kind {
    color: var(--ink-faint);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.widget .widget-kind { margin-bottom: 12px; }

/* The component's name and the group it sits in. The group is a display
 * concept, not a term, so it lives here and not in the form below. */
.widget-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.head-group { display: flex; align-items: center; gap: 6px; }
.head-group label { font-size: 11px; color: var(--ink-faint); }

.head-group select {
    font: inherit;
    font-size: 12px;
    background: #151b24;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 4px 6px;
}

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }

.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 11px; color: var(--ink-dim); }
.field input, .field select {
    font: inherit;
    font-size: 12px;
    background: #151b24;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 5px 7px;
    width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field input:read-only, .field input[readonly] { color: var(--ink-dim); background: #11161d; }

.field-note { font-size: 11px; color: var(--ink-faint); }

.subhead {
    margin: 16px 0 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-dim);
    border-top: 1px solid var(--line-soft);
    padding-top: 12px;
}

table.legs, table.schedule {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

table.legs th, table.schedule th {
    text-align: left;
    font-weight: 600;
    color: var(--ink-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 5px 8px;
    border-bottom: 1px solid var(--line);
}

table.legs td, table.schedule td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--line-soft);
    font-variant-numeric: tabular-nums;
}

table.legs tr:last-child td, table.schedule tr:last-child td { border-bottom: none; }

.generic-note {
    border-left: 2px solid var(--warn);
    padding: 8px 12px;
    background: #221d12;
    color: var(--ink-dim);
    font-size: 12px;
    border-radius: 0 var(--radius) var(--radius) 0;
}

/* --- The trade header -------------------------------------------------
 *
 * Reference data, not the instrument. It sits above the economics in a
 * fixed place, and its five field groups are the ones ores.trading
 * composes a trade from. */

.envelope-block {
    padding: 10px 14px 12px;
    background: #151b24;
    border-bottom: 1px solid var(--line);
}

.envelope-title {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-dim);
}

.envelope-title .legend { margin: 0; }

.env-board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px 18px;
}

.env-group h4 {
    margin: 0 0 5px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
}

.env-group .env-pair {
    flex-direction: row;
    justify-content: space-between;
    gap: 10px;
    padding: 1px 0;
}

.env-group .env-key { font-size: 11px; text-transform: none; letter-spacing: 0; }
.env-group .env-val { font-size: 11px; text-align: right; }

/* --- Economics tabs --------------------------------------------------- */

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 8px 14px 0;
    background: var(--panel-2);
    border-bottom: 1px solid var(--line);
}

.tabs button {
    margin-bottom: -1px;
    padding: 6px 12px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    background: transparent;
    color: var(--ink-dim);
}

.tabs button:hover { background: #26303f; border-color: var(--line); border-bottom: none; }

.tabs button.on {
    background: var(--panel);
    border-color: var(--line);
    border-bottom: 1px solid var(--panel);
    color: var(--ink);
    font-weight: 600;
}

/* --- Premium sub-leg -------------------------------------------------- */

.subleg {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.subleg-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
}

.subleg-head strong { font-variant-numeric: tabular-nums; }
.subleg .grow { flex: 1; min-width: 0; color: var(--ink-dim); }
.subleg .field-grid { padding: 12px; }
.subleg .legend { margin: 0; padding: 0 12px 12px; }

/* --- Audit drawer ----------------------------------------------------- */

.drawer {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.drawer > summary {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 14px;
    background: var(--panel-2);
    cursor: pointer;
    list-style: none;
}

.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary::before { content: "▸"; font-size: 10px; color: var(--ink-faint); }
.drawer[open] > summary::before { content: "▾"; }
.drawer > summary .legend { margin: 0; }

.summary-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-dim);
}

.drawer .audit-list { padding: 10px 14px; }

/* --- NPV strip -------------------------------------------------------- */

.npv-strip {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px;
}

.npv-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.npv-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-dim); }
.provenance { display: flex; flex-wrap: wrap; gap: 18px; flex: 1; }
.provenance div { font-size: 11px; color: var(--ink-faint); }
.provenance strong { display: block; color: var(--ink-dim); font-weight: 500; }

/* --- Audit ------------------------------------------------------------ */

.audit-list { list-style: none; margin: 0; padding: 0; font-size: 12px; max-height: 220px; overflow-y: auto; }
.audit-list li { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line-soft); }
.audit-list li:last-child { border-bottom: none; }
.audit-list .when { color: var(--ink-faint); font-variant-numeric: tabular-nums; flex: none; }

/* --- Dialogs ---------------------------------------------------------- */

dialog {
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0;
    width: min(720px, 92vw);
    max-height: 84vh;
}

dialog::backdrop { background: rgba(6, 9, 13, 0.66); }

dialog header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
}

dialog header h2 { margin: 0; font-size: 14px; }
dialog .dialog-body { padding: 14px 16px; overflow-y: auto; max-height: 62vh; }
dialog footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.picker-class { margin-bottom: 16px; }
.picker-class h4 {
    margin: 0 0 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
}

.picker-grid { display: flex; flex-wrap: wrap; gap: 6px; }

.pick {
    border: 1px solid var(--line);
    background: var(--panel-2);
    border-radius: var(--radius);
    padding: 7px 11px;
    cursor: pointer;
    text-align: left;
    min-width: 150px;
}

.pick:hover { border-color: var(--accent); background: #22303f; }
.pick .pick-name { display: block; font-size: 12px; font-weight: 600; }
.pick .pick-meta { display: block; font-size: 10px; color: var(--ink-faint); margin-top: 2px; }
.pick .pick-meta.specialised { color: var(--accent); }

.candidate-list { display: flex; flex-direction: column; gap: 6px; }
.candidate {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.candidate.selected { border-color: var(--accent); background: #16293d; }
.candidate .grow { flex: 1; min-width: 0; }

/* --- Mode switch ------------------------------------------------------ */

.mode-switch { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.mode-switch button { border: none; border-radius: 0; background: transparent; padding: 5px 11px; color: var(--ink-dim); }
.mode-switch button.on { background: var(--accent); color: #08121c; font-weight: 600; }

/* --- Pricing screen --------------------------------------------------- */

.ticker {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    color: var(--ink-dim);
}

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.paused { background: var(--ink-faint); }
.dot.tick { animation: pulse 0.45s ease-out; }

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(63, 191, 127, 0.5); }
    100% { box-shadow: 0 0 0 7px rgba(63, 191, 127, 0); }
}

.price-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.price-table th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--ink-dim); padding: 5px 8px; border-bottom: 1px solid var(--line);
}
.price-table td { padding: 5px 8px; border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; }
.price-table tr.leg-mode-row td:first-child { padding-left: 22px; color: var(--ink-dim); }
.price-table td.num, .price-table th.num { text-align: right; }

.tweak-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 12px; }
.tweak { display: flex; flex-direction: column; gap: 3px; }
.tweak label { font-size: 11px; color: var(--ink-dim); display: flex; justify-content: space-between; }
.tweak input[type=range] { width: 100%; accent-color: var(--accent); }

.npv-readout {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 14px 16px;
    background: var(--panel-2);
    border-radius: var(--radius);
    border: 1px solid var(--line);
}
.npv-readout .big { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta-up { color: var(--ok); font-size: 12px; font-variant-numeric: tabular-nums; }
.delta-down { color: var(--bad); font-size: 12px; font-variant-numeric: tabular-nums; }

.book-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.handoff-note {
    font-size: 12px;
    color: var(--ink-dim);
}

.legend { font-size: 11px; color: var(--ink-faint); margin-top: 8px; }
.legend code { color: var(--ink-dim); }
