:root,
html[data-theme="dark"] {
    --bg-top: #0f151b;
    --bg-bottom: #141c24;
    --panel: rgba(20, 29, 38, 0.88);
    --panel-soft: rgba(26, 37, 48, 0.92);
    --panel-border: rgba(150, 181, 171, 0.14);
    --ink: #eaf2ee;
    --muted: #96aaa6;
    --accent: #4ec9a6;
    --accent-strong: #8be5c7;
    --warm: #e3a65d;
    --danger: #f07b74;
    --shadow: 0 22px 48px rgba(0, 0, 0, 0.32);
    --radius: 22px;
    --button-primary-bg: #eef7f3;
    --button-primary-text: #102923;
    --button-secondary-bg: rgba(222, 232, 227, 0.14);
    --button-secondary-border: rgba(222, 232, 227, 0.24);
    --button-secondary-text: #f4fbf8;
    --button-ghost-bg: rgba(78, 201, 166, 0.18);
    --button-ghost-text: #c9fff0;
    --stat-bg: rgba(255, 255, 255, 0.04);
    --table-border: rgba(150, 181, 171, 0.1);
    --grid-line: rgba(234, 242, 238, 0.05);
}

html[data-theme="light"] {
    --bg-top: #f8f2e8;
    --bg-bottom: #eef3ef;
    --panel: rgba(255, 252, 247, 0.88);
    --panel-soft: rgba(255, 255, 255, 0.82);
    --panel-border: rgba(40, 63, 54, 0.14);
    --ink: #1f312d;
    --muted: #677873;
    --accent: #0c6b58;
    --accent-strong: #095446;
    --warm: #c07f3d;
    --danger: #b0483b;
    --shadow: 0 18px 45px rgba(37, 53, 49, 0.12);
    --radius: 22px;
    --button-primary-bg: #1f312d;
    --button-primary-text: #f7f3ed;
    --button-secondary-bg: rgba(18, 41, 36, 0.08);
    --button-secondary-border: rgba(18, 41, 36, 0.14);
    --button-secondary-text: #1f312d;
    --button-ghost-bg: rgba(12, 107, 88, 0.1);
    --button-ghost-text: #095446;
    --stat-bg: rgba(255, 255, 255, 0.62);
    --table-border: rgba(40, 63, 54, 0.1);
    --grid-line: rgba(31, 49, 45, 0.04);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(192, 127, 61, 0.18), transparent 28%),
        radial-gradient(circle at right 18%, rgba(12, 107, 88, 0.14), transparent 24%),
        linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 24px 24px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent 85%);
}

.shell {
    width: min(1500px, calc(100vw - 40px));
    margin: 0 auto;
    padding: 32px 0 40px;
}

.hero,
.main-grid,
.summary-grid {
    margin-bottom: 24px;
}

.hero {
    display: grid;
    grid-template-columns: 1.7fr 1fr;
    gap: 24px;
    align-items: stretch;
}

.hero-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}

.eyebrow {
    margin: 0 0 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--warm);
}

h1,
h2,
h3 {
    margin: 0;
    font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
    font-weight: 700;
}

h1 {
    font-size: clamp(2.2rem, 4vw, 4.2rem);
    line-height: 0.96;
    max-width: 12ch;
}

.subtitle {
    max-width: 62ch;
    color: var(--muted);
    font-size: 1.02rem;
    line-height: 1.7;
}

.card,
.panel {
    backdrop-filter: blur(10px);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card {
    padding: 22px;
}

.panel {
    padding: 24px;
}

.global-controls {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background:
        linear-gradient(140deg, rgba(12, 107, 88, 0.92), rgba(22, 76, 66, 0.92)),
        linear-gradient(180deg, #ffffff, #ffffff);
    color: #f5fbf8;
}

.control-label,
.helper {
    margin: 0;
    color: inherit;
    opacity: 0.88;
}

.theme-toggle {
    flex-shrink: 0;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
}

.copy-panel {
    margin-bottom: 24px;
}

.copy-grid {
    display: grid;
    grid-template-columns: 1.1fr 1.4fr 1fr;
    gap: 18px;
    align-items: start;
}

.copy-field {
    display: grid;
    gap: 10px;
    color: var(--muted);
    font-size: 0.92rem;
}

.copy-field span {
    color: var(--ink);
    font-weight: 600;
}

.copy-select {
    width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--panel-border);
    background: var(--panel-soft);
    color: var(--ink);
    font: inherit;
}

.copy-targets,
.copy-summary,
.copy-actions {
    min-height: 100%;
}

.copy-target-list,
.copy-summary {
    display: grid;
    gap: 10px;
}

.copy-target-option,
.copy-link-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--stat-bg);
    border: 1px solid var(--table-border);
}

.copy-target-option input {
    accent-color: var(--accent);
}

.copy-target-option {
    justify-content: space-between;
    gap: 14px;
}

.copy-target-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: var(--ink);
    font-weight: 600;
}

.copy-target-controls {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(110px, 140px);
    gap: 10px;
    width: min(100%, 360px);
}

.copy-link-item span {
    color: var(--muted);
}

.copy-actions {
    display: grid;
    gap: 12px;
    align-content: start;
}

.metric-card {
    position: relative;
    overflow: hidden;
}

.metric-card::after {
    content: "";
    position: absolute;
    inset: auto -30px -35px auto;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(12, 107, 88, 0.12), transparent 70%);
}

.metric-label {
    display: block;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 0.9rem;
}

.metric-card strong {
    font-size: clamp(1.8rem, 2.8vw, 2.6rem);
    line-height: 1;
}

.main-grid {
    display: grid;
    grid-template-columns: 1.6fr 0.9fr;
    gap: 24px;
}

.side-panel {
    min-height: 100%;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 16px;
    margin-bottom: 18px;
}

.accounts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 18px;
}

.account-card {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-height: 250px;
}

.account-head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 12px;
}

.account-title {
    font-size: 1.45rem;
}

.account-meta {
    margin: 8px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.status-pill,
.side-pill,
.status-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.status-pill {
    background: rgba(12, 107, 88, 0.12);
    color: var(--accent);
}

.status-pill.offline {
    background: rgba(176, 72, 59, 0.14);
    color: var(--danger);
}

.account-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.stat {
    padding: 12px 14px;
    border-radius: 16px;
    background: var(--stat-bg);
    border: 1px solid rgba(40, 63, 54, 0.08);
}

.stat span {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8rem;
    color: var(--muted);
}

.toggle-row,
.inline-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    border: 0;
    border-radius: 999px;
    padding: 12px 18px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 18px rgba(29, 46, 42, 0.12);
}

button.primary {
    background: var(--button-primary-bg);
    color: var(--button-primary-text);
}

button.secondary {
    background: var(--button-secondary-bg);
    color: var(--button-secondary-text);
    border: 1px solid var(--button-secondary-border);
}

button.ghost {
    background: var(--button-ghost-bg);
    color: var(--button-ghost-text);
}

button.danger {
    background: rgba(176, 72, 59, 0.12);
    color: var(--danger);
}

html[data-theme="dark"] button.danger {
    background: rgba(240, 123, 116, 0.18);
    color: #ffd7d3;
}

button.small {
    padding: 9px 14px;
    font-size: 0.88rem;
}

.compact {
    margin-top: auto;
}

.cell-meta {
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--muted);
}

.positions-panel {
    overflow: hidden;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1100px;
}

thead th {
    text-align: left;
    font-size: 0.76rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 14px 12px;
    border-bottom: 1px solid var(--table-border);
}

tbody td {
    padding: 16px 12px;
    border-bottom: 1px solid var(--table-border);
    vertical-align: middle;
}

.side-long {
    background: rgba(12, 107, 88, 0.12);
    color: var(--accent);
}

.side-short {
    background: rgba(176, 72, 59, 0.12);
    color: var(--danger);
}

.profit-up {
    color: var(--accent);
}

.profit-down {
    color: var(--danger);
}

.inline-editor {
    display: grid;
    grid-template-columns: repeat(2, minmax(90px, 1fr));
    gap: 8px;
}

.price-block {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.price-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.price-block-label {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.price-mode-select {
    min-width: 84px;
    padding: 6px 10px;
    border: 1px solid var(--table-border);
    border-radius: 999px;
    background: var(--panel-soft);
    color: var(--ink);
    font: inherit;
    font-size: 0.82rem;
}

.price-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--table-border);
    border-radius: 12px;
    background: var(--panel-soft);
    color: var(--ink);
    font: inherit;
}

.command-feed {
    display: grid;
    gap: 12px;
    max-height: 340px;
    overflow-y: auto;
    align-content: start;
    padding-right: 6px;
}

.history-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.history-modal.hidden {
    display: none;
}

.history-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 9, 13, 0.62);
    backdrop-filter: blur(6px);
}

.history-dialog {
    position: relative;
    z-index: 1;
    width: min(1280px, calc(100vw - 32px));
    max-height: min(80vh, 920px);
    overflow: auto;
}

.command-item {
    padding: 15px 16px;
    border-radius: 18px;
    background: var(--panel-soft);
    border: 1px solid rgba(40, 63, 54, 0.08);
}

.global-controls button.secondary {
    background: rgba(255, 255, 255, 0.18);
    color: #f5fbf8;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.global-controls button.is-active {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.22), 0 14px 28px rgba(7, 20, 17, 0.24);
    transform: translateY(-1px);
}

.global-controls button.is-inactive {
    opacity: 0.72;
}

.global-controls button.primary.is-active {
    background: #f4fbf8;
    color: #10322b;
}

.global-controls button.secondary.is-active {
    background: rgba(255, 255, 255, 0.26);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.42);
}

.command-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.command-meta,
.command-body {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.5;
    word-break: break-word;
}

.status-queued,
.status-sent {
    background: rgba(192, 127, 61, 0.14);
    color: var(--warm);
}

.status-completed {
    background: rgba(12, 107, 88, 0.12);
    color: var(--accent);
}

.status-failed {
    background: rgba(176, 72, 59, 0.12);
    color: var(--danger);
}

.empty-state,
.empty-row {
    padding: 24px;
    text-align: center;
    color: var(--muted);
}

@media (max-width: 1100px) {
    .shell {
        width: min(100vw - 28px, 1500px);
        padding: 24px 0 32px;
    }

    .hero,
    .main-grid,
    .copy-grid {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .shell {
        width: calc(100vw - 20px);
        padding: 16px 0 24px;
    }

    .hero,
    .main-grid,
    .summary-grid,
    .copy-grid,
    .accounts-grid,
    .account-stats {
        grid-template-columns: 1fr;
    }

    .card,
    .panel {
        padding: 16px;
        border-radius: 18px;
    }

    .hero-topbar,
    .panel-head,
    .account-head,
    .copy-target-option,
    .command-top {
        flex-direction: column;
        align-items: stretch;
    }

    .theme-toggle,
    .status-pill {
        align-self: flex-start;
    }

    .global-controls .toggle-row,
    .toggle-row,
    .inline-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .global-controls .toggle-row button,
    .toggle-row button,
    .inline-actions button {
        width: 100%;
    }

    .copy-target-controls {
        grid-template-columns: 1fr;
        width: 100%;
    }

    .copy-target-toggle {
        width: 100%;
    }

    .command-feed {
        max-height: 300px;
    }

    .history-modal {
        padding: 12px;
    }

    .history-dialog {
        width: min(100vw - 16px, 960px);
        max-height: calc(100vh - 16px);
        padding: 16px;
    }

    .table-wrap {
        overflow-x: visible;
    }

    table {
        min-width: 0;
    }

    thead {
        display: none;
    }

    tbody {
        display: grid;
        gap: 14px;
    }

    tbody tr {
        display: grid;
        gap: 10px;
        padding: 14px;
        border: 1px solid var(--table-border);
        border-radius: 16px;
        background: var(--panel-soft);
    }

    tbody td {
        display: grid;
        grid-template-columns: minmax(88px, 108px) minmax(0, 1fr);
        gap: 10px;
        padding: 0;
        border-bottom: 0;
        align-items: center;
    }

    tbody td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.76rem;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        font-weight: 700;
    }

    .inline-editor {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    body::before {
        background-size: 18px 18px;
    }

    h1 {
        max-width: none;
        font-size: clamp(1.8rem, 9vw, 2.4rem);
    }

    .subtitle {
        font-size: 0.95rem;
        line-height: 1.55;
    }

    .global-controls .toggle-row,
    .toggle-row,
    .inline-actions {
        grid-template-columns: 1fr;
    }

    tbody td {
        grid-template-columns: 1fr;
    }

    tbody td::before {
        margin-bottom: 4px;
    }
}
