/* Desktop Large (1400px+) */
@media (max-width: 1400px) {
  .container {
    max-width: 1140px;
  }

  .grid-4 {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Desktop (1200px) */
@media (max-width: 1200px) {
  .container {
    max-width: 960px;
  }

  .footer-grid {
    grid-template-columns: 2fr 1fr 1fr;
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Laptop (1024px) */
@media (max-width: 1024px) {
  .container {
    max-width: 100%;
    padding: 0 20px;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding: calc(var(--header-height) + 24px) 20px 24px 20px;
  }

  .header-nav {
    display: none;
  }

  .header-nav.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 20px 24px;
    gap: 16px;
    animation: fadeIn 0.3s ease;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .section-title {
    font-size: 28px;
  }
}

/* Tablet (768px) */
@media (max-width: 768px) {
  html {
    font-size: 15px;
  }

  .header-logo {
    font-size: 18px;
  }

  .header-logo img {
    height: 30px;
  }

  .header-actions .btn span {
    display: none;
  }

  .footer-grid {
    grid-template-columns: 1fr 1fr;
  }

  .footer-brand {
    grid-column: 1 / -1;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .grid-4,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .section-title {
    font-size: 24px;
  }

  .section-padding {
    padding: 60px 0;
  }

  .auth-card {
    padding: 28px 24px;
  }

  .page-title {
    font-size: 22px;
  }

  .welcome-name {
    font-size: 1.85rem;
  }

  .welcome-section {
    padding: 22px 18px 24px;
  }

  .welcome-title {
    font-size: 1.35rem;
  }

  .dashboard-header {
    flex-direction: column;
    align-items: stretch;
  }

  .dashboard-header-left {
    flex-direction: column;
    align-items: stretch;
  }

  .dashboard-search {
    min-width: 100%;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar .input-field,
  .filter-bar .select-field {
    width: 100%;
    min-width: 100%;
  }

  .content-card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .content-card-header .search-input {
    width: 100%;
    min-width: 0;
  }

  .content-card-header .search-input input {
    min-width: 0;
    width: 100%;
    flex: 1;
  }

  .table-container {
    margin: 0;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0;
  }

  .content-card {
    max-width: 100%;
    min-width: 0;
  }

  .main-content {
    max-width: 100vw;
    min-width: 0;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  .pagination {
    flex-wrap: wrap;
    max-width: 100%;
    padding: 0 4px;
  }

  .modal {
    padding: 24px 20px;
    max-width: 95%;
  }

  .toast {
    min-width: 0;
    max-width: calc(100vw - 40px);
  }

  .referral-box {
    flex-direction: column;
  }

  .referral-box input {
    width: 100%;
  }

  .nft-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile (480px) */
@media (max-width: 480px) {
  .container {
    padding: 0 16px;
  }

  .header-inner {
    padding: 0 16px;
  }

  .main-content {
    padding: calc(var(--header-height) + 20px) 16px 20px 16px;
  }

  .header-logo .logo-caption {
    display: none;
  }

  /* Keep brand name "Titan Vista" visible on mobile */
  .header-logo-name {
    display: block !important;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
    font-size: 15px;
  }

  .header-logo-text {
    display: flex !important;
  }

  .footer-grid {
    grid-template-columns: 1fr;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
  }

  .section-title {
    font-size: 20px;
  }

  .stat-card-value {
    font-size: 22px;
  }

  .auth-card {
    padding: 24px 20px;
  }

  .auth-header h1 {
    font-size: 20px;
  }

  .welcome-stats {
    flex-direction: column;
    gap: 12px;
  }

  .stats-grid {
    gap: 12px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .nft-grid {
    grid-template-columns: 1fr;
  }

  .matrix-node {
    width: 64px;
    height: 64px;
  }

  .matrix-node-icon {
    font-size: 16px;
  }
}

/* Large Mobile (360px) */
@media (max-width: 360px) {
  html {
    font-size: 14px;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-card-icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}

/* Sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 850;
}

.sidebar-overlay.active {
  display: block;
}

@media (max-width: 1024px) {
  .sidebar-overlay.active {
    display: block;
  }
}

/* ---- Mobile overflow / partners & tables ---- */
@media (max-width: 768px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .header .header-inner {
    padding-left: 12px !important;
    padding-right: 12px !important;
    gap: 8px;
    min-width: 0;
  }

  .header .header-inner > div {
    min-width: 0;
  }

  .header .wallet-btn {
    max-width: min(46vw, 160px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 1;
  }

  .header .wallet-btn #wallet-btn-text,
  .header .wallet-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header .notification-btn {
    flex-shrink: 0;
  }

  table {
    min-width: 560px;
  }

  th,
  td {
    padding: 12px 10px;
    font-size: 12px;
  }

  .search-input {
    width: 100%;
    box-sizing: border-box;
  }

  .search-input input {
    min-width: 0 !important;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .main-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .content-card-header {
    padding: 14px 14px;
  }

  .content-card-header h3 {
    font-size: 15px;
  }

  .header .wallet-btn {
    font-size: 11px !important;
    padding: 6px 10px !important;
    max-width: min(42vw, 140px);
  }

  /* Matrix page: tighter header so tree gets more space */
  body:has(.matrix-tree-page) .main-content.matrix-tree-page {
    padding-top: calc(var(--header-height) + 10px);
    padding-left: 0;
    padding-right: 0;
  }
}
