/**
 * DEFENCES.APP - MOBILE-FIRST RESPONSIVE DESIGN
 * ==============================================
 *
 * Mobile-first approach starting from 320px (iPhone SE)
 * Target: Lighthouse accessibility 100/100
 * WCAG 2.1 Level AA compliant
 *
 * Breakpoints:
 * - xs: 320px - 479px (iPhone SE, small phones)
 * - sm: 480px - 767px (iPhone, standard phones)
 * - md: 768px - 1023px (iPad, tablets)
 * - lg: 1024px+ (Desktop)
 *
 * ==============================================
 */

/* ==========================================
   BASE MOBILE STYLES (320px+)
   ========================================== */

/* Prevent horizontal scroll */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  /* Minimum 16px to prevent iOS zoom on input focus */
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-overflow-scrolling: touch;
}

/* Touch-friendly base - 44x44px minimum (WCAG 2.5.5) */
button,
a.btn,
[role="button"],
input[type="submit"],
input[type="button"] {
  min-height: 44px;
  min-width: 44px;
  padding: 0.75rem 1.5rem;
  -webkit-tap-highlight-color: rgba(245, 158, 11, 0.1);
  touch-action: manipulation;
}

/* Icon-only buttons */
.icon-btn,
button[aria-label]:not([aria-label*=" "]) {
  min-width: 48px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
}

/* Inputs - minimum 16px prevents iOS zoom */
input,
textarea,
select {
  font-size: 16px !important;
  min-height: 44px;
}

/* ==========================================
   HEADER - MOBILE FIRST (320px+)
   ========================================== */

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: auto;
  padding: 0;
}

header .px-6 {
  padding-left: 1rem;
  padding-right: 1rem;
}

header .flex.items-center.gap-4 {
  gap: 0.5rem;
}

/* Logo on mobile */
header .flex.items-center.gap-3 img {
  height: 2rem;
  width: 2rem;
}

header .flex.items-center.gap-3 .text-lg {
  font-size: 0.95rem;
}

/* Hide desktop elements on mobile */
@media (max-width: 767px) {
  /* Hide "Saved Research" text, show icon */
  #saved-research-btn .hidden.md\\:inline {
    display: none !important;
  }

  #saved-research-btn .md\\:hidden {
    display: inline !important;
    font-size: 1.25rem;
  }

  /* Hide user details in header */
  .hidden.md\\:flex {
    display: none !important;
  }

  .hidden.md\\:block {
    display: none !important;
  }

  /* User avatar smaller */
  #user-avatar {
    width: 2rem;
    height: 2rem;
    font-size: 0.875rem;
  }
}

/* ==========================================
   SEARCH BAR - MOBILE OPTIMIZED
   ========================================== */

.fixed.top-\\[57px\\] {
  top: 56px !important;
}

@media (max-width: 767px) {
  .fixed.top-\\[57px\\] {
    padding: 0.75rem 1rem;
  }

  #search-input {
    font-size: 16px !important; /* Prevent iOS zoom */
    padding: 0.875rem 1rem;
    padding-right: 3rem;
  }

  /* Quick filters - wrap and smaller */
  .flex.gap-2.mt-3 {
    gap: 0.5rem;
    margin-top: 0.75rem;
  }

  .quick-filter-btn {
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    min-height: 40px;
  }
}

/* ==========================================
   SIDEBAR - HIDE ON MOBILE, SHOW ON DESKTOP
   ========================================== */

/* Mobile: sidebar hidden by default */
aside.sidebar {
  display: none;
}

/* Desktop: sidebar visible */
@media (min-width: 1024px) {
  aside.sidebar {
    display: block !important;
  }
}

/* ==========================================
   MAIN CONTENT - FULL WIDTH ON MOBILE
   ========================================== */

main {
  padding: 1rem;
  width: 100%;
  max-width: 100%;
}

.pt-\\[170px\\] {
  padding-top: 140px !important;
}

@media (max-width: 767px) {
  .pt-\\[170px\\] {
    padding-top: 180px !important; /* Account for wrapped quick filters */
  }
}

/* Tablet */
@media (min-width: 768px) {
  main {
    padding: 1.5rem;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  main {
    padding: 2rem;
  }
}

/* ==========================================
   CASE CARDS - MOBILE OPTIMIZED
   ========================================== */

.case-card {
  padding: 1.25rem;
  border-radius: 12px;
}

.case-card h2,
.case-card h3 {
  font-size: 1.125rem;
  line-height: 1.4;
  margin-bottom: 0.75rem;
}

.case-card .flex.gap-4 {
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.case-card p {
  font-size: 0.9375rem;
  line-height: 1.6;
}

/* Buttons in cards - stack on mobile */
.case-card .flex.gap-3 {
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 480px) {
  .case-card .flex.gap-3 {
    flex-direction: row;
  }
}

/* Tablet */
@media (min-width: 768px) {
  .case-card {
    padding: 1.5rem;
  }

  .case-card h2,
  .case-card h3 {
    font-size: 1.25rem;
  }
}

/* ==========================================
   BADGES/PILLS - RESPONSIVE SIZING
   ========================================== */

.px-3.py-1 {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
}

@media (max-width: 479px) {
  /* Extra small phones - even smaller badges */
  .px-3.py-1 {
    padding: 0.25rem 0.5rem;
    font-size: 0.6875rem;
  }
}

/* ==========================================
   PAGINATION - MOBILE OPTIMIZED
   ========================================== */

nav[role="navigation"][aria-label="Pagination"] {
  flex-wrap: wrap;
  gap: 0.5rem;
}

nav[role="navigation"] button,
nav[role="navigation"] a {
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
}

@media (max-width: 479px) {
  /* Hide page numbers except current and adjacent */
  nav[role="navigation"] button:not([aria-current]):not(:first-child):not(:last-child):not(:nth-last-child(2)) {
    display: none;
  }
}

/* ==========================================
   USER DROPDOWN - MOBILE POSITIONING
   ========================================== */

#user-dropdown {
  position: fixed;
  right: 0.5rem;
  top: 4rem;
  width: calc(100vw - 1rem);
  max-width: 20rem;
}

@media (min-width: 768px) {
  #user-dropdown {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.5rem;
  }
}

/* ==========================================
   BOTTOM NAVIGATION BAR (MOBILE ONLY)
   ========================================== */

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: #1a1a1a;
  border-top: 1px solid #2e2e2e;
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
}

@media (max-width: 767px) {
  .mobile-bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
  }

  /* Add bottom padding to main content to avoid overlap */
  main {
    padding-bottom: calc(64px + env(safe-area-inset-bottom) + 1rem);
  }
}

.mobile-bottom-nav a,
.mobile-bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.6875rem;
  font-weight: 500;
  min-width: 60px;
  min-height: 56px;
  transition: all 0.2s ease;
  background: transparent;
  border: none;
  border-radius: 8px;
}

.mobile-bottom-nav a:active,
.mobile-bottom-nav button:active {
  background: rgba(245, 158, 11, 0.1);
}

.mobile-bottom-nav a.active {
  color: #f59e0b;
  border-bottom: 3px solid #f59e0b;
  border-radius: 0;
}

.mobile-bottom-nav svg {
  width: 1.5rem;
  height: 1.5rem;
}

/* Very small screens - hide labels */
@media (max-width: 360px) {
  .mobile-bottom-nav span:not(.sr-only) {
    display: none;
  }
}

/* ==========================================
   TYPOGRAPHY - MOBILE READABLE
   ========================================== */

/* Mobile base */
h1 {
  font-size: 1.75rem;
  line-height: 1.2;
}

h2 {
  font-size: 1.5rem;
  line-height: 1.3;
}

h3 {
  font-size: 1.25rem;
  line-height: 1.4;
}

p {
  font-size: 1rem;
  line-height: 1.6;
}

/* Tablet */
@media (min-width: 768px) {
  h1 {
    font-size: 2.25rem;
  }

  h2 {
    font-size: 1.875rem;
  }

  h3 {
    font-size: 1.5rem;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  h1 {
    font-size: 2.5rem;
  }

  h2 {
    font-size: 2rem;
  }

  h3 {
    font-size: 1.75rem;
  }
}

/* ==========================================
   MODALS/DIALOGS - MOBILE FULL SCREEN
   ========================================== */

[role="dialog"],
[role="alertdialog"] {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  border-radius: 0;
  padding: 1.5rem;
  transform: none;
}

@media (min-width: 768px) {
  [role="dialog"],
  [role="alertdialog"] {
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    width: auto;
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 16px;
    transform: translate(-50%, -50%);
  }
}

/* ==========================================
   FORMS - MOBILE OPTIMIZED
   ========================================== */

.form-group {
  margin-bottom: 1.25rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 0.9375rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"],
textarea,
select {
  width: 100%;
  padding: 0.875rem 1rem;
  font-size: 16px !important; /* Prevent iOS zoom */
  border-radius: 8px;
  border: 1px solid #2e2e2e;
  background: #0a0a0a;
  color: #f5f5f5;
  min-height: 48px;
}

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

/* ==========================================
   SPACING UTILITIES - RESPONSIVE
   ========================================== */

.container-mobile {
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 768px) {
  .container-mobile {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .container-mobile {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

/* ==========================================
   IMAGES - RESPONSIVE
   ========================================== */

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ==========================================
   TABLES - RESPONSIVE (MOBILE CARDS)
   ========================================== */

@media (max-width: 767px) {
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Or convert to cards */
  table.responsive-cards {
    display: block;
  }

  table.responsive-cards thead {
    display: none;
  }

  table.responsive-cards tbody,
  table.responsive-cards tr,
  table.responsive-cards td {
    display: block;
    width: 100%;
  }

  table.responsive-cards tr {
    margin-bottom: 1rem;
    padding: 1rem;
    background: #1a1a1a;
    border: 1px solid #2e2e2e;
    border-radius: 12px;
  }

  table.responsive-cards td {
    padding: 0.5rem 0;
    border: none;
    text-align: left;
  }

  table.responsive-cards td::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    color: #f59e0b;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
  }
}

/* ==========================================
   SAFE AREA INSETS (iPhone Notch)
   ========================================== */

@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }

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

  .mobile-bottom-nav {
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  }

  /* Fixed positioning with safe areas */
  .fixed-bottom {
    bottom: env(safe-area-inset-bottom);
  }

  .fixed-left {
    left: env(safe-area-inset-left);
  }

  .fixed-right {
    right: env(safe-area-inset-right);
  }
}

/* ==========================================
   ORIENTATION SUPPORT
   ========================================== */

@media (orientation: landscape) and (max-height: 500px) {
  /* Reduce vertical padding in landscape mode on phones */
  header .h-16 {
    height: 3.5rem;
  }

  .mobile-bottom-nav {
    height: 52px;
  }

  main {
    padding-top: 120px !important;
  }
}

/* ==========================================
   PRINT STYLES
   ========================================== */

@media print {
  /* Hide navigation and non-essential elements */
  header,
  .mobile-bottom-nav,
  .mobile-filter-btn,
  #mobile-filter-drawer,
  #mobile-menu-overlay,
  .quick-filter-btn,
  button,
  [role="button"] {
    display: none !important;
  }

  /* Reset colors for print */
  * {
    background: white !important;
    color: black !important;
    border-color: #ccc !important;
  }

  /* Ensure links are visible */
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }

  /* Page breaks */
  .case-card,
  article {
    page-break-inside: avoid;
  }
}

/* ==========================================
   REDUCED MOTION (WCAG)
   ========================================== */

@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;
  }

  .case-card:hover {
    transform: none !important;
  }

  button:hover,
  a:hover {
    transform: none !important;
  }
}

/* ==========================================
   HIGH CONTRAST MODE (WCAG)
   ========================================== */

@media (prefers-contrast: high) {
  /* Stronger borders */
  *:focus {
    outline-width: 4px !important;
    outline-offset: 4px !important;
  }

  button,
  input,
  select,
  textarea,
  .case-card,
  [role="button"] {
    border-width: 2px !important;
  }

  /* Higher contrast colors */
  :root {
    --bg-primary: #000000;
    --bg-secondary: #000000;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --border: #ffffff;
    --primary: #ffff00;
  }
}

/* ==========================================
   DARK MODE SUPPORT (USER PREFERENCE)
   ========================================== */

@media (prefers-color-scheme: dark) {
  /* Already dark by default, but ensure consistency */
  body {
    background: #0a0a0a;
    color: #f5f5f5;
  }
}

@media (prefers-color-scheme: light) {
  /* Light mode override if user prefers */
  body.light-mode {
    background: #ffffff;
    color: #1a1a1a;
  }

  body.light-mode .bg-\\[\\#1a1a1a\\] {
    background: #f5f5f5 !important;
    color: #1a1a1a !important;
  }

  body.light-mode .text-\\[\\#f5f5f5\\] {
    color: #1a1a1a !important;
  }

  body.light-mode .border-\\[\\#2e2e2e\\] {
    border-color: #e5e5e5 !important;
  }
}

/* ==========================================
   UTILITY CLASSES - MOBILE SPECIFIC
   ========================================== */

.mobile-only {
  display: block;
}

.desktop-only {
  display: none;
}

@media (min-width: 1024px) {
  .mobile-only {
    display: none;
  }

  .desktop-only {
    display: block;
  }
}

.tablet-only {
  display: none;
}

@media (min-width: 768px) and (max-width: 1023px) {
  .tablet-only {
    display: block;
  }
}

/* Touch-friendly spacing */
.tap-area {
  padding: 0.75rem;
  min-width: 48px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================
   LOADING STATES - MOBILE OPTIMIZED
   ========================================== */

.loading-spinner-mobile {
  width: 40px;
  height: 40px;
  border: 4px solid #2e2e2e;
  border-top-color: #f59e0b;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

/* ==========================================
   VIEWPORT HEIGHT FIX (MOBILE BROWSERS)
   ========================================== */

/* Use dvh where supported for better mobile browser behavior */
@supports (height: 100dvh) {
  .min-h-screen {
    min-height: 100dvh;
  }

  [role="dialog"],
  [role="alertdialog"] {
    max-height: 100dvh;
  }
}

/* Fallback for browsers without dvh support */
@supports not (height: 100dvh) {
  .min-h-screen {
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }
}

/* ==========================================
   END OF MOBILE-RESPONSIVE.CSS
   ========================================== */
