/* ==========================================
   UNIVERSAL MOBILE RESPONSIVE STYLES
   For: dashboard.php, protection.php, analytics.php, settings.php, billing.php
   ========================================== */

/* Prevent horizontal scroll on all devices */
html,
body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

* {
  box-sizing: border-box;
}

/* Mobile menu button */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 1001;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  color: var(--text-main);
  cursor: pointer;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
}

.mobile-menu-btn i {
  font-size: 1.25rem;
}

/* Mobile overlay */
.mobile-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-overlay.active {
  opacity: 1;
}

/* ==========================================
   TABLET BREAKPOINT (768px and below)
   ========================================== */
@media (max-width: 768px) {
  /* Show mobile menu button */
  .mobile-menu-btn {
    display: flex;
  }

  .mobile-overlay {
    display: block;
  }

  /* Sidebar mobile behavior */
  .sidebar {
    transform: translateX(-100%);
    width: 280px !important;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  }

  /* Main content - properly centered */
  .main-content {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: 1rem !important;
    padding-top: 5rem !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  /* Top bar responsive */
  .top-bar {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 1rem;
    width: 100%;
    margin-bottom: 1.5rem;
  }

  .top-bar h1 {
    font-size: 1.5rem !important;
    width: 100%;
    word-wrap: break-word;
  }

  .top-bar-controls,
  .top-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  /* Buttons responsive */
  .btn-primary,
  .btn-secondary {
    width: 100%;
    justify-content: center;
    padding: 0.875rem 1rem;
    font-size: 0.875rem;
    text-align: center;
  }

  /* Stats grid - 2 columns on tablet */
  .stats-grid,
  .stats-overview {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.875rem !important;
    width: 100%;
  }

  .stat-card {
    padding: 1.25rem 1rem;
    min-height: auto;
  }

  .stat-value {
    font-size: 1.5rem !important;
  }

  .stat-title,
  .stat-label {
    font-size: 0.75rem !important;
  }

  /* Section headers */
  .section-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 1rem;
    padding: 1rem 0;
  }

  .section-header h2 {
    font-size: 1.25rem;
  }

  /* Domain cards */
  .domain-list {
    gap: 0.75rem;
  }

  .domain-card {
    padding: 1rem;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 1rem;
  }

  .domain-info {
    width: 100%;
  }

  .domain-name {
    font-size: 1rem;
    flex-wrap: wrap;
  }

  .domain-stats {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem;
    margin: 0 !important;
  }

  .domain-stat {
    text-align: left;
  }

  .domain-actions {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem;
  }

  .btn-small {
    font-size: 0.75rem;
    padding: 0.5rem 0.75rem;
    text-align: center;
    justify-content: center;
  }

  /* Forms responsive */
  .form-row {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  .form-group label {
    font-size: 0.875rem;
  }

  .form-control {
    font-size: 0.875rem;
    padding: 0.75rem;
  }

  .form-actions {
    flex-direction: column;
    gap: 0.75rem;
  }

  .form-actions .btn-primary,
  .form-actions .btn-secondary {
    width: 100%;
  }

  /* Settings grid */
  .settings-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  .settings-card {
    padding: 1.25rem;
  }

  .settings-card h3 {
    font-size: 1rem;
  }

  /* API key display */
  .api-key-display {
    flex-direction: column;
    gap: 0.75rem;
  }

  .api-key-display input {
    width: 100%;
  }

  .api-key-display button {
    width: 100%;
  }

  /* Plans grid - billing page */
  .plans-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  .plan-card {
    padding: 1.5rem;
  }

  .plan-name {
    font-size: 1.25rem;
  }

  .plan-price {
    font-size: 2rem;
  }

  /* Analytics specific */
  .analytics-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  .analytics-tabs {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .tab-btn {
    flex: 1;
    min-width: calc(50% - 0.25rem);
    font-size: 0.8rem;
    padding: 0.6rem 0.75rem;
    text-align: center;
    justify-content: center;
  }

  .chart-section {
    padding: 1rem;
  }

  .chart-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 1rem;
  }

  .chart-container {
    height: 250px !important;
  }

  .time-selector {
    width: 100%;
    flex-wrap: wrap;
  }

  .time-btn {
    flex: 1;
    min-width: calc(33.33% - 0.5rem);
    text-align: center;
  }

  .detailed-analytics {
    grid-template-columns: 1fr !important;
  }

  .threat-analysis {
    padding: 1rem;
  }

  .threat-item {
    padding: 0.75rem;
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.5rem;
  }

  .waf-stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Tables responsive */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table th,
  .data-table td {
    font-size: 0.75rem;
    padding: 0.5rem;
    white-space: nowrap;
  }

  /* Domain selector */
  .domain-selector {
    width: 100%;
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.5rem;
  }

  .domain-selector select {
    width: 100%;
  }

  /* Refresh button */
  .refresh-btn {
    width: 100%;
    justify-content: center;
  }

  /* API status */
  .api-status {
    width: 100%;
    justify-content: center;
  }

  /* SSL section */
  .ssl-section {
    padding: 1rem;
  }

  .ssl-buttons {
    flex-direction: column;
    gap: 0.75rem;
  }

  .ssl-buttons button {
    width: 100%;
  }

  .dns-info-box,
  .cert-download-box {
    padding: 1rem;
  }

  .dns-info-box code {
    word-break: break-all;
    font-size: 0.75rem;
  }

  /* Modals */
  .modal-content {
    width: 95% !important;
    max-width: 95% !important;
    margin: 1rem auto;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.25rem;
  }

  /* Tab buttons */
  .tab-buttons {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .tab-button {
    flex: 1;
    min-width: calc(50% - 0.25rem);
    font-size: 0.875rem;
    padding: 0.75rem;
    text-align: center;
  }

  /* Toast notifications */
  .toast-container {
    top: 1rem;
    right: 1rem;
    left: 1rem;
  }

  .toast {
    min-width: auto;
    width: 100%;
  }

  /* Add domain form */
  .add-domain-form {
    padding: 1.25rem;
  }

  /* Protection page specific */
  .protection-stats {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Info messages */
  .info-message,
  .success-message,
  .error-message {
    padding: 1rem;
    font-size: 0.875rem;
  }

  /* Current plan info - billing */
  .current-plan-info {
    margin-bottom: 1.5rem;
  }

  .current-plan-info h3 {
    font-size: 1.1rem;
  }

  .current-plan-info p {
    font-size: 0.85rem;
  }
}

/* ==========================================
   SMALL MOBILE BREAKPOINT (480px and below)
   ========================================== */
@media (max-width: 480px) {
  .main-content {
    padding: 0.875rem !important;
    padding-top: 4.5rem !important;
  }

  .mobile-menu-btn {
    top: 0.75rem;
    left: 0.75rem;
    width: 40px;
    height: 40px;
    padding: 0.5rem;
  }

  .top-bar h1 {
    font-size: 1.25rem !important;
  }

  /* Single column stats on very small screens */
  .stats-grid,
  .stats-overview {
    grid-template-columns: 1fr !important;
  }

  .stat-card {
    padding: 1.25rem;
  }

  .stat-value {
    font-size: 1.75rem !important;
  }

  /* Single column domain actions */
  .domain-actions {
    grid-template-columns: 1fr !important;
  }

  .domain-stats {
    grid-template-columns: 1fr !important;
  }

  /* Analytics tabs - full width */
  .tab-btn {
    min-width: 100%;
  }

  .time-btn {
    min-width: calc(50% - 0.25rem);
  }

  /* WAF stats single column */
  .waf-stats-grid {
    grid-template-columns: 1fr !important;
  }

  /* Settings card */
  .settings-card {
    padding: 1rem;
  }

  .settings-card h3 {
    font-size: 0.95rem;
    flex-wrap: wrap;
  }

  /* Plan cards */
  .plan-card {
    padding: 1.25rem;
  }

  .plan-price {
    font-size: 1.75rem;
  }

  .plan-features li {
    font-size: 0.8rem;
  }

  /* Chart container smaller */
  .chart-container {
    height: 200px !important;
  }

  /* Section headers */
  .section-header h2 {
    font-size: 1.1rem;
  }

  /* Threat items */
  .threat-count {
    font-size: 1rem;
  }

  .threat-type {
    font-size: 0.8rem;
  }

  /* Protection stats */
  .protection-stats {
    grid-template-columns: 1fr !important;
  }

  /* Tab buttons single column */
  .tab-button {
    min-width: 100%;
  }

  /* Logs container */
  .logs-container {
    max-height: 300px;
  }

  .log-item {
    padding: 0.75rem;
    font-size: 0.75rem;
  }
}

/* ==========================================
   LANDSCAPE ORIENTATION FIXES
   ========================================== */
@media (max-width: 768px) and (orientation: landscape) {
  .main-content {
    padding-top: 4rem !important;
  }

  .sidebar.mobile-open {
    width: 250px !important;
  }

  .chart-container {
    height: 180px !important;
  }
}
