/* ============================================
   MOBILE OPTIMIZATIONS CSS
   Phase 3B - Mobile Optimization & Testing
   
   This file works alongside mobile-nav.css
   for enhanced mobile experience
   ============================================ */

/* ============================================
   COMPATIBILITY WITH EXISTING MOBILE-NAV.CSS
   ============================================ */

/* Ensure bottom nav consistency */
.mobile-bottom-tabs,
.bottom-nav {
  height: 70px;
  min-height: 70px;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Mobile tab items touch targets */
.mobile-tab-item {
  min-width: 44px;
  min-height: 44px;
}

/* Grid menu items touch targets */
.mobile-grid-item {
  min-height: 70px;
}

/* Menu toggle touch target */
.mobile-menu-toggle {
  min-width: 44px;
  min-height: 44px;
}

/* ============================================
   TOUCH TARGETS - 44px Minimum
   ============================================ */
@media (max-width: 767px) {
  /* Buttons */
  .btn,
  .btn--sm,
  .btn--lg {
    min-height: 44px;
    min-width: 44px;
  }

  .btn--icon {
    min-width: 44px;
    min-height: 44px;
  }

  /* Navigation items */
  .bottom-nav__item {
    min-height: 44px;
    min-width: 44px;
    padding: var(--space-2) var(--space-3);
  }

  .nav-item {
    min-height: 44px;
    padding: var(--space-3) var(--space-4);
  }

  /* Form inputs */
  .form-input,
  .form-select,
  .form-textarea {
    min-height: 44px;
    font-size: 16px; /* Prevent iOS zoom on focus */
  }

  /* Checkbox and radio */
  input[type="checkbox"],
  input[type="radio"] {
    min-width: 24px;
    min-height: 24px;
  }

  /* Priority checkbox */
  .priority-checkbox {
    width: 24px;
    height: 24px;
  }

  /* Filter buttons */
  .filter-btn,
  .filter-bar .btn {
    min-height: 44px;
    padding: var(--space-3) var(--space-4);
  }

  /* Card actions */
  .card__footer .btn,
  .printer-actions .btn {
    min-height: 44px;
    min-width: 44px;
  }

  /* Kanban column headers */
  .kanban-column-header {
    min-height: 44px;
  }

  /* List items */
  .priority-list-item,
  .upcoming-item,
  .day-detail-item {
    min-height: 44px;
    padding: var(--space-3);
  }

  /* Calendar day cells */
  .calendar-day {
    min-height: 44px;
  }

  /* Toast close button */
  .toast__close {
    min-width: 44px;
    min-height: 44px;
  }

  /* Complete button */
  .priority-complete-btn {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ============================================
   MOBILE SPACING - 16px Padding
   ============================================ */
@media (max-width: 767px) {
  .main__content {
    padding: var(--space-4);
  }

  .container {
    padding: 0 var(--space-4);
  }

  .card {
    padding: var(--space-4);
  }

  .card__header,
  .card__body,
  .card__footer {
    padding: var(--space-4);
  }

  .dashboard-header {
    padding: var(--space-4);
  }

  .inventory-header {
    padding: var(--space-4);
  }

  .section-header {
    margin-bottom: var(--space-4);
  }

  .welcome-card .card__body {
    padding: var(--space-4);
  }

  .empty-state {
    padding: var(--space-8) var(--space-4);
  }

  /* Grid gaps on mobile */
  .grid {
    gap: var(--space-4);
  }

  .dashboard-grid {
    gap: var(--space-4);
  }

  .printers-mini-grid {
    gap: var(--space-4);
  }

  .printers-grid {
    gap: var(--space-4);
  }

  .project-grid {
    gap: var(--space-4);
  }
}

/* ============================================
   BOTTOM NAVIGATION - Fixed 70px Height
   ============================================ */
.bottom-nav {
  height: var(--bottom-nav-height);
  min-height: var(--bottom-nav-height);
  padding: var(--space-2) 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background-color: var(--color-surface);
  border-top: 1px solid var(--color-border);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

/* Safe area support for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  }

  .main {
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  }

  .toast-container {
    bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + var(--space-4));
  }
}

/* ============================================
   BOTTOM NAV - ACTIVE STATE INDICATOR
   ============================================ */
.bottom-nav__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  transition: all var(--transition-base);
  cursor: pointer;
  border: none;
  background: none;
  border-radius: var(--radius-md);
}

.bottom-nav__item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 24px;
  height: 3px;
  background-color: var(--color-primary);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  transition: transform var(--transition-base);
}

.bottom-nav__item:hover {
  color: var(--color-text);
  background-color: var(--color-surface-hover);
}

.bottom-nav__item--active {
  color: var(--color-primary);
}

.bottom-nav__item--active::before {
  transform: translateX(-50%) scaleX(1);
}

.bottom-nav__item--active i {
  color: var(--color-primary);
}

.bottom-nav__item i {
  width: 24px;
  height: 24px;
  transition: transform var(--transition-base);
}

.bottom-nav__item--active i {
  transform: translateY(-2px);
}

/* ============================================
   VIEW TRANSITIONS - Smooth between views
   ============================================ */
.main__content {
  animation: fadeIn 200ms ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Page transition for sections */
.section-transition {
  animation: slideIn 200ms ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ============================================
   KEYBOARD APPEARANCE HANDLING
   ============================================ */
/* When virtual keyboard is open, adjust layout */
@media (max-width: 767px) and (max-height: 500px) {
  .bottom-nav {
    transform: translateY(100%);
    transition: transform var(--transition-base);
  }

  .main {
    padding-bottom: 0;
  }
}

/* ============================================
   LANDSCAPE MODE ADJUSTMENTS
   ============================================ */
@media (max-width: 767px) and (orientation: landscape) {
  /* Reduce bottom nav height in landscape */
  .bottom-nav {
    height: 56px;
    min-height: 56px;
  }

  .bottom-nav__item {
    flex-direction: row;
    gap: var(--space-2);
  }

  .bottom-nav__item i {
    width: 20px;
    height: 20px;
  }

  /* Adjust main content padding */
  .main {
    padding-bottom: 56px;
  }

  /* Hide some decorative elements */
  .welcome-badges {
    display: none;
  }

  /* Compact cards */
  .card {
    padding: var(--space-3);
  }

  .card__header,
  .card__body,
  .card__footer {
    padding: var(--space-3);
  }

  /* Side-by-side layouts where possible */
  .dashboard-stats-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .quick-actions-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ============================================
   TABLET BREAKPOINTS (768px - 1024px)
   ============================================ */
@media (min-width: 768px) and (max-width: 1024px) {
  /* Adjust sidebar width */
  .sidebar {
    width: 200px;
  }

  .main {
    margin-left: 200px;
  }

  /* 2-column grids */
  .grid--3 {
    grid-template-columns: repeat(2, 1fr);
  }

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

  /* Project grid */
  .project-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Printers grid */
  .printers-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Adjust kanban for tablet */
  .kanban-board {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
  }

  .kanban-column {
    min-width: 220px;
  }
}

/* ============================================
   MOBILE-SPECIFIC COMPONENT ADJUSTMENTS
   ============================================ */
@media (max-width: 767px) {
  /* Dashboard stats - horizontal scroll if needed */
  .dashboard-stats-row {
    display: flex;
    gap: var(--space-3);
    overflow-x: auto;
    padding-bottom: var(--space-2);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .dashboard-stats-row::-webkit-scrollbar {
    display: none;
  }

  .dashboard-stat {
    flex: 0 0 auto;
    min-width: 80px;
    padding: var(--space-3);
  }

  /* Filter bar horizontal scroll */
  .filter-bar {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding-bottom: var(--space-2);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }

  .filter-bar::-webkit-scrollbar {
    display: none;
  }

  .filter-bar .btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* Assignee filters on mobile */
  .assignee-filters {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
    margin-top: var(--space-2);
  }

  /* Welcome card adjustments */
  .welcome-card .card__body {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .welcome-title {
    font-size: var(--font-size-xl);
  }

  /* Printer cards - full width */
  .printer-card {
    width: 100%;
  }

  .printer-image-container {
    height: 120px;
  }

  /* Priority cards */
  .priority-card {
    width: 100%;
  }

  .priority-card-title {
    font-size: var(--font-size-base);
  }

  /* Project cards */
  .project-card {
    width: 100%;
  }

  .project-card-title {
    font-size: var(--font-size-base);
  }

  /* Kanban to list on mobile */
  .kanban-board {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .kanban-column {
    min-height: auto;
  }

  /* Calendar adjustments */
  .calendar-month-view {
    font-size: var(--font-size-sm);
  }

  .calendar-day {
    padding: var(--space-1);
  }

  .day-dots {
    display: none; /* Hide dots on very small screens */
  }

  /* Revenue chart container */
  .revenue-chart-container {
    flex-direction: column;
  }

  .revenue-sparkline {
    height: 80px;
  }

  /* Settings layout */
  .settings-layout {
    flex-direction: column;
  }

  .settings-sidebar {
    display: none;
  }

  .settings-nav-mobile {
    display: block;
  }

  /* Data table horizontal scroll */
  .data-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Modal adjustments */
  .modal-content {
    margin: var(--space-4);
    max-height: calc(100vh - var(--space-8));
  }

  /* Toast positioning */
  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
    bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0) + var(--space-4));
  }
}

/* ============================================
   SMALL MOBILE (< 360px)
   ============================================ */
@media (max-width: 360px) {
  :root {
    --space-4: 12px;
  }

  .bottom-nav__item {
    padding: var(--space-1) var(--space-2);
    font-size: 10px;
  }

  .bottom-nav__item i {
    width: 20px;
    height: 20px;
  }

  .welcome-title {
    font-size: var(--font-size-lg);
  }

  .dashboard-greeting {
    font-size: var(--font-size-xl);
  }
}

/* ============================================
   LARGE MOBILE (360px - 767px)
   ============================================ */
@media (min-width: 361px) and (max-width: 767px) {
  .quick-actions-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   NO HORIZONTAL SCROLL - Prevent overflow
   ============================================ */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

.main {
  max-width: 100vw;
  overflow-x: hidden;
}

.main__content {
  max-width: 100%;
  overflow-x: hidden;
}

/* Ensure images don't overflow */
img {
  max-width: 100%;
  height: auto;
}

/* Ensure tables don't overflow */
table {
  max-width: 100%;
}

/* Prevent long text from overflowing */
.card__title,
.printer-name,
.priority-card-title,
.project-card-title {
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* ============================================
   ACCESSIBILITY - Focus visible
   ============================================ */
@media (max-width: 767px) {
  :focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }

  /* Larger touch targets for accessibility */
  .btn:focus-visible,
  .bottom-nav__item:focus-visible,
  .nav-item:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
  }
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .main__content,
  .section-transition {
    animation: none;
  }

  .bottom-nav__item,
  .bottom-nav__item::before,
  .bottom-nav__item i {
    transition: none;
  }

  .card,
  .btn,
  .priority-card,
  .project-card {
    transition: none;
  }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */
@media (prefers-contrast: high) {
  .bottom-nav__item--active::before {
    height: 4px;
  }

  .btn {
    border-width: 2px;
  }

  .card {
    border-width: 2px;
  }
}

/* ============================================
   DARK MODE OPTIMIZATIONS (Mobile)
   ============================================ */
@media (max-width: 767px) and (prefers-color-scheme: dark) {
  .bottom-nav {
    background-color: var(--color-surface);
    border-top-color: var(--color-border);
  }
}
