/* ===== Global Responsive Styles ===== */
/* Scope: all pages under /opt/nginx/www */

/* Fix header-actions alignment on all screen sizes */
.header .header-actions,
body .header .header-actions {
  margin-left: auto;
}

@media (max-width: 768px) {
  /* Prevent horizontal scroll */
  html, body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

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

  /* Images & media */
  img, video, iframe {
    max-width: 100%;
    height: auto;
  }

  /* ===== Headers ===== */
  body .header,
  .header {
    padding: 0 0.75rem;
    gap: 0.5rem;
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
  }
  body .header-logo,
  .header-logo {
    font-size: 1rem;
    min-width: auto;
    gap: 0.35rem;
    flex-shrink: 0;
  }
  body .header-logo svg,
  .header-logo svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
  }
  body .header-search,
  .header-search {
    display: none;
  }
  body .header-actions,
  .header-actions {
    gap: 0.35rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-left: auto !important;
  }

  /* ===== Buttons ===== */
  body .btn-primary,
  body .btn-outline,
  body .btn,
  body .btn-icon,
  .btn-primary,
  .btn-outline,
  .btn,
  .btn-icon {
    padding: 0 0.75rem;
    height: 34px;
    font-size: 0.8rem;
  }
  body .btn-icon,
  .btn-icon {
    width: 34px;
    padding: 0;
  }
  body .menu-toggle,
  .menu-toggle {
    width: 34px;
    height: 34px;
    font-size: 1.2rem;
  }

  /* ===== Layouts with sidebar ===== */
  body .layout,
  .layout {
    flex-direction: column;
  }
  body .layout .sidebar,
  .layout .sidebar {
    position: static;
    transform: none;
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    height: auto;
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }
  body .layout .sidebar.open,
  body .layout .sidebar.active,
  .layout .sidebar.open,
  .layout .sidebar.active {
    transform: none;
  }
  body .layout .sidebar.collapsed,
  .layout .sidebar.collapsed {
    transform: none;
    width: 100%;
    padding: 0.5rem 0.75rem;
  }
  body .layout .sidebar .sidebar-section,
  .layout .sidebar .sidebar-section {
    display: none;
  }
  body .layout .sidebar .sidebar-item,
  .layout .sidebar .sidebar-item {
    margin: 0;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
  body .layout .sidebar > div:not(.sidebar-item),
  .layout .sidebar > div:not(.sidebar-item) {
    display: none;
  }
  body .main,
  .main {
    padding: 1rem;
    max-width: 100vw;
  }

  /* ===== Grids ===== */
  body .file-grid,
  .file-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.75rem;
  }
  body .file-grid > *,
  .file-grid > *,
  body [class*="-grid"] > *,
  [class*="-grid"] > * {
    min-width: 0;
  }
  body .services-grid,
  .services-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 1rem;
  }
  body .cards-grid,
  .cards-grid {
    grid-template-columns: 1fr;
  }

  /* ===== Tables ===== */
  body .data-table,
  .data-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  body .data-table th,
  body .data-table td,
  .data-table th,
  .data-table td {
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
  }

  /* ===== Chat ===== */
  body .chat-layout,
  .chat-layout {
    flex-direction: column;
  }
  body .sidebar-users,
  .sidebar-users {
    width: 100%;
    height: 35%;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }
  body .chat-area,
  .chat-area {
    height: 65%;
  }

  /* ===== Lists / rows ===== */
  body .file-list-header,
  body .file-row,
  .file-list-header,
  .file-row {
    gap: 0.5rem;
  }
  body .file-row-size,
  body .file-row-date,
  .file-row-size,
  .file-row-date {
    display: none;
  }

  /* ===== Modals ===== */
  body .modal-overlay,
  .modal-overlay {
    padding: 0.5rem;
    align-items: flex-end;
  }
  body .modal-box,
  .modal-box {
    width: 100%;
    max-width: 100vw;
    margin: 0;
    border-radius: 12px 12px 0 0;
    max-height: 90vh;
  }

  /* ===== Page builder ===== */
  body .builder-layout,
  .builder-layout {
    flex-direction: column;
    height: auto;
  }
  body .canvas-wrap,
  .canvas-wrap {
    padding: 1rem;
  }
  body .builder-layout .sidebar,
  .builder-layout .sidebar {
    position: relative;
    transform: none;
    width: 100%;
    height: auto;
    top: auto;
    bottom: auto;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: none;
  }
  body .builder-layout .sidebar.open,
  .builder-layout .sidebar.open {
    display: flex;
  }

  /* ===== Tabs ===== */
  body .tabs,
  .tabs {
    flex-wrap: wrap;
    gap: 0.35rem;
  }
  body .tab-btn,
  .tab-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
  }

  /* ===== Toolbar / breadcrumb ===== */
  body .toolbar,
  .toolbar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  body .breadcrumb,
  .breadcrumb {
    flex-wrap: wrap;
    font-size: 0.8rem;
  }

  /* ===== Empty states ===== */
  body .empty-state,
  .empty-state {
    padding: 1.5rem 1rem;
  }

  /* ===== Extra grids that need mobile fix ===== */
  body .disks-grid,
  .disks-grid {
    grid-template-columns: 1fr;
  }
  body .assistant-grid,
  .assistant-grid {
    grid-template-columns: 1fr;
  }
  body .notes-grid,
  .notes-grid {
    grid-template-columns: 1fr;
  }
  body .effects,
  .effects {
    grid-template-columns: 1fr;
  }
  body .sequencer,
  .sequencer {
    width: 100%;
  }
  body .code-block,
  .code-block,
  body .block-code,
  .block-code,
  body .editor-preview pre,
  .editor-preview pre {
    max-width: 100%;
    width: 100%;
  }
  body .page-wrap,
  .page-wrap {
    padding: 1rem;
  }
  body .block-hero h1,
  .block-hero h1 {
    font-size: 1.75rem;
  }
  body .block-hero p,
  .block-hero p {
    font-size: 1rem;
  }
  body .block-gallery,
  .block-gallery {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important;
  }
  body .block-cards,
  .block-cards {
    grid-template-columns: 1fr !important;
  }
  body .block-text p,
  .block-text p {
    font-size: 1rem;
  }

  /* ===== Login page (index.html) ===== */
  body .container,
  .container {
    padding: 1.5rem;
    max-width: calc(100% - 2rem);
  }
  body .feature-list,
  .feature-list {
    grid-template-columns: 1fr;
  }
}

/* ===== Very small screens (480px and below) ===== */
@media (max-width: 480px) {
  body .file-grid,
  .file-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  body .services-grid,
  .services-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  body .cards-grid,
  .cards-grid {
    grid-template-columns: 1fr;
  }
  body .dashboard,
  .dashboard {
    padding: 0 0.75rem;
  }
  /* Compress header buttons that are not primary/menu */
  body .header-actions .btn:not(.primary):not(.danger):not(.new-note-btn),
  .header-actions .btn:not(.primary):not(.danger):not(.new-note-btn) {
    padding: 0 0.5rem;
    font-size: 0.75rem;
  }
}
