/* Responsive shell — iPad, phone, desktop */
:root {
  --sidebar-w-mobile: min(88vw, 280px);
}

html.raya-touch .nav-item,
html.raya-touch .tb-btn,
html.raya-touch .btn,
html.raya-touch .btn-icon,
html.raya-touch .filter-select {
  min-height: 44px;
}

html.raya-touch .nav-item {
  padding-top: 10px;
  padding-bottom: 10px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 190;
  opacity: 0;
  transition: opacity 0.2s ease;
}

body.raya-sidebar-open .sidebar-backdrop {
  display: block;
  opacity: 1;
}

.sidebar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  flex-shrink: 0;
}

/* Tablet + phone */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: var(--sidebar-w-mobile);
  }

  .sidebar-menu-btn {
    display: inline-flex;
  }

  .sidebar {
    transform: translateX(100%);
    transition: transform 0.22s ease;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
  }

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

  .topbar {
    right: 0;
    left: 0;
    padding: 0 12px;
    gap: 8px;
  }

  .main {
    margin-right: 0;
    padding: 14px 12px;
  }

  .topbar-actions .tb-btn:not(.primary) span:not(:first-child) {
    display: none;
  }

  .topbar-actions .tb-btn.primary {
    padding: 8px 12px;
    font-size: 11px;
  }

  .topbar-actions .tb-btn:nth-child(n+4):not(.primary):not(#ai-btn) {
    display: none;
  }

  .page-header-top {
    flex-direction: column;
    align-items: stretch;
  }

  .page-actions {
    width: 100%;
  }

  .page-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
  }

  .jvl-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .jvl-toolbar .search-input-wrap,
  .jvl-toolbar .filter-select {
    width: 100%;
    min-width: 0;
  }

  .o-table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  .o-table {
    min-width: 720px;
  }

  .jvl-table {
    min-width: 960px;
  }

  .login-wrap {
    flex-direction: column;
    width: 100%;
    max-width: 420px;
  }

  .login-brand {
    width: 100%;
    padding: 28px 24px;
  }

  .login-form-side {
    padding: 32px 24px;
  }

  .modal {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    margin: 12px;
  }

  .modal.lg,
  .modal.xl {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
  }
}

/* Phone */
@media (max-width: 640px) {
  html {
    font-size: 12px;
  }

  .topbar-title {
    font-size: 13px;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-breadcrumb {
    display: none;
  }

  .topbar-actions .tb-btn.primary {
    display: none;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .user-name {
    display: none;
  }

  .card {
    border-radius: 8px;
  }
}

/* iPad landscape / small desktop comfort */
@media (min-width: 641px) and (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  .topbar {
    padding-top: max(0px, env(safe-area-inset-top));
  }

  .sidebar {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }

  .main {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
}
