/* ============================================================
   TEDDYMART UX v4.1 — MOBILE + FONT + SOURCE STABILITY LAYER
   Load this file LAST after page-specific CSS.
   ============================================================ */

:root {
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --tm-mobile-nav-h: 68px;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  font-family: var(--font);
  text-rendering: optimizeLegibility;
}

button, input, select, textarea, optgroup {
  font-family: inherit;
}

img, svg, video, canvas {
  max-width: 100%;
}

.main, .content, .card, .card-body, .card-header,
.form-group, form, fieldset, .topbar-left, .topbar-right {
  min-width: 0;
}

fieldset {
  max-width: 100%;
}

input, select, textarea, .form-control {
  max-width: 100%;
}

textarea {
  overflow-wrap: anywhere;
}

/* Ensure an old server/browser without color-mix still has opaque surfaces. */
.sidebar { background: var(--tm-panel, var(--bg-2)); }
.tm-topbar { background: var(--tm-shell, var(--bg-1)); }
.tm-mobile-nav { background: var(--tm-panel, var(--bg-2)); }
.tm-command-shell, .tm-shortcut-shell { background: var(--tm-panel, var(--bg-2)); }

/* Topbar must be shrinkable instead of pushing the whole page horizontally. */
.topbar {
  width: 100%;
  min-width: 0;
}
.topbar-left {
  min-width: 0;
  overflow: hidden;
}
.topbar-left h1,
.tm-page-title,
.tm-page-title h1 {
  min-width: 0;
}
.topbar-left h1,
.tm-page-title h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-right,
.tm-topbar-actions {
  flex: 0 0 auto;
  min-width: 0;
}

/* Mobile menu button is injected by ui-v4.js so every legacy/custom topbar works. */
.tm-mobile-menu {
  display: none;
  place-items: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--tm-line, var(--border));
  border-radius: 11px;
  color: var(--tm-text, var(--text-bright));
  background: var(--tm-panel, var(--bg-2));
  cursor: pointer;
}

/* Generic data tables remain usable instead of forcing the document wider. */
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.table-wrap table {
  width: 100%;
}
.table-wrap th,
.table-wrap td {
  overflow-wrap: anywhere;
}

/* Admin/system tabs should not enlarge the viewport. */
.system-control-tabs,
.tabs,
.tm-filter-group {
  max-width: 100%;
}

/* Better touch / Safari behavior. */
@media (max-width: 900px) {
  body {
    padding-bottom: calc(var(--tm-mobile-nav-h) + env(safe-area-inset-bottom, 0px));
  }

  .layout {
    display: block;
    width: 100%;
    min-height: 100dvh;
  }

  .main,
  body.tm-sidebar-collapsed .main {
    width: 100% !important;
    margin-left: 0 !important;
  }

  /*
   * Previous v4 used a 900px main breakpoint while legacy sidebar used 768px.
   * Between 769–900px the fixed sidebar covered the content. Unify it here.
   */
  .sidebar {
    display: flex !important;
    width: min(84vw, 300px) !important;
    max-width: 300px;
    transform: translate3d(-105%, 0, 0) !important;
    visibility: hidden;
    box-shadow: 16px 0 50px rgba(0,0,0,.34);
    transition: transform .22s ease, visibility .22s ease !important;
    will-change: transform;
  }

  body.tm-mobile-sidebar-open .sidebar,
  .sidebar.open {
    transform: translate3d(0, 0, 0) !important;
    visibility: visible;
  }

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

  .overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: block !important;
    background: rgba(2, 6, 14, .58);
    backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
  }

  body.tm-mobile-sidebar-open .overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .sidebar { z-index: 120; }
  .tm-mobile-nav { z-index: 115; }

  .tm-mobile-menu {
    display: grid;
  }

  .topbar,
  .tm-topbar {
    position: sticky;
    top: 0;
    z-index: 85;
    min-height: 58px;
    padding: 8px 12px !important;
    gap: 8px;
    background: var(--tm-shell, var(--bg-1));
  }

  .topbar-left {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    gap: 8px;
  }

  .topbar-left h1,
  .tm-topbar .topbar-left h1 {
    max-width: min(48vw, 320px);
    font-size: .94rem;
  }

  .topbar-right,
  .tm-topbar-actions {
    gap: 6px !important;
  }

  .shop-content,
  .marketplace-content,
  .content {
    width: 100%;
    max-width: 100%;
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  .shop-content,
  .marketplace-content {
    padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Never give checkbox/radio the global 44px input height. */
  input[type="checkbox"],
  input[type="radio"] {
    flex: 0 0 18px !important;
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    min-height: 18px !important;
    max-width: 18px !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* 16px prevents iOS Safari from zooming the page when a form gains focus. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
  select,
  textarea,
  .form-control {
    min-height: 46px;
    font-size: 16px !important;
  }

  input[type="file"] {
    max-width: 100%;
  }

  label:has(input[type="checkbox"]),
  label:has(input[type="radio"]),
  .proxy-toggle,
  .checkso-consent {
    align-items: flex-start !important;
    min-width: 0;
    line-height: 1.45;
  }

  .btn,
  .btn-nap {
    min-height: 44px;
  }

  .card {
    max-width: 100%;
    border-radius: 16px !important;
  }

  .card-header {
    min-width: 0;
  }

  .card-header > * {
    min-width: 0;
  }

  /* Inline two-column form layouts used by legacy pages. */
  .content > div[style*="grid-template-columns"],
  .card-body > div[style*="grid-template-columns"],
  form > div[style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* Keep progress/stat cards readable. */
  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Tool Center filter rail can scroll without moving the whole page. */
  .tm-filter-group,
  .shop-store-tabs,
  .system-control-tabs {
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .tm-filter-group::-webkit-scrollbar,
  .shop-store-tabs::-webkit-scrollbar,
  .system-control-tabs::-webkit-scrollbar {
    display: none;
  }

  /* Command palette becomes an actual mobile bottom sheet. */
  .tm-command-dialog,
  .tm-shortcut-dialog {
    top: auto !important;
    right: auto;
    bottom: 0;
    width: 100% !important;
    max-width: 100% !important;
    max-height: min(88dvh, 720px);
    transform: translateX(-50%) !important;
    border-radius: 20px 20px 0 0 !important;
  }
  .tm-command-shell,
  .tm-shortcut-shell {
    max-height: min(88dvh, 720px);
    border-radius: 20px 20px 0 0 !important;
  }
  .tm-command-results {
    max-height: min(58dvh, 460px) !important;
  }

  /* Tool context: description can wrap; price/trust move below only when useful. */
  .tm-tool-context {
    align-items: flex-start;
    gap: 10px;
    padding: 10px;
  }
  .tm-tool-context-main span {
    white-space: normal !important;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.4;
  }

  /* Admin table/forms. */
  .admin-actions,
  .market-dialog-actions,
  .checkso-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 620px) {
  .tm-command-trigger,
  [data-theme-toggle] {
    display: none !important;
  }

  .tm-balance-pill {
    min-width: 0;
    max-width: 82px;
    padding-inline: 8px !important;
  }
  .tm-balance-pill strong {
    max-width: 62px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tm-user-avatar,
  .topbar-right .user-avatar {
    flex: 0 0 36px;
    width: 36px !important;
    height: 36px !important;
  }

  .tm-topup-btn {
    display: grid !important;
    place-items: center;
    flex: 0 0 38px;
  }

  .tm-dashboard-primary,
  .tm-dashboard-balance,
  .tools-hero,
  .tool-policy-hero,
  .control-panel-hero,
  .history-hero,
  .membership-current {
    padding: 17px !important;
    border-radius: 16px !important;
  }

  .tm-dashboard-primary h2 {
    font-size: clamp(1.55rem, 8vw, 2rem) !important;
  }

  .tm-dashboard-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
  .tm-dashboard-actions .btn {
    width: 100%;
  }

  .tm-section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .tm-mobile-nav {
    width: calc(100vw - 12px) !important;
    bottom: max(6px, env(safe-area-inset-bottom, 0px)) !important;
    padding: 5px !important;
    border-radius: 15px !important;
  }

  .tm-mobile-nav a {
    min-width: 0;
    min-height: 48px;
  }

  .tm-mobile-nav a span {
    overflow: hidden;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tool-card-modern,
  .tools-grid.tm-list-view .tool-card-modern {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0 !important;
    min-height: 0 !important;
  }
  .tools-grid.tm-list-view .tool-card-head {
    display: flex !important;
  }
  .tools-grid.tm-list-view .tool-card-modern > p,
  .tools-grid.tm-list-view .tm-tool-meta,
  .tools-grid.tm-list-view .tool-card-actions {
    grid-column: auto !important;
    grid-row: auto !important;
  }

  .tool-policy-row {
    grid-template-columns: 1fr !important;
  }
  .tool-policy-icon {
    width: 44px !important;
    height: 44px !important;
  }
  .tool-policy-options {
    grid-template-columns: 1fr 1fr !important;
  }

  .system-control-tabs {
    display: flex !important;
    gap: 6px !important;
  }
  .system-control-tabs a {
    flex: 0 0 auto;
    min-width: 148px;
    justify-content: center !important;
  }

  .profile-card .email {
    overflow-wrap: anywhere;
  }
  .profile-stats {
    width: 100%;
    flex-wrap: wrap;
  }

  .checkso-card {
    padding: 17px !important;
  }
  .checkso-hero {
    padding: 18px !important;
  }
  .checkso-hero h2 {
    font-size: clamp(1.35rem, 7vw, 1.75rem);
  }
  .checkso-actions {
    display: grid !important;
    grid-template-columns: 1fr;
  }
  .checkso-actions .btn {
    width: 100%;
  }

  .file-drop-zone {
    padding: 20px 14px !important;
  }
  .file-drop-zone i {
    font-size: 2rem !important;
  }

  .tool-checker #bulk-progress-area > div[style*="display:flex"],
  .tool-checker #bulk-done-actions,
  .shop-inline-form {
    min-width: 0;
  }

  .pw-tabs {
    overflow-x: auto;
    display: flex !important;
    scrollbar-width: none;
  }
  .pw-tabs::-webkit-scrollbar { display: none; }
  .pw-tabs .tab-btn {
    flex: 0 0 auto;
    min-width: 128px;
    justify-content: center !important;
  }
  .pw-section-heading {
    min-width: 0;
  }
  .pw-section-heading > * {
    min-width: 0;
  }
}

@media (max-width: 420px) {
  .shop-content,
  .marketplace-content,
  .content,
  .tool-workspace-page .content {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  .topbar,
  .tm-topbar {
    padding-inline: 8px !important;
  }

  .topbar-left h1,
  .tm-topbar .topbar-left h1 {
    max-width: 42vw;
    font-size: .88rem;
  }

  .tm-balance-pill {
    display: none !important;
  }

  .stats-row {
    grid-template-columns: 1fr !important;
  }

  .tool-policy-options {
    grid-template-columns: 1fr !important;
  }

  .card-body {
    padding: 15px !important;
  }

  .tm-command-meta,
  .tm-command-foot {
    font-size: .58rem;
  }
  .tm-command-foot > span {
    display: none;
  }

  .tm-shortcut-shell {
    padding: 14px !important;
  }

  .tm-shortcut-grid > div {
    min-width: 0;
  }
}

/* PWA/safe-area-friendly bottom spacing for pages with fixed mobile nav. */
@supports (padding: max(0px)) {
  @media (max-width: 900px) {
    .tm-mobile-nav {
      padding-bottom: max(5px, env(safe-area-inset-bottom, 0px));
    }
  }
}

/* Reduce animation work on low-power mobile devices. */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .overlay,
  .tm-mobile-nav,
  .tm-command-dialog,
  .tm-shortcut-dialog {
    transition: none !important;
    animation: none !important;
  }
}


/* ============================================================
   RED BUNNY PRODUCT UX v4.6 — shortcuts, command groups, confirmations
   ============================================================ */
.tm-page-pin.active{color:#ff9a5b;border-color:rgba(255,122,56,.35);background:rgba(255,98,35,.08)}
.tm-sidebar-shortcut-list{display:grid;gap:2px;margin:0 0 8px}
.tm-sidebar-shortcut{display:flex;align-items:center;gap:9px;min-height:34px;padding:6px 9px;border-radius:8px;color:var(--tm-muted);font-size:.73rem;font-weight:650;text-decoration:none}
.tm-sidebar-shortcut:hover{color:var(--tm-text);background:rgba(148,163,184,.06)}
.tm-sidebar-shortcut kbd{display:grid;place-items:center;width:19px;height:19px;padding:0;border-radius:6px;color:var(--tm-subtle);background:var(--tm-panel-2);font-size:.56rem}
.tm-sidebar-shortcut span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
body.tm-sidebar-collapsed .tm-sidebar-shortcuts .nav-section,body.tm-sidebar-collapsed .tm-sidebar-shortcut span{display:none}
body.tm-sidebar-collapsed .tm-sidebar-shortcut{justify-content:center;padding-inline:0}
.tm-command-group{padding:8px 10px 4px;color:var(--tm-subtle);font-size:.58rem;font-weight:850;letter-spacing:.11em;text-transform:uppercase}
.tm-tool-category-filter select{min-height:36px;padding:7px 28px 7px 10px;border:1px solid var(--tm-line);border-radius:9px;color:var(--tm-muted);background:var(--tm-panel);font:inherit;font-size:.72rem}
.tm-toast-root{position:fixed;z-index:500;right:18px;bottom:18px;display:grid;gap:8px;width:min(380px,calc(100vw - 24px));pointer-events:none}
.tm-toast{display:grid;grid-template-columns:auto minmax(0,1fr) auto;align-items:center;gap:10px;padding:12px 13px;border:1px solid var(--tm-line-strong);border-radius:12px;color:var(--tm-text);background:color-mix(in srgb,var(--tm-panel) 96%,transparent);box-shadow:0 18px 54px rgba(0,0,0,.28);backdrop-filter:blur(16px);pointer-events:auto;animation:tmToastIn .18s ease}
.tm-toast>i{color:var(--tm-blue)}.tm-toast-error>i{color:#fb7185}.tm-toast-success>i{color:#4ade80}.tm-toast span{font-size:.76rem;line-height:1.4}.tm-toast button{border:0;color:var(--tm-subtle);background:transparent;cursor:pointer}.tm-toast.is-leaving{opacity:0;transform:translateY(6px);transition:.18s ease}
@keyframes tmToastIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.tm-confirm-dialog,.tm-customize-dialog{width:min(520px,calc(100vw - 24px));max-width:none;padding:0;border:0;border-radius:18px;color:var(--tm-text);background:transparent;box-shadow:0 28px 80px rgba(0,0,0,.38)}
.tm-confirm-dialog::backdrop,.tm-customize-dialog::backdrop{background:rgba(2,6,13,.66);backdrop-filter:blur(5px)}
.tm-confirm-shell,.tm-customize-shell{overflow:hidden;border:1px solid var(--tm-line-strong);border-radius:18px;background:var(--tm-panel)}
.tm-confirm-shell{display:grid;grid-template-columns:auto minmax(0,1fr);gap:13px;padding:18px}
.tm-confirm-icon{display:grid;place-items:center;width:42px;height:42px;border-radius:12px;color:#fb7185;background:rgba(244,63,94,.10)}
.tm-confirm-copy h2{margin:1px 0 6px;font-size:1rem}.tm-confirm-copy p{margin:0;color:var(--tm-muted);font-size:.78rem;line-height:1.55}
.tm-confirm-actions{grid-column:1/-1;display:flex;justify-content:flex-end;gap:8px;margin-top:5px}
.tm-customize-shell header{display:flex;align-items:flex-start;justify-content:space-between;gap:15px;padding:18px;border-bottom:1px solid var(--tm-line)}
.tm-customize-shell h2{margin:4px 0 2px;font-size:1.05rem}.tm-customize-shell header p{margin:0;color:var(--tm-muted);font-size:.73rem}
.tm-customize-options{display:grid;gap:7px;padding:12px}.tm-customize-options label{display:flex;align-items:flex-start;gap:11px;padding:11px;border:1px solid var(--tm-line);border-radius:11px;background:var(--tm-panel-2);cursor:pointer}.tm-customize-options input{margin-top:2px}.tm-customize-options strong,.tm-customize-options small{display:block}.tm-customize-options strong{font-size:.78rem}.tm-customize-options small{margin-top:2px;color:var(--tm-muted);font-size:.65rem}.tm-customize-shell footer{display:flex;justify-content:space-between;gap:8px;padding:12px;border-top:1px solid var(--tm-line)}
.admin-user-toolbar{display:grid;grid-template-columns:minmax(220px,1fr) 170px 170px;gap:8px;padding:10px 12px;border-top:1px solid var(--tm-line);border-bottom:1px solid var(--tm-line);background:var(--tm-panel-2)}
.admin-user-search{display:flex;align-items:center;gap:8px;min-height:38px;padding:0 10px;border:1px solid var(--tm-line);border-radius:9px;background:var(--tm-panel)}.admin-user-search i{color:var(--tm-subtle)}.admin-user-search input{min-width:0;flex:1;border:0;outline:0;color:var(--tm-text);background:transparent;font:inherit;font-size:.78rem}
.tabs{position:sticky;top:62px;z-index:24;display:flex;gap:5px;padding:6px;border:1px solid var(--tm-line);border-radius:13px;background:color-mix(in srgb,var(--tm-shell) 94%,transparent);backdrop-filter:blur(14px);overflow-x:auto;scrollbar-width:none}.tabs::-webkit-scrollbar{display:none}.tabs .tab-btn{display:flex;align-items:center;gap:7px;flex:0 0 auto}
[data-dashboard-section][hidden]{display:none!important}
@media(max-width:900px){.admin-user-toolbar{grid-template-columns:1fr 1fr}.admin-user-search{grid-column:1/-1}.tabs{top:58px}.tm-toast-root{right:10px;bottom:calc(82px + env(safe-area-inset-bottom,0px))}}
@media(max-width:560px){.admin-user-toolbar{grid-template-columns:1fr}.admin-user-search{grid-column:auto}.tm-tool-category-filter,.tm-tool-category-filter select{width:100%}.tm-confirm-actions,.tm-customize-shell footer{display:grid;grid-template-columns:1fr}.tm-confirm-actions .btn,.tm-customize-shell footer .btn{width:100%}.tm-confirm-shell{grid-template-columns:1fr}.tm-confirm-icon{width:38px;height:38px}.tm-toast-root{left:10px;right:10px;width:auto}}
