/* Shared responsive styles for IEEE Dashboard */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

iframe {
  max-width: 100%;
}

/* Prevent horizontal page scroll from nested content */
body {
  overflow-x: hidden;
}

/* Enhanced touch targets for mobile - minimum 44x44px per WCAG */
@media (max-width: 768px) {
  button,
  .btn,
  .action-btn,
  input[type="button"],
  input[type="submit"],
  a.button {
    min-height: 44px;
    min-width: 44px;
  }

  .sidebar ul li a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .close-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .password-toggle {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Touch-friendly form controls on mobile (prevents iOS zoom) */
@media (max-width: 768px) {
  input,
  select,
  textarea {
    font-size: 16px;
    min-height: 44px;
  }
}

/* Shared header patterns */
@media (max-width: 768px) {
  header {
    flex-wrap: wrap;
    padding: 12px 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    gap: 12px;
    font-size: 16px;
  }

  .header-title {
    flex: 1;
    min-width: 0;
    gap: 8px;
  }

  .header-title span {
    font-size: 11px;
    padding: 6px 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
  }

  .user-profile {
    padding: 10px 14px;
    font-size: 13px;
    max-width: 100%;
    min-width: 0;
  }

  .user-profile span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 120px;
  }
}

@media (max-width: 480px) {
  header {
    padding: 10px 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .header-title span {
    display: none;
  }

  .user-profile span {
    max-width: 90px;
  }
}

/* Scrollable tables on small screens */
@media (max-width: 768px) {
  .table-container {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
  }

  table {
    min-width: 600px;
  }

  th, td {
    padding: 10px 12px;
    font-size: 13px;
  }

  td {
    word-break: break-word;
  }
}

/* Card-based table view for very small screens (480px and below) */
@media (max-width: 480px) {
  .table-container {
    overflow-x: visible;
  }

  table {
    display: block;
    min-width: 100%;
  }

  thead {
    display: none;
  }

  tbody {
    display: block;
  }

  tr {
    display: block;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(0, 0, 0, 0.05);
  }

  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border: none;
    font-size: 14px;
    word-break: break-word;
  }

  td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    margin-right: 12px;
    flex-shrink: 0;
    min-width: 100px;
  }

  .action-buttons {
    flex-direction: column;
    width: 100%;
    margin-top: 12px;
  }

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

/* Shared button patterns */
@media (max-width: 768px) {
  .btn {
    width: 100%;
    justify-content: center;
    padding: 12px 20px;
  }

  .button-group {
    flex-direction: column;
    gap: 10px;
  }
}

/* Prevent text selection on touch for better UX */
@media (max-width: 768px) {
  .btn,
  button,
  .action-btn,
  .sidebar ul li a {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }
}

/* Improved focus states for keyboard navigation on mobile */
@media (max-width: 768px) {
  button:focus,
  .btn:focus,
  input:focus,
  select:focus,
  textarea:focus,
  a:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }
}

/* Dashboard header card mobile optimization */
@media (max-width: 768px) {
  .dashboard-header-card {
    flex-direction: column;
    text-align: center;
    padding: 20px;
  }

  .dashboard-header-card > div:first-child {
    margin: 0 auto;
  }

  .dashboard-header-card > div:nth-child(2) {
    text-align: center;
  }

  .dashboard-header-card .badge {
    display: inline-block;
    margin: 4px;
  }
}

/* Event cards mobile optimization */
@media (max-width: 768px) {
  .event-card {
    padding: 20px;
  }

  .event-card h3 {
    font-size: 16px;
  }

  .event-card p {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .event-card {
    padding: 16px;
  }

  .event-card h3 {
    font-size: 15px;
  }
}

/* Shared card grid patterns */
@media (max-width: 768px) {
  .card-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

@media (max-width: 480px) {
  .card-grid {
    gap: 12px;
  }
}

/* Shared container patterns */
@media (max-width: 768px) {
  .container {
    padding: 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

@media (max-width: 480px) {
  .container {
    padding: 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
}

/* Shared modal patterns */
@media (max-width: 768px) {
  .modal {
    padding: 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .modal-content {
    max-width: 100%;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    padding: 24px 20px;
    border-radius: 16px;
  }

  .modal-content-wide {
    max-width: 100%;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
  }

  .modal-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .modal-header h3 {
    font-size: 18px;
    line-height: 1.3;
    flex: 1;
    min-width: 0;
  }

  .close-btn {
    flex-shrink: 0;
  }

  .modal-footer {
    flex-direction: column-reverse;
    gap: 10px;
  }

  .modal-footer .btn {
    width: 100%;
    justify-content: center;
  }

  .form-group {
    margin-bottom: 16px;
  }

  .form-group label {
    font-size: 13px;
    line-height: 1.4;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px;
    padding: 12px 14px;
  }

  .form-group textarea {
    min-height: 80px;
    resize: vertical;
  }

  .form-group select[multiple] {
    height: 150px;
  }
}

@media (max-width: 480px) {
  .modal {
    padding: 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .modal-content {
    padding: 20px 16px;
    border-radius: 12px;
    max-height: calc(100vh - 16px);
  }

  .modal-content-wide {
    max-height: calc(100vh - 16px);
  }

  .modal-header h3 {
    font-size: 17px;
  }

  .form-group {
    margin-bottom: 14px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    padding: 10px 12px;
  }

  .btn {
    padding: 10px 16px;
    font-size: 14px;
  }
}

/* Shared form patterns */
@media (max-width: 768px) {
  .form-group {
    margin-bottom: 16px;
  }

  .form-group label {
    font-size: 13px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px;
    padding: 12px 14px;
  }
}

/* Shared stats grid patterns */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stat-card {
    padding: 20px;
  }

  .stat-card .icon {
    width: 56px;
    height: 56px;
    line-height: 56px;
    font-size: 24px;
  }

  .stat-card .number {
    font-size: 26px;
  }
}

/* Shared page header patterns */
@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .page-title {
    font-size: 22px;
    flex-wrap: wrap;
  }

  .page-title i {
    font-size: 26px;
  }
}

@media (max-width: 480px) {
  .page-title {
    font-size: 20px;
  }
}

/* Shared search/filter patterns */
@media (max-width: 768px) {
  .search-filter-container {
    flex-direction: column;
    gap: 10px;
  }

  .search-box,
  .filter-box {
    width: 100%;
    min-width: 0;
  }

  .search-box input,
  .filter-box select {
    width: 100%;
  }
}

/* Shared footer patterns */
@media (max-width: 768px) {
  footer {
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    font-size: 12px;
  }
}

/* Shared empty state patterns */
@media (max-width: 768px) {
  .empty-state {
    padding: 32px 16px;
  }

  .empty-state i {
    font-size: 40px;
  }
}

/* Hamburger menu for sidebar */
@media (max-width: 768px) {
  .hamburger-menu {
    display: block;
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    width: 280px;
    height: 100%;
    z-index: 1000;
    transition: left 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    padding-top: max(24px, env(safe-area-inset-top));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.active {
    left: 0;
  }

  .sidebar h3 {
    font-size: 16px;
    padding-bottom: 12px;
    margin-bottom: 16px;
  }

  .sidebar ul li a {
    padding: 14px 16px;
    font-size: 15px;
  }

  .sidebar ul li a i {
    font-size: 18px;
    width: 24px;
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: 260px;
    left: -260px;
  }

  .sidebar.active {
    left: 0;
  }

  .sidebar h3 {
    font-size: 15px;
  }

  .sidebar ul li a {
    padding: 12px 14px;
    font-size: 14px;
  }

  .sidebar ul li a i {
    font-size: 16px;
    width: 20px;
  }
}

/* Video container responsive */
@media (max-width: 768px) {
  .video-container iframe,
  .video-container video {
    min-height: 200px;
  }

  .youtube-player-wrapper {
    min-height: 200px;
  }

  .video-container {
    border-radius: 12px;
    overflow: hidden;
  }

  .video-list {
    margin-top: 16px;
  }

  .video-list li {
    padding: 12px 14px;
    font-size: 13px;
  }

  .video-list li i {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .video-container iframe,
  .video-container video {
    min-height: 180px;
  }

  .youtube-player-wrapper {
    min-height: 180px;
  }

  .video-list li {
    padding: 10px 12px;
    font-size: 12px;
  }

  .video-list li i {
    font-size: 12px;
  }
}

/* Community chat layout mobile optimization */
@media (max-width: 768px) {
  .community-chat-layout {
    grid-template-columns: 1fr;
    gap: 16px;
    min-height: auto;
  }

  .community-segments-panel {
    max-height: 200px;
    overflow-y: auto;
  }

  .community-chat-panel {
    min-height: 400px;
  }

  .community-chat-messages {
    max-height: 300px;
    overflow-y: auto;
  }

  .community-chat-compose {
    flex-direction: column;
    gap: 10px;
  }

  .community-chat-compose textarea {
    min-height: 60px;
  }

  .community-chat-compose button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .community-chat-panel {
    min-height: 350px;
  }

  .community-chat-messages {
    max-height: 250px;
  }
}

/* Login page specific responsive styles */
@media (max-width: 768px) {
  body {
    padding: 12px;
    align-items: flex-start;
  }

  .page-wrapper {
    grid-template-columns: 1fr;
    min-height: auto;
    max-width: 100%;
    border-radius: 20px;
  }

  .brand-panel {
    display: none;
  }

  .login-panel {
    padding: 40px 28px;
  }

  .login-header h2 {
    font-size: 24px;
  }

  .login-header p {
    font-size: 14px;
  }

  .orb {
    display: none;
  }
}

@media (max-width: 480px) {
  .page-wrapper {
    border-radius: 16px;
    margin: 8px;
  }

  .login-panel {
    padding: 32px 20px;
  }

  .login-header h2 {
    font-size: 22px;
  }

  .form-group label {
    font-size: 13px;
  }

  .input-wrapper input {
    font-size: 16px;
    padding: 12px 14px 12px 44px;
  }

  .btn-login {
    padding: 14px 20px;
    font-size: 15px;
  }
}

/* Tablet specific optimizations (768px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar {
    width: 240px;
  }

  .main {
    padding: 24px;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

/* Large desktop optimizations (1440px+) */
@media (min-width: 1440px) {
  .container {
    max-width: 1400px;
    margin: 0 auto;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  }
}

/* Ultra-wide screen optimizations (1920px+) */
@media (min-width: 1920px) {
  .container {
    max-width: 1600px;
  }

  .sidebar {
    width: 320px;
  }

  .main {
    padding: 40px;
  }
}

/* Landscape mobile optimizations */
@media (max-width: 768px) and (orientation: landscape) {
  .page-wrapper {
    min-height: auto;
    max-height: 90vh;
    overflow-y: auto;
  }

  .login-panel {
    padding: 20px 28px;
  }

  .brand-panel {
    display: none;
  }

  .orb {
    display: none;
  }
}

/* Print styles */
@media print {
  body {
    background: white;
  }

  .sidebar,
  .hamburger-menu,
  .header-actions,
  .btn,
  .action-buttons,
  .modal {
    display: none !important;
  }

  .main {
    padding: 0;
    margin: 0;
    box-shadow: none;
    border-radius: 0;
  }

  .table-container {
    box-shadow: none;
    border: 1px solid #000;
  }

  table {
    page-break-inside: avoid;
  }
}

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

  .orb {
    animation: none;
  }

  @keyframes float {
    0%, 100% { transform: translateY(0); }
  }

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

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn,
  .action-btn,
  input,
  select,
  textarea {
    border-width: 2px;
  }

  .card,
  .stat-card,
  .modal-content {
    border-width: 2px;
  }
}

/* Dark mode support preparation */
@media (prefers-color-scheme: dark) {
  /* Future dark mode implementation can go here */
  /* Currently using fixed color scheme per design */
}
