/* =========================================================
   Trading Engine - design system
   ========================================================= */
:root {
    --bg: #fffbfd;
    --card: #ffffff;
    --card-2: #f6f6f8;
    --text: #16161a;
    --muted: #77757a;
    --line: #e8e8ec;
    --ink: #16161a;
    --ink-text: #ffffff;
    --accent: #3f7be8;
    --accent-soft: #e6eefd;
    --green: #15803d;
    --green-soft: #dcf5e4;
    --red: #c62828;
    --red-soft: #fde2e2;
    --shadow: 0 0 0 1px #ececf0, 0 4px 14px rgba(20, 20, 30, .05);
    --radius: 16px;
}

:root[data-theme="dark"] {
    --bg: #121214;
    --card: #1b1b1f;
    --card-2: #232328;
    --text: #f2f0ea;
    --muted: #9a98a0;
    --line: #2d2d34;
    --ink: #f2f0ea;
    --ink-text: #16161a;
    --accent: #7aa7ff;
    --accent-soft: #1a2640;
    --green: #4ade80;
    --green-soft: #12301f;
    --red: #f87171;
    --red-soft: #3b1a1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Manrope", system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

a {
    color: inherit;
}

h1 {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -.02em;
    margin: 0 0 .3rem;
}

h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 .5rem;
}

.subtitle,
.muted {
    color: var(--muted);
}

/* ---------- brand ---------- */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    padding: 4px 6px 18px;
}

.brand-logo {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: none;
    box-shadow: none;
    border-radius: 0;
}

.brand-logo img {
    width: 34px;
    height: auto;
    display: block;
}

/* the logo file has a white background, so in dark mode it needs a tile */
:root[data-theme="dark"] .brand-logo {
    background: #121214;
    border-radius: 10px;
}

.brand-name {
    font-weight: 800;
    font-size: 15px;
    line-height: 1.15;
    letter-spacing: -.01em;
    background: linear-gradient(135deg, #2fc4c4, #4a86f0 55%, #a050f0);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand-name-lg {
    font-size: 20px;
}

.brand-name-lg {
    font-size: 16px;
}

/* ---------- app shell ---------- */
.shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    flex-shrink: 0;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 14px;
    border: 0;
    background: var(--card);
    color: var(--text);
    box-shadow: var(--shadow);
    text-decoration: none;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
}

.nav-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.nav-item:hover {
    background: var(--card-2);
}

.nav-item.active {
    background: var(--ink);
    color: var(--ink-text);
}

.badge {
    margin-left: auto;
    font-style: normal;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .05em;
    color: var(--accent);
}

.nav-item.active .badge {
    color: #9dbcff;
}

.sidebar-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.userchip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card);
    border-radius: 14px;
    padding: 8px;
    box-shadow: var(--shadow);
}

.userchip form {
    margin: 0;
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--ink-text);
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.who {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.who-email {
    font-size: 11px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.who-plan {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .05em;
    color: var(--accent);
    text-transform: uppercase;
}

.icon-btn {
    background: none;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    padding: 4px;
    display: grid;
    place-items: center;
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

.icon-btn:hover {
    color: var(--text);
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px 0;
}

.crumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.crumbs strong {
    color: var(--text);
    font-weight: 600;
}

.sep {
    opacity: .5;
}

.chip {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .06em;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--green-soft);
    color: var(--green);
    text-transform: uppercase;
}

.pill-soft {
    font-size: 11px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--card);
    color: var(--muted);
    box-shadow: var(--shadow);
}

.content {
    padding: 18px 24px 32px;
}

/* ---------- components ---------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}

.card-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
}

.grid {
    display: grid;
    gap: 16px;
}

.pills {
    display: inline-flex;
    gap: 2px;
    background: var(--card);
    padding: 4px;
    border-radius: 999px;
    box-shadow: var(--shadow);
}

.pills button {
    border: 0;
    background: none;
    color: var(--text);
    padding: 6px 12px;
    border-radius: 999px;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}

.pills button.on {
    background: var(--ink);
    color: var(--ink-text);
}

.tag {
    font-size: 10px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 6px;
    text-transform: uppercase;
}

.tag.buy {
    background: var(--green-soft);
    color: var(--green);
}

.tag.sell {
    background: var(--red-soft);
    color: var(--red);
}

.pos {
    color: var(--green);
}

.neg {
    color: var(--red);
}

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

table.t th {
    text-align: left;
    font-size: 10px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 8px 10px;
}

table.t td {
    padding: 9px 10px;
    border-top: 1px solid var(--line);
}

.disclaimer {
    margin-top: 24px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--muted);
}

/* ---------- forms and auth ---------- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    gap: 8px;
}

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

.auth-wrap .flash {
    width: min(380px, 92vw);
}

.auth-card {
    width: min(380px, 92vw);
    background: var(--card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.auth-card h1 {
    font-size: 24px;
    margin-bottom: 1.2rem;
}

.auth-card p {
    color: var(--muted);
    font-size: 13px;
}

.auth-card a {
    color: var(--accent);
    font-weight: 600;
}

.field {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: .3rem;
}

.field label {
    font-size: 12px;
    font-weight: 600;
}

.input {
    padding: .65rem .8rem;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card-2);
    color: var(--text);
    font: inherit;
}

.input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.btn {
    padding: .7rem 1rem;
    border: 0;
    border-radius: 999px;
    background: var(--ink);
    color: var(--ink-text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
}

.btn:hover {
    opacity: .9;
}

.btn-link {
    background: none;
    border: 0;
    color: var(--accent);
    cursor: pointer;
    padding: 0;
    font: inherit;
}

.error {
    color: var(--red);
    font-size: 12px;
}

.flash {
    padding: .6rem .9rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    font-weight: 500;
}

.flash.success {
    background: var(--green-soft);
    color: var(--green);
}

.flash.error {
    background: var(--red-soft);
    color: var(--red);
}

/* ---------- phone and tablet ---------- */
.menu-btn, .menu-close, .scrim { display: none; }
.brand-row { display: flex; align-items: flex-start; justify-content: space-between; }
.brand-row .brand { flex: 1; min-width: 0; }
img, svg, video, canvas { max-width: 100%; }
pre, code { overflow-wrap: anywhere; }

@media (max-width: 800px) {
    html { -webkit-text-size-adjust: 100%; }
    html.nav-open { overflow: hidden; }

    /* the sidebar becomes a menu that slides in from the left */
    .sidebar {
        display: flex;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100vh;
        height: 100dvh;
        width: min(288px, 86vw);
        z-index: 1001;
        background: var(--bg);
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 14px 12px calc(16px + env(safe-area-inset-bottom));
        transform: translateX(-104%);
        visibility: hidden;
        transition: transform .24s ease, visibility 0s linear .24s;
    }
    html.nav-open .sidebar {
        transform: none;
        visibility: visible;
        transition: transform .24s ease;
        box-shadow: 0 0 44px rgba(0, 0, 0, .28);
    }
    .scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1000;
        background: rgba(10, 10, 14, .48);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }
    html.nav-open .scrim { opacity: 1; pointer-events: auto; }
    .menu-close { display: grid; width: 40px; height: 40px; flex-shrink: 0; }
    .menu-btn {
        display: grid;
        place-items: center;
        width: 42px;
        height: 42px;
        flex-shrink: 0;
        border: 0;
        border-radius: 14px;
        background: var(--card);
        color: var(--text);
        box-shadow: var(--shadow);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .nav-item { min-height: 44px; }

    /* the page itself: never wider than the screen */
    .shell, .main { overflow-x: clip; max-width: 100%; }
    .topbar {
        position: sticky;
        top: 0;
        z-index: 50;
        gap: 10px;
        padding: 10px 14px;
        background: var(--bg);
    }
    .crumbs { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; }
    .crumbs > span:first-child, .crumbs > .sep { display: none; }
    .crumbs strong { overflow: hidden; text-overflow: ellipsis; }
    .pill-soft { display: none; }
    .content { padding: 8px 14px calc(28px + env(safe-area-inset-bottom)); min-width: 0; }
    h1 { font-size: 24px; }
    .card { padding: 14px; }
    .grid { gap: 12px; }

    /* 16px fields so phones do not zoom in when one is tapped */
    input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]), select, textarea { font-size: 16px; }
    .btn, .pills button { min-height: 40px; }

    /* wide rows scroll inside themselves instead of pushing the page */
    .pills, .jr-tabs, .draw-bar { max-width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .pills::-webkit-scrollbar, .jr-tabs::-webkit-scrollbar, .draw-bar::-webkit-scrollbar { display: none; }
    .pills button, .jr-tabs button { white-space: nowrap; flex-shrink: 0; }
    table.t, .tbl, .sc-table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 420px) {
    .content, .topbar { padding-left: 10px; padding-right: 10px; }
    h1 { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar, .scrim { transition: none; }
}
