/**
 * Admin mobile UX — mirrors customer estimate patterns.
 * Mobile / touch only. Desktop layout is not targeted.
 */

/* ── Dashboard home: 2-across grid + Create New Estimate ── */
@media screen and (max-width: 767px) {
  /* Force 2-column dashboard cards (3–4 rows) */
  body:not(:has(.a1-est-landing)):not(:has(.a1-est-embed))
    .grid.grid-cols-2.sm\:grid-cols-2.md\:grid-cols-3.lg\:grid-cols-4 {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.75rem !important;
    width: 100% !important;
  }

  [data-dashboard-card] {
    min-height: 0 !important;
  }
  [data-dashboard-card] .p-6 {
    padding: 0.9rem 0.55rem !important;
  }
  [data-dashboard-card] .w-16.h-16 {
    width: 3rem !important;
    height: 3rem !important;
    margin-bottom: 0.65rem !important;
    border-radius: 0.85rem !important;
  }
  [data-dashboard-card] .w-8.h-8 {
    width: 1.35rem !important;
    height: 1.35rem !important;
  }

  /* Prominent Create New Estimate under cards */
  #a1-admin-create-estimate-cta {
    display: flex !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    margin: 1rem 0 1.25rem !important;
    padding: 1rem 1.1rem !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.5rem !important;
    font: 800 1rem/1.2 system-ui, -apple-system, sans-serif !important;
    color: #fff !important;
    background: #d02127 !important;
    border: 0 !important;
    border-radius: 1rem !important;
    box-shadow: 0 8px 22px rgba(208, 33, 39, 0.35) !important;
    text-decoration: none !important;
    touch-action: manipulation !important;
  }
  #a1-admin-create-estimate-cta:active {
    transform: scale(0.98);
  }

  /* Hide duplicate small "New Estimate" in top bar on phone (CTA below is primary) */
  body.a1-admin-mobile-dash
    a[href="/estimate/new"]:not(#a1-admin-create-estimate-cta) {
    /* keep visible but slightly quieter */
  }

  /* ── Admin bottom sheet (lists + shared shell) ── */
  #a1-admin-sheet-root {
    position: fixed !important;
    inset: 0 !important;
    z-index: 2147483000 !important;
    display: none !important;
    pointer-events: none !important;
  }
  #a1-admin-sheet-root.a1-open {
    display: block !important;
    pointer-events: auto !important;
  }
  #a1-admin-sheet-root .a1-sheet-backdrop {
    position: absolute !important;
    inset: 0 !important;
    background: rgba(15, 23, 42, 0.5) !important;
  }
  #a1-admin-sheet-root .a1-sheet-panel {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    max-height: min(72dvh, 640px) !important;
    display: flex !important;
    flex-direction: column !important;
    background: #fff !important;
    border-radius: 1.1rem 1.1rem 0 0 !important;
    box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.2) !important;
    padding: 0.75rem 0.85rem
      max(1rem, env(safe-area-inset-bottom, 0px)) !important;
    box-sizing: border-box !important;
    transform: translateY(0) !important;
    overscroll-behavior: contain !important;
  }
  #a1-admin-sheet-root .a1-sheet-handle {
    width: 2.5rem !important;
    height: 0.28rem !important;
    border-radius: 999px !important;
    background: #cbd5e1 !important;
    margin: 0.15rem auto 0.65rem !important;
  }
  #a1-admin-sheet-root .a1-sheet-head {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 0.5rem !important;
    margin-bottom: 0.5rem !important;
    flex-shrink: 0 !important;
  }
  #a1-admin-sheet-root .a1-sheet-title {
    font: 800 1rem/1.2 system-ui, sans-serif !important;
    color: #0f172a !important;
    margin: 0 !important;
  }
  #a1-admin-sheet-root .a1-sheet-close {
    width: 2.25rem !important;
    height: 2.25rem !important;
    border-radius: 999px !important;
    border: 1px solid #e2e8f0 !important;
    background: #fff !important;
    color: #475569 !important;
    font-size: 1.25rem !important;
    line-height: 1 !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
  }
  #a1-admin-sheet-root .a1-sheet-body {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
    min-height: 0 !important;
  }
  #a1-admin-sheet-root .a1-sheet-item {
    display: block !important;
    width: 100% !important;
    text-align: left !important;
    padding: 0.75rem 0.65rem !important;
    border: 0 !important;
    border-bottom: 1px solid #f1f5f9 !important;
    background: transparent !important;
    color: #0f172a !important;
    font: 600 0.9rem/1.3 system-ui, sans-serif !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
  }
  #a1-admin-sheet-root .a1-sheet-item small {
    display: block !important;
    font-weight: 500 !important;
    color: #64748b !important;
    font-size: 0.75rem !important;
    margin-top: 0.15rem !important;
  }
  #a1-admin-sheet-root .a1-sheet-empty,
  #a1-admin-sheet-root .a1-sheet-loading {
    padding: 1.25rem 0.5rem !important;
    text-align: center !important;
    color: #64748b !important;
    font: 600 0.9rem/1.4 system-ui, sans-serif !important;
  }
  #a1-admin-sheet-root .a1-sheet-footer {
    flex-shrink: 0 !important;
    padding-top: 0.55rem !important;
  }
  #a1-admin-sheet-root .a1-sheet-footer a,
  #a1-admin-sheet-root .a1-sheet-footer button {
    display: flex !important;
    width: 100% !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0.75rem !important;
    border-radius: 0.75rem !important;
    border: 1px solid #e2e8f0 !important;
    background: #f8fafc !important;
    color: #0f172a !important;
    font: 700 0.9rem/1.2 system-ui, sans-serif !important;
    text-decoration: none !important;
    touch-action: manipulation !important;
  }

  /* ── Estimate generator: Dashboard chip ── */
  #a1-admin-dash-btn {
    position: fixed !important;
    top: max(0.55rem, env(safe-area-inset-top, 0px)) !important;
    left: 0.55rem !important;
    z-index: 2147482000 !important;
    display: none !important;
    align-items: center !important;
    gap: 0.3rem !important;
    padding: 0.45rem 0.7rem !important;
    border-radius: 999px !important;
    border: 1px solid #e2e8f0 !important;
    background: rgba(255, 255, 255, 0.96) !important;
    color: #0f172a !important;
    font: 700 0.75rem/1 system-ui, sans-serif !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12) !important;
    text-decoration: none !important;
    touch-action: manipulation !important;
  }
  body.a1-admin-mobile-est #a1-admin-dash-btn {
    display: inline-flex !important;
  }

  /* ── Estimate paper: isolated zoom host (customer pattern) ── */
  body.a1-admin-mobile-est {
    overflow-x: hidden !important;
    overscroll-behavior-x: none !important;
  }
  body.a1-admin-mobile-est .w-full.overflow-x-auto:has(#estimate-document) {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    margin: 0.35rem 0 0.75rem !important;
    border-radius: 1rem !important;
    background: transparent !important;
    clip-path: inset(0 round 1rem) !important;
    -webkit-clip-path: inset(0 round 1rem) !important;
    touch-action: pan-y;
  }
  body.a1-admin-mobile-est #estimate-document.estimate-document,
  body.a1-admin-mobile-est #estimate-document {
    width: var(--a1-doc-natural-w, 1000px) !important;
    min-width: var(--a1-doc-natural-w, 1000px) !important;
    max-width: none !important;
    margin-left: auto !important;
    margin-right: auto !important;
    transform-origin: top center !important;
    zoom: normal !important;
    box-sizing: border-box !important;
  }

  /*
   * Service / description option dropdown → bottom sheet
   * (existing React absolute panel)
   */
  body.a1-admin-mobile-est
    .absolute.z-\[100\].top-full.left-0.w-\[600px\] {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: min(68dvh, 560px) !important;
    margin: 0 !important;
    border-radius: 1.1rem 1.1rem 0 0 !important;
    box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.22) !important;
    z-index: 2147482500 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }
  body.a1-admin-mobile-est
    .absolute.z-\[100\].top-full.left-0.w-\[600px\]
    > * {
    /* keep flex children scrollable */
  }
  /* Scroll inside sheet; sheet stays pinned */
  body.a1-admin-mobile-est
    .absolute.z-\[100\]
    .overflow-y-auto,
  body.a1-admin-mobile-est
    .absolute.z-\[100\]
    .flex-1,
  body.a1-admin-mobile-est
    .absolute.z-\[100\]
    .overflow-auto {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
    max-height: none !important;
    min-height: 0 !important;
  }

  /*
   * Mic on the LEFT of the description row (more natural when zoomed).
   * Structure: [textarea flex-1] [mic border-l] → reverse to mic | text
   */
  body.a1-admin-mobile-est
    .description-column
    .relative.w-full.h-full.min-h-\[40px\].flex.items-stretch {
    flex-direction: row-reverse !important;
  }
  body.a1-admin-mobile-est
    .description-column
    .flex.flex-row.border-l.border-gray-200 {
    border-left: 0 !important;
    border-right: 1px solid #e5e7eb !important;
  }
  body.a1-admin-mobile-est
    .description-column
    .desc-textarea-input {
    font-size: 16px !important; /* prevent iOS zoom on focus */
  }

  /* Slightly tighter chrome above paper on admin phone */
  body.a1-admin-mobile-est .max-w-\[1000px\] {
    max-width: 100% !important;
  }
}

/* Touch tablets — same admin mobile shell */
@media screen and (min-width: 768px) and (max-width: 1024px) and (hover: none) and (pointer: coarse) {
  body:not(:has(.a1-est-landing))
    .grid.grid-cols-2.sm\:grid-cols-2.md\:grid-cols-3.lg\:grid-cols-4 {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.9rem !important;
  }
  #a1-admin-create-estimate-cta {
    display: flex !important;
  }
  body.a1-admin-mobile-est #a1-admin-dash-btn {
    display: inline-flex !important;
  }
}
