/**
 * ToolGrid Tablet Responsiveness Fixes — v2.5 production build
 * Targeted CSS for tablet breakpoints (641px to 1024px)
 * Fixes root layout issues without affecting mobile or desktop.
 *
 * Key fixes in this version:
 *   - Restore text selection on tablets (remove blanket user-select: none)
 *   - 3-column grid on mid-tablets (was 2)
 *   - AI workspace chat fills available height on tablets
 *   - Tool box doesn't force-center AI workspace content
 *   - Premium workspaces align with tablet bands
 *   - Navigation drawer sized properly for tablets
 */

/* =========================================================
   1. IPAD AIR / IPAD PRO 11" (768px–850px)
   ========================================================= */
@media (min-width: 768px) and (max-width: 850px) {
  .container {
    padding-left: 16px;
    padding-right: 16px;
    max-width: 100%;
  }

  .tg-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }

  .tg-card {
    padding: 18px;
  }

  .tg-card h3 {
    font-size: 15px;
  }

  .tg-card p {
    font-size: 13px;
  }

  .tg-tool-form-row {
    grid-template-columns: 1fr;
  }

  .tg-mode-toggle {
    flex-direction: row;
  }

  .tg-mode-toggle button {
    flex: 1;
    width: auto;
  }

  .tg-hero {
    padding: 40px 16px;
  }

  .tg-hero h1 {
    font-size: 28px;
  }

  .tg-hero p {
    font-size: 15px;
  }

  .tg-search {
    font-size: 16px;
    padding: 12px 14px;
  }

  .tg-cat-btn {
    padding: 10px 14px;
    font-size: 13px;
  }

  .tg-tool-wrap {
    padding: 20px 16px;
  }

  .tg-tool-header h1 {
    font-size: 24px;
  }

  .tg-tool-header p {
    font-size: 14px;
  }

  .tg-howto,
  .tg-related {
    padding: 20px 0;
  }

  .tg-related-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

/* =========================================================
   2. IPAD STANDARD / IPAD AIR 2 (851px–900px)
   ========================================================= */
@media (min-width: 851px) and (max-width: 900px) {
  .container {
    padding-left: 18px;
    padding-right: 18px;
    max-width: 100%;
  }

  .tg-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
  }

  .tg-card {
    padding: 18px;
  }

  .tg-card h3 {
    font-size: 16px;
  }

  .tg-card p {
    font-size: 14px;
  }

  .tg-tool-form-row {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  .tg-mode-toggle {
    flex-direction: row;
  }

  .tg-mode-toggle button {
    flex: 1;
    width: auto;
  }

  .tg-hero {
    padding: 45px 18px;
  }

  .tg-hero h1 {
    font-size: 30px;
  }

  .tg-hero p {
    font-size: 16px;
  }

  .tg-search {
    font-size: 16px;
    padding: 12px 14px;
  }

  .tg-cat-btn {
    padding: 11px 15px;
    font-size: 14px;
  }

  .tg-tool-wrap {
    padding: 24px 18px;
  }

  .tg-tool-header h1 {
    font-size: 26px;
  }

  .tg-tool-header p {
    font-size: 15px;
  }

  .tg-howto,
  .tg-related {
    padding: 24px 0;
  }

  .tg-related-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
  }
}

/* =========================================================
   3. SURFACE PRO 7 / IPAD PRO 10.5" (901px–950px)
   ========================================================= */
@media (min-width: 901px) and (max-width: 950px) {
  .container {
    padding-left: 20px;
    padding-right: 20px;
    max-width: 100%;
  }

  .tg-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }

  .tg-card {
    padding: 18px;
  }

  .tg-card h3 {
    font-size: 16px;
  }

  .tg-card p {
    font-size: 14px;
  }

  .tg-tool-form-row {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }

  .tg-mode-toggle {
    flex-direction: row;
  }

  .tg-mode-toggle button {
    flex: 1;
    width: auto;
  }

  .tg-hero {
    padding: 50px 20px;
  }

  .tg-hero h1 {
    font-size: 32px;
  }

  .tg-hero p {
    font-size: 17px;
  }

  .tg-search {
    font-size: 16px;
    padding: 12px 14px;
    max-width: 600px;
  }

  .tg-cat-btn {
    padding: 12px 16px;
    font-size: 14px;
  }

  .tg-tool-wrap {
    padding: 28px 20px;
  }

  .tg-tool-header h1 {
    font-size: 28px;
  }

  .tg-tool-header p {
    font-size: 15px;
  }

  .tg-howto,
  .tg-related {
    padding: 28px 0;
  }

  .tg-related-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }
}

/* =========================================================
   4. IPAD PRO 12.9" (951px–1024px)
   ========================================================= */
@media (min-width: 951px) and (max-width: 1024px) {
  .container {
    padding-left: 24px;
    padding-right: 24px;
    max-width: 100%;
  }

  .tg-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
  }

  .tg-card {
    padding: 20px;
  }

  .tg-card h3 {
    font-size: 17px;
  }

  .tg-card p {
    font-size: 14px;
  }

  .tg-tool-form-row {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  .tg-mode-toggle {
    flex-direction: row;
  }

  .tg-mode-toggle button {
    flex: 1;
    width: auto;
  }

  .tg-hero {
    padding: 60px 24px;
  }

  .tg-hero h1 {
    font-size: 36px;
  }

  .tg-hero p {
    font-size: 18px;
  }

  .tg-search {
    font-size: 16px;
    padding: 13px 15px;
    max-width: 700px;
  }

  .tg-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 32px;
  }

  .tg-cat-btn {
    padding: 12px 18px;
    font-size: 14px;
  }

  .tg-tool-wrap {
    padding: 32px 24px;
  }

  .tg-tool-header h1 {
    font-size: 32px;
  }

  .tg-tool-header p {
    font-size: 16px;
  }

  .tg-howto,
  .tg-related {
    padding: 32px 0;
  }

  .tg-related-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
  }
}

/* =========================================================
   5. AI WORKSPACE — tablet-specific chat & layout fixes
   ========================================================= */
@media (min-width: 641px) and (max-width: 1024px) {
  /* Workspace: fill available vertical space without excess gaps */
  .tg-ai-native-workspace,
  .tg-ai-workspace {
    margin-bottom: 16px;
  }

  /* Body: remove the aggressive 500px minimum that wastes vertical space on tablets */
  .tg-workspace-body {
    min-height: 0 !important;
    height: auto !important;
  }

  /* Chat history: taller on tablets to use the viewport */
  .tg-chat-history {
    max-height: min(520px, 55vh) !important;
  }

  /* Composer adjustments for tablets */
  .tg-composer {
    padding: 12px 16px 16px;
  }

  /* Result cards: full width on tablets */
  .tg-result-card {
    width: 100%;
  }

  /* Prompt chips: allow more wrapping on tablets */
  .tg-prompt-chips {
    gap: 6px;
  }

  .tg-prompt-chip {
    font-size: 11.5px;
    padding: 5px 10px;
  }

  /* Tool box: don't force centering when AI workspace is inside */
  #tool-view .tg-tool-box {
    text-align: left !important;
    display: block !important;
    min-height: 0 !important;
    justify-content: unset !important;
    align-items: unset !important;
  }
}

/* =========================================================
   6. LANDSCAPE ORIENTATION ADJUSTMENTS
   ========================================================= */
@media (orientation: landscape) and (max-height: 600px) {
  .tg-hero {
    padding: 20px 16px;
  }

  .tg-hero h1 {
    font-size: 22px;
    margin-bottom: 8px;
  }

  .tg-hero p {
    font-size: 13px;
    margin-bottom: 12px;
  }

  .search-container {
    margin-top: 12px;
  }

  .tg-cats {
    margin-bottom: 16px;
  }

  .tg-grid {
    gap: 12px;
  }

  .tg-chat-history {
    max-height: min(280px, 40vh) !important;
  }
}

/* =========================================================
   7. PORTRAIT ORIENTATION ADJUSTMENTS
   ========================================================= */
@media (orientation: portrait) and (min-width: 768px) and (max-width: 1024px) {
  body {
    font-size: 14px;
  }

  .tg-grid {
    grid-auto-rows: minmax(200px, auto);
  }

  .tg-tool-form-row {
    grid-template-columns: 1fr;
  }

  .tg-mode-toggle {
    flex-direction: column;
  }

  .tg-mode-toggle button {
    width: 100%;
  }

  .tg-chat-history {
    max-height: min(400px, 45vh) !important;
  }
}

/* =========================================================
   8. FOLDABLE DEVICE SUPPORT
   ========================================================= */
@media (screen-spanning: single-fold-vertical) {
  .container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
  }

  .tg-grid {
    grid-column: 1 / -1;
  }
}

@media (screen-spanning: single-fold-horizontal) {
  .container {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 0;
  }

  .tg-grid {
    grid-row: 1 / -1;
  }
}

/* =========================================================
   9. TOUCH-FRIENDLY ADJUSTMENTS FOR TABLET
   ========================================================= */
@media (hover: none) and (pointer: coarse) and (min-width: 768px) and (max-width: 1024px) {
  .tg-btn,
  .tg-input,
  .tg-textarea,
  .tg-select {
    min-height: 44px;
  }

  .tg-card {
    padding: 18px;
  }

  .tg-cat-btn {
    min-height: 44px;
    padding: 12px 16px;
  }

  /* Increase touch target sizes */
  button,
  a,
  input[type="checkbox"],
  input[type="radio"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Add more spacing for touch */
  .tg-mode-toggle button {
    padding: 14px 16px;
  }
}

/* =========================================================
   10. TABLET SAFETY — NO LAYOUT SHIFTS, TEXT SELECTABLE
   ========================================================= */
@media (min-width: 768px) and (max-width: 1024px) {
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* FIX: Allow text selection everywhere on tablets */
  body {
    -webkit-user-select: text;
    user-select: text;
  }

  /* Ensure inputs and interactive elements remain selectable */
  input,
  textarea,
  select,
  button,
  a,
  [contenteditable],
  .tg-chat-history,
  .tg-chat-msg,
  .tg-composer-textarea,
  .tg-result-text,
  .tg-msg-body,
  .tg-attachment-chip,
  .tg-active-file-pill,
  .tg-result-card,
  .tg-md-pre,
  .tg-md-code,
  .tg-md-table {
    -webkit-user-select: text !important;
    user-select: text !important;
  }

  /* Prevent unwanted scrollbars */
  html {
    overflow-y: scroll;
  }

  /* Smooth scrolling */
  html {
    scroll-behavior: smooth;
  }
}

/* =========================================================
   11. PREMIUM WORKSPACES — align 800px breakpoint
   ========================================================= */
@media (min-width: 768px) and (max-width: 800px) {
  .tg-premium-grid {
    grid-template-columns: 1fr;
  }

  .tg-premium-preview {
    position: static;
    min-height: 240px;
  }

  .tg-premium-head {
    display: block;
  }

  .tg-premium-fields {
    grid-template-columns: 1fr;
  }
}

/* =========================================================
   12. NAVIGATION — hamburger drawer sized for tablets
   ========================================================= */
@media (min-width: 768px) and (max-width: 1024px) {
  .nav-toggle {
    display: flex !important;
  }

  .nav-menu {
    width: min(360px, 85vw) !important;
    padding: 88px 24px 32px !important;
  }

  .nav-menu a {
    font-size: 1rem !important;
    padding: 12px 14px !important;
  }
}
