/**
 * Compact Visual Grid V2 - Responsive Layout & Touch Target Stylesheet
 * (src/ui/compact_grid_v2.css)
 */

/* 1. Page Root: Zero page-level horizontal overflow */
html, body, .app-container {
  width: 100vw;
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* 2. Board Wrapper: Owns external viewport margins */
@media (max-width: 480px) {
  .grid-card {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
  #grid-wrapper {
    padding: 0 !important;
    margin: 0 !important;
  }
}

.investigation-board-wrapper {
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  overflow: hidden;
  direction: rtl;
}

/* 3. Board Viewport: Controlled horizontal scrolling with touch momentum */
.investigation-board-viewport {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  border-radius: 16px;
  border: 1px solid #d4c5b9;
  background: #fdfbf7;
  box-sizing: border-box;
}

@media (min-width: 768px) {
  .investigation-board-viewport {
    max-width: fit-content;
    width: fit-content;
    margin: 0 auto;
  }
}

/* 4. Canvas: Exact track matching with dynamic grid template */
.investigation-board-canvas {
  display: grid;
  direction: rtl;
  padding: 0;
  margin: 0 auto;
  box-sizing: content-box;
  column-gap: 5px;
  row-gap: 8px;
}

/* 5. Sticky Row Category Header (RTL Pinned Right) */
.matrix-row-header-sticky {
  position: sticky;
  right: 0;
  z-index: 5;
  width: 64px;
  min-width: 64px;
  background: #f0e6dc;
  border-left: 1px solid #d8c7b8;
  box-shadow: -3px 0 6px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.78rem;
  color: #8c6b4f;
  text-align: center;
  padding: 4px 3px;
  box-sizing: border-box;
  border-radius: 8px;
  line-height: 1.25;
}

.cat-pill-v2 {
  display: block;
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.2;
  color: #78350f;
  text-align: center;
  word-break: break-word;
}

/* 6. Interactive Matrix Cell (>= 48px Envelope) */
.matrix-cell {
  width: 54px;
  min-width: 54px;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  touch-action: manipulation;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  user-select: none;
  position: relative;
  padding: 2px;
}

.matrix-cell:hover, .matrix-cell:focus-visible {
  transform: scale(1.03);
  outline: 2px solid #3b82f6;
}

.matrix-cell.state-unknown {
  background: #ffffff;
  border: 1.5px dashed #cbd5e1;
  color: #64748b;
}

.matrix-cell.state-unknown:hover,
.matrix-cell.state-unknown:focus-visible {
  border-color: #3b82f6;
  background: #f8fafc;
}

.matrix-cell.state-eliminated {
  background: #fef2f2;
  border: 1.5px solid #fca5a5;
  color: #991b1b;
}

.matrix-cell.state-confirmed {
  background: #f0fdf4;
  border: 1.5px solid #86efac;
}

.elim-mark-sm {
  font-size: 1.15rem;
  line-height: 1;
}

.unknown-mark-sm {
  font-size: 1.15rem;
  line-height: 1;
  color: #94a3b8;
}

.badge-icon-sm {
  font-size: 0.85rem;
  line-height: 1;
}

.badge-label-sm {
  font-size: 0.72rem;
  font-weight: 700;
  color: #166534;
}

.entity-pin-mini {
  font-size: 0.72rem;
  line-height: 1;
  margin-bottom: 2px;
}

.entity-icon-badge {
  font-size: 1.1rem;
  line-height: 1;
  margin-bottom: 2px;
}

#direct-solution-tray-wrapper {
  display: none !important;
}

.cell-confirmed-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  gap: 2px;
}

.cell-confirmed-badge-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #166534;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  max-width: 50px;
}

/* Why Button: 48px hit envelope with 22px visual badge */
.btn-why-sm {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  touch-action: manipulation;
  border-radius: 8px;
}

.btn-why-sm:hover,
.btn-why-sm:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 1px;
}

.btn-why-icon {
  width: 22px;
  height: 22px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid #86efac;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  pointer-events: none;
}

/* 7. Entity Header Card (Interactive & Editable) */
.entity-card-v2 {
  width: 54px;
  min-width: 54px;
  min-height: 58px;
  background: #ffffff;
  border: 1px solid #e2d9cf;
  border-radius: 10px;
  padding: 4px 2px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-sizing: border-box;
  touch-action: manipulation;
  transition: transform 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.entity-card-v2:hover, .entity-card-v2:focus-visible {
  transform: scale(1.03);
  outline: 2px solid #3b82f6;
}

.entity-card-v2.state-unknown {
  background: #ffffff;
  border: 1.5px dashed #cbd5e1;
  color: #64748b;
}

.entity-card-v2.state-unknown:hover,
.entity-card-v2.state-unknown:focus-visible {
  border-color: #3b82f6;
  background: #f8fafc;
}

.entity-card-v2.state-confirmed {
  background: #f0fdf4;
  border: 1.5px solid #86efac;
}

.entity-card-v2.state-eliminated {
  background: #fef2f2;
  border: 1.5px solid #fca5a5;
  color: #991b1b;
}

.entity-pos-mini {
  font-size: 0.68rem;
  font-weight: 800;
  color: #78350f;
  margin-bottom: 2px;
  line-height: 1;
  white-space: nowrap;
}

.entity-card-v2 .badge-label-compact {
  font-size: 0.76rem;
  font-weight: 800;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

/* ==========================================================================
   MOBILE & TABLET UI STREAMLINING: ELIMINATE BUTTON CLUTTER & OVERCROWDING
   ========================================================================== */
@media (max-width: 992px) {
  /* 1. Sleek Clue Pager: Prev/Next >= 48x48px touch targets */
  .clue-nav-buttons {
    gap: 6px !important;
    display: flex !important;
    align-items: center !important;
  }

  .btn-clue-nav,
  #btn-prev-clue,
  #btn-next-clue {
    padding: 8px 12px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    width: 48px !important;
    height: 48px !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 12px !important;
    touch-action: manipulation !important;
  }
  .btn-clue-nav span {
    display: none !important; /* Hide "السابق" and "التالي" text, show clean arrows */
  }

  /* Compact All Clues pill >= 48px height */
  .btn-clue-all,
  #btn-open-all-clues {
    padding: 8px 14px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    height: 48px !important;
    font-size: 0.82rem !important;
    border-radius: 12px !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    touch-action: manipulation !important;
  }

  /* Compact Voice button >= 48x48px */
  .btn-voice-reader,
  #btn-read-active-clue {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    border-radius: 12px !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    touch-action: manipulation !important;
  }

  /* Mobile Primary Action Dock buttons (>= 48x48px touch envelope) */
  .mobile-action-dock {
    display: grid !important;
    grid-template-columns: 1fr 1fr 1.8fr !important;
    gap: 8px !important;
    margin-top: 10px !important;
    width: 100% !important;
  }

  .mobile-action-dock .btn-powerup,
  .mobile-action-dock .action-verify-btn,
  #btn-undo-mobile,
  #powerup-hint-mobile,
  #btn-verify-mobile {
    min-width: 48px !important;
    min-height: 48px !important;
    height: 48px !important;
    box-sizing: border-box !important;
    touch-action: manipulation !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Hide strike button on mobile/tablet to prevent child misclicks */
  #btn-strike-active-clue {
    display: none !important;
  }

  /* Hide redundant instruction block & stars button under the grid */
  .matrix-instructions {
    display: none !important;
  }

  /* Hide legacy scroll controls */
  #grid-scroll-controls {
    display: none !important;
  }

  /* Subtle why badge in confirmed cell to avoid cockpit button clutter */
  .btn-why-icon {
    width: 18px !important;
    height: 18px !important;
    font-size: 11px !important;
    opacity: 0.85;
  }
}

/* 8. Modal Styles */
.entity-detail-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  direction: rtl;
  padding: 16px;
}

.entity-detail-card {
  background: #ffffff;
  border-radius: 20px;
  max-width: 400px;
  width: 100%;
  padding: 20px;
  position: relative;
  box-shadow: 0 12px 32px rgba(0,0,0,0.2);
}

.detail-close-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  background: #f1f5f9;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
}
