* {
    box-sizing: border-box;
}

:root {
    --bg: #eef2f6;
    --surface: #ffffff;
    --surface-2: #f6f8fb;
    --ink: #15202b;
    --muted: #627080;
    --line: #d8e0e8;
    --blue: #2059d3;
    --green: #147a52;
    --green-bg: #e5f5ed;
    --red: #be3434;
    --red-bg: #fae8e8;
    --amber: #b7650a;
    --shadow: 0 10px 30px rgba(21, 32, 43, 0.08);
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: minmax(210px, 1fr) minmax(220px, 340px) minmax(220px, 1fr);
    align-items: center;
    gap: 16px;
    min-height: 74px;
    padding: 14px 22px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
}

.brand,
.wallet-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    display: inline-grid;
    width: 44px;
    height: 44px;
    place-items: center;
    overflow: hidden;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #ffffff;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.brand strong,
.brand > div span {
    display: block;
}

.brand > div span,
.muted {
    color: var(--muted);
    font-size: 12px;
}

.wallet-actions {
    justify-content: flex-end;
}

.market-switcher {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 10px;
}

.market-switcher label {
    color: var(--muted);
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #ffffff;
    color: var(--ink);
    padding: 8px 10px;
}

textarea {
    resize: vertical;
}

.primary-btn,
.secondary-btn,
.icon-btn {
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 0 14px;
    font-weight: 750;
}

.primary-btn {
    background: var(--blue);
    color: #ffffff;
}

.secondary-btn,
.icon-btn {
    border-color: var(--line);
    background: var(--surface);
    color: var(--ink);
}

.table-action-btn {
    min-height: 30px;
    padding: 0 10px;
    font-size: 12px;
}

.danger-action {
    border-color: #f0b7b7;
    color: #9f1d1d;
    background: #fff5f5;
}

.icon-btn {
    width: 38px;
    padding: 0;
}

.full {
    width: 100%;
}

.workspace {
    width: min(1600px, 100%);
    margin: 0 auto;
    padding: 22px;
}

.market-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.market-strip article,
.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(21, 32, 43, 0.04);
}

.market-strip article {
    min-height: 92px;
    padding: 18px;
}

.market-strip span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.market-strip strong {
    display: block;
    margin-top: 12px;
    font-size: 24px;
    line-height: 1;
}

.trade-grid {
    display: grid;
    grid-template-columns: minmax(360px, 1.1fr) minmax(320px, 0.8fr) minmax(320px, 0.9fr);
    grid-template-areas:
        "chart chart ticket"
        "book trades orders"
        "assets assets assets";
    gap: 14px;
}

.chart-panel {
    grid-area: chart;
}

.book-panel {
    grid-area: book;
}

.ticket-panel {
    grid-area: ticket;
}

.trades-panel {
    grid-area: trades;
}

.orders-panel {
    grid-area: orders;
}

.assets-panel {
    grid-area: assets;
}

.panel {
    overflow: hidden;
}

.market-chart-shell {
    position: relative;
    height: 460px;
    min-height: 360px;
    background: #ffffff;
}

.market-chart-shell canvas {
    display: block;
    height: 100%;
    width: 100%;
}

.chart-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-weight: 750;
    pointer-events: none;
}

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

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 58px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

h2,
h3,
p {
    margin: 0;
}

h2 {
    font-size: 17px;
}

h3 {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.book {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 14px;
}

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

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
}

tbody tr:hover {
    background: var(--surface-2);
}

tr.clickable-row {
    cursor: pointer;
}

tr.clickable-row:focus-within,
tr.clickable-row:hover {
    background: #eef5ff;
}

.stack-form,
.inline-form {
    padding: 16px;
}

.stack-form {
    display: grid;
    gap: 13px;
}

.stack-form.compact {
    padding-top: 0;
}

.inline-form {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 10px;
    border-bottom: 1px solid var(--line);
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 750;
}

label input,
label select,
label textarea {
    color: var(--ink);
    font-weight: 400;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 150px;
    border: 1px solid var(--line);
    border-radius: 7px;
    overflow: hidden;
}

.segmented button {
    min-height: 34px;
    border: 0;
    background: #ffffff;
    color: var(--muted);
    font-weight: 750;
}

.segmented button.active:first-child {
    background: var(--green-bg);
    color: var(--green);
}

.segmented button.active:last-child {
    background: var(--red-bg);
    color: var(--red);
}

.quote-row,
.balance-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 42px;
    border-radius: 7px;
    background: var(--surface-2);
    padding: 10px 12px;
}

.balance-display {
    margin: 14px 16px;
}

.quote-row span,
.balance-display span {
    color: var(--muted);
}

.form-message {
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--muted);
    padding: 9px 10px;
    font-size: 12px;
    line-height: 1.35;
}

.form-message.error {
    border-color: rgba(190, 52, 52, 0.35);
    background: var(--red-bg);
    color: var(--red);
}

.form-message.success {
    border-color: rgba(20, 122, 82, 0.35);
    background: var(--green-bg);
    color: var(--green);
}

.form-message.hidden {
    display: none;
}

.deposit-addresses {
    display: grid;
    gap: 10px;
    margin: 0 16px 16px;
    border-top: 1px solid var(--line);
    padding-top: 14px;
}

.subhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.subhead span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.deposit-address-list {
    display: grid;
    gap: 8px;
}

.deposit-address-row {
    display: grid;
    grid-template-columns: minmax(72px, auto) 1fr auto;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface-2);
    padding: 10px;
}

.deposit-address-row code {
    overflow-wrap: anywhere;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
}

.deposit-address-row .address-meta {
    display: grid;
    gap: 2px;
}

.deposit-address-row .address-meta strong,
.deposit-address-row .address-meta span {
    display: block;
}

.deposit-address-row .address-meta span {
    color: var(--muted);
    font-size: 12px;
}

.deposit-address-row .button-row {
    min-width: 146px;
}

.transaction-row .transaction-meta {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.intent-box {
    display: none;
    margin: 0 16px 16px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface-2);
    padding: 12px;
}

.intent-box.active {
    display: grid;
    gap: 10px;
}

.intent-box code {
    display: block;
    overflow-wrap: anywhere;
    color: var(--ink);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
}

.send-form {
    border-top: 1px solid var(--line);
}

.asset-list {
    display: grid;
    gap: 10px;
    padding: 14px;
}

.asset-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
}

.asset-logo {
    position: relative;
    display: inline-grid;
    width: 36px;
    height: 36px;
    place-items: center;
    overflow: hidden;
    border-radius: 8px;
    background: #dce8f8;
    color: var(--blue);
    font-weight: 850;
}

.asset-logo img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #ffffff;
}

.asset-row strong,
.asset-row span {
    display: block;
}

.asset-row span {
    color: var(--muted);
    font-size: 12px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 0 9px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
}

.badge.buy,
.bid-price {
    color: var(--green);
}

.badge.sell,
.ask-price {
    color: var(--red);
}

.badge.buy {
    background: var(--green-bg);
}

.badge.sell {
    background: var(--red-bg);
}

.empty {
    color: var(--muted);
    text-align: center;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 20;
    max-width: min(420px, calc(100vw - 40px));
    transform: translateY(18px);
    opacity: 0;
    border-radius: 8px;
    background: #111820;
    color: #ffffff;
    padding: 12px 14px;
    box-shadow: var(--shadow);
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
}

.toast.active {
    transform: translateY(0);
    opacity: 1;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    background: rgba(17, 24, 32, 0.42);
    padding: 20px;
}

body.auth-page-mode .workspace {
    display: none;
}

body.auth-page-mode .modal {
    position: static;
    min-height: calc(100vh - 74px);
    place-items: start center;
    background: var(--bg);
    padding: 34px 16px;
}

body.auth-page-mode .account-dialog {
    width: min(560px, 100%);
}

body.auth-page-mode #account-close {
    display: none;
}

.hidden,
.modal.hidden,
.auth-view {
    display: none;
}

.modal-content {
    width: min(560px, 100%);
    max-height: calc(100vh - 40px);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.account-dialog {
    width: min(780px, 100%);
}

.auth-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}

.auth-tabs button {
    min-height: 36px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-weight: 750;
}

.auth-tabs button.active {
    border-color: var(--line);
    background: var(--surface);
    color: var(--ink);
}

.auth-view.active {
    display: block;
}

#auth-wallet.active + #auth-security.active {
    border-top: 1px solid var(--line);
}

.file-status {
    min-height: 22px;
    color: var(--muted);
    font-size: 12px;
}

.security-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 16px 16px 0;
    border-radius: 7px;
    background: var(--surface-2);
    padding: 10px 12px;
}

.security-status span {
    color: var(--muted);
}

.secret-box {
	display: grid;
	gap: 8px;
	border: 1px solid var(--line);
	border-radius: 7px;
	background: var(--surface-2);
	padding: 12px;
}

#generated-wallets,
#session-generated-wallets {
	max-height: min(42vh, 360px);
	overflow: auto;
}

.keyfile-head {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 10px;
	align-items: center;
}

.keyfile-head .primary-btn {
	min-height: 34px;
	padding: 7px 10px;
	white-space: nowrap;
}

.keyfile-note {
	margin: 0;
	color: var(--muted);
	font-size: 12px;
	line-height: 1.4;
}

.generated-keyfile-row {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto auto;
	gap: 8px 10px;
	align-items: center;
	border-top: 1px solid var(--line);
	padding-top: 8px;
}

.generated-keyfile-row div,
.generated-keyfile-row span,
.generated-keyfile-row code {
	min-width: 0;
}

.generated-keyfile-row span {
	display: block;
	color: var(--muted);
	font-size: 12px;
	font-weight: 750;
	text-transform: uppercase;
}

.generated-keyfile-row small {
	color: var(--muted);
	font-size: 12px;
	font-weight: 750;
}

.secret-box code {
	overflow-wrap: anywhere;
	font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
	font-size: 12px;
}

.copy-field {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 10px;
    align-items: center;
}

.copy-field span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
}

.copy-field code {
    grid-column: 1 / -1;
}

.auth-notice {
    display: grid;
    gap: 12px;
    margin: 0 16px 16px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--green-bg);
    padding: 12px;
}

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

.recovery-grid code {
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.78);
    padding: 7px 8px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
}

.qr-image {
    width: 180px;
    height: 180px;
    justify-self: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 8px;
}

.qr-fallback {
    justify-self: stretch;
    border: 1px dashed var(--line);
    border-radius: 7px;
    background: #ffffff;
    color: var(--muted);
    padding: 14px;
    text-align: center;
    font-weight: 750;
}

.button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.hidden {
    display: none !important;
}

@media (max-width: 1160px) {
    .app-header {
        grid-template-columns: 1fr;
    }

    .wallet-actions {
        justify-content: flex-start;
    }

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

    .trade-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "chart chart"
            "ticket book"
            "trades orders"
            "assets assets";
    }
}

@media (max-width: 760px) {
    .workspace {
        padding: 14px;
    }

    .market-strip,
    .trade-grid,
    .book,
    .inline-form {
        grid-template-columns: 1fr;
    }

    .trade-grid {
        grid-template-areas:
            "chart"
            "ticket"
            "book"
            "trades"
            "orders"
            "assets";
    }

    .panel-head {
        align-items: stretch;
        flex-direction: column;
    }

    .segmented {
        width: 100%;
    }

    .deposit-address-row {
        grid-template-columns: 1fr;
    }

    .deposit-address-row .button-row {
        min-width: 0;
    }

    .keyfile-head,
    .generated-keyfile-row {
        grid-template-columns: 1fr;
    }

    .keyfile-head .primary-btn,
    .generated-keyfile-row .secondary-btn {
        width: 100%;
    }
}
