/* Global responsive enhancements (mobile-first tweaks) */

/* === Base layout adjustments === */
html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  overflow-x: hidden;
}

.container {
  width: 100%;
  min-height: 100vh;
  display: flex;
}

.main-content,
.chat-container,
.edit-form-container,
.detail-view-container,
.content-panel,
.table-container {
  width: 100%;
  min-width: 0;
}

/* Base: make images and iframes scale */
img,
video,
canvas,
iframe {
  max-width: 100%;
  height: auto;
}

/* Forms */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="number"],
select,
textarea,
.form-control {
  width: 100%;
  box-sizing: border-box;
}

/* Buttons */
.btn,
button {
  max-width: 100%;
}

/* Layout containers for data filters */
.search-filter-container,
.table-toolbar,
.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.search-filter-container > *,
.table-toolbar > *,
.filters-row > * {
  flex: 1 1 220px;
  min-width: 0;
}

/* Tables */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
}

/* Sidebar responsive helpers */
.sidebar {
  position: relative;
}

.sidebar-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1400;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #ff6b35, #f7931e);
  color: #ffffff;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(255, 107, 53, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sidebar-toggle:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.8);
  outline-offset: 3px;
}

.sidebar-toggle:active {
  transform: scale(0.95);
  box-shadow: 0 6px 18px rgba(255, 107, 53, 0.4);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 1300;
}

.sidebar-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 1.4rem;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.sidebar-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.02);
}

.sidebar-close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 2px;
}

/* Breakpoint: large tablets / small laptops */
@media (max-width: 1280px) {
  .page-header {
    flex-wrap: wrap;
    gap: 14px;
  }

  .page-header > * {
    flex: 1 1 100%;
    text-align: center;
  }

  .search-filter-container > *,
  .table-toolbar > *,
  .filters-row > * {
    flex: 1 1 180px;
  }
}

/* Breakpoint: phones & compact tablets (<=767px) */
@media (max-width: 767px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .container {
    flex-direction: column;
    min-height: 100vh;
    height: auto;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 320px);
    max-width: 360px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1500;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px 18px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.35);
    left: 0 !important;
    right: auto !important;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .sidebar-backdrop {
    opacity: 0;
    pointer-events: none;
    display: block;
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: all;
  }

  .sidebar-close {
    display: inline-flex;
  }

  .main-content,
  .chat-container {
    margin-left: 0 !important;
    padding: 16px;
    padding-top: clamp(56px, 12vw, 72px);
    padding-bottom: 20px;
    height: auto;
  }

  .page-header,
  .chat-header {
    margin-top: 0;
    padding: 16px 20px;
    gap: 12px;
    flex-direction: column;
    text-align: center;
  }

  .page-header h1 {
    font-size: 1.35rem;
  }

  .btn,
  button {
    padding: 10px 14px;
    font-size: 0.95rem;
  }

  .detail-grid,
  .edit-form-grid,
  .row-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
}

/* Tablet portrait (e.g., iPad) keeps full sidebar experience */
@media (min-width: 641px) and (max-width: 1024px) {
  .sidebar-menu {
    display: flex !important;
    flex-direction: column;
  }

  .profile-section {
    display: flex !important;
    flex-direction: column;
    margin-top: auto;
    gap: 12px;
  }

  .profile-info {
    display: flex !important;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .logo-container {
    display: flex !important;
  }
}

/* Breakpoint: mobile (phones) */
@media (max-width: 767px) {
  .main-content,
  .chat-container {
    padding: 14px;
    padding-top: clamp(56px, 16vw, 78px);
    padding-bottom: 18px;
  }

  .search-filter-container,
  .table-toolbar,
  .filters-row {
    gap: 10px;
  }

  .search-filter-container > *,
  .table-toolbar > *,
  .filters-row > * {
    flex: 1 1 100%;
  }

  .search-filter-container .btn,
  .search-filter-container button,
  .search-filter-container select,
  .search-filter-container input {
    width: 100%;
  }

  .page-header {
    gap: 10px;
  }

  .page-header h1 {
    font-size: 1.25rem;
  }

  .form-group {
    margin-bottom: 12px;
  }

  .form-group label {
    font-size: 0.95rem;
  }

  .form-control {
    padding: 10px 12px;
    font-size: 1rem;
  }

  .detail-grid,
  .edit-form-grid,
  .row-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .table-container {
    border-radius: 12px;
  }

  table th,
  table td {
    padding: 10px 8px;
    white-space: nowrap;
  }

  .action-buttons {
    gap: 6px;
    flex-wrap: wrap;
  }

  .modal-content {
    width: 96%;
    max-width: 100%;
    border-radius: 14px;
    margin: 20px auto;
  }
}

/* Breakpoint: phones only */
@media (max-width: 640px) {
  .sidebar {
    width: min(88vw, 320px);
    padding: 18px 16px;
  }

  .sidebar-menu {
    display: flex !important;
    flex-direction: column;
    gap: 12px;
  }

  .profile-section {
    display: flex !important;
    flex-direction: column;
    margin-top: auto;
    margin-left: 0 !important;
    gap: 12px;
  }

  .profile-info {
    display: flex !important;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .logo-container {
    display: flex !important;
  }
}

/* Breakpoint: small phones */
@media (max-width: 480px) {
  .sidebar-toggle {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
  }

  .sidebar {
    left: 0 !important;
  }

  .btn,
  button {
    padding: 9px 10px;
    font-size: 0.9rem;
  }

  table th,
  table td {
    padding: 8px 6px;
  }

  .page-header h1 {
    font-size: 1.15rem;
  }
}

@media (min-width: 1025px) {
  .sidebar-backdrop {
    display: none !important;
  }
}
