/* Mobile app shell for authenticated trading pages. Desktop sidebar remains owned by style.css. */
:root {
  --tm-mobile-topbar-h: 58px;
  --tm-mobile-bottomnav-h: 66px;
}

.tm-mobile-shell {
  display: none;
}

@media (min-width: 769px) {
  .tm-mobile-shell {
    display: none !important;
  }
}

@media (max-width: 768px) {
  html {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    padding-left: 0 !important;
    max-width: 100%;
    overflow-x: hidden;
  }

  body.tm-mobile-drawer-open {
    overflow: hidden;
    touch-action: none;
  }

  .topnav {
    display: none !important;
  }

  .tm-mobile-shell {
    display: block;
  }

  .tm-mobile-shell,
  .tm-mobile-shell * {
    box-sizing: border-box;
  }

  .tm-mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 1100;
    min-height: calc(var(--tm-mobile-topbar-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 12px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(14px);
  }

  .tm-mobile-brand {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--fg-strong);
    text-decoration: none;
  }

  .tm-mobile-brand-mark,
  .tm-mobile-avatar,
  .tm-mobile-link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--accent);
    background: var(--accent-light);
  }

  .tm-mobile-brand-mark {
    width: 36px;
    height: 36px;
    border: 1px solid rgba(15, 118, 110, 0.18);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.02em;
  }

  .tm-mobile-brand-mark svg {
    width: auto;
    height: 18px;
  }

  .tm-mobile-page-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
    font-weight: 750;
  }

  .tm-mobile-topbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  .tm-mobile-icon-btn,
  .tm-mobile-avatar-btn {
    position: relative;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--fg);
    background: var(--panel);
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
  }

  .tm-mobile-icon-btn svg,
  .tm-mobile-tab-icon svg {
    width: 20px;
    height: 20px;
    stroke-width: 1.9;
  }

  .tm-mobile-icon-btn:focus-visible,
  .tm-mobile-avatar-btn:focus-visible,
  .tm-mobile-tab:focus-visible,
  .tm-mobile-drawer-link:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
  }

  .tm-mobile-avatar-btn {
    padding: 0;
  }

  .tm-mobile-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
  }

  .tm-mobile-avatar--lg {
    width: 42px;
    height: 42px;
    font-size: 15px;
  }

  .tm-mobile-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    border: 2px solid var(--panel);
  }

  .tm-mobile-badge--danger {
    background: #ef4444;
  }

  .tm-mobile-badge--warning {
    background: #f59e0b;
  }

  .tm-mobile-bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    min-height: calc(var(--tm-mobile-bottomnav-h) + env(safe-area-inset-bottom));
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    border-top: 1px solid var(--border);
    box-shadow: 0 -12px 30px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(14px);
  }

  .tm-mobile-tab {
    position: relative;
    min-width: 0;
    min-height: 52px;
    padding: 5px 3px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--muted);
    background: transparent;
    text-decoration: none;
    font: inherit;
    cursor: pointer;
  }

  .tm-mobile-tab.active {
    color: var(--accent);
    background: var(--accent-light);
    font-weight: 750;
  }

  .tm-mobile-tab-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
  }

  .tm-mobile-tab-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    line-height: 1.1;
  }

  .tm-mobile-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1190;
    background: rgba(15, 23, 42, 0.42);
    backdrop-filter: blur(2px);
  }

  .tm-mobile-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1200;
    width: min(360px, 92vw);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-left: 1px solid var(--border);
    box-shadow: -18px 0 42px rgba(15, 23, 42, 0.22);
  }

  .tm-mobile-drawer-header {
    padding: calc(16px + env(safe-area-inset-top)) 14px 12px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
  }

  .tm-mobile-user {
    min-width: 0;
    display: flex;
    align-items: flex-start;
    gap: 10px;
  }

  .tm-mobile-user-meta {
    min-width: 0;
    display: grid;
    gap: 2px;
  }

  .tm-mobile-user-meta h2 {
    margin: 0;
    color: var(--fg-strong);
    font-size: 16px;
    line-height: 1.2;
  }

  .tm-mobile-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--fg);
    font-size: 13px;
    font-weight: 700;
  }

  .tm-mobile-user-role,
  .tm-mobile-section-label {
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .tm-mobile-account-meta {
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .tm-mobile-drawer-nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 12px 6px;
    display: grid;
    align-content: start;
    gap: 14px;
  }

  .tm-mobile-drawer-section {
    display: grid;
    gap: 5px;
  }

  .tm-mobile-section-label {
    padding: 0 8px 4px;
  }

  .tm-mobile-drawer-link {
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--fg);
    text-decoration: none;
    font-size: 14px;
    font-weight: 650;
  }

  .tm-mobile-drawer-link.active {
    color: var(--accent);
    background: var(--accent-light);
  }

  .tm-mobile-link-icon {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-md);
    font-size: 10px;
    font-weight: 850;
    letter-spacing: 0.03em;
  }

  .tm-mobile-drawer-footer {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    display: grid;
    gap: 10px;
  }

  .tm-mobile-theme-row {
    min-height: 44px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .tm-mobile-theme-label {
    color: var(--fg);
    font-size: 14px;
    font-weight: 700;
  }

  .tm-mobile-login-cta,
  .tm-mobile-logout {
    width: 100%;
    justify-content: center;
  }

  .container {
    padding-top: 14px;
    padding-bottom: calc(var(--tm-mobile-bottomnav-h) + env(safe-area-inset-bottom) + 22px);
  }

  .app-footer {
    padding-bottom: calc(var(--tm-mobile-bottomnav-h) + env(safe-area-inset-bottom));
  }

  html[data-theme='dark'] .tm-mobile-topbar,
  html[data-theme='dark'] .tm-mobile-bottomnav {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.26);
  }
}
