/*
 * mobile-optimized.css
 * Phone styling for non-cards pages (campaign log, investigators, rules,
 * friends, expansions, etc). Matches the design language used by the inline
 * phone shell on the /cards page.
 *
 * Design tokens:
 *   bg          #0e151c
 *   panel       #131c25
 *   sidebar     #11181f
 *   text        #ffffff
 *   muted       #b9c7d4
 *   border      rgba(255,255,255,0.12)
 *   accent      #6ab7ff
 */

/* ===========================================================================
   GLOBAL TOUCH POLISH (always applied, not just on phones)
   =========================================================================== */
* {
  -webkit-tap-highlight-color: rgba(106, 183, 255, 0.25);
}

button,
.btn,
a.btn,
input[type="submit"],
input[type="button"] {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* ===========================================================================
   PHONE LAYOUT (max-width: 932px)
   =========================================================================== */
@media (max-width: 932px) {
  html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overscroll-behavior-y: none;
  }

  body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: #0e151c;
    color: #fff;
    background-attachment: scroll;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  }

  *, *::before, *::after { box-sizing: border-box; }

  img, svg, video, canvas {
    max-width: 100%;
    height: auto;
  }

  /* ---------- Hide desktop nav variants ---------- */
  .ah-nav,
  nav.ah-nav,
  nav.topnav {
    display: none !important;
  }

  /* ---------- Header ---------- */
  .mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 56px;
    padding: 8px 12px;
    background: #0e151c;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .mobile-header .brand,
  .mobile-header a.brand {
    flex: 1;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
  }

  .mobile-header .brand img {
    height: 32px;
    width: 32px;
    flex-shrink: 0;
    display: block;
  }

  .mobile-header .brand span {
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-header .menu-btn,
  .mobile-header .filters-btn,
  .mobile-header > button {
    min-width: 44px;
    min-height: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    padding: 0 12px;
  }

  .mobile-header .filters-btn {
    background: rgba(106, 183, 255, 0.18);
    border-color: rgba(106, 183, 255, 0.55);
    padding: 0 14px;
    font-size: 14px;
  }

  /* ---------- Sidebar ---------- */
  .sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    max-width: 86vw;
    height: 100vh;
    height: 100dvh;
    z-index: 12000;
    background: #11181f;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
    transition: left 0.22s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.open { left: 0; }

  .sidebar-content {
    padding: 16px;
    height: auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .sidebar-logo {
    display: flex;
    justify-content: center;
    padding: 12px 0;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .sidebar-logo img {
    height: 48px;
    width: auto;
  }

  .sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

  .sidebar-nav .nav-item,
  .sidebar-nav a.nav-item {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 14px;
    margin: 0;
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.92);
    text-decoration: none;
    font-size: 15px;
    line-height: 1.2;
  }

  .sidebar-nav .nav-item.active,
  .sidebar-nav a.nav-item.active,
  .sidebar-nav .nav-item:active {
    background: rgba(255, 255, 255, 0.08);
  }

  .sidebar-user,
  .sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }

  .sidebar-footer-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .sidebar-footer-links a {
    font-size: 13px;
    padding: 8px 0;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
  }

  .user-action {
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 15px;
    width: 100%;
    margin-bottom: 6px;
  }

  /* Sidebar backdrop */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 11000;
    background: rgba(0, 0, 0, 0.55);
  }

  .sidebar.open ~ .sidebar-backdrop,
  .sidebar-backdrop.active {
    display: block;
  }

  /* ---------- Main content area ---------- */
  .main-content {
    margin: 0 !important;
    padding: 68px 12px 24px !important;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    min-height: calc(100vh - 56px);
    min-height: calc(100dvh - 56px);
  }

  /* Generic containers that pages use */
  .container,
  .wrap,
  .content-panel,
  .panel,
  .glass-panel,
  .campaign-log-container,
  .investigators-container,
  .rules-container,
  .expansions-container,
  .friends-container,
  .friends-page,
  .campaigns-container,
  .settings-container,
  .profile-container,
  .contact-container,
  .custom-content-container,
  .credit-section,
  .admin-container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 14px;
    box-sizing: border-box;
  }

  /* Panels get a subtle elevation */
  .panel,
  .glass-panel,
  .content-panel,
  .log-entry,
  .log-section {
    background: #131c25;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    margin-bottom: 12px;
  }

  /* ---------- Typography ---------- */
  h1, .page-title {
    color: #fff;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 14px;
    word-wrap: break-word;
  }

  h2, .section-title {
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.25;
    margin: 0 0 12px;
    word-wrap: break-word;
  }

  h3 {
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.25;
    margin: 0 0 10px;
    word-wrap: break-word;
  }

  p, li, label {
    color: #fff;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
  }

  /* ---------- Buttons ---------- */
  button:not(.mobile-header button):not(.chip):not(.btn-icon),
  .btn,
  a.btn,
  input[type="button"],
  input[type="submit"] {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 18px;
    border-radius: 10px;
    background: rgba(106, 183, 255, 0.18);
    border: 1px solid rgba(106, 183, 255, 0.55);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-sizing: border-box;
  }

  button:active,
  .btn:active,
  a.btn:active {
    transform: scale(0.98);
  }

  .btn-icon {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 50%;
  }

  .chip {
    min-height: 36px;
    min-width: 36px;
    padding: 8px 12px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: #131c25;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .chip.is-active,
  .chip.active {
    background: rgba(106, 183, 255, 0.18);
    border-color: rgba(106, 183, 255, 0.55);
  }

  /* ---------- Forms ---------- */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  textarea,
  select {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 10px;
    background: #131c25;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 16px; /* prevent iOS zoom */
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
    outline: none;
  }

  input:focus,
  textarea:focus,
  select:focus {
    border-color: rgba(106, 183, 255, 0.55);
    box-shadow: 0 0 0 3px rgba(106, 183, 255, 0.18);
  }

  textarea {
    min-height: 120px;
    resize: vertical;
  }

  label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
  }

  select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    padding-right: 40px;
  }

  /* ---------- Generic grids: stack vertically on phone ---------- */
  .grid,
  .cards-grid,
  .campaigns-grid,
  .investigator-grid,
  .expansion-grid,
  .deck-grid,
  .decks-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    box-sizing: border-box;
  }

  .card,
  .campaign-card,
  .investigator-card,
  .expansion-card,
  .deck-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border-radius: 12px;
    overflow: hidden;
    background: #131c25;
    border: 1px solid rgba(255, 255, 255, 0.12);
  }

  /* ---------- Tables ---------- */
  table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  th { color: #fff; font-weight: 700; }

  /* ---------- Modals ---------- */
  .modal,
  [class*="-modal-panel"],
  .investigator-popup,
  .investigator-detail {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    z-index: 20000 !important;
    background: rgba(8, 12, 16, 0.95) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-content {
    padding: 16px;
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
  }

  .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .modal-close,
  .close,
  button.close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* ---------- Background lock when sidebar / modal is open ---------- */
  body.sidebar-open,
  body.modal-open,
  body.mobile-lock {
    overflow: hidden !important;
  }

  /* ---------- Hide desktop filters bars (handled by mobile filters panel) ---------- */
  .filtersBar:not(#mobileFiltersPanel .filtersBar),
  #classBar:not(#mobileFiltersPanel #classBar),
  .classBar:not(#mobileFiltersPanel .classBar) {
    display: none !important;
  }

  /* ---------- Mobile filters panel (still used on cards-related sub-pages) ---------- */
  #mobileFiltersPanel {
    position: fixed;
    top: 56px;
    left: 100%;
    right: auto;
    bottom: 0;
    width: 100vw;
    z-index: 11000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    box-sizing: border-box;
    background: #11181f;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    display: none;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
  }

  #mobileFiltersPanel.open,
  body.filters-open #mobileFiltersPanel {
    display: block;
    left: 0;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
  }

  .filters-backdrop {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 10999;
  }

  .filters-backdrop.active,
  body.filters-open .filters-backdrop {
    display: block;
  }

  /* ---------- Safe area insets ---------- */
  @supports (padding: env(safe-area-inset-top)) {
    .mobile-header {
      padding-top: max(8px, env(safe-area-inset-top));
      padding-left: max(12px, env(safe-area-inset-left));
      padding-right: max(12px, env(safe-area-inset-right));
      min-height: calc(56px + env(safe-area-inset-top));
    }

    .main-content {
      padding-top: calc(56px + env(safe-area-inset-top)) !important;
      padding-bottom: max(24px, env(safe-area-inset-bottom)) !important;
    }

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

    #mobileFiltersPanel {
      top: calc(56px + env(safe-area-inset-top));
      padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
  }

  /* ---------- Word wrap for long strings ---------- */
  h1, h2, h3, h4, h5, h6,
  p, span, div, a, li, td, th {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
}

/* ===========================================================================
   DESKTOP (min-width: 933px)
   Hide every phone-only chrome element so the desktop layout never sees it.
   =========================================================================== */
@media (min-width: 933px) {
  .mobile-header,
  .sidebar-backdrop,
  #mobileFiltersPanel,
  .filters-backdrop {
    display: none !important;
  }
}

/* ===========================================================================
   ACCESSIBILITY
   =========================================================================== */
*:focus-visible {
  outline: 3px solid rgba(106, 183, 255, 0.5);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
