/**
 * Responsive Styles for brachot.net
 * Organized by breakpoints for better maintainability
 * Refactored: January 2025
 *
 * Breakpoints:
 * - Mobile: 0-767px (xs)
 * - Tablet: 768-1279px (sm/md)
 * - Desktop: 1280px+ (lg)
 */

/* ============================================
   VIEWPORT CONFIGURATION
   ============================================ */

@-ms-viewport {
  width: device-width;
}

/* ============================================
   VISIBILITY UTILITIES - Base Definitions
   ============================================ */

/* Hidden by default */
.visible-xs,
tr.visible-xs,
th.visible-xs,
td.visible-xs,
.visible-sm,
tr.visible-sm,
th.visible-sm,
td.visible-sm,
.visible-md,
tr.visible-md,
th.visible-md,
td.visible-md,
.visible-lg,
tr.visible-lg,
th.visible-lg,
td.visible-lg {
  display: none;
}

/* Shown by default */
.hidden-xs,
.hidden-sm,
.hidden-md,
.hidden-lg {
  display: block;
}

table.hidden-xs,
table.hidden-sm,
table.hidden-md,
table.hidden-lg {
  display: table;
}

tr.hidden-xs,
tr.hidden-sm,
tr.hidden-md,
tr.hidden-lg {
  display: table-row;
}

th.hidden-xs,
td.hidden-xs,
th.hidden-sm,
cd.hidden-sm,
th.hidden-md,
td.hidden-md,
th.hidden-lg,
td.hidden-lg {
  display: table-cell;
}

/* ============================================
   MOBILE STYLES (0-767px)
   ============================================ */

@media (max-width: 767px) {
  /* === Visibility === */
  .visible-xs {
    display: block;
  }

  table.visible-xs {
    display: table;
  }

  tr.visible-xs {
    display: table-row;
  }

  th.visible-xs,
  td.visible-xs {
    display: table-cell;
  }

  .hidden-xs,
  tr.hidden-xs,
  th.hidden-xs,
  td.hidden-xs {
    display: none;
  }

  /* === Base Typography & Layout === */
  body {
    font-size: 14px;
    overflow-x: hidden;
    overflow-x: clip;
    background-image: url('../../images/bg_header_top_mobile.jpg');
    background-repeat: repeat-x;
    -webkit-text-size-adjust: 100%;
  }

  html, body {
    overflow-x: hidden;
    overflow-x: clip; /* clip, unlike hidden, does not turn body into a scroll container */
    max-width: 100vw;
  }

  * {
    box-sizing: border-box;
  }

  /* Prevent text overflow */
  body, p, div, span, h1, h2, h3, h4, h5, h6 {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* === Typography === */
  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.3rem;
  }

  h3 {
    font-size: 1.2rem;
  }

  h4 {
    font-size: 1.1rem;
  }

  h1, h2, h3, h4, h5, h6 {
    margin-bottom: 0.75em;
    line-height: 1.3;
  }

  p {
    margin-bottom: 1em;
  }

  /* === Grid System === */
  .container {
    padding: 0 10px;
    max-width: 100%;
  }

  .row {
    margin: 0;
  }

  .columns {
    padding: 0 10px;
  }

  /* All columns full width on mobile */
  .one.columns, .two.columns, .three.columns,
  .four.columns, .five.columns, .six.columns,
  .seven.columns, .eight.columns, .nine.columns,
  .ten.columns, .eleven.columns, .twelve.columns {
    width: 100%;
    margin-left: 0;
  }

  /* === Layout === */
  #wrapper {
    background: #FAF9F4;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    margin: 0 auto;
    padding: 0;
  }

  #content {
    float: none;
    width: 100%;
    max-width: 100%;
  }

  #mainContent {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 10px;
    background: white;
    box-sizing: border-box;
  }

  /* === Header & Navigation === */
  #logo {
    width: 100%;
    max-width: 100%;
    height: 58px;
    background: url('../../images/he/sprite/header_mobile.png');
    background-size: cover;
    background-position: center;
  }

  #logoPic {
    display: block;
    width: 100%;
    max-width: 100%;
    height: 58px;
  }

  .header {
    height: 58px;
    clear: both;
    width: 100%;
  }

  /* Add spacing below header - prevents content from sticking to menu */
  #bellowNav {
    margin-top: 24px;
  }

  /* Navigation improvements */
  .navbar ul li {
    display: block;
    width: 100%;
  }

  .navbar ul li a {
    padding: 12px 15px;
    font-size: 16px;
  }

  /* === Forms & Inputs === */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="search"],
  textarea,
  select {
    font-size: 16px;  /* Prevents zoom on iOS */
    padding: 10px;
    max-width: 100%;
  }

  #searchBox {
    height: 26px;
    border: 1px solid #999;
    padding: 10px 8px;
    font-size: 16px;
    color: #999;
    width: 100%;
    max-width: 250px;
    box-sizing: border-box;
  }

  #searchButton1 {
    float: left;
    height: 23px;
    margin: 4px 5px 0 10px;
  }

  /* === Buttons - Touch-friendly === */
  button, .btn, a.button, input[type="submit"],
  .SearchButton, .defPrimaryButton {
    min-height: 35px;
    min-width: 44px;
    padding: 10px 15px;
    touch-action: manipulation;
  }

  .SearchButton {
    font-size: 18px;
    padding: 10px 20px;
    margin-top: 15px;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
  }

  /* === Links === */
  a {
    padding: 5px 2px;
    display: inline-block;
  }

  /* === Ads & Banners === */
  .bannerHolder,
  .container_resp {
    margin-top: 20px;
    margin-bottom: 20px;
  }

  /* === Media Elements === */
  img, video, iframe, embed {
    max-width: 100%;
    height: auto;
  }

  img {
    max-width: 100%;
    height: auto;
  }

  /* Generator page: preserve small icon dimensions */
  .echo_firguns_list img,
  .share_icons img,
  .icon_share {
    height: inherit;  /* Preserve inline height styles */
    max-height: 30px;  /* Prevent expansion */
    width: auto;
  }

  /* Generator page: absolutely positioned icons */
  .echo_firguns_list img[style*="position: absolute"] {
    height: 15px;  /* Maintain small icon size */
    width: auto;
  }

  /* === Tables === */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* === Cards & Grids === */
  .cardLine li {
    width: 100%;
    margin: 10px 0;
  }

  /* === Sorting Controls === */
  .sorting-controls {
    justify-content: center;
    gap: 8px;
  }

  .sorting-label {
    font-size: 13px;
  }

  .sorting-buttons {
    gap: 5px;
  }

  .sort-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  /* === Performance Optimizations === */
  html {
    -webkit-overflow-scrolling: touch;
  }

  .btn, button, a.button {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
}

/* ============================================
   MOBILE - Extra Small Phones (0-375px)
   ============================================ */

@media (max-width: 375px) {
  body {
    font-size: 13px;
  }

  #searchBox {
    font-size: 14px;
    max-width: 200px;
  }

  #mainContent {
    padding: 8px;
  }

  .SearchButton {
    font-size: 16px;
    padding: 8px 16px;
  }
}

/* ============================================
   MOBILE - Larger Phones (481px-767px)
   ============================================ */

@media (min-width: 481px) and (max-width: 767px) {
  .container {
    padding: 0 20px;
  }

  #wrapper {
    max-width: 600px;
  }

  #mainContent {
    padding: 15px;
  }

  /* Two column layout for cards */
  .cardLine li {
    width: 48%;
    display: inline-block;
    vertical-align: top;
  }

  /* Three column layout for birthday cards */
  .birthday-cards-grid {
    gap: 10px;
  }

  .birthday-card-item {
    flex: 0 0 calc(30% - 5px);
    max-width: calc(30% - 5px);
  }

  .birthday-card-img {
    height: 150px;
  }

  /* Recommended categories - responsive */
  .recommended-category-item {
    flex: 1 1 calc(50% - 10px);
    min-width: 140px;
  }
}

/* ============================================
   MOBILE - Landscape Orientation
   ============================================ */

@media (max-width: 767px) and (orientation: landscape) {
  body {
    font-size: 13px;
  }

  .header {
    height: auto;
    min-height: 50px;
  }
}

/* ============================================
   TABLET STYLES (768-1279px)
   ============================================ */

@media (min-width: 768px) and (max-width: 1279px) {
  /* === Visibility === */
  .visible-sm {
    display: block;
  }

  table.visible-sm {
    display: table;
  }

  tr.visible-sm {
    display: table-row;
  }

  th.visible-sm,
  td.visible-sm {
    display: table-cell;
  }

  .visible-md {
    display: block;
  }

  table.visible-md {
    display: table;
  }

  tr.visible-md {
    display: table-row;
  }

  th.visible-md,
  td.visible-md {
    display: table-cell;
  }

  .hidden-sm,
  tr.hidden-sm,
  th.hidden-sm,
  td.hidden-sm,
  .hidden-md,
  tr.hidden-md,
  th.hidden-md,
  td.hidden-md {
    display: none;
  }

  /* === Combined visibility classes === */
  .visible-xs.visible-sm,
  .visible-xs.visible-md {
    display: block;
  }

  table.visible-xs.visible-sm,
  table.visible-xs.visible-md {
    display: table;
  }

  tr.visible-xs.visible-sm,
  tr.visible-xs.visible-md {
    display: table-row;
  }

  th.visible-xs.visible-sm,
  td.visible-xs.visible-sm,
  th.visible-xs.visible-md,
  td.visible-xs.visible-md {
    display: table-cell;
  }

  .visible-sm.visible-xs,
  .visible-md.visible-sm {
    display: block;
  }

  .visible-sm.visible-md {
    display: block;
  }

  .hidden-xs.hidden-sm,
  .hidden-xs.hidden-md,
  .hidden-sm.hidden-xs,
  .hidden-sm.hidden-md,
  .hidden-md.hidden-xs,
  .hidden-md.hidden-sm {
    display: none;
  }

  /* === Layout === */
  #bellowNav {
    margin-top: 20px;
  }
}

/* ============================================
   DESKTOP STYLES (1280px+)
   ============================================ */

@media (min-width: 1280px) {
  /* === Visibility === */
  .visible-lg {
    display: block;
  }

  table.visible-lg {
    display: table;
  }

  tr.visible-lg {
    display: table-row;
  }

  th.visible-lg,
  td.visible-lg {
    display: table-cell;
  }

  .hidden-lg,
  tr.hidden-lg,
  th.hidden-lg,
  td.hidden-lg {
    display: none;
  }

  /* === Combined visibility classes === */
  .visible-xs.visible-lg,
  .visible-sm.visible-lg,
  .visible-md.visible-lg {
    display: block;
  }

  table.visible-xs.visible-lg,
  table.visible-sm.visible-lg,
  table.visible-md.visible-lg {
    display: table;
  }

  tr.visible-xs.visible-lg,
  tr.visible-sm.visible-lg,
  tr.visible-md.visible-lg {
    display: table-row;
  }

  th.visible-xs.visible-lg,
  td.visible-xs.visible-lg,
  th.visible-sm.visible-lg,
  td.visible-sm.visible-lg,
  th.visible-md.visible-lg,
  td.visible-md.visible-lg {
    display: table-cell;
  }

  .visible-lg.visible-xs,
  .visible-lg.visible-sm,
  .visible-lg.visible-md {
    display: block;
  }

  .hidden-xs.hidden-lg,
  .hidden-sm.hidden-lg,
  .hidden-md.hidden-lg,
  .hidden-lg.hidden-xs,
  .hidden-lg.hidden-sm,
  .hidden-lg.hidden-md {
    display: none;
  }
}

/* ============================================
   SHARED COMPONENTS - All Breakpoints
   ============================================ */

/* Sorting Controls - Minimalist Design */
.sorting-controls {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin: 15px 0;
  padding: 0;
  background: transparent;
  border: none;
}

.sorting-label {
  font-weight: 500;
  color: #666;
  font-size: 14px;
  white-space: nowrap;
}

.sorting-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  background: transparent;
  padding: 0;
}

/* Modern sorting buttons - accessible and responsive */
.sorting-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 15px 0;
  padding: 0;
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  min-height: 44px;
  min-width: 44px;
  border: 2px solid #ddd;
  border-radius: 6px;
  background: #fff;
  color: #555;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
  white-space: nowrap;
  cursor: pointer;
  box-sizing: border-box;
}

.sort-btn:hover {
  border-color: #007bff;
  color: #007bff;
  background: #f8f9fa;
}

.sort-btn:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

.sort-btn:active {
  transform: scale(0.98);
}

.sort-btn.active {
  background: #007bff;
  border-color: #007bff;
  color: #fff;
  font-weight: 600;
  cursor: default;
}

.sort-btn.active:hover {
  background: #0056b3;
  border-color: #0056b3;
}

/* Mobile optimization */
@media (max-width: 767px) {
  .sort-btn {
    padding: 8px 14px;
    font-size: 13px;
    min-height: 44px;
  }
}
