:root {
    --sidebar-w: 266px;
    --subnav-w: 268px;
    --topbar-h: 84px;
    --footer-h: 44px;
    --composer-h: 60px;
    --subnav-w-tablet: 220px;
    --sidebar-w-tablet: 200px;
    --topbar-h-tablet: 70px;
}

.app-topbar {
    position: fixed;
    inset: 0 0 auto 0;
    display: flex;
    align-items: stretch;
    height: var(--topbar-h);
    background: var(--vp-topbar-bg);
    border-bottom: 1px solid var(--vp-border);
    z-index: 1100;
}

.app-topbar-stripes {
    display: flex;
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w);
    flex-direction: column;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
}

.app-topbar-stripe {
    display: block;
    flex: 1 1 auto;
}

.app-topbar-stripe.is-cyan {
    background: var(--vp-cyan);
}

.app-topbar-stripe.is-yellow {
    background: var(--vp-yellow);
}

.app-topbar-stripe.is-black {
    background: var(--vp-black);
}

.app-topbar-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex: 1 1 auto;
    min-width: 0;
    padding: 0 1.15rem 0 1.35rem;
}

.app-topbar-main {
    justify-content: flex-end;
}

.app-topbar-left,
.app-topbar-right,
.app-topbar-actions {
    display: flex;
    align-items: center;
    min-width: 0;
}

.app-topbar-left,
.app-topbar-right {
    gap: 0.85rem;
    padding: 0.38rem 0.85rem;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(4px);
}

.app-topbar-left {
    display: none;
}

.app-topbar-right {
    justify-content: flex-end;
}

.app-topbar-actions {
    gap: 0.6rem;
    white-space: nowrap;
}

.app-topbar-title-chip {
    display: inline-flex;
    align-items: center;
    max-width: min(58vw, 560px);
    padding: 0.4rem 1rem;
    color: #888888;
    background: linear-gradient(180deg, #fefefe 0%, #ececec 100%);
    border: 1px solid #d7d7d7;
    border-radius: 10px;
    box-shadow: inset 0 1px 0 #ffffff;
    font-size: 1.02rem;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-topbar-title-chip:hover {
    color: #6f6f6f;
    text-decoration: none;
}

.app-topbar-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    min-width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 6px;
    font-size: 1.2rem;
    line-height: 1;
}

.app-topbar-link,
.app-topbar-icon-link {
    text-decoration: none;
}

.app-topbar-link {
    color: var(--vp-link);
    font-weight: 700;
}

.app-topbar-link:hover {
    color: var(--vp-link-hover);
}

.app-topbar-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #8ea0b6;
    font-size: 1.24rem;
    line-height: 1;
}

.app-topbar-icon-link:hover {
    color: #678bbc;
}

.app-topbar-sep {
    color: #bdbdbd;
}

.app-topbar-nick {
    text-transform: uppercase;
}

.app-topbar-balance {
    color: #c48d09;
}

.app-topbar-balance-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: -3px;
}

.app-mobile-menu-account {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid #cfcfcf;
    background: #e8e8e8;
}

.app-mobile-menu-user {
    color: var(--vp-link);
    font-weight: 700;
    text-decoration: none;
}

.app-sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    overflow: hidden;
    border-right: 1px solid var(--vp-border);
    background: var(--vp-sidebar-bg);
    z-index: 1000;
}

.app-sidebar-mobile-toolbar {
    display: none;
}

.app-sidebar-mobile-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid #bdbdbd;
    border-radius: 6px;
    background: #f4f4f4;
    color: #666666;
    font-size: 1rem;
    line-height: 1;
}

.app-sidebar .scroll {
    height: 100%;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.app-sidebar-nav {
    padding: 0;
}

.app-sidebar-group {
    border-bottom: 1px solid #c8c8c8;
}

.app-sidebar-heading {
    position: relative;
    margin: 0;
    padding: 0.78rem 1rem 0.52rem;
    font-size: 1rem;
    font-weight: 400;
    color: #6f6f6f;
    background: linear-gradient(180deg, #ececec 0%, #dddddd 100%);
}

.app-sidebar-heading::after {
    content: '›';
    position: absolute;
    top: 50%;
    right: 0.75rem;
    transform: translateY(-50%);
    color: #b1b1b1;
    font-size: 1.25rem;
    line-height: 1;
}

.app-sidebar-links {
    padding: 0.2rem 0 0.55rem;
}

.app-sidebar-link {
    display: block;
    padding: 0.44rem 1rem 0.44rem 1.35rem;
    border-left: 6px solid transparent;
    color: #666666;
    text-decoration: none;
    font-size: 0.95rem;
    line-height: 1.15;
}

.app-sidebar-link:hover {
    background: #ececec;
    color: #444444;
}

.app-sidebar-link.is-active {
    background: #f8f8f8;
    border-left-color: #ff6b6b;
    color: #343434;
    font-weight: 700;
    box-shadow: inset 0 1px 0 #ffffff, inset 0 -1px 0 #d9d9d9;
}

.app {
    height: calc(100vh - var(--topbar-h));
    margin-top: var(--topbar-h);
    display: flex;
    background: var(--vp-page-bg);
    overflow: hidden;
}

.app-main {
    display: flex;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex-direction: row;
    background: var(--vp-page-bg);
}

/* When .chat is present, .app-main must NOT scroll - the chat handles its own scroll internally */
.app-main:has(.chat) {
    overflow: hidden;
}

.app-subnav {
    width: var(--subnav-w);
    border-left: 1px solid var(--vp-border);
    position: sticky;
    top: 0;
    height: 100%;
    overflow: auto;
    scrollbar-gutter: stable;
    background: #efefef;
}

.chat {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-messages {
    flex: 1;
    min-height: 0;
}

.chat-composer {
    border-top: 1px solid var(--vp-border);
    background: #e7e7e7;
}

.app-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--footer-h);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 1rem;
    border-top: 1px solid var(--vp-border);
    background: #ececec;
    z-index: 1100;
}

.table td.market-quantity,
.table th.market-quantity {
    text-align: right;
    min-width: 80px;
}

.offcanvas.offcanvas-start {
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    background: #ededed;
    border-right: 1px solid var(--vp-border);
}

/* ========================================================
   TABLET (576px – 991px) — subnav visible, más compacto
   ======================================================== */
@media (max-width: 991.98px) and (min-width: 576px) {
    :root {
        --topbar-h: var(--topbar-h-tablet);
        --sidebar-w: 44px;
        --sidebar-w-expanded: var(--sidebar-w-tablet);
        --subnav-w: var(--subnav-w-tablet);
        --sidebar-w-collapsed: 44px;
    }

    .app-sidebar {
        display: block !important;
        width: var(--sidebar-w);
        z-index: 1000;
    }

    .app-sidebar-mobile-toolbar {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        height: 42px;
        padding: 0.25rem 0.35rem;
        border-bottom: 1px solid var(--vp-border);
        background: rgba(255, 255, 255, 0.4);
    }

    .app-sidebar .scroll {
        height: calc(100% - 42px);
    }

    .app {
        margin-left: var(--sidebar-w) !important;
    }

    .app-main {
        flex-direction: row;
        height: 100%;
    }

    .app-subnav {
        display: block !important;
        width: var(--subnav-w);
        min-width: var(--subnav-w);
        max-width: var(--subnav-w);
    }

    .chat {
        height: 100%;
    }

    .chat-composer {
        padding: 0.45rem;
    }

    .app-footer {
        left: var(--sidebar-w);
    }

    .app-topbar-main {
        padding: 0 0.7rem;
    }

    .app-topbar-menu-button {
        display: inline-flex !important;
    }
    .app-topbar-left {
        display: flex !important;
    }
    .app-topbar-logo-link {
        display: none !important;
    }

    .app-topbar-title-chip {
        max-width: calc(100vw - 160px);
        padding: 0.35rem 0.8rem;
        font-size: 0.94rem;
    }

    .app-topbar-actions {
        gap: 0.45rem;
    }

    .app-topbar-balance,
    .app-topbar-nick,
    .app-topbar-sep {
        display: inline-flex;
    }

    .app-sidebar .scroll {
        padding-top: 0.1rem;
    }

    .app-sidebar-heading {
        padding: 0.2rem 0.5rem;
        font-size: 11px;
    }

    .app-sidebar-link {
        padding: 0.24rem 0.45rem 0.24rem 1.2rem;
        font-size: 11px;
        line-height: 1.15;
        word-break: break-word;
    }

    .app-sidebar-link::before {
        left: 0.52rem;
    }

    .app-sidebar-link-badge {
        display: block;
        width: fit-content;
        margin: 0.22rem 0 0;
    }

    body.mobile-sidebar-expanded .app-sidebar {
        width: var(--sidebar-w-expanded);
    }
    body.mobile-sidebar-expanded .app,
    body.mobile-sidebar-expanded .app-footer {
        margin-left: var(--sidebar-w-expanded) !important;
        left: var(--sidebar-w-expanded);
    }
    body.mobile-sidebar-expanded .app-sidebar-mobile-toolbar {
        justify-content: flex-end;
        padding: 0.2rem 0.3rem;
    }
    body.mobile-sidebar-expanded .app-sidebar .scroll {
        display: block;
    }

    .app-main {
        overflow-x: auto;
    }
    .table {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Classic theme: preserve desktop sidebar behavior */
    body.vp-classic .app-sidebar-mobile-toolbar {
        display: none !important;
    }
    body.vp-classic.mobile-sidebar-collapsed .app,
    body.vp-classic.mobile-sidebar-collapsed .app-footer {
        margin-left: var(--sidebar-w) !important;
    }
}

/* ========================================================
   MÓVIL PEQUEÑO (<576px) — subnav oculto (usar offcanvas),
   pero nick + balance visibles
   ======================================================== */
@media (max-width: 575.98px) {
    :root {
        --topbar-h: 58px;
        --sidebar-w: 44px;
        --sidebar-w-expanded: 126px;
        --sidebar-w-collapsed: 44px;
        --subnav-w: 0px;
    }

    .app-sidebar {
        display: block !important;
        width: var(--sidebar-w);
        z-index: 1000;
    }

    .app-sidebar-mobile-toolbar {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        height: 38px;
        padding: 0.2rem 0.3rem;
        border-bottom: 1px solid var(--vp-border);
        background: rgba(255, 255, 255, 0.4);
    }

    .app-sidebar .scroll {
        height: calc(100% - 38px);
        padding-top: 0.1rem;
    }

    .app {
        margin-left: var(--sidebar-w) !important;
    }

    .app-main {
        flex-direction: column;
        height: 100%;
    }

    .app-subnav {
        display: none !important;
    }

    .chat {
        height: 100%;
    }

    .chat-composer {
        padding: 0.45rem 0.5rem 0.5rem;
    }

    .app-footer {
        left: var(--sidebar-w);
    }

    .app-topbar-main {
        padding: 0 0.6rem;
    }

    .app-topbar-menu-button {
        display: inline-flex !important;
    }
    .app-topbar-left {
        display: flex !important;
    }
    .app-topbar-logo-link {
        display: none !important;
    }

    .app-topbar-title-chip {
        max-width: calc(100vw - 150px);
        padding: 0.3rem 0.7rem;
        font-size: 0.88rem;
    }

    .app-topbar-actions {
        gap: 0.35rem;
    }

    /* Nick y balance visibles incluso en móvil pequeño */
    .app-topbar-balance,
    .app-topbar-nick,
    .app-topbar-sep {
        display: inline-flex;
        font-size: 0.85rem;
    }

    .app-topbar-balance-icon {
        width: 14px;
        height: 14px;
    }

    .app-sidebar-heading {
        padding: 0.2rem 0.5rem;
        font-size: 11px;
    }

    .app-sidebar-link {
        padding: 0.24rem 0.45rem 0.24rem 1.2rem;
        font-size: 11px;
        line-height: 1.15;
        word-break: break-word;
    }

    .app-sidebar-link::before {
        left: 0.52rem;
    }

    .app-sidebar-link-badge {
        display: block;
        width: fit-content;
        margin: 0.22rem 0 0;
    }

    body.mobile-sidebar-expanded .app-sidebar {
        width: var(--sidebar-w-expanded);
    }
    body.mobile-sidebar-expanded .app,
    body.mobile-sidebar-expanded .app-footer {
        margin-left: var(--sidebar-w-expanded) !important;
        left: var(--sidebar-w-expanded);
    }
    body.mobile-sidebar-expanded .app-sidebar-mobile-toolbar {
        justify-content: flex-end;
        padding: 0.2rem 0.3rem;
    }
    body.mobile-sidebar-expanded .app-sidebar .scroll {
        display: block;
    }

    .app-main {
        overflow-x: auto;
    }
    .table {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Classic theme: preserve desktop sidebar behavior */
    body.vp-classic .app-sidebar-mobile-toolbar {
        display: none !important;
    }
    body.vp-classic.mobile-sidebar-collapsed .app,
    body.vp-classic.mobile-sidebar-collapsed .app-footer {
        margin-left: var(--sidebar-w) !important;
    }
}

/* ========================================================
   DESKTOP (≥992px)
   ======================================================== */
@media (min-width: 992px) {
    .app {
        margin-left: var(--sidebar-w);
    }

    .app-footer {
        left: var(--sidebar-w);
    }

    body {
        overflow: hidden;
    }

    /* Classic theme: protect from mobile-sidebar-collapsed */
    body.vp-classic.mobile-sidebar-collapsed .app,
    body.vp-classic.mobile-sidebar-collapsed .app-footer {
        margin-left: var(--sidebar-w) !important;
    }

    .table {
        width: auto !important;
        max-width: none !important;
    }
}
