/* ============================================================================
   KFC COS Management System - Mobile CSS
   Mobile-First Responsive Design (RTL Support)
   ============================================================================ */

/* ============================================================================
   1. MOBILE-FIRST BASE STYLES (Below 769px)
   ============================================================================ */

@media (max-width: 768px) {
  /* Root adjustments for mobile */
  :root {
    --sidebar-width: 0;
    --font-size-base: 13px;
    --font-size-md: 15px;
    --spacing-lg: 16px;
    --spacing-xl: 20px;
    --topbar-height: 56px;
    --bottom-nav-height: 70px;
  }

  /* Hide sidebar on mobile */
  .sidebar {
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    z-index: var(--z-fixed);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.mobile-open {
    display: flex;
    transform: translateX(0);
    width: 260px;
  }

  /* Mobile sidebar overlay */
  .mobile-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-fixed) - 1);
  }

  .mobile-sidebar-overlay.active {
    display: block;
  }

  /* Adjust layout for mobile */
  #app {
    flex-direction: column;
  }

  .main-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: var(--bottom-nav-height);
  }

  /* Show hamburger menu */
  .topbar-hamburger,
  .hamburger-btn {
    display: flex;
  }

  /* Adjust topbar for mobile */
  .topbar {
    height: var(--topbar-height);
    padding: 0 var(--spacing-md);
  }

  .topbar-search {
    max-width: none;
    flex: 1;
    margin: 0 var(--spacing-md);
  }

  .topbar-right {
    gap: var(--spacing-md);
  }

  /* Pages container adjustments */
  .pages-container {
    padding: var(--spacing-md);
    background-color: var(--bg-secondary);
  }

  /* Bottom navigation */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background-color: var(--bottom-nav-bg);
    border-top: 1px solid var(--border-color);
    z-index: var(--z-sticky);
    align-items: stretch;
    padding-bottom: max(0px, env(safe-area-inset-bottom));
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    text-decoration: none;
    padding: var(--spacing-xs);
    min-width: 0;
  }

  .bottom-nav-item:hover {
    color: var(--text-primary);
    background-color: var(--bg-secondary);
  }

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

  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    width: 3px;
    height: 3px;
    background-color: var(--primary);
    border-radius: var(--radius-full);
  }

  .bottom-nav-icon {
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .bottom-nav-label {
    font-size: 10px;
    font-weight: var(--fw-semibold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Cards - full width on mobile */
  .card {
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
  }

  .stat-card {
    padding: var(--spacing-md);
  }

  .stat-value {
    font-size: var(--font-size-xl);
  }

  /* Compact stat cards for mobile */
  .stat-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .stat-content {
    width: 100%;
  }

  .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  /* Data cards stack better on mobile */
  .data-card {
    padding: var(--spacing-sm);
  }

  .data-card-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .data-card-title {
    font-size: var(--font-size-xs);
  }

  /* Form elements - full width */
  .form-input,
  .form-select,
  .form-textarea {
    width: 100%;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  /* Buttons - full width on mobile when needed */
  .btn {
    width: 100%;
    justify-content: center;
  }

  .btn-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
  }

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

  /* Table adjustments for mobile */
  .data-table {
    font-size: var(--font-size-xs);
    overflow-x: auto;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
  }

  .data-table tr {
    display: flex;
    flex-direction: column;
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    margin-bottom: 0;
    border-bottom: none;
  }

  .data-table td {
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .data-table td::before {
    content: attr(data-label);
    font-weight: var(--fw-semibold);
    color: var(--text-secondary);
    flex: 1;
  }

  /* Modal adjustments for mobile */
  .modal-content {
    max-width: 100%;
    width: calc(100% - var(--spacing-lg));
    max-height: 90vh;
    border-radius: var(--radius-xl);
  }

  /* Popup full-screen on small screens */
  .popup-content {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 80vh;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    animation: slideUpMobile var(--transition-base);
  }

  /* Filter bar adjustments */
  .filter-bar {
    flex-direction: column;
    gap: var(--spacing-md);
  }

  .filter-item {
    width: 100%;
  }

  /* Greeting bar adjustments */
  .greeting-bar {
    flex-direction: column;
    text-align: center;
  }

  .greeting-content {
    flex-direction: column;
    width: 100%;
  }

  .greeting-action {
    width: 100%;
    flex-direction: column;
  }

  .greeting-action .btn {
    width: 100%;
  }

  /* Tabs on mobile */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--spacing-md);
  }

  .tab-btn {
    padding: var(--spacing-md) var(--spacing-md);
    font-size: var(--font-size-xs);
    white-space: nowrap;
  }

  /* Tooltips mobile adjustments */
  .tooltip .tooltip-text {
    width: 150px;
    bottom: auto;
    top: -40px;
  }

  .tooltip .tooltip-text::after {
    top: auto;
    bottom: -6px;
    border-top-color: transparent;
    border-bottom-color: var(--text-primary);
  }

  /* Toast positioning for mobile */
  .toast-container {
    top: auto;
    bottom: var(--bottom-nav-height);
    right: var(--spacing-sm);
    left: var(--spacing-sm);
  }

  .toast {
    min-width: auto;
    max-width: none;
    width: 100%;
  }

  /* Chart containers */
  .chart-container {
    height: 250px;
    padding: var(--spacing-md);
  }

  .chart-title {
    font-size: var(--font-size-md);
  }

  /* Avatar adjustments */
  .user-avatar {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }

  .greeting-avatar {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }

  .user-profile-avatar {
    width: 64px;
    height: 64px;
    font-size: 28px;
  }

  /* Badge adjustments */
  .badge {
    padding: 3px 6px;
    font-size: 10px;
  }

  /* Utility adjustments */
  .hide-on-mobile {
    display: none !important;
  }

  /* Sticky action bars on mobile */
  .sticky-action-bar {
    position: sticky;
    bottom: var(--bottom-nav-height);
    background-color: var(--card-bg);
    padding: var(--spacing-md);
    border-top: 1px solid var(--divider);
    display: flex;
    gap: var(--spacing-md);
    z-index: var(--z-sticky);
  }

  .sticky-action-bar .btn {
    flex: 1;
  }

  /* FAB Button (Floating Action Button) */
  .fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--spacing-lg));
    right: var(--spacing-lg);
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background-color: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    transition: all var(--transition-fast);
  }

  .fab:active {
    transform: scale(0.95);
  }

  .fab:hover {
    box-shadow: var(--shadow-xl);
  }

  /* Compact header on mobile */
  .sidebar-header {
    display: none;
  }

  /* Responsive image sizing */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Typography adjustments for mobile */
  h1 {
    font-size: var(--font-size-2xl);
  }

  h2 {
    font-size: var(--font-size-xl);
  }

  h3 {
    font-size: var(--font-size-lg);
  }

  h4 {
    font-size: var(--font-size-md);
  }

  h5, h6 {
    font-size: var(--font-size-base);
  }

  p {
    margin-bottom: var(--spacing-md);
  }

  /* User menu on mobile */
  .user-menu {
    gap: var(--spacing-xs);
  }

  .topbar-icon-btn {
    padding: var(--spacing-xs);
    font-size: var(--font-size-lg);
  }

  /* Dropdown menu adjustments */
  .dropdown {
    position: relative;
  }

  .dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    min-width: 200px;
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    display: none;
  }

  .dropdown.active .dropdown-menu {
    display: block;
  }

  .dropdown-item {
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--text-primary);
    cursor: pointer;
    border-bottom: 1px solid var(--divider);
    font-size: var(--font-size-sm);
    transition: background-color var(--transition-fast);
  }

  .dropdown-item:last-child {
    border-bottom: none;
  }

  .dropdown-item:hover {
    background-color: var(--bg-secondary);
  }

  .dropdown-item.danger {
    color: var(--danger);
  }

  /* Loading states */
  .loading {
    position: relative;
    color: transparent;
  }

  .loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
  }

  /* Empty states */
  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    color: var(--text-tertiary);
    text-align: center;
  }

  .empty-state-icon {
    font-size: 48px;
    margin-bottom: var(--spacing-lg);
  }

  .empty-state-title {
    font-size: var(--font-size-md);
    font-weight: var(--fw-bold);
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
  }

  .empty-state-description {
    font-size: var(--font-size-sm);
    margin-bottom: var(--spacing-lg);
  }

  /* Responsive grid */
  .grid {
    display: grid;
    gap: var(--spacing-md);
  }

  .grid-cols-1 {
    grid-template-columns: 1fr;
  }

  .grid-cols-auto {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

/* ============================================================================
   2. TABLET SCREENS (769px - 1024px)
   ============================================================================ */

@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 200px;
    --font-size-base: 13px;
    --font-size-lg: 17px;
  }

  .sidebar {
    width: var(--sidebar-width);
  }

  .nav-label {
    font-size: var(--font-size-xs);
  }

  .pages-container {
    padding: var(--spacing-md);
  }

  .stat-card {
    padding: var(--spacing-md);
  }

  .card {
    padding: var(--spacing-md);
  }

  .btn {
    padding: 6px 12px;
    font-size: var(--font-size-xs);
  }

  /* Hide certain elements on tablet */
  .hide-on-tablet {
    display: none !important;
  }

  /* Adjust modals for tablet */
  .modal-content {
    max-width: 600px;
  }

  /* Grid adjustments for tablet */
  .grid-cols-auto {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  /* Compact topbar search on tablet */
  .topbar-search {
    max-width: 250px;
  }

  /* Data table more compact */
  .data-table {
    font-size: var(--font-size-xs);
  }

  .data-table th,
  .data-table td {
    padding: var(--spacing-sm);
  }
}

/* ============================================================================
   3. DESKTOP SCREENS (1025px and above)
   ============================================================================ */

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

  .bottom-nav {
    display: none !important;
  }

  .main-container {
    padding-bottom: 0 !important;
  }

  .pages-container {
    padding: var(--spacing-lg);
  }
}

/* ============================================================================
   4. LANDSCAPE ORIENTATION ON MOBILE
   ============================================================================ */

@media (max-width: 768px) and (orientation: landscape) {
  :root {
    --topbar-height: 48px;
    --bottom-nav-height: 50px;
  }

  .greeting-bar {
    flex-direction: row;
    text-align: left;
  }

  .greeting-content {
    flex-direction: row;
  }

  .greeting-avatar {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  .pages-container {
    padding: var(--spacing-sm);
  }

  .card {
    padding: var(--spacing-sm);
  }

  /* Reduce margin/padding in landscape */
  h1 {
    font-size: var(--font-size-xl);
  }

  h2 {
    font-size: var(--font-size-lg);
  }

  .stat-card {
    padding: var(--spacing-sm);
  }

  .modal-content {
    max-height: 95vh;
  }
}

/* ============================================================================
   5. LARGE SCREENS (1440px+)
   ============================================================================ */

@media (min-width: 1440px) {
  :root {
    --sidebar-width: 280px;
    --spacing-lg: 28px;
    --spacing-xl: 36px;
  }

  .pages-container {
    max-width: 1400px;
    margin: 0 auto;
  }

  .grid-cols-auto {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
}

/* ============================================================================
   6. TOUCH DEVICE OPTIMIZATIONS
   ============================================================================ */

@media (hover: none) and (pointer: coarse) {
  /* Increase touch target sizes */
  .btn {
    min-height: 44px;
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .bottom-nav-item {
    min-height: 60px;
  }

  .nav-item {
    padding: var(--spacing-md) var(--spacing-lg);
    min-height: 44px;
  }

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

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

  /* Remove hover effects on touch devices */
  .btn:hover {
    background-color: inherit;
  }

  .card:hover {
    box-shadow: inherit;
  }

  .nav-item:hover {
    background-color: inherit;
  }

  /* Add active state instead */
  .btn:active {
    opacity: 0.8;
  }

  .card:active {
    box-shadow: var(--shadow-lg);
  }

  /* Prevent zoom on input focus */
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

/* ============================================================================
   7. HIGH DPI SCREENS (Retina)
   ============================================================================ */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .card-border,
  .border-color,
  .divider {
    border-width: 0.5px;
  }
}

/* ============================================================================
   8. PRINT ADJUSTMENTS
   ============================================================================ */

@media print {
  .sidebar,
  .topbar,
  .bottom-nav,
  .sticky-action-bar,
  .fab {
    display: none !important;
  }

  .main-container,
  .pages-container {
    padding: 0;
  }

  .card {
    page-break-inside: avoid;
  }

  body {
    background-color: white;
    color: black;
  }
}

/* ============================================================================
   9. DARK MODE MOBILE ADJUSTMENTS
   ============================================================================ */

@media (prefers-color-scheme: dark) and (max-width: 768px) {
  .modal-overlay {
    background-color: rgba(0, 0, 0, 0.7);
  }

  .popup-content {
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  }
}

/* ============================================================================
   10. REDUCED MOTION
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================================
   11. MOBILE ANIMATIONS
   ============================================================================ */

@keyframes slideUpMobile {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes slideDownMobile {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================================================
   12. SAFE AREA INSETS (iPhone notch/dynamic island support)
   ============================================================================ */

@supports (padding: max(0px)) {
  .topbar {
    padding-top: max(var(--spacing-md), env(safe-area-inset-top));
    padding-bottom: max(var(--spacing-md), env(safe-area-inset-bottom));
  }

  .pages-container {
    padding-left: max(var(--spacing-lg), env(safe-area-inset-left));
    padding-right: max(var(--spacing-lg), env(safe-area-inset-right));
  }

  .bottom-nav {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

/* ============================================================================
   13. MOBILE-SPECIFIC UTILITY CLASSES
   ============================================================================ */

.show-on-mobile {
  display: none;
}

@media (max-width: 768px) {
  .show-on-mobile {
    display: block;
  }

  .show-on-mobile.flex {
    display: flex;
  }

  .show-on-mobile.inline-flex {
    display: inline-flex;
  }

  .show-on-mobile.grid {
    display: grid;
  }

  /* Mobile spacing utilities */
  .mobile-p-sm {
    padding: var(--spacing-sm);
  }

  .mobile-p-md {
    padding: var(--spacing-md);
  }

  .mobile-m-0 {
    margin: 0;
  }

  .mobile-mt-md {
    margin-top: var(--spacing-md);
  }

  .mobile-mb-md {
    margin-bottom: var(--spacing-md);
  }

  /* Mobile text utilities */
  .mobile-text-center {
    text-align: center;
  }

  .mobile-text-sm {
    font-size: var(--font-size-sm);
  }

  /* Mobile flex utilities */
  .mobile-flex-col {
    flex-direction: column;
  }

  .mobile-flex-row {
    flex-direction: row;
  }

  .mobile-gap-sm {
    gap: var(--spacing-sm);
  }

  .mobile-gap-md {
    gap: var(--spacing-md);
  }
}

/* ============================================================================
   14. RESPONSIVE GRID SYSTEM
   ============================================================================ */

@media (max-width: 768px) {
  .grid-cols-2 {
    grid-template-columns: 1fr;
  }

  .grid-cols-3 {
    grid-template-columns: 1fr 1fr;
  }

  .grid-cols-4 {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .grid-cols-3 {
    grid-template-columns: repeat(2, 1fr);
  }

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

@media (min-width: 1025px) {
  .grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
  }

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

/* ============================================================================
   15. MODAL & POPUP MOBILE SPECIFICS
   ============================================================================ */

@media (max-width: 768px) {
  /* Full-screen modal on small screens */
  .modal-overlay.mobile-fullscreen .modal-content {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    margin: 0;
  }

  /* Bottom sheet style popup */
  .bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--card-bg);
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    max-height: 90vh;
    overflow-y: auto;
    z-index: var(--z-modal);
    animation: slideUpMobile var(--transition-base);
  }

  .bottom-sheet-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--divider);
    text-align: center;
  }

  .bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background-color: var(--border-color);
    border-radius: var(--radius-full);
    margin: var(--spacing-sm) auto;
  }

  .bottom-sheet-content {
    padding: var(--spacing-lg);
  }

  /* Drawer style sidebar */
  .drawer {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 80vw;
    max-width: 320px;
    background-color: var(--card-bg);
    z-index: var(--z-fixed);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    overflow-y: auto;
  }

  .drawer.open {
    transform: translateX(0);
  }
}

/* ============================================================================
   16. CONTEXTUAL RESPONSIVE ADJUSTMENTS
   ============================================================================ */

/* Adjust content for split-view on iPad */
@media (min-width: 820px) and (max-height: 600px) {
  .greeting-bar {
    padding: var(--spacing-sm);
  }

  .card {
    padding: var(--spacing-sm);
  }

  .topbar {
    height: 48px;
  }
}

/* Small phone (< 375px width) */
@media (max-width: 374px) {
  :root {
    --font-size-base: 12px;
    --spacing-md: 12px;
    --spacing-lg: 14px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .card {
    padding: var(--spacing-md);
  }

  .badge {
    padding: 2px 4px;
    font-size: 9px;
  }

  .bottom-nav-label {
    font-size: 9px;
  }

  .user-avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }
}

/* Large phone (> 430px width) */
@media (min-width: 430px) and (max-width: 768px) {
  .grid-cols-auto {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }

  .btn-group {
    flex-direction: row;
  }

  .btn-group .btn {
    width: auto;
    flex: 1;
  }
}

/* ============================================================================
   HTML CLASS ALIASES FOR MOBILE — map actual HTML classes to mobile styles
   ============================================================================ */
@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: var(--bottom-nav-height);
  }

  .hamburger {
    display: flex;
  }

  .top-bar {
    height: var(--topbar-height);
    padding: 0 var(--spacing-md);
  }

  .top-bar-actions {
    gap: var(--spacing-md);
  }

  .sidebar-close {
    display: block;
  }

  .mobile-overlay.active {
    display: block;
  }
}
