/* === 1440px+ === */
@media (min-width: 1440px) {
  .container, .pricing-grid, .features-grid {
    max-width: 1300px;
  }
  .hero h1 {
    font-size: 4.5rem;
  }
}

/* === 1024px - 1439px === */
@media (max-width: 1024px) {
  .checkout-layout {
    grid-template-columns: 1fr;
  }
  .order-summary {
    position: static;
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

/* Dashboard category cards responsive */
@media (max-width: 768px) {
  .dh-cat-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Home category cards responsive */
@media (max-width: 768px) {
  .categories-grid-home {
    grid-template-columns: 1fr !important;
  }
  .features-grid-home {
    grid-template-columns: 1fr !important;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .trusted-logos {
    gap: 20px !important;
  }
  .trusted-logos span {
    font-size: 0.9rem !important;
  }
  .footer-home .footer-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 24px !important;
  }
}

@media (max-width: 480px) {
  .footer-home .footer-grid {
    grid-template-columns: 1fr !important;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .stat-item .stat-number {
    font-size: 1.8rem !important;
  }
  .pricing-hero h1 {
    font-size: 1.8rem !important;
  }
}

/* Checkout layout responsive */
@media (max-width: 767px) {
  .checkout-layout-new {
    grid-template-columns: 1fr !important;
  }
  .checkout-summary {
    position: static !important;
    order: -1;
  }
  .payment-options {
    grid-template-columns: 1fr !important;
  }
}

/* === 768px - 1023px === */
@media (max-width: 768px) {
  header {
    bottom: 16px;
  }

  .dock-logo {
    top: 14px;
    left: 14px;
    padding: 6px 12px;
    font-size: 0.9rem;
  }

  .dock-logo i {
    font-size: 0.95rem;
  }

  .pill-nav {
    height: 46px;
    padding: 0 4px;
    gap: 0;
    max-width: calc(100vw - 16px);
  }

  .nav-links {
    display: flex;
    align-items: center;
    gap: 0;
    position: static;
    flex-direction: row;
    background: none;
    backdrop-filter: none;
    border: none;
    border-radius: 0;
    padding: 0;
    opacity: 1;
    pointer-events: all;
    max-height: none;
    overflow: visible;
    box-shadow: none;
    width: auto;
    transform: none;
  }

  .nav-links a,
  .nav-links .dropdown-trigger {
    height: 36px;
    padding: 0 10px;
    max-width: none;
    border-radius: 30px;
    gap: 6px;
    justify-content: flex-start;
    overflow: visible;
  }

  .nav-links a i:first-child,
  .nav-links .dropdown-trigger i:first-child {
    font-size: 0.9rem;
  }

  .nav-links a .dock-label,
  .nav-links .dropdown-trigger .dock-label {
    max-width: 0;
    opacity: 0;
    margin-left: 0;
    font-size: 0.68rem;
  }

  .nav-links a.active .dock-label,
  .nav-links .dropdown-trigger.active .dock-label {
    max-width: 90px;
    opacity: 1;
    margin-left: 6px;
    font-size: 0.68rem;
  }

  .nav-right {
    gap: 2px;
    padding-left: 4px;
    margin-left: 2px;
  }

  .dock-auth-btn {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    max-width: 30px;
  }

  .dock-auth-btn i {
    font-size: 0.8rem !important;
  }

  .dock-auth-btn:hover {
    max-width: 100px;
    padding: 0 8px 0 5px !important;
    gap: 3px !important;
    background: rgba(128, 128, 128, 0.1);
  }

  .logout-btn {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    max-width: 30px;
  }

  .logout-btn:hover {
    max-width: 100px;
    padding: 0 8px 0 5px !important;
    gap: 3px !important;
  }

  .theme-switch-label {
    width: 30px;
    height: 30px;
  }

  .theme-switch {
    width: 26px;
    height: 14px;
  }

  .theme-switch-slider::before {
    width: 10px;
    height: 10px;
  }

  .theme-switch input:checked + .theme-switch-slider::before {
    transform: translateX(12px);
  }

  .eye-toggle {
    width: 28px;
    height: 28px;
    font-size: 0.8rem;
  }

  .pill-nav.tucked {
    width: 38px;
    height: 38px;
  }

  .pill-nav.tucked .eye-toggle {
    font-size: 0.95rem;
  }

  .mega-column a {
    justify-content: flex-start;
    text-align: left;
  }

  .header-dropdown .dropdown-menu {
    position: static;
    bottom: auto;
    transform: none;
    opacity: 1;
    pointer-events: all;
    display: none;
    width: 100%;
    margin-top: 4px;
    box-shadow: none;
    border-radius: 12px;
    border: 1px solid var(--border);
    max-height: none;
  }

  .header-dropdown .dropdown-menu.open {
    display: block;
  }

  .mega-menu {
    position: static;
    bottom: auto;
    transform: none;
    opacity: 1;
    pointer-events: all;
    display: none;
    flex-direction: column;
    gap: 6px;
    max-width: 100%;
    width: 100%;
    border-radius: 12px;
    margin-top: 4px;
    box-shadow: none;
    border: 1px solid var(--border);
    max-height: none;
    overflow-y: visible;
    padding: 10px;
  }

  .header-dropdown.mega-dropdown:hover .mega-menu,
  .header-dropdown.mega-dropdown .mega-menu.open {
    display: flex;
  }

  .mega-column {
    min-width: auto;
    max-width: none;
    width: 100%;
  }

  .mega-column a {
    justify-content: flex-start;
  }

  .nav-right {
    gap: 2px;
    padding-left: 4px;
    margin-left: 2px;
  }

  .nav-links a.active,
  .nav-links .dropdown-trigger.active {
    max-width: 120px;
    padding: 0 10px;
    gap: 4px;
  }

  .hero h1 {
    font-size: 2.5rem;
  }

  .hero p {
    font-size: 1rem;
  }

  .features-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .pricing-grid {
    grid-template-columns: 1fr;
    gap: 25px;
    max-width: 400px;
    margin: 0 auto;
  }

  .pricing-card.popular {
    transform: none;
  }

  .pricing-card.popular:hover {
    transform: translateY(-8px);
  }

  .steps {
    flex-direction: column;
    align-items: center;
  }

  .step-connector {
    display: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }

  .stat-item h2 {
    font-size: 2.2rem;
  }

  .payment-methods {
    grid-template-columns: repeat(2, 1fr);
  }

  .auth-card {
    padding: 30px 25px;
  }

  /* Dashboard mobile */
  .dashboard-sidebar {
    transform: translateX(-100%);
  }

  .dashboard-sidebar.open {
    transform: translateX(0);
  }

  .dashboard-main {
    margin-left: 0;
    padding: 20px;
  }

  .tab-bar {
    gap: 5px;
  }

  .tab-btn {
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  .tool-options {
    flex-direction: column;
    gap: 12px;
  }

  .card-row {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    transform: translateX(-100%);
    z-index: 101;
  }

  .admin-sidebar.open {
    transform: translateX(0);
  }

  .admin-main {
    margin-left: 0;
    padding: 20px;
  }

  .stats-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .footer-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* === 480px - 767px === */
@media (max-width: 480px) {
  section {
    padding: 60px 4%;
  }

  .hero {
    padding: 100px 4% 60px;
  }

  .hero h1 {
    font-size: 2rem;
  }

  .hero-buttons {
    flex-direction: column;
    align-items: center;
  }

  .hero-buttons .btn {
    width: 100%;
    max-width: 250px;
  }

  .section-title {
    font-size: 1.8rem;
  }

  .feature-card {
    padding: 25px 20px;
  }

  .pricing-card {
    padding: 30px 20px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 15px;
  }

  .payment-methods {
    grid-template-columns: 1fr 1fr;
  }

  .history-filters {
    flex-direction: column;
  }

  .admin-filters {
    flex-direction: column;
  }

  .stats-cards {
    grid-template-columns: 1fr;
  }

  .footer-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    padding: 30px 20px;
  }

  .modal-buttons {
    flex-direction: column;
  }

  .preview-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Admin mobile hamburger */
.admin-hamburger {
  display: none;
  position: fixed;
  top: 15px;
  left: 15px;
  z-index: 110;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text);
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px var(--shadow);
}

.admin-hamburger i {
  pointer-events: none;
}

@media (max-width: 768px) {
  .admin-hamburger {
    display: flex;
  }
  .admin-sidebar {
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .admin-sidebar.open {
    transform: translateX(0);
  }
  .admin-main {
    margin-left: 0;
    padding: 20px;
    padding-top: 60px;
  }
}

/* Dashboard mobile enhancements */
@media (max-width: 768px) {
  .dashboard-sidebar {
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .dashboard-sidebar.open {
    transform: translateX(0);
  }
  .dashboard-main {
    margin-left: 0;
    padding: 20px;
    padding-top: 20px;
  }
  .tool-card-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }
  .tool-card {
    padding: 12px 8px;
  }
  .tool-card-icon {
    width: 36px;
    height: 36px;
    font-size: 0.95rem;
  }
  .tool-card-label {
    font-size: 0.75rem;
  }
}

/* Smooth page transitions */
body {
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
}

/* === 320px - 479px === */
@media (max-width: 479px) {
  .hero h1 {
    font-size: 1.6rem;
  }

  .btn {
    padding: 10px 20px;
    font-size: 0.85rem;
  }

  .dock-logo {
    top: 10px;
    left: 10px;
    padding: 4px 8px;
    font-size: 0.8rem;
  }
  .dock-logo i {
    font-size: 0.85rem;
  }
  header {
    bottom: 10px;
  }
  .pill-nav {
    height: 42px;
    padding: 0 3px;
    gap: 0;
    max-width: calc(100vw - 12px);
  }
  .nav-links a,
  .nav-links .dropdown-trigger {
    height: 32px;
    max-width: none;
    padding: 0 8px;
    gap: 4px;
  }
  .nav-links a i:first-child,
  .nav-links .dropdown-trigger i:first-child {
    font-size: 0.85rem;
  }
  .nav-links a .dock-label,
  .nav-links .dropdown-trigger .dock-label {
    max-width: 0;
    opacity: 0;
    margin-left: 0;
    font-size: 0.62rem;
  }

  .nav-links a.active .dock-label,
  .nav-links .dropdown-trigger.active .dock-label {
    max-width: 90px;
    opacity: 1;
    margin-left: 4px;
    font-size: 0.62rem;
  }

  .nav-right {
    gap: 1px;
    padding-left: 3px;
    margin-left: 1px;
  }
  .dock-auth-btn {
    width: 26px !important;
    height: 26px !important;
    min-width: 26px !important;
    max-width: 26px;
  }
  .dock-auth-btn i {
    font-size: 0.7rem !important;
  }
  .dock-auth-btn:hover {
    max-width: 80px;
    padding: 0 6px 0 4px !important;
    gap: 2px !important;
    background: rgba(128, 128, 128, 0.1);
  }
  .logout-btn {
    width: 26px !important;
    height: 26px !important;
    min-width: 26px !important;
    max-width: 26px;
  }
  .logout-btn:hover {
    max-width: 80px;
    padding: 0 6px 0 4px !important;
    gap: 2px !important;
  }
  .theme-switch-label {
    width: 26px;
    height: 26px;
  }
  .theme-switch {
    width: 22px;
    height: 12px;
  }
  .theme-switch-slider::before {
    width: 8px;
    height: 8px;
  }
  .theme-switch input:checked + .theme-switch-slider::before {
    transform: translateX(10px);
  }

  .eye-toggle {
    width: 24px;
    height: 24px;
    font-size: 0.7rem;
  }

  .pill-nav.tucked {
    width: 32px;
    height: 32px;
  }

  .pill-nav.tucked .eye-toggle {
    font-size: 0.85rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .preview-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 20px 15px;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .admin-section h2 {
    font-size: 1.3rem;
  }

  .stat-card .stat-number {
    font-size: 1.5rem;
  }
}

@media (max-width: 768px) {
  .dock-logo.right {
    left: auto;
    right: 10px;
    top: 10px;
  }
}

@media (max-width: 479px) {
  .dock-logo.right {
    right: 8px;
    top: 8px;
  }
}

/* Responsive top-right profile icon */
@media (max-width: 768px) {
  .top-right-profile {
    top: 14px !important;
    right: 14px !important;
    width: 36px !important;
    height: 36px !important;
    font-size: 1.2rem !important;
  }
}
@media (max-width: 479px) {
  .top-right-profile {
    top: 10px !important;
    right: 10px !important;
    width: 32px !important;
    height: 32px !important;
    font-size: 1rem !important;
  }
}

/* === TOOL PAGE RESPONSIVE FIXES === */

/* Tool page main heading */
@media (max-width: 768px) {
  .tool-page-main h1,
  #toolPageTitle {
    font-size: 1.5rem !important;
  }
  .tool-page-main .container > div:first-child p,
  #toolPageDesc {
    font-size: 0.85rem !important;
  }
  /* Tool page options area */
  #toolPageOptions {
    padding: 16px !important;
  }
  /* Drop zone mobile */
  .drop-zone {
    padding: 30px 16px !important;
  }
  .drop-zone i {
    font-size: 2rem !important;
  }
  .drop-zone h3 {
    font-size: 1rem !important;
  }
  .drop-zone p {
    font-size: 0.8rem !important;
  }
  /* Convert area */
  #convertArea > div,
  #downloadArea > div {
    padding: 16px !important;
  }
  #convertHeading {
    font-size: 1rem !important;
  }
  /* Tool run button */
  #toolRunBtn {
    padding: 12px 24px !important;
    font-size: 0.95rem !important;
  }
  /* Start convert button */
  #startConvertBtn {
    padding: 10px 24px !important;
    font-size: 0.9rem !important;
  }
  /* Tool page footer */
  .tool-page-main + footer .footer,
  .tool-page-main ~ footer {
    padding: 20px 16px !important;
  }
}

@media (max-width: 480px) {
  .tool-page-main h1,
  #toolPageTitle {
    font-size: 1.3rem !important;
  }
  #toolPageOptions {
    padding: 12px !important;
  }
  .drop-zone {
    padding: 20px 12px !important;
  }
  .drop-zone i {
    font-size: 1.6rem !important;
  }
}

/* === CHECKOUT RESPONSIVE === */
@media (max-width: 640px) {
  .payment-options {
    grid-template-columns: 1fr !important;
  }
  .checkout-layout-new {
    grid-template-columns: 1fr !important;
  }
  .checkout-summary {
    position: static !important;
  }
  .checkout-form > div {
    padding: 20px 16px !important;
  }
  .checkout-section h2 {
    font-size: 1.5rem !important;
  }
  /* Card expiry row */
  .checkout-form [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
}

/* === PRICING PAGE RESPONSIVE === */
@media (max-width: 640px) {
  .pricing-tabs {
    flex-direction: column;
    max-width: 100%;
    border-radius: 12px;
  }
  .pricing-tab {
    padding: 12px 16px;
  }
  .billing-toggle {
    flex-wrap: wrap;
    gap: 10px;
  }
}

/* === GENERAL TOUCH TARGET & OVERFLOW FIXES === */
@media (max-width: 768px) {
  /* Ensure all buttons have minimum touch target */
  .btn-sm {
    min-height: 44px;
    padding: 10px 18px !important;
  }
  .btn {
    min-height: 44px;
  }
  /* Ensure no horizontal overflow on body */
  body {
    overflow-x: hidden;
    width: 100%;
  }
  /* Ensure all main wrappers don't overflow */
  main, .container, .tool-page-main {
    max-width: 100vw;
    overflow-x: hidden;
  }
  /* Fix any image/iframe overflow */
  img, video, canvas, iframe {
    max-width: 100%;
    height: auto;
  }
  /* tables should scroll */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Ensure inputs don't overflow */
  input, select, textarea {
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* === PROFILE PAGE RESPONSIVE === */
@media (max-width: 640px) {
  .profile-page-wrap {
    padding: 80px 16px 30px !important;
  }
  .profile-card {
    padding: 24px 20px !important;
  }
  .profile-avatar-wrap .avatar-img {
    width: 90px !important;
    height: 90px !important;
    font-size: 2.2rem !important;
  }
  .crop-container {
    height: 260px !important;
  }
}

/* === BACKGROUND REMOVER / SPECIAL PAGES === */
@media (max-width: 768px) {
  .tool-icon-large {
    width: 48px !important;
    height: 48px !important;
    font-size: 1.3rem !important;
  }
}

/* === CATEGORY PAGE RESPONSIVE === */
@media (max-width: 768px) {
  .category-page-main h1 {
    font-size: 1.5rem !important;
  }
}

/* === ADMIN DASHBOARD MOBILE FIXES === */
@media (max-width: 480px) {
  .admin-filters {
    flex-direction: column;
    gap: 8px;
  }
  .admin-filters input,
  .admin-filters select {
    width: 100%;
  }
  .admin-table-wrapper {
    margin: 0 -16px;
    border-radius: 0;
  }
  .admin-table th {
    font-size: 0.72rem;
    padding: 10px 10px;
  }
  .admin-table td {
    font-size: 0.78rem;
    padding: 10px 10px;
  }
  .admin-table {
    min-width: 500px;
  }
  .admin-main h2 {
    font-size: 1.2rem !important;
  }
  .stat-card .stat-number {
    font-size: 1.4rem !important;
  }
  .admin-main {
    padding: 60px 12px 20px !important;
  }
  .settings-card {
    padding: 16px !important;
  }
}

/* === AI STUDIO MOBILE IMPROVEMENTS === */
@media (max-width: 480px) {
  .studio-tab-btn {
    padding: 8px 10px !important;
    font-size: 0.75rem !important;
  }
  .studio-tab-btn span {
    display: none;
  }
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
    gap: 8px !important;
  }
  .prompt-bar-inline .prompt-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .studio-canvas {
    min-height: 220px !important;
  }
  .studio-sidebar-page {
    width: 260px !important;
  }
  .mobile-studio-nav-panel {
    width: 260px !important;
  }
}

/* === FLOATING DOCK NAVBAR SAFE AREA === */
@media (max-width: 768px) {
  header {
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
  }
}

/* === IMAGE COMPARISON / BEFORE-AFTER SLIDER === */
@media (max-width: 640px) {
  .before-after-container {
    flex-direction: column !important;
    gap: 16px !important;
  }
  .before-after-container > div {
    width: 100% !important;
  }
}

/* === UNIT CONVERTER (already partially done in tools.css, enhance) === */
@media (max-width: 480px) {
  .unit-converter-grid {
    gap: 8px !important;
  }
}

/* === TIMELINE / STEPS (how it works) === */
@media (max-width: 640px) {
  .step {
    min-width: 100% !important;
    max-width: 100% !important;
  }
}

/* === HOMEPAGE SPECIFIC FIXES === */
@media (max-width: 480px) {
  .hero-home {
    padding: 100px 12px 50px !important;
  }
  .hero-badge {
    font-size: 0.75rem !important;
    padding: 6px 14px !important;
  }
  .cta-section {
    padding: 50px 16px !important;
  }
  .cta-section h2 {
    font-size: 1.5rem !important;
  }
  .search-wrapper {
    max-width: 100% !important;
  }
  .search-wrapper input {
    padding: 12px 16px 12px 40px !important;
    font-size: 0.85rem !important;
  }
  .search-wrapper i {
    left: 14px !important;
  }
  .category-card-home {
    padding: 16px 18px !important;
    gap: 14px !important;
  }
  .category-card-home .cat-icon {
    width: 44px !important;
    height: 44px !important;
    font-size: 1.15rem !important;
  }
  .category-card-home .cat-info h4 {
    font-size: 0.85rem !important;
  }
  .category-card-home .cat-info p {
    font-size: 0.75rem !important;
  }
  .category-card-home .cat-arrow {
    width: 30px !important;
    height: 30px !important;
    font-size: 0.85rem !important;
  }
  .feature-card-home {
    padding: 20px 18px !important;
  }
  .feature-card-home .icon {
    width: 42px !important;
    height: 42px !important;
    font-size: 1.1rem !important;
  }
  .feature-card-home h3 {
    font-size: 0.9rem !important;
  }
  .feature-card-home p {
    font-size: 0.82rem !important;
  }
}

/* === DASHBOARD MOBILE SIDEBAR OVERLAY === */
@media (max-width: 768px) {
  .dashboard-sidebar {
    box-shadow: 4px 0 30px rgba(0,0,0,0.2);
    width: 280px !important;
  }
  .dash-sidebar-close {
    display: flex !important;
  }
}

/* === DASHBOARD TOOL CARD GRID EXTRA SMALL === */
@media (max-width: 420px) {
  .tool-card-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .tool-card {
    padding: 10px 6px !important;
  }
  .tool-card-label {
    font-size: 0.68rem !important;
  }
  .tool-card-icon {
    width: 32px !important;
    height: 32px !important;
    font-size: 0.85rem !important;
  }
  .dashboard-section h2 {
    font-size: 1.2rem !important;
  }
}

/* === CHECKOUT PLAN AND PRICE MOBILE === */
@media (max-width: 480px) {
  .order-plan {
    font-size: 1rem !important;
  }
  .order-price {
    font-size: 1.4rem !important;
  }
}

/* === MODAL RESPONSIVE === */
@media (max-width: 480px) {
  .modal {
    padding: 24px 16px !important;
    width: 95% !important;
  }
  .modal i {
    font-size: 2rem !important;
  }
  .modal h3 {
    font-size: 1.2rem !important;
  }
}

/* === LOGIN/SIGNUP PHONE AUTH === */
@media (max-width: 480px) {
  .phone-btn-full {
    max-width: 100% !important;
  }
}
