/* ==========================================================================
   Samshodhana Mandiram — Native Android Material 3 Mobile UX Design System
   Applies native mobile app feeling, bottom navigation, top app bar,
   touch target ergonomics, bottom sheets, and responsive adaptability across all pages.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Root Variables & Touch Ergonomics
   -------------------------------------------------------------------------- */
:root {
  --android-status-bar-bg: #121218;
  --android-app-bar-bg: #1a1b26;
  --android-surface-bg: #13141f;
  --android-card-bg: #1f202e;
  --android-primary: #7f5af0;
  --android-primary-container: rgba(127, 90, 240, 0.18);
  --android-on-primary: #ffffff;
  --android-text-main: #fffffe;
  --android-text-muted: #94a1b2;
  --android-border: rgba(255, 255, 255, 0.08);
  --android-nav-height: 64px;
  --android-top-bar-height: 56px;
  --android-touch-min: 48px;
  --android-radius-lg: 24px;
  --android-radius-md: 16px;
  --android-radius-sm: 12px;
}

/* Base Body Adjustments for Mobile App Feel */
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Restrict container bounds and touch behavior overrides to mobile viewports */
@media (max-width: 768px) {
  body {
    overscroll-behavior-y: auto;
  }
  body, html {
    max-width: 100vw;
    overflow-x: clip;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }
}

/* Touch Targets Minimum 48px Size for Touch Screens */
@media (max-width: 768px) {
  button, 
  .btn, 
  a.nav-link, 
  .icon-btn, 
  input[type="button"], 
  input[type="submit"], 
  .tab-btn, 
  .chip, 
  .action-btn {
    min-height: var(--android-touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    touch-action: manipulation;
  }
}

/* Material Active Ripple / Press Feedback */
button:active, 
.btn:active, 
.android-nav-item:active, 
.card-clickable:active {
  transform: scale(0.97);
  transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --------------------------------------------------------------------------
   2. Native Android Top App Bar
   -------------------------------------------------------------------------- */
.android-top-app-bar {
  display: none; /* Shown on mobile viewports */
}

@media (max-width: 768px) {
  .android-top-app-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: var(--android-top-bar-height);
    background: var(--android-app-bar-bg);
    color: var(--android-text-main);
    padding: 0 12px;
    z-index: 999;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid var(--android-border);
    box-sizing: border-box;
  }

  .android-top-app-bar .top-bar-left {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .android-top-app-bar .top-bar-back-btn {
    background: transparent;
    border: none;
    color: var(--android-text-main);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
  }

  .android-top-app-bar .top-bar-title {
    font-size: 18px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    letter-spacing: 0.2px;
  }

  .android-top-app-bar .top-bar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .android-top-app-bar .top-bar-action-icon {
    background: transparent;
    border: none;
    color: var(--android-text-main);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
  }
}

/* --------------------------------------------------------------------------
   3. Native Android Bottom Navigation Bar
   -------------------------------------------------------------------------- */
.android-bottom-nav-bar {
  display: none; /* Hidden on desktop */
}

@media (max-width: 768px) {
  body.has-android-nav {
    padding-bottom: calc(var(--android-nav-height) + 12px) !important;
  }

  .android-bottom-nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-around;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--android-nav-height);
    background: rgba(22, 23, 34, 0.94);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10000;
    padding: 4px 8px env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  }

  .android-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--android-text-muted);
    font-size: 11px;
    font-weight: 500;
    flex: 1;
    height: 100%;
    padding: 4px 0;
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .android-nav-item .nav-icon-pill {
    width: 48px;
    height: 28px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin-bottom: 2px;
    transition: background 0.2s ease, transform 0.15s ease;
  }

  .android-nav-item.active {
    color: #a78bfa;
    font-weight: 600;
  }

  .android-nav-item.active .nav-icon-pill {
    background: rgba(127, 90, 240, 0.28);
    color: #a78bfa;
  }
}

/* --------------------------------------------------------------------------
   4. Android Bottom Sheet & Slide-up Modals
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .modal-dialog, 
  .modal-content, 
  .bottom-sheet-target {
    border-radius: var(--android-radius-lg) var(--android-radius-lg) 0 0 !important;
  }

  /* Universal Bottom Sheet class for mobile viewports */
  .android-bottom-sheet {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 88vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--android-radius-lg) var(--android-radius-lg) 0 0 !important;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6) !important;
    animation: slideUpSheet 0.28s cubic-bezier(0, 0, 0.2, 1) forwards;
    z-index: 10050 !important;
    margin: 0 !important;
  }

  /* Sheet drag handle indicator */
  .android-bottom-sheet::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.3);
    margin: 10px auto 14px;
  }
}

@keyframes slideUpSheet {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* --------------------------------------------------------------------------
   5. General Mobile Adaptability & Layout Helpers
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* Prevent side cut-offs on containers */
  .container, 
  .container-fluid, 
  .main-content, 
  .wrapper, 
  .page-container {
    padding-left: 12px !important;
    padding-right: 12px !important;
    box-sizing: border-box !important;
  }

  /* Convert desktop horizontal flex tables / forms into stacked layouts */
  .mobile-stack {
    flex-direction: column !important;
    width: 100% !important;
  }

  .mobile-full-width {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Smooth scrollable tables */
  .table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    border-radius: var(--android-radius-sm);
  }

  /* Mobile Grid Harmonization */
  .grid-mobile-1col {
    grid-template-columns: 1fr !important;
  }

  /* Hide raw desktop headers when mobile bar is visible */
  .desktop-only-header {
    display: none !important;
  }
}

/* --------------------------------------------------------------------------
   6. Library Search & Advanced Search Mobile Ergonomics
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* Hero Content & Container Width Adaptability */
  .hero-content {
    width: 98% !important;
    padding: 0 4px !important;
  }

  .search-container {
    padding: 16px 12px !important;
    border-radius: 16px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Search Mode Toggle Buttons (Basic / Advanced / AI Search) */
  .search-mode-toggle {
    margin-bottom: 16px !important;
    width: 100% !important;
  }

  .search-mode-toggle .toggle-group {
    display: flex !important;
    width: 100% !important;
    gap: 6px !important;
    background: rgba(0, 0, 0, 0.25) !important;
    padding: 4px !important;
    border-radius: 14px !important;
    box-sizing: border-box !important;
  }

  .search-mode-toggle .toggle-btn {
    flex: 1 !important;
    min-height: 44px !important;
    padding: 8px 4px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    text-align: center !important;
    border-radius: 10px !important;
    white-space: nowrap !important;
    justify-content: center !important;
  }

  /* Basic Search Panel Controls */
  .basic-search-wrapper .basic-search-form {
    width: 100% !important;
    flex-direction: column !important;
    gap: 10px !important;
  }

  .basic-search-wrapper .basic-search-form .tags-wrapper {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  .basic-search-wrapper .basic-search-form button[type="submit"] {
    width: 100% !important;
    min-height: 48px !important;
    font-size: 15px !important;
    border-radius: 12px !important;
    justify-content: center !important;
  }

  /* Search Logic & Sanskrit Toggles */
  .search-logic-group {
    flex-direction: column !important;
    gap: 8px !important;
    margin-bottom: 14px !important;
  }

  .search-logic-group div[style*="background"] {
    width: 100% !important;
    display: flex !important;
    box-sizing: border-box !important;
  }

  .search-logic-group .logic-label {
    flex: 1 !important;
    text-align: center !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }

  /* Advanced Search Rows */
  .advanced-search-row {
    flex-direction: column !important;
    gap: 12px !important;
  }

  .advanced-label-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .advanced-label-row > div {
    display: flex !important;
    width: 100% !important;
    gap: 8px !important;
  }

  .advanced-label-row select {
    flex: 1 !important;
    min-height: 40px !important;
    font-size: 13px !important;
  }

  .text-query-row {
    flex-direction: column !important;
    gap: 10px !important;
    width: 100% !important;
  }

  .text-query-row .tags-wrapper {
    width: 100% !important;
    min-width: 0 !important;
  }

  #advancedSearchPanel .toggle-card {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 10px 14px !important;
    justify-content: flex-start !important;
  }

  .text-query-row button.search-button {
    width: 100% !important;
    min-height: 48px !important;
    justify-content: center !important;
  }

  .advanced-options-row {
    flex-direction: column !important;
    gap: 10px !important;
  }
}

