:root {
    --page: #131722;
    --panel: #1e222d;
    --panel-soft: #252a36;
    --panel-strong: #0f141d;
    --line: #3a4150;
    --line-soft: #2d3441;
    --text: #f4f6fb;
    --muted: #8b95a7;
    --faint: #5e6673;
    --gold: #f0b90b;
    --green: #16c784;
    --red: #ea3943;
    --blue: #5b8def;
    --violet: #9b6bff;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
}

body {
    background: var(--page);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
    overflow: hidden;
}

button,
input {
    font: inherit;
}

button {
    touch-action: manipulation;
}

.app-shell {
    width: 100vw;
    height: 100dvh;
    min-height: 100vh;
    display: grid;
    grid-template-rows: 54px 1fr;
    background: var(--page);
    overflow: hidden;
}

.app-shell.locked {
    display: none;
}

.auth-screen {
    width: 100vw;
    height: 100dvh;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
    background: var(--page);
    overflow: auto;
}

.auth-card {
    width: min(680px, 100%);
    max-height: calc(100dvh - 36px);
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: auto;
    padding: 18px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.auth-brand h1 {
    margin: 0;
    font-size: 20px;
    line-height: 1.15;
}

.auth-brand p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.auth-switch {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 4px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #171c27;
    margin-bottom: 14px;
}

.auth-switch-button {
    min-height: 36px;
    border: 0;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
    font-size: 13px;
    font-weight: 900;
}

.auth-switch-button.active {
    color: #151515;
    background: var(--gold);
}

.auth-form {
    display: none;
    gap: 12px;
}

.auth-form.active {
    display: grid;
}

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

.signup-section-title {
    color: var(--gold);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
    border-bottom: 1px solid var(--line-soft);
    background: rgba(19, 23, 34, 0.96);
    z-index: 20;
}

.brand-block,
.top-actions,
.chart-actions,
.worker-buttons,
.form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-mark {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(240, 185, 11, 0.65);
    border-radius: 7px;
    color: var(--gold);
    font-weight: 800;
    background: #191f2b;
}

.brand-title {
    font-size: 14px;
    font-weight: 800;
    line-height: 1.1;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.2;
}

.icon-button,
.compact-button,
.primary-button,
.secondary-button {
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    background: var(--panel-soft);
    min-height: 34px;
    cursor: pointer;
}

.icon-button {
    width: 34px;
    padding: 0;
    font-weight: 800;
}

.icon-button.active {
    color: var(--gold);
    border-color: rgba(240, 185, 11, 0.75);
}

.compact-button {
    padding: 7px 11px;
    font-size: 12px;
    font-weight: 700;
}

.compact-button.danger {
    color: var(--red);
    border-color: rgba(234, 57, 67, 0.65);
}

.compact-button.active {
    color: #151515;
    border-color: var(--gold);
    background: var(--gold);
}

.primary-button,
.secondary-button {
    padding: 10px 13px;
    font-size: 13px;
    font-weight: 800;
}

.primary-button {
    background: var(--gold);
    color: #151515;
    border-color: var(--gold);
}

.secondary-button {
    background: transparent;
}

.connection-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--muted);
    background: #171c27;
    font-size: 12px;
    font-weight: 700;
}

.user-pill {
    color: var(--gold);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--red);
}

.status-dot.running {
    background: var(--green);
}

.terminal-grid {
    display: grid;
    grid-template-columns: 35% 1fr;
    grid-template-rows: 74% 1fr;
    gap: 10px;
    min-height: 0;
    padding: 10px;
    padding-bottom: 10px;
}

.panel {
    min-width: 0;
    min-height: 0;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.news-panel {
    grid-row: 1 / span 2;
}

.trade-panel {
    display: grid;
    grid-template-rows: minmax(260px, 1fr) 26%;
    gap: 10px;
    grid-column: 2;
    grid-row: 1 / span 2;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.config-panel {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: none;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--line-soft);
}

.panel-header.compact {
    padding: 9px 10px;
}

.panel-header h1,
.panel-header h2,
.form-section h2 {
    margin: 0;
    font-size: 15px;
    line-height: 1.1;
}

.account-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 36px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.account-line strong {
    color: var(--text);
}

.panel-header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 11px;
}

.count-badge {
    min-width: 30px;
    height: 24px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--gold);
    background: #151a24;
    font-size: 12px;
    font-weight: 800;
}

.feed-list,
.positions-table,
.config-form,
.connector-list {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.feed-list {
    height: calc(100% - 61px);
    padding: 10px;
}

.news-item {
    min-width: 0;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    background: #171c27;
}

.news-meta,
.position-meta,
.order-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: 11px;
}

.news-title {
    max-width: 100%;
    margin: 7px 0;
    color: var(--text);
    font-size: 13px;
    line-height: 1.35;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.coin-row,
.trade-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.coin-chip {
    border: 1px solid rgba(240, 185, 11, 0.45);
    border-radius: 6px;
    padding: 3px 6px;
    color: var(--gold);
    background: rgba(240, 185, 11, 0.08);
    font-size: 11px;
    font-weight: 800;
}

.trade-row {
    margin-top: 8px;
}

.trade-button {
    min-height: 30px;
    border: 1px solid rgba(22, 199, 132, 0.55);
    border-radius: 7px;
    color: var(--green);
    background: rgba(22, 199, 132, 0.1);
    padding: 5px 8px;
    font-size: 12px;
    font-weight: 800;
}

.trade-chart,
.positions-panel {
    min-height: 0;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: var(--panel);
    overflow: hidden;
}

.trade-chart {
    position: relative;
}

.chart-toolbar {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    pointer-events: none;
}

.chart-toolbar button {
    pointer-events: auto;
}

.chart-symbol {
    color: var(--text);
    font-size: 18px;
    font-weight: 900;
}

.chart-entry {
    margin-top: 2px;
    color: var(--gold);
    font-size: 12px;
    font-weight: 800;
}

.chart-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: var(--panel-strong);
    display: none;
}

.chart-frame.loaded {
    display: block;
}

.chart-swipe-handle {
    position: absolute;
    top: 56px;
    right: 0;
    bottom: 0;
    z-index: 6;
    width: 30px;
    border: 0;
    background: transparent;
    padding: 0;
    cursor: ew-resize;
    touch-action: pan-y;
}

.chart-swipe-handle::before {
    content: "";
    position: absolute;
    top: 50%;
    right: 7px;
    width: 4px;
    height: 58px;
    border-radius: 999px;
    background: rgba(240, 185, 11, 0.52);
    box-shadow: 0 0 0 1px rgba(15, 20, 29, 0.8);
    transform: translateY(-50%);
}

.chart-swipe-handle.open::before {
    background: rgba(91, 141, 239, 0.7);
}

.chart-placeholder {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background:
        linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px),
        linear-gradient(0deg, rgba(255,255,255,0.035) 1px, transparent 1px),
        #111722;
    background-size: 54px 54px;
}

.chart-placeholder.hidden {
    display: none;
}

.placeholder-grid {
    position: absolute;
    left: 8%;
    right: 8%;
    top: 28%;
    bottom: 18%;
    clip-path: polygon(0 70%, 12% 52%, 25% 60%, 38% 35%, 51% 42%, 63% 25%, 76% 31%, 88% 18%, 100% 24%, 100% 100%, 0 100%);
    background: rgba(22, 199, 132, 0.16);
    border-top: 2px solid var(--green);
}

.placeholder-symbol {
    position: absolute;
    left: 12px;
    bottom: 12px;
    color: rgba(244, 246, 251, 0.08);
    font-size: clamp(38px, 8vw, 96px);
    font-weight: 900;
}

.entry-line {
    position: absolute;
    left: 0;
    right: 0;
    top: 48%;
    height: 1px;
    background: var(--gold);
    box-shadow: 0 0 0 1px rgba(240, 185, 11, 0.18);
}

.positions-table {
    height: calc(100% - 55px);
}

.position-row,
.order-row {
    display: grid;
    grid-template-columns: minmax(96px, 1.1fr) minmax(82px, 0.8fr) minmax(92px, 0.9fr) minmax(90px, 0.9fr) minmax(96px, 0.9fr) 112px;
    align-items: center;
    gap: 8px;
    min-height: 43px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--line-soft);
    font-size: 12px;
}

.position-row.header {
    min-height: 30px;
    color: var(--faint);
    font-weight: 800;
    background: #1a1f2a;
}

.position-symbol {
    color: var(--text);
    font-weight: 900;
}

.side {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    height: 22px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 900;
}

.side.long,
.side.buy {
    color: var(--green);
    background: rgba(22, 199, 132, 0.1);
}

.side.short,
.side.sell {
    color: var(--red);
    background: rgba(234, 57, 67, 0.1);
}

.pnl-positive {
    color: var(--green);
}

.pnl-negative {
    color: var(--red);
}

.close-button {
    width: 100%;
    min-height: 28px;
    border: 1px solid rgba(234, 57, 67, 0.65);
    border-radius: 7px;
    color: var(--red);
    background: rgba(234, 57, 67, 0.08);
    font-size: 11px;
    font-weight: 900;
}

.empty-state {
    height: 100%;
    min-height: 120px;
    display: grid;
    place-items: center;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
    padding: 18px;
}

.config-panel {
    padding-bottom: 0;
}

.guide-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border-bottom: 1px solid var(--line-soft);
    background: #1a1f2a;
}

.guide-tab-button {
    min-height: 32px;
    border: 0;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
    font-size: 12px;
    font-weight: 900;
}

.guide-tab-button.active {
    color: var(--gold);
    background: rgba(240, 185, 11, 0.14);
}

.guide-stack {
    height: calc(100% - 112px);
    min-height: 0;
}

.guide-panel {
    display: none;
    height: 100%;
    min-height: 0;
}

.guide-panel.active {
    display: grid;
    grid-template-rows: auto 1fr;
}

.guide-panel[data-guide-panel="settings"].active {
    display: block;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.guide-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 38px;
    padding: 7px 10px;
    border-bottom: 1px solid var(--line-soft);
    background: #252a36;
    color: var(--muted);
    font-size: 11px;
}

.guide-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.guide-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.mini-status {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    max-width: 180px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px 7px;
    color: var(--muted);
    background: #171c27;
    font-size: 10px;
    font-weight: 900;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mini-status.connected,
.mini-status.synced,
.mini-status.configured {
    color: var(--green);
    border-color: rgba(22, 199, 132, 0.55);
}

.mini-status.connecting {
    color: var(--gold);
    border-color: rgba(240, 185, 11, 0.55);
}

.mini-status.error,
.mini-status.missing-config,
.mini-status.configured-disabled {
    color: var(--red);
    border-color: rgba(234, 57, 67, 0.55);
}

.compact-input {
    min-height: 32px;
    max-width: 180px;
    font-size: 12px;
}

.guide-list {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
}

.guide-row,
.rule-card,
.delay-row {
    border-bottom: 1px solid var(--line-soft);
    background: #171c27;
}

.guide-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 42px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 13px;
}

.rule-card {
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    margin-bottom: 8px;
    overflow: hidden;
}

.rule-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 42px;
    padding: 8px 10px;
}

.rule-title {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    color: var(--text);
    background: transparent;
    padding: 0;
    font-size: 13px;
    font-weight: 900;
    text-align: left;
}

.rule-title span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-light {
    width: 11px;
    height: 11px;
    border-radius: 999px;
    background: var(--red);
}

.status-light.active {
    background: var(--green);
}

.switch {
    position: relative;
    width: 42px;
    height: 22px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 999px;
    background: #333946;
    padding: 0;
}

.switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #ffffff;
    transition: transform 120ms ease;
}

.switch.active {
    background: var(--green);
}

.switch.active::after {
    transform: translateX(20px);
}

.rule-body {
    display: none;
    padding: 10px;
    background: #1a1e26;
}

.rule-card.expanded .rule-body {
    display: grid;
    gap: 10px;
}

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

.mini-actions,
.toggle-grid,
.chip-row,
.delay-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.mini-actions {
    flex: 0 0 auto;
}

.mini-actions button {
    min-height: 28px;
}

.toggle-control {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}

.list-editor {
    display: grid;
    gap: 6px;
}

.list-editor strong,
.delay-heading {
    color: var(--text);
    font-size: 11px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 23px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 3px 6px;
    color: var(--text);
    background: #252a36;
    font-size: 11px;
}

.empty-inline {
    color: var(--faint);
    font-size: 11px;
}

.chip button {
    border: 0;
    color: var(--red);
    background: transparent;
    padding: 0;
    min-height: 0;
    font-weight: 900;
}

.inline-add {
    display: flex;
    gap: 5px;
}

.inline-add input {
    min-height: 28px;
    font-size: 11px;
}

.inline-add button {
    min-height: 28px;
}

.delay-section {
    display: grid;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line-soft);
}

.delay-row {
    justify-content: space-between;
    padding: 8px;
    border: 1px solid var(--line-soft);
    border-radius: 7px;
}

.delay-inputs {
    display: flex;
    align-items: center;
    gap: 5px;
}

.delay-inputs input {
    width: 70px;
    min-height: 30px;
    font-size: 11px;
}

.config-form {
    height: auto;
    padding: 12px;
}

.form-section {
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    background: #171c27;
}

.form-section h2 {
    margin-bottom: 10px;
    color: var(--gold);
    font-size: 13px;
}

label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

input {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    background: var(--panel-soft);
    padding: 8px 10px;
    outline: none;
}

input:focus {
    border-color: rgba(240, 185, 11, 0.8);
}

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

.quick-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.form-actions {
    position: sticky;
    bottom: 0;
    padding: 10px 0 2px;
    background: var(--panel);
}

.connector-list {
    max-height: 112px;
    padding: 0 12px 12px;
}

.connector-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--line-soft);
    border-radius: 7px;
    padding: 8px 10px;
    margin-bottom: 6px;
    background: #171c27;
    color: var(--muted);
    font-size: 12px;
}

.connector-row strong {
    color: var(--text);
}

.bottom-tabs {
    display: none;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
    transform: translate(-50%, 120px);
    max-width: min(480px, calc(100vw - 28px));
    padding: 11px 14px;
    border-radius: 8px;
    color: var(--text);
    background: #232a36;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-size: 13px;
    transition: transform 160ms ease;
    z-index: 100;
}

.toast.show {
    transform: translate(-50%, 0);
}

.toast.error {
    border-color: rgba(234, 57, 67, 0.75);
}

.toast.success {
    border-color: rgba(22, 199, 132, 0.75);
}

@media (orientation: portrait), (max-width: 760px) {
    body {
        overflow: hidden;
    }

    .app-shell {
        grid-template-rows: calc(54px + env(safe-area-inset-top, 0px)) 1fr calc(64px + env(safe-area-inset-bottom, 0px));
    }

    .topbar {
        min-height: calc(54px + env(safe-area-inset-top, 0px));
    }

    .brand-subtitle {
        display: none;
    }

    .connection-pill {
        max-width: 108px;
    }

    .user-pill {
        display: none;
    }

    #logoutButton {
        max-width: 76px;
        padding-inline: 8px;
    }

    .connection-pill span:last-child {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .terminal-grid {
        display: block;
        padding: 8px;
        padding-bottom: 8px;
        overflow: hidden;
    }

    .panel {
        display: none;
        height: 100%;
        box-shadow: none;
    }

    .panel.active {
        display: block;
    }

    .trade-panel.active {
        display: grid;
        grid-template-rows: minmax(280px, 44%) 1fr;
        gap: 8px;
        border: 0;
        background: transparent;
    }

    .trade-chart,
    .positions-panel {
        min-height: 0;
    }

    .position-row,
    .order-row {
        grid-template-columns: minmax(86px, 1fr) 66px 82px 88px 96px;
    }

    .position-row > :nth-child(5),
    .position-row.header > :nth-child(5) {
        display: none;
    }

    .position-row {
        font-size: 11px;
    }

    .field-grid,
    .quick-grid,
    .signup-grid,
    .rule-grid {
        grid-template-columns: 1fr;
    }

    .guide-stack {
        height: calc(100% - 112px);
    }

    .guide-toolbar,
    .guide-toolbar-actions {
        align-items: stretch;
    }

    .guide-toolbar {
        flex-direction: column;
    }

    .guide-title {
        justify-content: space-between;
    }

    .guide-toolbar-actions {
        width: 100%;
    }

    .compact-input {
        max-width: none;
    }

    .guide-toolbar-actions .compact-input {
        flex: 1;
    }

    .bottom-tabs {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        align-items: stretch;
        padding: 7px 8px calc(7px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid var(--line-soft);
        background: rgba(19, 23, 34, 0.98);
        z-index: 20;
    }

    .tab-button {
        border: 0;
        border-radius: 8px;
        color: var(--muted);
        background: transparent;
        font-size: 13px;
        font-weight: 900;
    }

    .tab-button.active {
        color: #151515;
        background: var(--gold);
    }
}

@media (orientation: landscape) and (min-width: 761px) {
    .terminal-grid.show-config .trade-panel {
        display: none;
    }

    .terminal-grid.show-config .config-panel {
        display: block;
    }
}
