/* Admin Responsive Styles - Mobile-First PWA */

/* =================================================================
   PWA Safe Area Insets (iOS notch, Android gesture bar)
   ================================================================= */
:root {
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);
}

/* Prevent horizontal scroll on body */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* =================================================================
   Base Mobile Improvements (applies to all screens)
   ================================================================= */

/* Minimum touch target size for interactive elements */
button,
a.btn,
input[type="button"],
input[type="submit"],
input[type="reset"],
.btn,
.icon-btn {
  min-height: 44px;
}

/* Prevent text size adjustment on orientation change */
html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Better tap highlighting */
* {
  -webkit-tap-highlight-color: rgba(200, 155, 140, 0.2);
}

/* =================================================================
   Mobile Navigation (max-width: 768px)
   ================================================================= */
@media (max-width: 768px) {
  /* Hide secondary header tools on mobile */
  .admin-header__tools,
  .admin-header__link,
  .admin-header__divider {
    display: none !important;
  }

  /* Mobile header improvements with safe-area */
  .admin-header {
    padding-top: var(--safe-area-inset-top);
    height: calc(var(--admin-header-height, 64px) + var(--safe-area-inset-top));
  }

  .admin-header__inner {
    padding: 0 12px;
    padding-left: calc(12px + var(--safe-area-inset-left));
    padding-right: calc(12px + var(--safe-area-inset-right));
  }

  /* Page title truncation on mobile */
  .admin-header__title {
    font-size: 16px;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Mobile menu toggle - larger touch target */
  .admin-header__menu-toggle {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    margin-left: -8px;
  }


  /* Sidebar mobile overlay and positioning */
  .admin-sidebar {
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
  }

  /* Sidebar nav items - larger touch targets */
  .admin-sidebar__section-header,
  .admin-sidebar__child-link {
    min-height: 48px;
    padding: 12px 16px;
  }

  /* Footer safe area */
  .admin-footer {
    padding-bottom: var(--safe-area-inset-bottom);
  }

  .admin-footer__inner {
    padding-bottom: calc(12px + var(--safe-area-inset-bottom));
  }
}

/* =================================================================
   Hours row responsive
   ================================================================= */
@media (max-width: 768px) {
  .hours-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .hours-row strong {
    margin-bottom: 8px;
    display: block;
  }

  .hours-row input[type="time"] {
    width: 100%;
    margin-bottom: 8px;
  }

  .hours-row label {
    display: flex;
    align-items: center;
    gap: 8px;
  }
}

/* =================================================================
   Small Mobile (max-width: 480px) - Primary mobile breakpoint
   ================================================================= */
@media (max-width: 480px) {
  /* Header compact */
  .admin-header {
    padding: 12px 0;
    margin-bottom: 12px;
  }

  .admin-header__inner {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .admin-header__title {
    font-size: 15px;
    max-width: 140px;
  }

  .admin-header__left {
    gap: 4px;
  }

  .admin-header__user {
    width: auto;
  }

  /* Container padding */
  .admin-container {
    padding: 0 12px;
    overflow-x: hidden;
  }

  /* Cards */
  .admin-card {
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 10px;
  }

  .admin-card h2 {
    font-size: 18px;
    margin-bottom: 14px;
  }

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

  /* Content area */
  .admin-content {
    padding: 12px;
    padding-left: calc(12px + var(--safe-area-inset-left));
    padding-right: calc(12px + var(--safe-area-inset-right));
    padding-bottom: calc(12px + var(--safe-area-inset-bottom));
  }

  /* =================================================================
     Forms - Full width inputs on mobile
     ================================================================= */
  .form .field {
    margin-bottom: 14px;
  }

  .form input,
  .form select,
  .form textarea,
  .admin-card .field input,
  .admin-card .field select,
  .admin-card .field textarea {
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 12px 14px;
    min-height: 48px;
    width: 100%;
    box-sizing: border-box;
  }

  .form textarea,
  .admin-card .field textarea {
    min-height: 100px;
  }

  /* Form labels */
  .form .field label,
  .admin-card .field label {
    font-size: 14px;
    margin-bottom: 6px;
  }

  /* =================================================================
     Buttons - Full width on mobile
     ================================================================= */
  .btn {
    min-height: 48px;
    padding: 12px 16px;
    font-size: 15px;
    width: 100%;
    justify-content: center;
  }

  .btn-row {
    flex-direction: column;
    gap: 10px;
  }

  .btn-row .btn {
    width: 100%;
  }

  /* Small buttons keep inline */
  .btn-small,
  .btn--small {
    min-height: 40px;
    padding: 10px 14px;
    font-size: 13px;
    width: auto;
  }

  /* Icon buttons - maintain square aspect */
  .icon-btn {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }

  /* =================================================================
     Tables - Card layout on mobile
     ================================================================= */
  .table-controls {
    flex-direction: column;
    gap: 10px;
  }

  .table-search,
  .table-filter {
    width: 100%;
    font-size: 16px;
    min-height: 48px;
    padding: 12px 14px;
  }

  .table-count {
    margin-left: 0;
    text-align: center;
    font-size: 12px;
  }

  /* Table as stacked cards on mobile */
  .admin-table {
    font-size: 13px;
    display: block;
    overflow-x: visible;
  }

  .admin-table thead,
  .admin-table tbody,
  .admin-table tr {
    display: block;
  }

  .admin-table thead {
    display: none;
  }

  .admin-table tr {
    margin-bottom: 12px;
    border: 1px solid rgba(43,43,43,.1);
    border-radius: 10px;
    padding: 14px;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }

  .admin-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 0;
    border-bottom: 1px solid rgba(43,43,43,.05);
    text-align: right;
    gap: 12px;
  }

  .admin-table td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  .admin-table td:first-child {
    padding-top: 0;
  }

  .admin-table td::before {
    content: attr(data-label);
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
    color: rgba(43,43,43,.7);
    font-size: 12px;
  }

  /* Table actions stack horizontally */
  .table-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    justify-content: flex-end;
  }

  .table-actions .btn {
    width: auto;
    min-width: 44px;
  }

  .table-image {
    width: 70px;
    height: 70px;
  }

  /* =================================================================
     Photo/Media grids
     ================================================================= */
  .photo-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* =================================================================
     Submissions/Leads
     ================================================================= */
  .submission-item,
  .latest-item {
    padding: 14px;
    margin-bottom: 12px;
  }

  /* =================================================================
     Dashboard Stats
     ================================================================= */
  .dashboard-stats {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-card__value {
    font-size: 28px;
  }

  .stat-card__icon {
    width: 52px;
    height: 52px;
  }

  /* =================================================================
     Modals
     ================================================================= */
  .admin-modal-content,
  .calendar-modal-content,
  .calendar-edit-modal-content {
    margin: 10px;
    max-height: calc(100vh - 20px);
    max-width: calc(100vw - 20px);
    width: 100%;
  }

  .admin-modal-form,
  .calendar-edit-form {
    padding: 14px;
  }

  .admin-modal-header,
  .calendar-modal-header,
  .calendar-edit-modal-header {
    padding: 14px 16px;
  }

  .admin-modal-header h3,
  .calendar-modal-header h3,
  .calendar-edit-modal-header h3 {
    font-size: 18px;
  }

  /* Modal form rows stack on mobile */
  .form-row,
  .modal-form-row,
  .calendar-edit-form .form-row {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  /* Modal form actions stack on mobile */
  .form-actions,
  .modal-form-actions,
  .calendar-edit-form .form-actions {
    flex-direction: column;
    gap: 10px;
  }

  .form-actions .btn,
  .modal-form-actions .btn,
  .calendar-edit-form .form-actions .btn {
    width: 100%;
  }

  /* Modal close button - larger touch target */
  .admin-modal-close,
  .calendar-modal-close,
  .calendar-edit-modal-close {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }

  /* =================================================================
     View toggle buttons
     ================================================================= */
  .view-toggle {
    padding: 3px;
  }

  .view-toggle-btn {
    padding: 10px 12px;
    min-width: 44px;
    min-height: 44px;
  }

  /* =================================================================
     Booking cards
     ================================================================= */
  .booking-cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .booking-card__body {
    padding: 14px;
  }

  .booking-card__footer {
    padding: 12px 14px;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .booking-card__status-select {
    width: 100%;
    min-height: 44px;
    font-size: 14px;
    padding: 10px 12px;
  }

  .booking-card__actions {
    justify-content: flex-end;
  }

  /* =================================================================
     Breadcrumbs
     ================================================================= */
  .admin-breadcrumb__list {
    font-size: 12px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .admin-breadcrumb__item:not(:last-child)::after {
    margin-left: 4px;
  }

  /* Hide middle breadcrumb items on very small screens */
  .admin-breadcrumb__item:not(:first-child):not(:last-child) {
    display: none;
  }

  /* =================================================================
     Alerts
     ================================================================= */
  .admin-alert {
    padding: 12px 14px;
    font-size: 14px;
    border-radius: 10px;
  }
}

/* =================================================================
   Tablet (481px - 768px)
   ================================================================= */
@media (min-width: 481px) and (max-width: 768px) {
  .admin-container {
    padding: 0 16px;
  }

  .admin-card {
    padding: 20px;
  }

  .admin-header__inner {
    flex-wrap: wrap;
  }

  .admin-header__title {
    max-width: 280px;
  }

  .btn-row {
    flex-wrap: wrap;
  }

  .btn-row .btn {
    flex: 1 1 auto;
    min-width: 120px;
  }

  .table-controls {
    flex-wrap: wrap;
  }

  .admin-table {
    font-size: 13px;
  }

  .admin-table th,
  .admin-table td {
    padding: 10px 12px;
  }

  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Two-column booking cards on tablet */
  .booking-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* =================================================================
   Desktop (769px and up)
   ================================================================= */
@media (min-width: 769px) {
  .admin-container {
    max-width: 1400px;
  }

  .admin-card {
    padding: 24px;
  }

  /* Buttons default to auto width on desktop */
  .btn {
    width: auto;
  }
}

/* =================================================================
   Touch device improvements (touchscreens)
   ================================================================= */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets on touch devices */
  .btn,
  .btn-small,
  .icon-btn {
    min-height: 48px;
    min-width: 48px;
  }

  /* Table headers with sort - larger tap area */
  .admin-table th[data-sort] {
    padding: 14px 16px;
    min-height: 52px;
    touch-action: manipulation;
  }

  /* Table action buttons */
  .table-actions .btn,
  .table-actions .icon-btn {
    min-height: 48px;
    min-width: 48px;
  }

  /* Sidebar links */
  .admin-sidebar__link,
  .admin-sidebar__section-header,
  .admin-sidebar__child-link {
    min-height: 52px;
    padding: 14px 20px;
  }

  /* Mobile menu toggle */
  .admin-header__menu-toggle {
    min-width: 52px;
    min-height: 52px;
  }

  /* Modal close */
  .admin-modal-close,
  .calendar-modal-close,
  .calendar-edit-modal-close {
    min-width: 48px;
    min-height: 48px;
  }

  /* Form inputs - prevent iOS zoom */
  input, select, textarea {
    font-size: 16px;
    min-height: 48px;
    padding: 12px 14px;
  }

  /* Specific form field inputs */
  .admin-card .field input,
  .admin-card .field select,
  .admin-card .field textarea {
    font-size: 16px;
    min-height: 48px;
  }

  /* Calendar booking items - larger tap targets */
  .calendar-booking {
    min-height: 44px;
    padding: 8px 10px;
  }

  /* Status selects */
  select[name="status"],
  .booking-card__status-select {
    min-height: 44px;
    padding: 10px 12px;
  }
}

/* =================================================================
   Keyboard navigation focus states
   ================================================================= */
.admin-sidebar__link:focus-visible,
.admin-sidebar__section-header:focus-visible,
.admin-sidebar__child-link:focus-visible,
.admin-header__menu-toggle:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.admin-modal-close:focus-visible {
  outline: 3px solid var(--blush, #c89b8c);
  outline-offset: 2px;
  z-index: 1;
}

/* =================================================================
   Mouse/pointer device hover effects
   ================================================================= */
@media (hover: hover) and (pointer: fine) {
  .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(43,43,43,.15);
  }

  .admin-sidebar__link:hover,
  .admin-sidebar__section-header:hover,
  .admin-sidebar__child-link:hover {
    transform: translateX(2px);
  }

  .admin-card:hover {
    box-shadow: 0 8px 24px rgba(43,43,43,.12);
  }

  .icon-btn:hover {
    transform: scale(1.05);
  }
}

/* =================================================================
   Landscape mobile
   ================================================================= */
@media (max-width: 768px) and (orientation: landscape) {
  .admin-header {
    padding: 8px 0;
    margin-bottom: 12px;
  }

  .admin-card {
    padding: 14px;
  }

  .admin-sidebar {
    max-height: 100vh;
    overflow-y: auto;
  }

  .admin-content {
    padding: 12px;
  }

  /* Modals in landscape - more compact */
  .admin-modal-content,
  .calendar-modal-content,
  .calendar-edit-modal-content {
    max-height: 85vh;
  }
}

/* =================================================================
   Calendar specific mobile fixes
   ================================================================= */
@media (max-width: 480px) {
  /* Prevent calendar horizontal overflow */
  .booking-calendar-container,
  #bookingCalendar {
    overflow-x: hidden;
    max-width: 100%;
  }

  /* Calendar grid - compact on mobile */
  .calendar-grid {
    gap: 2px;
  }

  /* Calendar day cells - smaller on mobile */
  .calendar-day {
    min-height: 65px;
    padding: 4px;
  }

  .calendar-day-number {
    font-size: 12px;
  }

  /* Calendar day names - abbreviated */
  .calendar-day-name {
    font-size: 10px;
    padding: 6px 2px;
  }

  /* Calendar bookings - compact */
  .calendar-booking {
    font-size: 8px;
    padding: 3px 4px;
    min-height: 36px;
  }

  .calendar-booking-time {
    font-size: 7px;
  }

  .calendar-booking-name {
    font-size: 8px;
  }

  /* Calendar header */
  .calendar-header {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
  }

  .calendar-title {
    font-size: 16px;
    flex: 1 1 100%;
    text-align: center;
    order: -1;
  }

  .calendar-nav-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }
}

/* =================================================================
   Table responsive wrapper
   ================================================================= */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* On mobile, tables become cards so no horizontal scroll needed */
@media (max-width: 480px) {
  .table-responsive {
    overflow-x: visible;
  }
}

/* =================================================================
   Print styles
   ================================================================= */
@media print {
  .admin-header,
  .admin-sidebar,
  .admin-footer,
  .btn,
  .table-actions,
  .table-controls,
  .view-toggle {
    display: none !important;
  }

  .admin-main {
    margin-left: 0 !important;
  }

  .admin-card {
    box-shadow: none;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  .admin-table {
    display: table;
  }

  .admin-table thead {
    display: table-header-group;
  }

  .admin-table tr {
    display: table-row;
    page-break-inside: avoid;
  }

  .admin-table td {
    display: table-cell;
  }

  .admin-table td::before {
    display: none;
  }
}

/* =================================================================
   Utility classes for mobile visibility
   ================================================================= */
@media (max-width: 480px) {
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 481px) {
  .show-mobile-only {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .hide-tablet-down {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .hide-desktop {
    display: none !important;
  }
}
