/**
 * Responsive CSS Framework - WhereToGoHK
 *
 * Mobile-first responsive grid system and utilities.
 * Designed to complement /themes/default/main.css CSS custom properties.
 *
 * IMPORTANT: Add the following viewport meta tag to every HTML page:
 * <meta name="viewport" content="width=device-width, initial-scale=1.0">
 *
 * Breakpoints:
 *   Mobile:  < 768px  (default / base styles)
 *   Tablet:  768px – 1023px
 *   Desktop: ≥ 1024px
 *
 * Requirements: 18.1, 18.2, 18.3, 18.4, 18.5
 */

/* ===== Responsive Custom Properties ===== */

:root {
  --bp-tablet:  768px;
  --bp-desktop: 1024px;

  /* Touch-friendly tap target minimum */
  --touch-target-min: 44px;

  /* Responsive font scale */
  --fluid-font-sm:   clamp(12px, 1.5vw, 14px);
  --fluid-font-base: clamp(14px, 2vw,   16px);
  --fluid-font-lg:   clamp(16px, 2.5vw, 18px);
  --fluid-font-xl:   clamp(18px, 3vw,   24px);
  --fluid-font-2xl:  clamp(22px, 4vw,   32px);
  --fluid-font-3xl:  clamp(28px, 5vw,   40px);
}

/* ===== Container ===== */

.container {
  width: 100%;
  padding-right: var(--spacing-4, 16px);
  padding-left:  var(--spacing-4, 16px);
  margin-right: auto;
  margin-left:  auto;
}

@media (min-width: 768px) {
  .container {
    max-width: 720px;
    padding-right: var(--spacing-6, 24px);
    padding-left:  var(--spacing-6, 24px);
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 960px;
  }
}

@media (min-width: 1200px) {
  .container {
    max-width: 1140px;
  }
}

.container-fluid {
  width: 100%;
  padding-right: var(--spacing-4, 16px);
  padding-left:  var(--spacing-4, 16px);
  margin-right: auto;
  margin-left:  auto;
}

/* ===== Grid System ===== */

.row {
  display: flex;
  flex-wrap: wrap;
  margin-right: calc(var(--spacing-4, 16px) / -2);
  margin-left:  calc(var(--spacing-4, 16px) / -2);
}

/* All columns share base padding */
[class^="col"],
[class*=" col"] {
  padding-right: calc(var(--spacing-4, 16px) / 2);
  padding-left:  calc(var(--spacing-4, 16px) / 2);
  width: 100%;
}

/* Mobile-first: all columns stack by default */
.col    { flex: 1 1 0%; min-width: 0; }
.col-1  { flex: 0 0 8.3333%;  max-width: 8.3333%; }
.col-2  { flex: 0 0 16.6667%; max-width: 16.6667%; }
.col-3  { flex: 0 0 25%;      max-width: 25%; }
.col-4  { flex: 0 0 33.3333%; max-width: 33.3333%; }
.col-5  { flex: 0 0 41.6667%; max-width: 41.6667%; }
.col-6  { flex: 0 0 50%;      max-width: 50%; }
.col-7  { flex: 0 0 58.3333%; max-width: 58.3333%; }
.col-8  { flex: 0 0 66.6667%; max-width: 66.6667%; }
.col-9  { flex: 0 0 75%;      max-width: 75%; }
.col-10 { flex: 0 0 83.3333%; max-width: 83.3333%; }
.col-11 { flex: 0 0 91.6667%; max-width: 91.6667%; }
.col-12 { flex: 0 0 100%;     max-width: 100%; }

/* Tablet columns (md) */
@media (min-width: 768px) {
  .col-md    { flex: 1 1 0%; min-width: 0; }
  .col-md-1  { flex: 0 0 8.3333%;  max-width: 8.3333%; }
  .col-md-2  { flex: 0 0 16.6667%; max-width: 16.6667%; }
  .col-md-3  { flex: 0 0 25%;      max-width: 25%; }
  .col-md-4  { flex: 0 0 33.3333%; max-width: 33.3333%; }
  .col-md-5  { flex: 0 0 41.6667%; max-width: 41.6667%; }
  .col-md-6  { flex: 0 0 50%;      max-width: 50%; }
  .col-md-7  { flex: 0 0 58.3333%; max-width: 58.3333%; }
  .col-md-8  { flex: 0 0 66.6667%; max-width: 66.6667%; }
  .col-md-9  { flex: 0 0 75%;      max-width: 75%; }
  .col-md-10 { flex: 0 0 83.3333%; max-width: 83.3333%; }
  .col-md-11 { flex: 0 0 91.6667%; max-width: 91.6667%; }
  .col-md-12 { flex: 0 0 100%;     max-width: 100%; }
}

/* Desktop columns (lg) */
@media (min-width: 1024px) {
  .col-lg    { flex: 1 1 0%; min-width: 0; }
  .col-lg-1  { flex: 0 0 8.3333%;  max-width: 8.3333%; }
  .col-lg-2  { flex: 0 0 16.6667%; max-width: 16.6667%; }
  .col-lg-3  { flex: 0 0 25%;      max-width: 25%; }
  .col-lg-4  { flex: 0 0 33.3333%; max-width: 33.3333%; }
  .col-lg-5  { flex: 0 0 41.6667%; max-width: 41.6667%; }
  .col-lg-6  { flex: 0 0 50%;      max-width: 50%; }
  .col-lg-7  { flex: 0 0 58.3333%; max-width: 58.3333%; }
  .col-lg-8  { flex: 0 0 66.6667%; max-width: 66.6667%; }
  .col-lg-9  { flex: 0 0 75%;      max-width: 75%; }
  .col-lg-10 { flex: 0 0 83.3333%; max-width: 83.3333%; }
  .col-lg-11 { flex: 0 0 91.6667%; max-width: 91.6667%; }
  .col-lg-12 { flex: 0 0 100%;     max-width: 100%; }
}

/* ===== Responsive Navigation (hamburger pattern) ===== */

.nav-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--nav-padding-y, 16px) var(--nav-padding-x, 24px);
  background-color: var(--nav-bg, #ffffff);
  box-shadow: var(--nav-shadow, 0 2px 4px rgba(0,0,0,.1));
  min-height: var(--nav-height, 64px);
}

.nav-brand {
  font-size: var(--font-size-xl, 20px);
  font-weight: var(--font-weight-bold, 700);
  color: var(--color-primary, #667eea);
  text-decoration: none;
}

/* Hamburger toggle button — visible only on mobile */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 28px;
  height: 20px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  min-height: var(--touch-target-min);
  min-width:  var(--touch-target-min);
  align-items: center;
}

.nav-toggle-bar {
  display: block;
  width: 28px;
  height: 2px;
  background-color: var(--color-text-primary, #333);
  border-radius: 2px;
  transition: var(--transition-all, all 300ms ease-in-out);
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: var(--spacing-6, 24px);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-menu a {
  color: var(--color-text-primary, #333);
  font-weight: var(--font-weight-medium, 500);
  text-decoration: none;
  padding: var(--spacing-2, 8px) var(--spacing-3, 12px);
  border-radius: var(--radius-base, 6px);
  transition: var(--transition-colors, color 300ms ease-in-out);
  display: inline-block;
  min-height: var(--touch-target-min);
  line-height: calc(var(--touch-target-min) - 16px);
}

.nav-menu a:hover {
  color: var(--color-primary, #667eea);
  background-color: var(--color-bg-hover, #f8f9fa);
}

/* Mobile navigation */
@media (max-width: 767px) {
  .nav-toggle {
    display: flex;
  }

  .nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background-color: var(--nav-bg, #ffffff);
    box-shadow: var(--shadow-md, 0 6px 12px rgba(0,0,0,.1));
    z-index: var(--z-index-dropdown, 1000);
    padding: var(--spacing-2, 8px) 0;
  }

  .nav-menu.is-open {
    display: flex;
  }

  .nav-menu a {
    padding: var(--spacing-3, 12px) var(--spacing-6, 24px);
    border-radius: 0;
    min-height: var(--touch-target-min);
    line-height: var(--touch-target-min);
    padding-top: 0;
    padding-bottom: 0;
  }
}

/* ===== Touch-Friendly Buttons and Links ===== */

/* Ensure all interactive elements meet 44px minimum on mobile */
@media (max-width: 767px) {
  .btn,
  button,
  input[type="submit"],
  input[type="button"],
  input[type="reset"],
  select {
    min-height: var(--touch-target-min);
    padding-top: var(--spacing-3, 12px);
    padding-bottom: var(--spacing-3, 12px);
    font-size: var(--font-size-base, 16px); /* prevent iOS zoom on focus */
  }

  .form-control,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  input[type="number"],
  textarea {
    min-height: var(--touch-target-min);
    font-size: var(--font-size-base, 16px); /* prevent iOS zoom on focus */
  }

  /* Larger tap targets for checkboxes and radios */
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
  }
}

/* ===== Responsive Tables ===== */

/* Horizontal scroll wrapper for tables on mobile */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: var(--table-cell-padding-y, 12px) var(--table-cell-padding-x, 12px);
  text-align: left;
  border-bottom: 1px solid var(--table-border-color, #e9ecef);
  white-space: nowrap; /* keeps columns readable when scrolling */
}

th {
  background-color: var(--table-header-bg, #f8f9fa);
  font-weight: var(--font-weight-semibold, 600);
}

tr:hover td {
  background-color: var(--table-hover-bg, #f8f9fa);
}

@media (max-width: 767px) {
  /* Allow text wrapping on very small screens for readability */
  th, td {
    white-space: normal;
    min-width: 100px;
  }
}

/* ===== Responsive Images ===== */

img,
video,
iframe,
embed,
object {
  max-width: 100%;
  height: auto;
}

.img-fluid {
  max-width: 100%;
  height: auto;
  display: block;
}

.img-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== Responsive Typography ===== */

/* Base: mobile */
body {
  font-size: var(--fluid-font-base);
}

h1 { font-size: var(--fluid-font-3xl); }
h2 { font-size: var(--fluid-font-2xl); }
h3 { font-size: var(--fluid-font-xl); }
h4 { font-size: var(--fluid-font-lg); }
h5 { font-size: var(--fluid-font-base); }
h6 { font-size: var(--fluid-font-sm); }

/* Tablet */
@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --fluid-font-base: 15px;
    --fluid-font-lg:   17px;
    --fluid-font-xl:   20px;
    --fluid-font-2xl:  26px;
    --fluid-font-3xl:  32px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  :root {
    --fluid-font-base: 16px;
    --fluid-font-lg:   18px;
    --fluid-font-xl:   24px;
    --fluid-font-2xl:  32px;
    --fluid-font-3xl:  40px;
  }
}

/* ===== Visibility Utilities ===== */

/* Hide on mobile (< 768px) */
.hide-mobile {
  display: none !important;
}

/* Show on mobile only */
.show-mobile {
  display: block !important;
}

@media (min-width: 768px) {
  .hide-mobile  { display: block !important; }
  .show-mobile  { display: none  !important; }
}

/* Hide on tablet (768px – 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .hide-tablet { display: none  !important; }
  .show-tablet { display: block !important; }
}

@media (max-width: 767px),
       (min-width: 1024px) {
  .show-tablet { display: none  !important; }
}

/* Hide on desktop (≥ 1024px) */
@media (min-width: 1024px) {
  .hide-desktop { display: none  !important; }
  .show-desktop { display: block !important; }
}

@media (max-width: 1023px) {
  .show-desktop { display: none  !important; }
}

/* ===== Responsive Spacing Utilities ===== */

@media (max-width: 767px) {
  .p-mobile-0  { padding: 0 !important; }
  .p-mobile-1  { padding: var(--spacing-1, 4px)  !important; }
  .p-mobile-2  { padding: var(--spacing-2, 8px)  !important; }
  .p-mobile-4  { padding: var(--spacing-4, 16px) !important; }

  .mt-mobile-0 { margin-top: 0 !important; }
  .mt-mobile-4 { margin-top: var(--spacing-4, 16px) !important; }
  .mb-mobile-4 { margin-bottom: var(--spacing-4, 16px) !important; }

  .text-mobile-center { text-align: center !important; }
  .text-mobile-left   { text-align: left   !important; }
}

/* ===== Responsive Flex Utilities ===== */

.d-flex         { display: flex; }
.flex-column    { flex-direction: column; }
.flex-wrap      { flex-wrap: wrap; }
.align-center   { align-items: center; }
.justify-center { justify-content: center; }
.justify-between{ justify-content: space-between; }

@media (max-width: 767px) {
  .flex-mobile-column { flex-direction: column !important; }
  .flex-mobile-wrap   { flex-wrap: wrap !important; }
}

/* ===== Mobile-Specific Layout Adjustments ===== */

@media (max-width: 767px) {
  /* Stack cards vertically */
  .card-grid {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4, 16px);
  }

  /* Full-width buttons on mobile */
  .btn-mobile-full {
    display: block;
    width: 100%;
    text-align: center;
  }

  /* Reduce card padding */
  .card {
    padding: var(--spacing-4, 16px);
  }

  /* Reduce section spacing */
  section,
  .section {
    padding-top: var(--spacing-8, 32px);
    padding-bottom: var(--spacing-8, 32px);
  }
}

/* ===== Tablet-Specific Layout Adjustments ===== */

@media (min-width: 768px) and (max-width: 1023px) {
  .card-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-5, 20px);
  }

  section,
  .section {
    padding-top: var(--spacing-12, 48px);
    padding-bottom: var(--spacing-12, 48px);
  }
}

/* ===== Desktop Layout ===== */

@media (min-width: 1024px) {
  .card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-6, 24px);
  }

  section,
  .section {
    padding-top: var(--spacing-16, 64px);
    padding-bottom: var(--spacing-16, 64px);
  }
}
