/* ============================================================================
   ROAA DIGITAL JOURNAL — True Responsive Design & Mobile UX (320px .. 1920px+)
   Zero unintended horizontal overflow; 44px touch targets; mobile nav drawer;
   mobile table cards toggle; Safe Area insets; A4 print-safe viewport fit.
   ============================================================================ */

html, body {
  max-width: 100%;
  overflow-x: clip;
}

* {
  box-sizing: border-box;
}

/* Mobile Hamburger & Slide-out RTL Drawer */
button.mobile-menu-btn,
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
}

.mobile-nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9050;
  background: rgba(5, 18, 12, 0.52);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.mobile-nav-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-nav-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 9100;
  width: min(300px, 84vw);
  background: var(--theme-surface, #FFFFFF);
  color: var(--theme-text, #13211A);
  border-left: 1px solid var(--theme-border, #D9DFD8);
  box-shadow: -12px 0 36px rgba(0, 0, 0, 0.22);
  transform: translateX(105%);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  direction: rtl;
}

.mobile-nav-drawer.open {
  transform: translateX(0);
}

.mobile-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 16px;
  background: var(--theme-header-bg);
  color: #FFFFFF;
}

.mobile-drawer-title {
  font-weight: 800;
  font-size: 14px;
}

.mobile-drawer-close {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  font-size: 18px;
  cursor: pointer;
}

.mobile-drawer-links {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mobile-drawer-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--theme-text, #13211A);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.mobile-drawer-link:hover {
  background: var(--theme-primary-tint, #F2FAF4);
}

.mobile-drawer-link.active {
  background: var(--theme-primary, #053E26);
  color: #FFFFFF;
}

.mobile-drawer-footer {
  padding: 12px;
  border-top: 1px solid var(--theme-border, #D9DFD8);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Responsive Table Wrapper */
.table-wrap,
.table-scroll,
.responsive-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.view-mode-toggle {
  display: none;
  align-items: center;
  gap: 6px;
}

/* Breakpoint: Tablet & Narrow Desktop (<= 1180px) */
@media (max-width: 1180px) {
  .topbar {
    padding: 8px 12px !important;
    gap: 8px !important;
  }
  .nav-tabs,
  .topbar-nav {
    display: none !important;
  }
  button.mobile-menu-btn,
  .mobile-menu-btn {
    display: inline-flex;
  }
  .theme-studio-layout {
    grid-template-columns: 1fr !important;
  }
  .theme-live-preview-box {
    position: static !important;
  }
  .workspace,
  .editor-grid,
  .editor-layout {
    grid-template-columns: 1fr !important;
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
  }
  .workspace:not(.active) {
    display: none !important;
  }
  .form-panel,
  .preview-panel {
    width: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
  }
}

/* Breakpoint: Tablet Portrait & Mobile (<= 768px) */
@media (max-width: 768px) {
  .page-view,
  .workspace.active,
  .main-wrap,
  .container {
    padding-left: 10px !important;
    padding-right: 10px !important;
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .topbar {
    flex-wrap: nowrap !important;
    min-height: 58px;
  }

  .brand-text span,
  .brand-sub,
  .topbar-role-extra,
  .sync-pill-time {
    display: none !important;
  }

  .brand-text h1,
  .brand-title {
    font-size: 13.5px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
  }

  .sync-pill {
    padding: 5px 8px;
    max-width: 112px;
    font-size: 11px;
  }

  /* Touch-friendly controls (44px min height) */
  .btn,
  .btn-action,
  .form-control,
  .form-select,
  input[type="text"],
  input[type="password"],
  input[type="date"],
  input[type="number"],
  input[type="search"],
  select {
    min-height: 44px;
  }

  .btn-sm,
  .btn-mini {
    min-height: 38px;
    padding: 6px 10px;
  }

  .kpi-grid,
  .dash-grid,
  .stats-grid,
  .dashboard-grid,
  .form-row,
  .form-grid,
  .grid-2,
  .grid-3,
  .grid-4,
  .two-col,
  .three-col {
    grid-template-columns: 1fr !important;
  }

  .toolbar,
  .toolbar-row,
  .card-header,
  .section-bar,
  .action-bar,
  .filter-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .toolbar > *,
  .toolbar-row > *,
  .filter-bar > * {
    max-width: 100% !important;
  }

  .search-input {
    width: 100% !important;
    min-width: 0 !important;
  }

  .view-mode-toggle {
    display: inline-flex;
  }

  /* Mobile Card View Mode for Queue & Archive Tables */
  .mobile-cards-mode .data-table,
  .mobile-cards-mode .data-table tbody,
  .mobile-cards-mode .data-table tr,
  .mobile-cards-mode .data-table td {
    display: block;
    width: 100%;
  }

  .mobile-cards-mode .data-table thead {
    display: none;
  }

  .mobile-cards-mode .data-table tr {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--theme-border, #D9DFD8);
    background: var(--theme-surface, #FFFFFF);
    box-shadow: var(--theme-shadow-sm);
  }

  .mobile-cards-mode .data-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 0 !important;
    border: none !important;
    border-bottom: 1px dashed var(--theme-divider, #E6EAE5) !important;
    text-align: left;
    word-break: break-word;
  }

  .mobile-cards-mode .data-table td:last-child {
    border-bottom: none !important;
    padding-top: 10px !important;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .mobile-cards-mode .data-table td::before {
    content: attr(data-label);
    font-weight: 800;
    font-size: 11.5px;
    color: var(--theme-text-muted, #6C7D74);
    text-align: right;
    flex-shrink: 0;
  }

  /* Login screen mobile polish */
  .login-card {
    width: calc(100vw - 24px) !important;
    padding: 22px 18px !important;
    margin: 12px auto !important;
  }

  .theme-presets-grid {
    grid-template-columns: 1fr !important;
  }

  .theme-color-grid {
    grid-template-columns: 1fr !important;
  }

  .a4-preview-toolbar {
    justify-content: center;
  }
}

/* Breakpoint: Small Mobile (<= 520px) */
@media (max-width: 520px) {
  .topbar {
    padding: 6px 10px !important;
    gap: 6px !important;
  }
  .brand-badge {
    display: none !important;
  }
  .brand-text h1,
  .brand-title {
    max-width: 138px;
    font-size: 13px !important;
  }
  .sync-pill-label {
    display: none;
  }
  .sync-pill {
    padding: 6px 8px;
  }
  .topbar-user-name,
  #roleBadge,
  #topbarRoleBadge,
  #logoutBtn {
    display: none !important;
  }
}
