/**
 * ENNU Face Chart - iPad/Tablet Optimization
 * IMPORTANT: All styles wrapped in media query to only apply on tablets
 *
 * iPad Models Optimized:
 * - iPad Pro 12.9" (2732 x 2048)
 * - iPad Pro 11" (2388 x 1668)
 * - iPad Air (2360 x 1640)
 * - iPad 10.9" (2360 x 1640)
 * - iPad Mini (2266 x 1488)
 * - iPad 9.7" (2048 x 1536)
 *
 * @package ENNU_Face_Charting
 * @version 2.1.0 - Fixed to only apply on tablet devices
 */

/* ==========================================================================
   TABLET-ONLY STYLES
   Target: Touch devices with tablet-size screens (768px - 1366px)
   ========================================================================== */

@media only screen
  and (min-width: 768px)
  and (max-width: 1366px)
  and (pointer: coarse) {

  /* ==========================================================================
     iPad Viewport & Touch Configuration
     ========================================================================== */

  html,
  body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
    touch-action: pan-x pan-y;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }

  /* Main container - full iPad screen */
  .ennu-face-chart-container {
    width: 100vw;
    min-height: 100vh;
    height: -webkit-fill-available;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
    user-select: none;
    -webkit-user-select: none;
  }

  /* ==========================================================================
     Touch-Optimized Header (Minimum 60px touch target)
     ========================================================================== */

  .face-chart-header {
    min-height: 80px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .header-logo {
    max-width: 320px;
    height: 48px;
    object-fit: contain;
  }

  .patient-info {
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 17px;
  }

  .patient-avatar {
    width: 36px;
    height: 36px;
  }

  /* ==========================================================================
     iPad Touch-Friendly Buttons (Minimum 44x44px Apple HIG)
     ========================================================================== */

  .btn-back,
  .btn-save,
  .btn-complete,
  .btn-canvas-action,
  .btn-primary,
  .btn-secondary,
  .btn-danger,
  .btn-add-treatment {
    min-height: 52px;
    min-width: 120px;
    padding: 16px 32px;
    border-radius: 14px;
    font-size: 17px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  /* Button press effect for touch feedback */
  .btn-back:active,
  .btn-save:active,
  .btn-complete:active,
  .btn-primary:active,
  .btn-secondary:active {
    transform: scale(0.96);
  }

  /* ==========================================================================
     Tool Buttons - Touch optimized
     ========================================================================== */

  .tool-btn {
    width: 56px;
    height: 56px;
    border-radius: 12px;
  }

  .tool-btn:active {
    transform: scale(0.92);
  }

  .tool-btn i {
    font-size: 24px;
  }

  /* ==========================================================================
     Form Controls - iPad Touch Optimized
     ========================================================================== */

  .form-group label {
    font-size: 17px;
  }

  .form-control,
  input[type="text"],
  input[type="number"],
  input[type="email"],
  select,
  textarea {
    padding: 16px 20px;
    border-radius: 12px;
    font-size: 17px;
    min-height: 56px;
  }

  textarea {
    min-height: 120px;
  }

  /* Checkbox and Radio - Large touch targets */
  .form-check {
    min-height: 44px;
  }

  .form-check-input {
    width: 28px;
    height: 28px;
    margin-right: 12px;
  }

  .form-check-label {
    font-size: 17px;
  }

  /* Range input - Large thumb for touch */
  input[type="range"] {
    height: 44px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 32px;
    height: 32px;
    margin-top: -12px;
  }

  /* ==========================================================================
     Sidebar Panel - Touch optimized
     ========================================================================== */

  .sidebar-panel {
    width: 420px;
    touch-action: pan-x;
  }

  .sidebar-panel .btn-close-sidebar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 24px;
  }

  .sidebar-panel .btn-close-sidebar:active {
    transform: scale(0.9);
  }

  /* ==========================================================================
     Treatment List - Touch-optimized
     ========================================================================== */

  .treatment-item {
    border-radius: 16px;
    padding: 20px;
    min-height: 80px;
  }

  .treatment-item:active {
    transform: scale(0.98);
  }

  .treatment-name {
    font-size: 18px;
  }

  /* ==========================================================================
     Modal - Optimized for iPad
     ========================================================================== */

  .modal-content {
    border-radius: 24px;
    width: 90%;
    max-width: 800px;
  }

  .modal-header {
    padding: 28px;
  }

  .modal-close {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 28px;
  }

  .modal-body {
    padding: 28px;
    -webkit-overflow-scrolling: touch;
  }

  /* ==========================================================================
     Product Grid - Touch-optimized
     ========================================================================== */

  #treatment-products-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    -webkit-overflow-scrolling: touch;
  }

  .product-card {
    border-radius: 12px;
    padding: 16px;
    min-height: 180px;
  }

  .product-card:active {
    transform: scale(0.95);
  }

  /* ==========================================================================
     Notifications - iPad positioned
     ========================================================================== */

  .notification {
    top: 100px;
    right: 20px;
    border-radius: 16px;
    padding: 20px 24px;
    min-width: 320px;
    max-width: 480px;
  }

  .notification-icon {
    font-size: 28px;
  }

  .notification-message {
    font-size: 17px;
  }

  .notification-close {
    width: 36px;
    height: 36px;
  }

  /* ==========================================================================
     Touch Gesture Support
     ========================================================================== */

  /* Pinch to zoom canvas */
  .canvas-wrapper {
    touch-action: pinch-zoom;
  }

  /* ==========================================================================
     iPad Edge-to-Edge Canvas Display
     Ensures image fills width without skewing at 100% zoom
     ========================================================================== */

  /* Canvas wrapper - full width, no horizontal scroll at 100% */
  .canvas-wrapper,
  .ennu-fc-canvas-wrapper {
    width: 100% !important;
    max-width: 100vw !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow-x: hidden !important;
  }

  /* Enable horizontal scroll only when zoomed in */
  .canvas-wrapper.zoomed-in,
  .ennu-fc-canvas-wrapper.zoomed-in {
    overflow-x: auto !important;
  }

  /* Canvas - edge to edge, preserve aspect ratio */
  #face-chart-canvas {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1275 / 1650;
    margin: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    transform-origin: 0 0 !important;
  }

  /* Prevent accidental selection */
  .ennu-face-chart-container * {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
  }

  /* Allow text selection in forms */
  input,
  textarea,
  [contenteditable] {
    -webkit-user-select: text;
    user-select: text;
  }

  /* ==========================================================================
     Performance Optimizations
     ========================================================================== */

  .sidebar-panel,
  .modal-overlay,
  .modal-content,
  .notification {
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }

  .sidebar-content,
  .modal-body,
  #treatment-products-grid {
    -webkit-overflow-scrolling: touch;
  }

  /* ==========================================================================
     Hide hover effects on touch devices
     ========================================================================== */

  .btn-primary:hover,
  .btn-save:hover,
  .btn-complete:hover,
  .product-card:hover,
  .treatment-item:hover {
    transform: none;
  }

  /* Scrollbar styling for iPad */
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
  }

  /* Focus styles for keyboard navigation (external keyboards) */
  *:focus-visible {
    outline: 3px solid #C9A962;
    outline-offset: 2px;
  }

} /* End tablet media query */


/* ==========================================================================
   iPad Landscape Optimizations
   ========================================================================== */

@media only screen
  and (orientation: landscape)
  and (min-width: 768px)
  and (max-width: 1366px)
  and (pointer: coarse) {

  .sidebar-panel {
    width: 480px;
  }

  .treatment-list {
    padding-right: 12px;
  }
}


/* ==========================================================================
   iPad Portrait Optimizations
   ========================================================================== */

@media only screen
  and (orientation: portrait)
  and (min-width: 768px)
  and (max-width: 1366px)
  and (pointer: coarse) {

  .sidebar-panel {
    width: 80%;
    max-width: 600px;
  }

  #treatment-products-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}


/* ==========================================================================
   iPad Pro 12.9" Specific
   ========================================================================== */

@media only screen
  and (min-width: 1024px)
  and (max-width: 1400px)
  and (pointer: coarse) {

  .face-chart-header {
    padding: 24px 32px;
    min-height: 88px;
  }

  .btn-primary,
  .btn-save,
  .btn-complete {
    min-height: 60px;
    padding: 18px 40px;
    font-size: 19px;
  }

  .modal-content {
    max-width: 1000px;
  }

  #treatment-products-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}


/* ==========================================================================
   Print Styles - Optimize for AirPrint
   ========================================================================== */

@media print {
  .canvas-tools,
  .color-palette,
  .brush-size-control {
    display: none !important;
  }
}


/* ==========================================================================
   PWA Support for iPad Home Screen
   ========================================================================== */

@media (display-mode: standalone) {
  .face-chart-header {
    padding-top: env(safe-area-inset-top, 20px);
  }
}

@supports (padding: env(safe-area-inset-top)) {
  @media only screen and (min-width: 768px) and (max-width: 1366px) and (pointer: coarse) {
    .ennu-face-chart-container {
      padding-top: env(safe-area-inset-top);
      padding-left: env(safe-area-inset-left);
      padding-right: env(safe-area-inset-right);
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}
