/* Mobile-first responsive optimizations for LLM Router (supracord.com) */

/* === Base Mobile Typography === */
@media (max-width: 768px) {
  html { font-size: 14px; }
  body { -webkit-text-size-adjust: 100%; }
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
  h3 { font-size: 1.1rem !important; }
}

/* === Touch-Friendly Buttons === */
@media (max-width: 768px) {
  button, 
  [role="button"],
  .btn,
  a.button {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
    font-size: 14px;
    touch-action: manipulation;
  }
}

/* === Tables → Cards on Mobile === */
@media (max-width: 640px) {
  table, thead, tbody, th, td, tr {
    display: block;
  }
  thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  tr {
    border: 1px solid var(--border, #30363d);
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 8px;
  }
  td {
    border: none;
    border-bottom: 1px solid var(--border, #30363d);
    position: relative;
    padding-left: 50%;
    text-align: right;
    font-size: 13px;
  }
  td:before {
    content: attr(data-label);
    position: absolute;
    left: 12px;
    width: 45%;
    white-space: nowrap;
    font-weight: 600;
    text-align: left;
    color: var(--text2, #8b949e);
    font-size: 11px;
    text-transform: uppercase;
  }
  td:last-child { border-bottom: 0; }
}

/* === Grid → Stack === */
@media (max-width: 768px) {
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  [style*="minmax(400px"] {
    grid-template-columns: 1fr !important;
  }
  [style*="display: grid"] {
    gap: 12px !important;
  }
}

/* === Navigation: Bottom Tab Bar === */
@media (max-width: 768px) {
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg2, #161b22);
    border-top: 1px solid var(--border, #30363d);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .mobile-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text2, #8b949e);
    text-decoration: none;
    padding: 4px 0;
  }
  .mobile-nav a.active {
    color: var(--accent, #58a6ff);
  }
  .mobile-nav a svg {
    width: 22px;
    height: 22px;
    margin-bottom: 2px;
  }
  
  /* Push content above tab bar */
  body { padding-bottom: 60px; }
}

/* === Sidebar → Off-Canvas === */
@media (max-width: 768px) {
  aside, .sidebar, [class*="sidebar"] {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 999;
    transition: left 0.3s ease;
    overflow-y: auto;
  }
  aside.open, .sidebar.open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 998;
  }
  .sidebar-overlay.open { display: block; }
}

/* === Forms: Full-Width === */
@media (max-width: 640px) {
  input, select, textarea {
    width: 100%;
    font-size: 16px; /* prevent iOS zoom */
    padding: 10px 12px;
    border-radius: 8px;
  }
  label {
    font-size: 13px;
    margin-bottom: 4px;
  }
}

/* === Modals: Full-Screen === */
@media (max-width: 640px) {
  .modal, [class*="modal"], [class*="dialog"] {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    top: 0 !important;
    left: 0 !important;
  }
}

/* === Code Blocks: Horizontal Scroll === */
@media (max-width: 640px) {
  pre, code {
    font-size: 11px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: pre-wrap;
    word-break: break-all;
  }
}

/* === Hidden on Mobile === */
@media (max-width: 640px) {
  .desktop-only { display: none !important; }
}

/* === Shown only on Mobile === */
@media (min-width: 769px) {
  .mobile-only { display: none !important; }
}

/* === Safe Area for Notch Phones === */
@supports (padding: env(safe-area-inset-top)) {
  .safe-top { padding-top: env(safe-area-inset-top); }
  .safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
}

/* === Performance: Reduce Motion === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* === Touch: Remove Tap Highlight === */
* {
  -webkit-tap-highlight-color: transparent;
}

/* === Scroll: Smooth on Mobile === */
@media (max-width: 768px) {
  html { scroll-behavior: smooth; }
  ::-webkit-scrollbar { width: 0; }
}
