/* TradeMate mobile UX refinement · 2026-10-18
   A final, non-destructive layer over existing page styles.
   Keep page-specific desktop layouts intact. */
:root { --tm-mobile-gutter: 16px; --tm-touch-target: 44px; }
html { scroll-padding-top: 82px; }
:where(.workspace,.content,.app-shell,main,section,article) { min-width: 0; }
:where(.workspace,.content) :where(img,video,canvas) { max-width: 100%; }
:where(.workspace,.content) :where(h1,h2,h3,p) { overflow-wrap: break-word; }
:where(a,button,input,select,textarea,[role="button"]):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
:where(input,textarea,select) { max-width: 100%; }
.tm-skip-link { position:fixed;z-index:2000;top:10px;left:12px;transform:translateY(-180%);padding:12px 18px;border-radius:10px;color:#fff;background:var(--accent);font-weight:750;text-decoration:none; }
.tm-skip-link:focus { transform:translateY(0); }
body.mobile-nav-open { overflow: hidden; }
/* Drawer remains reachable on narrow tablets; the original sidebar sizing remains on desktop. */
@media (max-width:900px) {
  .workspace,body.sidebar-collapsed .workspace { margin-left:0 !important; }
  .mobile-menu,.icon-button.mobile-only { display:grid !important; }
  .desktop-only { display:none !important; }
  .sidebar,body.sidebar-collapsed .sidebar {
    position:fixed;z-index:62;top:0;bottom:0;left:0;right:auto;
    width:min(86vw,316px) !important;height:100dvh;max-height:100dvh;
    padding:calc(19px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
    transform:translateX(-105%);box-shadow:none;
  }
  .sidebar.mobile-open,body.sidebar-collapsed .sidebar.mobile-open { transform:translateX(0);box-shadow:15px 0 60px #0005; }
  .sidebar-nav,body.sidebar-collapsed .sidebar-nav { min-height:0;flex:1;overflow-y:auto;overscroll-behavior:contain;margin-top:20px !important;padding:5px 4px 18px; }
  .sidebar-foot { flex:none;padding-bottom:3px; }
  .sidebar-backdrop { position:fixed;inset:0;z-index:60;background:rgba(5,8,20,.67);backdrop-filter:blur(2px); }
  body.mobile-nav-open .sidebar-backdrop { display:block; }
  .sidebar-label,body.sidebar-collapsed .sidebar-label { width:auto !important;opacity:1 !important;pointer-events:auto; }
  .sidebar .brand-name,body.sidebar-collapsed .sidebar .brand-name { display:inline !important; }
  .sidebar-head,body.sidebar-collapsed .sidebar-head { justify-content:space-between; }
  .sidebar .nav-item,body.sidebar-collapsed .sidebar .nav-item { min-height:46px;height:auto;padding:10px 13px !important;justify-content:flex-start !important;gap:12px;white-space:normal; }
  .sidebar .sidebar-section-label { margin-top:12px; }
  .sidebar .nav-item.active { border-radius:11px; }
  .topbar { height:58px;padding:0 20px; }
  .topbar .icon-button.mobile-menu { flex:0 0 44px;width:44px;height:44px;margin-left:-7px;color:var(--text); }
  .topbar-title { min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:12px; }
  .topbar-title>:last-child { overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
}
@media (max-width:720px) {
  html { scroll-padding-top:72px; }
  .content { padding:24px var(--tm-mobile-gutter) calc(111px + env(safe-area-inset-bottom)) !important; }
  .topbar { height:56px;padding-inline:var(--tm-mobile-gutter); }
  .topbar-title { gap:6px; }
  .topbar-title strong { font-size:12px; }
  .tm-mobile-dock { min-height:68px;padding:5px max(7px,env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(7px,env(safe-area-inset-left));z-index:45; }
  .tm-mobile-dock>a,.tm-mobile-dock>button { min-height:51px;border-radius:11px;touch-action:manipulation; }
  .tm-mobile-dock>a:active,.tm-mobile-dock>button:active { background:var(--accent-soft); }
  .tm-mobile-dock .tm-dock-create>span:first-child { min-width:36px;min-height:32px; }
  :where(.content) :where(input:not([type="checkbox"]):not([type="radio"]),textarea,select) { font-size:16px !important; } /* Prevents iOS auto-zoom */
  :where(.content) :where(.tm-action-primary,.secondary-button,.ops-button,.journal-advanced-toggle) { min-height:44px; }
  :where(.content) :where(button,a,select,input,textarea) { touch-action:manipulation; }
  :where(.content) :where(h1,h2) { text-wrap:pretty; }
  .tm-toast,.toast-stack { max-width:calc(100vw - 28px); }
  .toast-stack { bottom:calc(87px + env(safe-area-inset-bottom)); }
  .tm-confirm-overlay { padding:14px; }
  .tm-confirm-dialog { width:100%;max-height:calc(100dvh - 36px);overflow-y:auto; }
  .tm-confirm-actions>button { min-height:44px; }
  /* Card lists: text and actions are legible on phones; tablet grids stay as designed. */
  .pl-filter-tabs{ overflow-x:auto;overscroll-behavior-x:contain;scrollbar-width:none;flex-wrap:nowrap;scroll-snap-type:x proximity;-webkit-overflow-scrolling:touch; }
  .pl-filter-tabs::-webkit-scrollbar{ display:none; }
  .pl-filter-tabs>button { flex:none;min-height:42px;padding:0 13px; }
  .pl-card-bookmark { min-width:44px;min-height:44px;width:44px;height:44px; }
  .pl-card-link,.pl-card-native { min-height:38px;display:inline-flex;align-items:center; }
  /* Forms and editors: actions and labels do not run out of the viewport. */
  .journal-head-actions,.ops-page-head { flex-wrap:wrap; }
  .journal-save-bar { max-width:100%; }
  .journal-save-bar :where(button,a) :where(button,a) { min-height:44px; }
  .account-modal-dialog { scroll-padding-bottom:30px; }
  .account-modal-close,.account-password-toggle { min-height:44px;min-width:44px; }
  .account-table .account-row-actions .ops-button { min-height:44px; }
  .account-checkbox { width:20px;height:20px; }
}
@media (max-width:540px) {
  /* One full-width card instead of two 160px-wide cards. */
  .pl-grid { grid-template-columns:minmax(0,1fr);gap:13px; }
  .pl-card { border-radius:17px; }
  .pl-card-cover { height:205px; }
  .pl-card-body { padding:15px; }
  .pl-card h3 { min-height:auto;font-size:15px;line-height:1.5; }
  .pl-card-note { display:-webkit-box;font-size:12px; }
  .pl-card-footer { align-items:center; }
  .pl-stat-row { gap:7px; }
  .pl-stat { padding:12px; }
  .pl-hero-progress { width:100%;max-width:none; }
  .account-toolbar { grid-template-columns:minmax(0,1fr); }
  .account-selection-bar { flex-wrap:wrap; }
  .ops-page-head>.ops-button { width:100%; }
}
@media (max-width:370px) {
  :root { --tm-mobile-gutter:12px; }
  .topbar-title strong,.topbar-title>span:nth-of-type(2) { display:none; }
  .pl-stat { padding-inline:9px; }
  .tm-mobile-dock>a,.tm-mobile-dock>button { font-size:9px; }
}
@media (prefers-reduced-motion:reduce) {
  .sidebar,.tm-mobile-dock { transition-duration:.01ms!important;animation-duration:.01ms!important; }
  html { scroll-behavior:auto!important; }
}
/* High-value at-a-glance view on small phones: preserve all four KPIs above the fold. */
@media (max-width:540px) {
  .dashboard-summary-grid { grid-template-columns:repeat(2,minmax(0,1fr));gap:10px; }
  .dashboard-stat-card { min-height:112px;padding:14px 12px; }
  .dashboard-stat-head { gap:5px; }
  .dashboard-stat-card strong { display:block;font-size:clamp(17px,5vw,23px);overflow-wrap:anywhere; }
  .dashboard-stat-card>p,.dashboard-stat-with-links>p { font-size:10px;line-height:1.5; }
  .dashboard-hero { gap:12px; }
  .dashboard-hero-actions { flex-direction:row;gap:8px; }
  .dashboard-hero-actions .tm-action-primary,.dashboard-hero-actions .secondary-button { flex:1 1 0;min-height:46px;height:auto;padding:8px;font-size:11px; }
  .pl-hero { min-height:0;padding:21px 19px;gap:14px; }
  .pl-hero h2 { margin:10px 0 8px;font-size:clamp(22px,6vw,27px); }
  .pl-hero-progress { padding:14px 17px; }
  .pl-progress-figure { margin:8px 0; }
  .pl-progress-figure strong { font-size:42px; }
  .pl-hero-progress p { margin-bottom:0;margin-top:8px; }
  .pl-hero-copy>p { margin-bottom:0; }
  .pl-stat { min-height:83px; }
}
@media (max-width:370px) {
  .dashboard-hero-actions { flex-direction:column; }
  .dashboard-hero-actions .tm-action-primary,.dashboard-hero-actions .secondary-button { width:100%;flex:0 0 auto; }
}

/* Sidebar drawer: group labels remain visible on tablets and phones. */
@media(max-width:900px) {
  .sidebar,body.sidebar-collapsed .sidebar {padding-inline:14px;}
  .sidebar-head,body.sidebar-collapsed .sidebar-head {min-height:56px;flex:0 0 56px;padding:0 3px;justify-content:space-between;}
  .sidebar-head .brand,body.sidebar-collapsed .sidebar-head .brand {display:flex !important;}
  .sidebar-head .brand-name,body.sidebar-collapsed .sidebar-head .brand-name {display:inline !important;opacity:1 !important;width:auto !important;}
  .sidebar-head .sidebar-collapse-control,.sidebar-head .sidebar-rail-open,
  body.sidebar-collapsed .sidebar-head .sidebar-collapse-control,
  body.sidebar-collapsed .sidebar-head .sidebar-rail-open {display:none !important;}
  .sidebar-head .sidebar-mobile-close,body.sidebar-collapsed .sidebar-head .sidebar-mobile-close {display:inline-grid !important;}
  .sidebar-nav,body.sidebar-collapsed .sidebar-nav {margin-top:16px !important;gap:13px;padding:0 0 20px;}
  .sidebar-group-toggle,body.sidebar-collapsed .sidebar-group-toggle {
    display:flex;min-height:44px;padding:0 12px;color:color-mix(in srgb,var(--text) 80%,var(--muted));
    font-size:13px;font-weight:800;letter-spacing:.015em;
  }
  .sidebar-group-title,body.sidebar-collapsed .sidebar-group-title {display:block !important;opacity:1 !important;width:auto !important;visibility:visible;}
  .sidebar-group-links,body.sidebar-collapsed .sidebar-group-links {display:flex;flex-direction:column;gap:3px;padding-top:3px;}
  .sidebar-nav-group.is-folded .sidebar-group-links,
  body.sidebar-collapsed .sidebar-nav-group.is-folded .sidebar-group-links {display:none;}
  .sidebar-nav-group + .sidebar-nav-group,body.sidebar-collapsed .sidebar-nav-group + .sidebar-nav-group {border:0;padding:0;}
  .sidebar .sidebar-nav-group .nav-item,body.sidebar-collapsed .sidebar .sidebar-nav-group .nav-item {
    min-height:46px;height:auto;min-width:0;justify-content:flex-start !important;padding:11px 13px !important;gap:12px;
  }
  .sidebar .sidebar-nav-group .nav-item .sidebar-label,
  body.sidebar-collapsed .sidebar .sidebar-nav-group .nav-item .sidebar-label {display:inline !important;opacity:1 !important;width:auto !important;white-space:normal;}
  .sidebar-foot .nav-item .sidebar-label,body.sidebar-collapsed .sidebar-foot .nav-item .sidebar-label {display:inline !important;opacity:1 !important;width:auto !important;}
  .sidebar-foot .nav-item,body.sidebar-collapsed .sidebar-foot .nav-item {justify-content:flex-start !important;padding:10px 13px !important;gap:12px;}
}
