/**
 * Morph Unified Portal - Advanced Responsive Styles
 * Mobile-first design with tablet and desktop breakpoints
 * Tables-to-cards conversion and mobile navigation
 */

/* ============================================
   CSS VARIABLES FOR RESPONSIVE BREAKPOINTS
   ============================================ */
:root {
  --breakpoint-mobile: 480px;
  --breakpoint-tablet: 768px;
  --breakpoint-laptop: 1024px;
  --breakpoint-desktop: 1280px;
  
  /* Mobile-friendly touch targets */
  --touch-target-min: 44px;
  --spacing-mobile: 0.75rem;
  --spacing-tablet: 1rem;
  --spacing-desktop: 1.5rem;
}

/* ============================================
   MOBILE NAVIGATION - HAMBURGER MENU
   ============================================ */
.mobile-menu-toggle {
  display: none;
  background: transparent;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  z-index: 1002;
}

.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 28px;
  height: 20px;
}

.hamburger span {
  display: block;
  height: 3px;
  width: 100%;
  background: #fff;
  border-radius: 3px;
  transition: all 0.3s ease;
}

.mobile-menu-toggle.active .hamburger span:nth-child(1) {
  transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-toggle.active .hamburger span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active .hamburger span:nth-child(3) {
  transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile Navigation Overlay */
.nav-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.nav-overlay.active {
  display: block;
  opacity: 1;
}

/* ============================================
   TABLE TO CARD CONVERSION
   ============================================ */
.responsive-table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Card-based table display for mobile */
@media (max-width: 768px) {
  .table-as-cards table,
  .table-as-cards thead,
  .table-as-cards tbody,
  .table-as-cards th,
  .table-as-cards td,
  .table-as-cards tr {
    display: block;
  }
  
  .table-as-cards thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  
  .table-as-cards tbody tr {
    background: linear-gradient(145deg, #1a3d2a, #113d2a);
    border: 1px solid rgba(40, 167, 69, 0.3);
    border-radius: 12px;
    margin-bottom: 1rem;
    padding: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }
  
  .table-as-cards tbody tr:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  }
  
  .table-as-cards td {
    position: relative;
    padding: 0.75rem 0.75rem 0.75rem 45%;
    border: none;
    border-bottom: 1px solid rgba(143, 188, 143, 0.1);
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
  }
  
  .table-as-cards td:last-child {
    border-bottom: none;
  }
  
  .table-as-cards td::before {
    content: attr(data-label);
    position: absolute;
    left: 0.75rem;
    width: 40%;
    padding-right: 10px;
    font-weight: 600;
    color: #8fbc8f;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  
  /* Action buttons in cards */
  .table-as-cards td .actions-btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    margin: 0.25rem;
  }
}

/* ============================================
   DATA CARDS (Alternative to tables)
   ============================================ */
.data-cards-container {
  display: none;
}

@media (max-width: 768px) {
  .data-cards-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .data-card {
    background: linear-gradient(145deg, #1a3d2a, #113d2a);
    border: 1px solid rgba(40, 167, 69, 0.3);
    border-radius: 16px;
    padding: 1.25rem;
    position: relative;
    overflow: hidden;
  }
  
  .data-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #28a745, #20c997);
  }
  
  .data-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(143, 188, 143, 0.15);
  }
  
  .data-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
  }
  
  .data-card-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(40, 167, 69, 0.2);
    color: #28a745;
    border: 1px solid rgba(40, 167, 69, 0.4);
  }
  
  .data-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .data-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(143, 188, 143, 0.08);
  }
  
  .data-card-row:last-child {
    border-bottom: none;
  }
  
  .data-card-label {
    color: #8fbc8f;
    font-size: 0.85rem;
    font-weight: 500;
  }
  
  .data-card-value {
    color: #fff;
    font-weight: 600;
    font-size: 0.95rem;
    text-align: right;
  }
  
  .data-card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(143, 188, 143, 0.15);
  }
  
  .data-card-actions button,
  .data-card-actions a {
    flex: 1;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    transition: all 0.3s ease;
  }
}

/* ============================================
   MOBILE BREAKPOINT (< 480px)
   ============================================ */
@media (max-width: 480px) {
  /* Typography */
  html {
    font-size: 14px;
  }
  
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
  h3 { font-size: 1.1rem !important; }
  
  /* Navigation */
  .main-nav,
  .landing-nav {
    padding: 0.75rem !important;
  }
  
  .brand-text {
    font-size: 1rem !important;
  }
  
  .brand-icon {
    font-size: 1.3rem !important;
  }
  
  .mobile-menu-toggle {
    display: flex;
  }
  
  .nav-links {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, #0f5132 0%, #0d2818 100%);
    flex-direction: column;
    padding: 1rem;
    gap: 0.5rem;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 999;
    overflow-y: auto;
  }
  
  .nav-links.active {
    transform: translateX(0);
  }
  
  .nav-link {
    width: 100%;
    padding: 1rem !important;
    justify-content: flex-start;
    font-size: 1rem !important;
    border-radius: 12px;
  }
  
  .nav-actions {
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
  }
  
  .nav-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 0.875rem 1rem;
  }
  
  /* Content */
  .main-content {
    padding: 0.75rem !important;
    margin-top: 60px;
  }
  
  .section-header {
    padding: 0 0.5rem;
    margin-bottom: 1.5rem !important;
  }
  
  /* Hero */
  .hero {
    padding: 80px 1rem 2rem !important;
    min-height: auto;
    text-align: center;
  }
  
  .hero h1 {
    font-size: 1.75rem !important;
    line-height: 1.3;
  }
  
  .hero-subtitle {
    font-size: 1rem !important;
  }
  
  .hero-actions {
    flex-direction: column;
    width: 100%;
  }
  
  .hero-actions .btn {
    width: 100%;
  }
  
  .hero-visual {
    display: none;
  }
  
  /* Corporation Cards */
  .corp-cards-grid,
  .corp-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }
  
  .corp-card {
    padding: 1.25rem !important;
  }
  
  .corp-icon {
    font-size: 2rem !important;
  }
  
  .corp-card h3 {
    font-size: 1.1rem !important;
  }
  
  /* Tabs */
  .corp-tabs {
    flex-direction: column;
    padding: 0.5rem !important;
    gap: 0.5rem !important;
  }
  
  .corp-tab {
    width: 100%;
    justify-content: center;
    padding: 0.875rem !important;
  }
  
  /* Quick Access */
  .quick-cards-grid {
    grid-template-columns: 1fr !important;
  }
  
  .quick-card {
    padding: 1.25rem !important;
  }
  
  /* Benefits Grid */
  .benefits-grid {
    grid-template-columns: 1fr !important;
  }
  
  /* Buttons */
  .btn {
    min-height: var(--touch-target-min);
    padding: 0.75rem 1rem !important;
  }
  
  .btn-lg {
    padding: 1rem 1.25rem !important;
    font-size: 1rem !important;
  }
  
  /* User Menu */
  .user-menu {
    padding: 0.25rem;
  }
  
  .user-info {
    display: none !important;
  }
  
  .user-avatar {
    width: 36px !important;
    height: 36px !important;
  }
  
  /* Modals */
  .modal-content {
    width: 95% !important;
    max-width: none !important;
    margin: 1rem auto !important;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  /* Forms */
  .form-row,
  .form-grid {
    grid-template-columns: 1fr !important;
  }
  
  input, select, textarea {
    font-size: 16px !important; /* Prevents zoom on iOS */
    padding: 0.875rem !important;
    min-height: var(--touch-target-min);
  }
  
  /* Iframes */
  .corp-iframe,
  .full-iframe {
    height: calc(100vh - 70px) !important;
    min-height: 400px !important;
  }
  
  /* Footer */
  .landing-footer {
    padding: 2rem 1rem !important;
  }
  
  .footer-brand {
    font-size: 1.1rem !important;
  }
}

/* ============================================
   TABLET BREAKPOINT (481px - 768px)
   ============================================ */
@media (min-width: 481px) and (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
  }
  
  .nav-links {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, #0f5132 0%, #0d2818 100%);
    flex-direction: column;
    padding: 1.5rem;
    gap: 0.75rem;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 999;
    overflow-y: auto;
  }
  
  .nav-links.active {
    transform: translateX(0);
  }
  
  .nav-link {
    width: 100%;
    padding: 1rem 1.25rem !important;
    justify-content: flex-start;
    font-size: 1rem;
  }
  
  .main-content {
    margin-top: 60px;
    padding: 1rem;
  }
  
  .hero {
    flex-direction: column;
    padding: 100px 2rem 3rem;
    text-align: center;
  }
  
  .hero h1 {
    font-size: 2.25rem;
  }
  
  .hero-visual {
    margin-top: 2rem;
  }
  
  .corp-orbit {
    width: 220px;
    height: 220px;
  }
  
  .corp-cards-grid,
  .corp-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
  
  .corp-tabs {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .corp-tab {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 140px;
  }
  
  .quick-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .capital-overview-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .benefits-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   TABLET LANDSCAPE / SMALL LAPTOP (769px - 1024px)
   ============================================ */
@media (min-width: 769px) and (max-width: 1024px) {
  .main-content {
    padding: 1.5rem;
  }
  
  .hero {
    padding: 100px 3rem 4rem;
  }
  
  .hero h1 {
    font-size: 2.75rem;
  }
  
  .corp-cards-grid,
  .corp-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
  
  .capital-overview-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .nav-links {
    gap: 0.35rem;
  }
  
  .nav-link {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
  }
}

/* ============================================
   IPAD SPECIFIC STYLES
   ============================================ */
/* iPad Mini & iPad (Portrait) */
@media only screen 
  and (min-device-width: 768px) 
  and (max-device-width: 1024px) 
  and (orientation: portrait) {
  
  .main-nav {
    height: auto;
    flex-wrap: wrap;
    padding: 1rem;
  }
  
  .nav-brand {
    margin-bottom: 0.5rem;
  }
  
  .nav-links {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  
  .nav-link {
    padding: 0.6rem 1rem;
  }
  
  .main-content {
    margin-top: 100px;
  }
  
  .corp-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* iPad (Landscape) */
@media only screen 
  and (min-device-width: 768px) 
  and (max-device-width: 1024px) 
  and (orientation: landscape) {
  
  .corp-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .capital-overview-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* iPad Pro (Portrait) */
@media only screen 
  and (min-device-width: 1024px) 
  and (max-device-width: 1366px) 
  and (orientation: portrait) {
  
  .corp-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .hero {
    flex-direction: column;
    text-align: center;
  }
}

/* iPad Pro (Landscape) */
@media only screen 
  and (min-device-width: 1024px) 
  and (max-device-width: 1366px) 
  and (orientation: landscape) {
  
  .corp-cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ============================================
   SAFE AREA INSETS (iPhone X+, etc.)
   ============================================ */
@supports (padding: max(0px)) {
  .main-nav,
  .landing-nav {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  
  .main-content {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
  
  .landing-footer {
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }
}

/* ============================================
   TOUCH-FRIENDLY INTERACTIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .corp-card:hover,
  .quick-card:hover,
  .benefit-card:hover,
  .data-card:hover {
    transform: none;
  }
  
  /* Active states instead */
  .corp-card:active,
  .quick-card:active,
  .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
  }
  
  /* Larger touch targets */
  .actions-btn,
  .dropdown-item {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
  }
  
  /* Prevent text selection on buttons */
  button, .btn, .nav-link, .corp-tab {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
  .main-nav,
  .landing-nav,
  .mobile-menu-toggle,
  .nav-overlay,
  .cta-section {
    display: none !important;
  }
  
  .main-content {
    margin-top: 0;
    padding: 0;
  }
  
  body {
    background: white;
    color: black;
  }
  
  .corp-card {
    break-inside: avoid;
    border: 1px solid #ccc;
    background: white;
  }
}

/* ============================================
   DARK MODE PREFERENCE
   ============================================ */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
  }
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .orbit-item {
    animation: none !important;
  }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */
@media (prefers-contrast: high) {
  .corp-card,
  .quick-card,
  .benefit-card,
  .data-card {
    border-width: 2px;
  }
  
  .btn {
    border-width: 2px;
  }
  
  .nav-link {
    border-width: 2px;
  }
}
