/* =========================================================
   RolePilot - Mobile Responsive Fixes
   Centralized mobile CSS for all pages.
   Loaded AFTER design-system.css on every page.
   ========================================================= */

/* --- Global Overflow Guard -------------------------------- */
/* Prevent decorative elements from causing horizontal scroll */
html,
body {
  overflow-x: hidden;
  overflow-x: clip;
}

/* --- Hide ambient glows on mobile (they overflow viewport) */
@media (max-width: 768px) {
  .rp-glow {
    display: none !important;
  }
}

/* --- Hero illustration safety: always absolute, hidden on mobile -- */
.hero__bg-illustration {
  position: absolute !important;
}

@media (max-width: 768px) {
  .hero__bg-illustration {
    display: none !important;
  }
}

/* --- Sidebar Overlay Backdrop --------------------------- */
/* When sidebar is open on mobile, dim the background */
@media (max-width: 1024px) {
  .sidebar.open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }
}

/* --- Small Mobile (<=640px) ----------------------------- */
@media (max-width: 640px) {

  /* --- Stats Grid (Dashboard) --- */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
  }

  .stat-card {
    padding: var(--space-4);
  }

  .stat-card__value {
    font-size: var(--text-2xl);
  }

  /* --- Section Headers --- */
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .section-header__title {
    font-size: var(--text-lg);
  }

  /* --- Page Headers --- */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .page-header__title {
    font-size: var(--text-2xl);
  }

  /* --- Application Cards (Applications) --- */
  .app-card {
    padding: var(--space-3) var(--space-4);
  }

  .app-card__actions {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .app-card__meta {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
  }

  /* --- Filters (Applications) --- */
  .filters {
    overflow-x: auto;
    flex-wrap: nowrap;

    scrollbar-width: none;
    padding-bottom: var(--space-2);
  }

  .filters::-webkit-scrollbar {
    display: none;
  }

  .filter-btn {
    flex-shrink: 0;
    min-height: 44px;
  }

  /* --- Studio tabs horizontal scroll --- */
  .studio-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;

    scrollbar-width: none;
    padding-bottom: var(--space-2);
  }

  .studio-tabs::-webkit-scrollbar {
    display: none;
  }

  .studio-tab {
    flex-shrink: 0;
    min-height: 40px;
    white-space: nowrap;
  }

  /* --- Form Actions (Studio, Dashboard) --- */
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions .rp-btn {
    justify-content: center;
  }

  /* --- Touch Targets (minimum 44px) --- */
  .rp-btn,
  .rp-nav-item,
  .filter-btn,
  .studio-tab,
  .action-btn,
  .chip,
  .status-select {
    min-height: 44px;
  }

  /* --- Pricing plan cards extra padding --- */
  .plan-card {
    padding: var(--space-6);
  }

  /* --- Modal fullscreen on mobile --- */
  .rp-modal,
  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    border-radius: var(--radius-lg);
    margin: var(--space-2);
  }

  /* --- Footer (landing page) --- */
  .footer__inner {
    flex-direction: column;
    text-align: center;
    gap: var(--space-3);
  }

  .footer__links {
    justify-content: center;
  }

  /* --- Feature chips wrap fix (Studio) --- */
  .feature-chips {
    gap: var(--space-1);
  }

  .feature-chip {
    font-size: 10px;
    padding: var(--space-1) var(--space-2);
  }

  /* --- Kanban board -> horizontal scroll --- */
  .kanban-board {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;

    gap: var(--space-3);
    padding-bottom: var(--space-2);
  }

  .kanban-board::-webkit-scrollbar {
    display: none;
  }

  .kanban-column {
    min-width: 260px;
    scroll-snap-align: start;
    flex-shrink: 0;
  }

  /* --- Notification banners tighter --- */
  .notify-banner {
    font-size: var(--text-xs);
    padding: var(--space-2) var(--space-3);
  }

  /* --- Output area (Studio) --- */
  .output-area {
    font-size: 13px;
    padding: var(--space-3);
  }

  /* --- CTA card stack (Landing page) --- */
  .cta__card {
    flex-direction: column;
    text-align: center;
    padding: var(--space-6);
  }

  .cta__actions {
    width: 100%;
    justify-content: center;
  }

  /* --- Pricing page nav squeeze --- */
  .top-nav__actions .rp-btn--sm span {
    display: none;
  }

  /* --- FAQ items --- */
  .faq-section {
    margin-top: var(--space-12);
  }

  /* --- HERO (Landing Page) ------------------------------ */
  /* Fix: title broke mid-word "Bui" on narrow screens */
  .hero__title {
    font-size: clamp(1.75rem, 8vw, 2.5rem);
    overflow-wrap: break-word;
    word-break: normal;
    -webkit-hyphens: none;
    hyphens: none;
  }

  .hero {
    min-height: auto;
    padding-top: 100px;
    padding-bottom: var(--space-8);
  }

  .hero__container {
    padding: 0 var(--space-4);
    gap: var(--space-6);
  }

  .hero__subtitle {
    font-size: var(--text-base);
    line-height: 1.6;
  }

  .hero__actions {
    flex-direction: column;
    align-items: center;
  }

  .hero__actions .rp-btn {
    width: 100%;
    justify-content: center;
  }

  .hero__chips {
    justify-content: center;
    margin-top: var(--space-4);
  }

  .hero__card {
    max-width: 100%;
    overflow: hidden;
  }

  /* --- APPLICATIONS TRACKER ----------------------------- */
  /* Fix: filters wrapping into 2 rows -> horizontal scroll */
  .filters {
    display: flex;
    flex-wrap: nowrap !important;
    overflow-x: auto;

    scrollbar-width: none;
    gap: var(--space-2);
    padding-bottom: var(--space-2);
  }

  .filters::-webkit-scrollbar {
    display: none;
  }

  .filter-btn {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: var(--text-xs);
    min-height: 44px;
  }

  /* Fix: app cards stacking for mobile readability */
  .app-card {
    grid-template-columns: 1fr;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
  }

  .app-card__actions {
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: flex-start;
  }

  .app-card__meta {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
  }

  /* Fix: status dropdown dark theme on mobile */
  .status-select {
    -moz-appearance: none;
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--color-surface, #1c1f26);
    color: var(--color-text-primary, #f3f4f6);
    border: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
    border-radius: var(--radius-md, 8px);
    padding: var(--space-2) var(--space-4) var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    min-height: 44px;
    min-width: 120px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 32px;
  }

  .status-select option {
    background-color: #1c1f26;
    color: #f3f4f6;
  }

  /* Fix: delete button alignment */
  .action-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Fix: page header (Applications) */
  .page-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-4);
  }

  .page-header__title {
    font-size: var(--text-2xl);
  }

  .page-header__actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .page-header__actions .rp-btn {
    width: 100%;
    justify-content: center;
  }

  /* Fix: main content area padding */
  .main__content {
    padding: var(--space-6) var(--space-4);
  }

  .main {
    margin-left: 0;
  }

  /* --- AGENT CHAT PAGE ---------------------------------- */
  /* Fix: agent header cramped on mobile */
  .agent-header {
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }

  .agent-header .agent-name {
    font-size: var(--text-lg);
  }

  .agent-header .agent-role {
    font-size: var(--text-xs);
  }

  /* Fix: chat messages need breathing room */
  .chat-container,
  .messages-container {
    padding: var(--space-3);
  }

  .message-bubble {
    max-width: 90%;
    font-size: var(--text-sm);
  }

  /* Fix: input area full width and proper spacing */
  .input-area,
  .chat-input-container {
    padding: var(--space-3) var(--space-4);
  }

  .chat-input,
  .input-area input,
  .input-area textarea {
    font-size: 16px;
    /* Prevents iOS zoom on focus */
  }

  /* Fix: quick action chips horizontal scroll on agent page */
  .quick-actions,
  .suggestion-chips {
    display: flex;
    overflow-x: auto;
    flex-wrap: nowrap;

    scrollbar-width: none;
    gap: var(--space-2);
    padding-bottom: var(--space-2);
  }

  .quick-actions::-webkit-scrollbar,
  .suggestion-chips::-webkit-scrollbar {
    display: none;
  }

  .quick-action,
  .suggestion-chip {
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* Fix: language switcher spacing */
  .lang-switch {
    gap: var(--space-1);
  }

  .lang-switch button {
    min-width: 36px;
    min-height: 36px;
    font-size: var(--text-xs);
  }
}

/* --- Extra Small (<=480px) ------------------------------ */
@media (max-width: 480px) {

  /* Stats -> 1 col */
  .stats-grid {
    grid-template-columns: 1fr;
  }

  /* Before/After -> tighter */
  .before-after__grid {
    gap: var(--space-3);
  }

  /* Logos cloud -> smaller gap */
  .logos__cloud {
    gap: var(--space-2) var(--space-3);
  }

  .logos__item {
    font-size: var(--text-xs);
    padding: var(--space-1) var(--space-3);
  }
}

/* --- Hover -> Touch Corrections -------------------------- */
/* Remove hover lift effects on touch devices */
@media (hover: none) {

  .rp-card:hover,
  .app-card:hover,
  .job-card:hover,
  .plan-card:hover {
    transform: none;
  }
}

/* --- Safe Area (iOS notch support) ---------------------- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {

  .input-area,
  .sidebar__footer {
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }

  .mobile-header {
    padding-top: env(safe-area-inset-top);
  }

  .rp-help-fab {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* --- Help Widget Mobile (<=640px) ----------------------- */
@media (max-width: 640px) {
  .rp-help-fab {
    bottom: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    opacity: 0.5;
    transition: opacity 0.2s ease;
    font-size: 14px;
  }

  .rp-help-fab:hover,
  .rp-help-fab:focus {
    opacity: 1;
  }

  .rp-help-popup {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 80vh;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    transform: translateY(100%);
  }

  .rp-help-popup--open {
    transform: translateY(0);
  }
}