/* ============================================
   MOBILE RESPONSIVE STYLES FOR SCRIPTSERV
   Mobile-friendly transformation while preserving
   retro/hacker aesthetic (dark blue + cyan theme)
   ============================================ */

/* ============================================
   CSS CUSTOM PROPERTIES FOR MOBILE
   ============================================ */
:root {
  --mobile-padding: 10px;
  --mobile-header-height: 120px;
  --touch-target-size: 48px;
  --card-spacing: 15px;
}

/* ============================================
   PHASE 1: FOUNDATION STYLES
   Mobile: 320px-767px
   ============================================ */

/* Base Typography & Spacing */
@media (max-width: 767px) {
  body {
    font-size: 0.95rem;
    padding: var(--mobile-padding);
  }

  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.2rem; }

  .main-content {
    gap: 15px;
    padding: var(--mobile-padding);
  }
}

/* Mobile Header Transformation */
@media (max-width: 767px) {
  .header {
    flex-direction: column;
    min-height: var(--mobile-header-height);
    padding: var(--mobile-padding);
    gap: 10px;
    align-items: center;
  }

  .header-image img {
    height: 60px;
    margin: 0;
  }

  .header-text {
    text-align: center;
  }

  .header-text h1 {
    font-size: 1.5rem;
  }

  .header-text p {
    display: none; /* Hide subtitle on mobile */
  }

  .search-bar {
    width: 100%;
    max-width: 100%;
    font-size: 16px; /* Prevent iOS zoom */
    min-height: 44px;
    padding: 12px;
  }

  /* Share/GitHub icon buttons */
  .icon-button {
    width: 44px;
    height: 44px;
    padding: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* Touch Target Minimums (48x48px) */
@media (max-width: 767px) {
  button {
    min-height: var(--touch-target-size);
    padding: 12px 16px;
    font-size: 16px; /* Prevent iOS zoom */
    cursor: pointer;
  }

  .nav a {
    padding: 12px 16px;
    min-height: var(--touch-target-size);
    display: flex;
    align-items: center;
  }

  input[type="text"],
  input[type="email"],
  input[type="url"],
  input[type="tel"],
  textarea,
  select {
    min-height: 44px;
    font-size: 16px; /* Prevent iOS zoom */
    padding: 10px 12px;
  }

  textarea {
    min-height: 120px;
  }

  /* Tags need larger touch area */
  .tag {
    padding: 6px 12px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
  }

  /* Download buttons */
  .download-btn {
    min-height: var(--touch-target-size);
    padding: 12px 16px;
  }
}

/* ============================================
   PHASE 3: TABLE CARD TRANSFORMATION
   ============================================ */

/* Hide table on mobile, show cards */
@media (max-width: 767px) {
  .table-container table {
    display: none;
  }

  /* Card container */
  .script-cards {
    display: flex;
    flex-direction: column;
    gap: var(--card-spacing);
  }

  /* Individual script card */
  .script-card {
    background: var(--form-bg);
    border: 1px solid var(--borders);
    border-left: 4px solid var(--borders);
    border-radius: 8px;
    padding: 15px;
    transition: all 0.3s ease;
    cursor: pointer;
  }

  .script-card:active {
    border-left-color: var(--headings);
    transform: translateX(5px);
  }

  /* Card header */
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--borders);
    gap: 10px;
  }

  .script-name {
    font-size: 1.1rem;
    color: var(--headings);
    margin: 0;
    flex: 1;
    line-height: 1.3;
    word-break: break-word;
  }

  .category-badge {
    background: var(--lightbg);
    color: var(--text);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Card metadata */
  .card-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.9rem;
  }

  .meta-item {
    color: var(--subtext);
  }

  .meta-item strong {
    color: var(--text);
    display: block;
    margin-bottom: 2px;
  }

  /* Tags in cards */
  .card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 12px;
  }

  .card-tags .tag {
    padding: 6px 12px;
    font-size: 0.85rem;
    min-height: 32px;
  }

  /* Mobile download button */
  .download-btn-mobile {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    min-height: var(--touch-target-size);
    background: var(--lightbg);
    border: 2px solid var(--borders);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
  }

  .download-btn-mobile:active {
    background: var(--headings);
    color: var(--pagebg);
    transform: scale(0.98);
  }
}

/* Stack two-column layouts vertically */
@media (max-width: 767px) {
  .main-content {
    flex-direction: column;
  }

  .left-column,
  .right-column {
    width: 100%;
    max-width: 100%;
  }

  /* Welcome section (right) appears first, table (left) below */
  .right-column {
    order: 1;
  }

  .left-column {
    order: 2;
  }
}

/* ============================================
   PHASE 4: PERFORMANCE OPTIMIZATION
   ============================================ */

/* Loading indicator */
@media (max-width: 767px) {
  .loading {
    text-align: center;
    padding: 40px 20px;
    color: var(--borders);
    font-size: 1.2rem;
  }

  /* Skeleton cards while loading */
  .skeleton-card {
    background: var(--pagebg-highlight);
    border: 1px solid var(--borders);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    animation: pulse 1.5s ease-in-out infinite;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
  }
}

/* ============================================
   PHASE 5: PAGE-SPECIFIC OPTIMIZATIONS
   ============================================ */

/* Guestbook Page - Form First Layout */
@media (max-width: 767px) {
  /* Target guestbook page by checking for guestbook-specific elements */
  body:has(.guestbook-form-section) .main-content,
  .guestbook-page .main-content {
    flex-direction: column-reverse;
  }

  /* Collapsible form toggle */
  .form-collapse-toggle {
    width: 100%;
    padding: 12px;
    min-height: var(--touch-target-size);
    background: var(--lightbg);
    border: 2px solid var(--borders);
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 10px;
    border-radius: 8px;
    cursor: pointer;
  }

  .guestbook-form.collapsed {
    display: none;
  }

  /* Guestbook controls */
  .guestbook-controls {
    flex-direction: column;
    gap: 10px;
  }

  .guestbook-controls button {
    width: 100%;
    min-height: var(--touch-target-size);
  }
}

/* Contact Page */
@media (max-width: 767px) {
  .contact-section {
    width: 95vw;
    padding: 20px;
  }

  .contact-section input,
  .contact-section textarea,
  .contact-section select {
    font-size: 16px;
    min-height: 44px;
  }

  .contact-section textarea {
    min-height: 120px;
  }

  .contact-methods li {
    padding: 12px 0;
  }

  .contact-section button[type="submit"] {
    width: 100%;
    min-height: var(--touch-target-size);
  }
}

/* Links Page */
@media (max-width: 767px) {
  .links-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .category-section {
    padding: 15px;
  }

  .action-buttons {
    flex-direction: column;
    gap: 10px;
  }

  .action-btn {
    width: 100%;
    min-height: var(--touch-target-size);
  }

  .link-item {
    padding: 10px;
    min-height: var(--touch-target-size);
  }
}

/* About Page */
@media (max-width: 767px) {
  .about-section {
    width: 95vw;
    padding: 20px;
  }

  .about-content p {
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 16px;
  }

  .about-content h3 {
    font-size: 1.3rem;
    margin-top: 24px;
    margin-bottom: 12px;
  }

  .about-content ul,
  .about-content ol {
    padding-left: 20px;
  }

  .about-content li {
    margin-bottom: 8px;
  }
}

/* Modal Enhancements for Mobile */
@media (max-width: 767px) {
  .modal-content {
    width: 95%;
    max-width: none;
    margin: 20px auto;
    padding: 20px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--err0r);
    border-radius: 50%;
    top: 10px;
    right: 10px;
    font-size: 1.5rem;
    cursor: pointer;
  }

  /* Modal inputs */
  .modal-content input,
  .modal-content textarea,
  .modal-content select {
    font-size: 16px;
    min-height: 44px;
  }

  .modal-content button {
    min-height: var(--touch-target-size);
    width: 100%;
    margin-top: 10px;
  }
}

/* ============================================
   PHASE 2: NAVIGATION & TOUCH INTERACTIONS
   ============================================ */

/* Hamburger Menu Button */
@media (max-width: 767px) {
  .nav-toggle {
    display: flex;
    position: fixed;
    top: 10px;
    right: 10px;
    width: var(--touch-target-size);
    height: var(--touch-target-size);
    background: var(--lightbg);
    border: 2px solid var(--borders);
    border-radius: 8px;
    z-index: 1001;
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 0;
  }

  .hamburger-line {
    width: 24px;
    height: 2px;
    background: var(--borders);
    transition: all 0.3s ease;
    display: block;
  }

  /* Hamburger animation when active */
  .nav-toggle.active .hamburger-line:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }

  .nav-toggle.active .hamburger-line:nth-child(2) {
    opacity: 0;
  }

  .nav-toggle.active .hamburger-line:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  /* Slide-in Navigation */
  .nav {
    position: fixed;
    top: 0;
    left: -100%;
    width: 80%;
    max-width: 300px;
    height: 100vh;
    background: var(--pagebg);
    border-right: 2px solid var(--borders);
    flex-direction: column;
    gap: 0;
    transition: left 0.3s ease;
    z-index: 1000;
    padding-top: 60px;
    overflow-y: auto;
  }

  .nav.nav-open {
    left: 0;
  }

  .nav a {
    width: 100%;
    padding: 16px 20px;
    border-bottom: 1px solid var(--borders);
    text-align: left;
    justify-content: flex-start;
  }

  /* Overlay backdrop */
  body.nav-overlay::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }
}

/* Hide hamburger on desktop */
@media (min-width: 768px) {
  .nav-toggle {
    display: none;
  }
}

/* Touch-Friendly Active States (Replace Hover) */
@media (max-width: 767px) {
  /* Table row active state */
  tr:active {
    background-color: var(--pagebg-highlight);
    border-left: 3px solid var(--borders);
  }

  /* Navigation active state */
  .nav a:active {
    background-color: var(--lightbg);
    transform: scale(0.98);
  }

  /* Tags active feedback */
  .tag:active {
    background-color: var(--borders);
    color: var(--pagebg);
    transform: scale(0.95);
  }

  /* Remove hover transform on mobile (doesn't work on touch) */
  .tag:hover {
    transform: none;
  }

  /* Download button active state */
  .download-btn:active {
    transform: scale(0.95);
    background-color: var(--headings);
  }

  /* Button active states */
  button:active {
    transform: scale(0.98);
    opacity: 0.9;
  }
}

/* ============================================
   FOOTER OPTIMIZATIONS
   ============================================ */

@media (max-width: 767px) {
  .sub-footer,
  .main-footer {
    padding: 15px 10px;
    font-size: 0.85rem;
  }

  .counter {
    font-size: 0.7rem;
    word-break: break-all;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

@media (max-width: 767px) {
  /* Hide on mobile */
  .hide-mobile {
    display: none !important;
  }

  /* Full width on mobile */
  .full-width-mobile {
    width: 100% !important;
  }

  /* Text center on mobile */
  .text-center-mobile {
    text-align: center !important;
  }
}

/* ============================================
   SMALL MOBILE (320px-479px) ADJUSTMENTS
   ============================================ */

@media (max-width: 479px) {
  body {
    font-size: 0.9rem;
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.3rem; }
  h3 { font-size: 1.1rem; }

  .header-image img {
    height: 50px;
  }

  .script-card {
    padding: 12px;
  }

  .card-meta {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .modal-content {
    margin: 10px auto;
    padding: 15px;
  }
}

/* ============================================
   TABLET (768px-1023px) ADJUSTMENTS
   ============================================ */

@media (min-width: 768px) and (max-width: 1023px) {
  /* Restore some desktop features but optimized for tablet */
  .header {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .search-bar {
    width: 300px;
  }

  /* Tablet might show table with fewer columns */
  .left-column {
    width: 65%;
  }

  .right-column {
    width: 35%;
  }
}

/* ============================================
   LANDSCAPE ORIENTATION OPTIMIZATIONS
   ============================================ */

@media (max-width: 767px) and (orientation: landscape) {
  .header {
    min-height: 80px;
    padding: 8px;
  }

  .header-image img {
    height: 40px;
  }

  .nav {
    width: 60%;
    max-width: 350px;
  }
}
