/**
 * Mobile-First Responsive Design
 * Optimized untuk touch interfaces dan slow networks
 * Breakpoints: 320px (mobile), 768px (tablet), 1024px (desktop), 1440px (wide)
 */

/* ====== GLOBAL RESPONSIVE SETTINGS ====== */

/* Prevent zoom on input focus (mobile) */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important; /* Prevents iOS zoom */
  }
}

/* Touch-friendly tap targets (minimum 48x48px recommended) - ONLY for buttons and explicit targets */
button, [role="button"], input[type="button"], input[type="submit"], .btn {
  min-height: 48px;
  min-width: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
}

/* Reduce padding on small screens */
@media (max-width: 576px) {
  button, [role="button"], input[type="button"], input[type="submit"], .btn {
    padding: 10px 12px;
  }
}

/* ====== MOBILE NAVIGATION (320px - 768px) ====== */

.navbar {
  padding: 0.5rem 0 !important;
  position: sticky;
  top: 0;
  z-index: 999;
}

.navbar-brand {
  font-size: 1rem;
  font-weight: 700;
}

@media (max-width: 768px) {
  .navbar {
    padding: 0.25rem 0 !important;
  }
  
  .navbar-brand {
    font-size: 0.875rem;
  }
  
  .navbar-collapse {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border);
    z-index: 998;
    max-height: calc(100vh - 60px);
    overflow-y: auto;
  }
  
  .navbar-nav {
    flex-direction: column;
    gap: 0;
  }
  
  .nav-link {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
  }
}

/* ====== MOBILE CONTAINER & SPACING ====== */

.container-fluid {
  padding-left: 12px;
  padding-right: 12px;
}

@media (max-width: 576px) {
  .container-fluid {
    padding-left: 8px;
    padding-right: 8px;
  }
  
  .container, .container-sm {
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* Hero section responsive */
.hero {
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

@media (max-width: 768px) {
  .hero {
    min-height: auto;
    padding: 1.5rem 1rem;
  }
  
  .hero h1 {
    font-size: 1.75rem;
  }
  
  .hero p {
    font-size: 1rem;
  }
}

/* ====== MOBILE GRID & LAYOUTS ====== */

/* Single column on mobile */
.grid-auto-2, .grid-auto-3, .grid-auto-4 {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 576px) {
  .grid-auto-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  .grid-auto-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 992px) {
  .grid-auto-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Flex direction mobile */
.flex-row-reverse-mobile {
  flex-direction: column-reverse;
}

@media (min-width: 768px) {
  .flex-row-reverse-mobile {
    flex-direction: row-reverse;
  }
}

/* ====== MOBILE TYPOGRAPHY ====== */

html {
  font-size: 15px; /* Mobile-first, slightly larger for readability */
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

h1 {
  font-size: 1.75rem;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.25rem;
}

@media (min-width: 768px) {
  h1 {
    font-size: 2.5rem;
  }
  
  h2 {
    font-size: 2rem;
  }
  
  h3 {
    font-size: 1.75rem;
  }
}

/* ====== MOBILE FORMS ====== */

.form-group {
  margin-bottom: 1rem;
}

.form-control, .form-select {
  font-size: 16px; /* Prevent iOS zoom */
  padding: 12px;
}

@media (max-width: 576px) {
  .form-control, .form-select {
    width: 100%;
    display: block;
  }
  
  .form-row {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  
  .form-row > * {
    flex: 1;
  }
}

/* ====== MOBILE TABLES ====== */

/* Stack tables horizontally on mobile */
@media (max-width: 768px) {
  .table-responsive {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    font-size: 0.875rem;
  }
  
  th, td {
    padding: 8px;
  }
}

/* ====== MOBILE CARDS ====== */

.card {
  margin-bottom: 1rem;
  border-radius: 8px;
  overflow: hidden;
}

@media (max-width: 576px) {
  .card {
    margin-bottom: 0.75rem;
    border-radius: 6px;
  }
  
  .card-body {
    padding: 12px;
  }
}

/* ====== MOBILE MODALS ====== */

@media (max-width: 576px) {
  .modal-dialog {
    margin: 0.5rem;
  }
  
  .modal-content {
    border-radius: 8px;
  }
}

/* ====== MOBILE BUTTONS ====== */

.btn {
  border-radius: 6px;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.875rem;
}

@media (max-width: 576px) {
  .btn-block, .btn-mobile-full {
    display: block;
    width: 100%;
  }
  
  /* Make full-width buttons on mobile */
  .btn-group {
    display: flex;
    flex-direction: column;
  }
  
  .btn-group > .btn {
    width: 100%;
  }
}

/* ====== MOBILE NAVBAR SEARCH ====== */

.navbar-search {
  display: none;
}

@media (max-width: 768px) {
  .navbar-search {
    display: block;
    padding: 8px 12px;
  }
  
  .navbar-search input {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
  }
}

/* ====== MOBILE SIDEBAR ====== */

.sidebar {
  display: none;
}

@media (min-width: 992px) {
  .sidebar {
    display: block;
    position: sticky;
    top: 80px;
  }
}

/* ====== MOBILE FOOTER ====== */

footer {
  padding: 1.5rem 1rem;
}

@media (min-width: 768px) {
  footer {
    padding: 2rem;
  }
}

.footer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 768px) {
  .footer-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

/* ====== MOBILE IMAGES & MEDIA ====== */

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Responsive video embeds */
.video-container {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  overflow: hidden;
}

.video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ====== MOBILE ALERTS ====== */

.alert {
  margin-bottom: 1rem;
  border-radius: 6px;
}

@media (max-width: 576px) {
  .alert {
    padding: 12px;
    font-size: 0.875rem;
  }
}

/* ====== MOBILE PAGINATION ====== */

.pagination {
  flex-wrap: wrap;
  gap: 4px;
}

@media (max-width: 576px) {
  .pagination {
    justify-content: center;
  }
  
  .page-link {
    padding: 6px 8px;
    font-size: 0.875rem;
  }
}

/* ====== MOBILE BADGES ====== */

.badge {
  font-size: 0.75rem;
  padding: 4px 8px;
}

/* ====== MOBILE DROPDOWNS ====== */

.dropdown-menu {
  position: fixed;
  top: auto !important;
  left: auto !important;
  right: 0;
  max-height: 50vh;
  overflow-y: auto;
}

@media (min-width: 768px) {
  .dropdown-menu {
    position: absolute;
    top: auto;
    right: auto;
  }
}

/* ====== HAMBURGER MENU ====== */

.hamburger {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  gap: 4px;
  width: 24px;
  height: 24px;
  background: none;
  border: none;
}

.hamburger span {
  width: 100%;
  height: 3px;
  background-color: var(--color-text);
  border-radius: 2px;
  transition: all var(--transition-fast);
}

.hamburger.active span:nth-child(1) {
  transform: rotate(45deg) translate(8px, 8px);
}

.hamburger.active span:nth-child(2) {
  opacity: 0;
}

.hamburger.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

/* ====== SLOW NETWORK OPTIMIZATION ====== */

@media (prefers-reduced-data: reduce) {
  /* Reduce animations */
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  /* Disable background images */
  body, div, section, article {
    background-image: none !important;
  }
  
  /* Reduce image quality hints */
  img {
    loading: lazy;
  }
}

/* ====== PRINT STYLES ====== */

@media print {
  .navbar, footer, .sidebar, .pagination {
    display: none;
  }
  
  body {
    background: white;
    color: black;
  }
  
  a {
    text-decoration: underline;
  }
}
