/* ExamCrow enterprise mobile app-shell
   Purpose:
   - Premium Android-like bottom navigation
   - Material-style active pill indicator
   - Better install sheet polish
   - Safer mobile spacing / safe-area handling
   - Mobile admin/dashboard shell normalization
*/

:root {
  --shell-nav-bg: rgba(255, 255, 255, 0.97);
  --shell-nav-border: rgba(15, 23, 42, 0.08);
  --shell-nav-shadow:
    0 16px 40px rgba(15, 23, 42, 0.12),
    0 6px 18px rgba(15, 23, 42, 0.05),
    0 1px 0 rgba(255, 255, 255, 0.94) inset;

  --shell-active-surface: rgba(30, 64, 175, 0.10);
  --shell-active-surface-strong: rgba(30, 64, 175, 0.14);
  --shell-active-text: var(--primary);
  --shell-inactive-text: #64748b;

  --shell-install-bg: rgba(255, 255, 255, 0.98);
  --shell-install-border: rgba(15, 23, 42, 0.08);
  --shell-install-shadow:
    0 18px 42px rgba(15, 23, 42, 0.12),
    0 6px 18px rgba(15, 23, 42, 0.05);

  --shell-radius: 22px;
  --shell-pill-radius: 16px;
  --shell-safe-bottom: env(safe-area-inset-bottom, 0px);
  --shell-safe-top: env(safe-area-inset-top, 0px);

  --admin-mobile-panel-bg: rgba(255, 255, 255, 0.96);
  --admin-mobile-panel-border: rgba(15, 23, 42, 0.08);
  --admin-mobile-panel-shadow:
    0 16px 36px rgba(15, 23, 42, 0.08),
    0 6px 16px rgba(15, 23, 42, 0.05);
}

@media (max-width: 900px) {
  html {
    background: #f8fafc;
  }

  body.has-mobile-bottom-nav {
    padding-bottom: calc(112px + var(--shell-safe-bottom));
  }

  .navbar {
    background: rgba(255, 255, 255, 0.90);
    backdrop-filter: blur(20px) saturate(160%);
  }

  /* ------------------------------------------------------------------
     Mobile admin/dashboard shell
     ------------------------------------------------------------------ */

  .dashboard-wrap {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }

  .dashboard-wrap > .sidebar,
  .dashboard-wrap > .admin-sidebar {
    width: 100%;
    min-width: 0;
    margin: 0;
  }

  .sidebar,
  .admin-sidebar {
    position: relative;
    padding: 16px;
    border: 1px solid var(--admin-mobile-panel-border);
    border-radius: 24px;
    background: var(--admin-mobile-panel-bg);
    backdrop-filter: blur(18px) saturate(150%);
    box-shadow: var(--admin-mobile-panel-shadow);
    overflow: hidden;
  }

  .sidebar-head {
    margin-bottom: 12px;
  }

  .sidebar-label {
    margin: 0;
    color: #334155;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.2;
  }

  .sidebar-nav {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .sidebar-nav::-webkit-scrollbar {
    display: none;
  }

  .sidebar-item {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 18px;
    border-radius: 16px;
    border: 1px solid rgba(30, 41, 59, 0.08);
    background: rgba(255, 255, 255, 0.96);
    color: #475569;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    box-shadow:
      0 8px 18px rgba(15, 23, 42, 0.05),
      0 1px 0 rgba(255, 255, 255, 0.9) inset;
    transition:
      background 0.18s ease,
      color 0.18s ease,
      border-color 0.18s ease,
      transform 0.16s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-item:active {
    transform: scale(0.98);
  }

  .sidebar-item.active,
  .sidebar-item[aria-current="page"] {
    color: var(--primary);
    border-color: rgba(30, 64, 175, 0.14);
    background: rgba(30, 64, 175, 0.08);
  }

  .dashboard-wrap > .main {
    min-width: 0;
    padding-bottom: calc(150px + var(--shell-safe-bottom));
  }

  .page-header {
    margin-top: 0;
  }

  .page-header .page-title,
  .page-title {
    line-height: 1.08;
  }

  .page-header-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
  }

  .page-header-actions .btn {
    flex: 1 1 100%;
    justify-content: center;
  }

  .breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    word-break: break-word;
  }

  /* Admin content page specific mobile stabilization */
  .admin-content-view .grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .admin-content-view .grid.two {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .admin-content-view .mini-card {
    min-width: 0;
  }

  .admin-content-view .card,
  .admin-content-view .card-body,
  .admin-content-view .form-group,
  .admin-content-view .input,
  .admin-content-view textarea {
    min-width: 0;
  }

  /* ------------------------------------------------------------------
     Mobile bottom navigation
     ------------------------------------------------------------------ */

  .mobile-bottom-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + var(--shell-safe-bottom));
    z-index: 120;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--shell-nav-border);
    border-radius: var(--shell-radius);
    background: var(--shell-nav-bg);
    backdrop-filter: blur(22px) saturate(160%);
    box-shadow: var(--shell-nav-shadow);
  }

  .mobile-bottom-link {
    position: relative;
    min-height: 62px;
    border-radius: var(--shell-pill-radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    color: var(--shell-inactive-text);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    text-decoration: none;
    transition:
      background 0.18s ease,
      color 0.18s ease,
      transform 0.16s ease,
      box-shadow 0.18s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .mobile-bottom-link:active {
    transform: scale(0.97);
  }

  .mobile-bottom-link.active,
  .mobile-bottom-link[aria-current="page"] {
    color: var(--shell-active-text);
    background: var(--shell-active-surface);
  }

  .mobile-bottom-link.active::before,
  .mobile-bottom-link[aria-current="page"]::before {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    top: 8px;
    height: 34px;
    border-radius: 999px;
    background: var(--shell-active-surface-strong);
    z-index: 0;
  }

  .mobile-bottom-icon,
  .mobile-bottom-label {
    position: relative;
    z-index: 1;
  }

  .mobile-bottom-icon {
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    color: currentColor;
    line-height: 1;
  }

  .mobile-bottom-icon svg {
    width: 22px;
    height: 22px;
    display: block;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mobile-bottom-link.active .mobile-bottom-icon svg,
  .mobile-bottom-link[aria-current="page"] .mobile-bottom-icon svg {
    stroke-width: 2.2;
  }

  .mobile-bottom-label {
    white-space: nowrap;
    font-size: 0.70rem;
    line-height: 1;
  }

  .mobile-bottom-badge {
    position: absolute;
    top: 8px;
    right: 14px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #dc2626;
    color: #fff;
    font-size: 0.62rem;
    font-weight: 800;
    line-height: 1;
    z-index: 2;
    box-shadow: 0 6px 14px rgba(220, 38, 38, 0.22);
  }

  /* ------------------------------------------------------------------
     Install bar
     ------------------------------------------------------------------ */

  .pwa-install-bar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(96px + var(--shell-safe-bottom));
    z-index: 121;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-radius: 20px;
    border: 1px solid var(--shell-install-border);
    background: var(--shell-install-bg);
    backdrop-filter: blur(22px) saturate(160%);
    box-shadow: var(--shell-install-shadow);
  }

  .pwa-install-copy {
    color: var(--text);
    font-size: 0.94rem;
    font-weight: 700;
    line-height: 1.5;
  }

  .pwa-install-sub {
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.5;
    margin-top: -4px;
  }

  .pwa-install-actions {
    display: flex;
    gap: 10px;
  }

  .pwa-install-actions .btn {
    flex: 1 1 0;
  }

  .footer {
    padding-bottom: calc(128px + var(--shell-safe-bottom));
  }
}

@media (max-width: 640px) {
  body.has-mobile-bottom-nav {
    padding-bottom: calc(116px + var(--shell-safe-bottom));
  }

  .mobile-bottom-nav {
    left: 10px;
    right: 10px;
    bottom: calc(10px + var(--shell-safe-bottom));
    padding: 7px;
    gap: 4px;
    border-radius: 20px;
  }

  .mobile-bottom-link {
    min-height: 60px;
    font-size: 0.68rem;
  }

  .mobile-bottom-link.active::before,
  .mobile-bottom-link[aria-current="page"]::before {
    left: 8px;
    right: 8px;
    top: 8px;
    height: 32px;
  }

  .pwa-install-bar {
    left: 10px;
    right: 10px;
  }

  .admin-content-view .grid.four {
    grid-template-columns: 1fr;
  }

  .admin-content-view .page-header-actions .btn {
    width: 100%;
  }

  .dashboard-wrap > .main {
    padding-bottom: calc(160px + var(--shell-safe-bottom));
  }
}

@media (min-width: 901px) {
  .mobile-bottom-nav,
  .pwa-install-bar {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-bottom-link,
  .mobile-bottom-link::before,
  .sidebar-item {
    transition: none !important;
  }
}
