/* ==========================================================================
   ADL ROOFING SOLUTIONS, INC. - ADMIN DASHBOARD STYLE SHEET
   ========================================================================== */

:root {
  --admin-dark: #1e2229;
  --admin-dark-light: #2c313c;
  --admin-blue: #007bff;
  --admin-blue-light: rgba(0, 123, 255, 0.1);
  --admin-green: #28a745;
  --admin-red: #dc3545;
  --admin-bg: #f4f6f9;
  --admin-card-bg: #ffffff;
  --admin-text-dark: #333333;
  --admin-text-muted: #888888;
}

body.admin-body {
  background-color: var(--admin-bg);
  font-family: 'Open Sans', sans-serif;
  color: var(--admin-text-dark);
  margin: 0;
  padding: 0;
}

/* Dashboard Layout */
.admin-header {
  background-color: var(--admin-dark);
  color: white;
  padding: 15px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.admin-header h1 {
  font-size: 1.4rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-header h1 span {
  font-size: 0.8rem;
  background-color: var(--color-gold);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
}

.admin-nav {
  display: flex;
  gap: 15px;
}

.admin-nav-link {
  color: #a0a5b1;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 15px;
  border-radius: 4px;
  transition: all 0.3s;
}

.admin-nav-link:hover, .admin-nav-link.active {
  color: white;
  background-color: var(--admin-dark-light);
}

.admin-main {
  max-width: 1300px;
  margin: 30px auto;
  padding: 0 20px;
}

/* Stats Cards */
.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

.admin-stat-card {
  background-color: var(--admin-card-bg);
  padding: 25px;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
  border-left: 5px solid var(--admin-blue);
  display: flex;
  flex-direction: column;
}

.admin-stat-card.visits { border-left-color: var(--admin-blue); }
.admin-stat-card.submissions { border-left-color: var(--admin-green); }
.admin-stat-card.conversion { border-left-color: var(--color-gold); }
.admin-stat-card.scroll { border-left-color: #6f42c1; }

.admin-stat-title {
  font-size: 0.85rem;
  color: var(--admin-text-muted);
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.admin-stat-val {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--admin-text-dark);
  line-height: 1;
}

/* Content Grid */
.admin-content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(0, 1.2fr);
  gap: 30px;
}

.admin-content-grid > * {
  min-width: 0;
}

.admin-card {
  background-color: var(--admin-card-bg);
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
  margin-bottom: 30px;
  overflow: hidden;
}

.admin-card-header {
  padding: 20px;
  border-bottom: 1px solid var(--color-border-gray);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fafbfc;
}

.admin-card-header h2 {
  font-size: 1.1rem;
  margin: 0;
  font-weight: 700;
}

.admin-card-body {
  padding: 20px;
}

/* API Configuration Box */
.api-config-row {
  display: flex;
  gap: 15px;
  align-items: center;
}

/* Media Uploader Styles */
.media-section {
  margin-bottom: 30px;
}

.media-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 15px;
  color: var(--admin-text-dark);
  border-bottom: 1px dashed var(--color-border-gray);
  padding-bottom: 8px;
}

.drag-drop-zone {
  border: 2px dashed #ccd1d9;
  border-radius: 6px;
  padding: 30px;
  text-align: center;
  cursor: pointer;
  background-color: #fafbfc;
  transition: all 0.3s;
}

.drag-drop-zone:hover, .drag-drop-zone.dragover {
  border-color: var(--color-gold);
  background-color: rgba(229, 169, 60, 0.04);
}

.drag-drop-icon {
  font-size: 2rem;
  color: var(--admin-text-muted);
  margin-bottom: 10px;
}

.drag-drop-text {
  font-size: 0.9rem;
  font-weight: 600;
}

.drag-drop-subtext {
  font-size: 0.75rem;
  color: var(--admin-text-muted);
  margin-top: 5px;
}

/* Upload Progress */
.upload-progress-container {
  margin-top: 15px;
  display: none;
}

.upload-progress-bar {
  height: 6px;
  background-color: #e9ecef;
  border-radius: 3px;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  width: 0%;
  background-color: var(--admin-green);
  transition: width 0.1s;
}

.upload-status-text {
  font-size: 0.8rem;
  color: var(--admin-text-muted);
  margin-top: 5px;
  text-align: right;
}

/* Image Previews & Lists */
.hero-preview-container {
  display: flex;
  gap: 20px;
  align-items: center;
  background-color: #f8f9fa;
  padding: 15px;
  border-radius: 6px;
}

.hero-preview-img {
  width: 120px;
  height: 75px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #ccd1d9;
}

.hero-preview-info {
  font-size: 0.85rem;
}

/* Portfolio grid editor */
.portfolio-edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 15px;
  margin-top: 15px;
}

.portfolio-edit-card {
  position: relative;
  border-radius: 6px;
  border: 1px solid var(--color-border-gray);
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
}

.portfolio-edit-img-container {
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  aspect-ratio: 4/3;
}

.portfolio-edit-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portfolio-edit-controls {
  display: flex;
  justify-content: space-around;
  background: #f1f3f5;
  border-radius: 4px;
  padding: 4px;
}

.portfolio-control-btn {
  background: none;
  border: none;
  color: #333333;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 3px;
  border-radius: 3px;
}

.portfolio-control-btn:hover {
  background-color: var(--color-gold);
  color: white;
}

.portfolio-control-btn.delete:hover {
  background-color: var(--admin-red);
  color: white;
}

.portfolio-card-select {
  width: 100%;
  padding: 6px;
  font-size: 0.75rem;
  border: 1px solid #ccd1d9;
  border-radius: 4px;
  background-color: #f8f9fa;
  color: #333333;
  font-family: inherit;
  outline: none;
}

.portfolio-card-select:focus {
  border-color: var(--color-gold);
}

/* Table Style */
.admin-table-container {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.admin-table th, .admin-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border-gray);
}

.admin-table th {
  background-color: #fafbfc;
  font-weight: 700;
  color: var(--admin-text-dark);
}

.admin-table tr:hover {
  background-color: #fcfdfe;
}

.badge-source {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 20px;
  text-transform: uppercase;
}

.badge-source.form {
  background-color: var(--admin-blue-light);
  color: var(--admin-blue);
}

.badge-source.chat {
  background-color: rgba(40, 167, 69, 0.1);
  color: var(--admin-green);
}

/* Telemetry Insights */
.analytics-metric-row {
  margin-bottom: 20px;
}

.analytics-metric-label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

.analytics-bar-bg {
  height: 10px;
  background-color: #e9ecef;
  border-radius: 5px;
  overflow: hidden;
}

.analytics-bar-fill {
  height: 100%;
  background-color: var(--color-gold);
  border-radius: 5px;
}

/* AI Recommendation List */
.ai-recommendations-box {
  background-color: rgba(229, 169, 60, 0.05);
  border: 1px solid rgba(229, 169, 60, 0.2);
  border-radius: 6px;
  padding: 20px;
  margin-top: 20px;
}

.ai-recommendations-header {
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--color-gold-hover);
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
}

.ai-recommendations-list {
  padding-left: 20px;
}

.ai-recommendations-list li {
  margin-bottom: 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--color-graphite);
}

/* General Layout Responsive */
@media (max-width: 1024px) {
  .admin-stats-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  
  .admin-content-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 600px) {
  .admin-stats-grid {
    grid-template-columns: 1fr;
  }
  
  .admin-header {
    flex-direction: column;
    gap: 15px;
  }
}

/* Maintenance Mode Toggle styling */
.btn-red {
  background-color: var(--admin-red) !important;
  color: white !important;
}
.btn-red:hover {
  background-color: #bd2130 !important;
}
.btn-green {
  background-color: var(--admin-green) !important;
  color: white !important;
}
.btn-green:hover {
  background-color: #218838 !important;
}

.badge-green {
  background-color: rgba(40, 167, 69, 0.1) !important;
  color: var(--admin-green) !important;
  border: 1px solid rgba(40, 167, 69, 0.2) !important;
}

.badge-red {
  background-color: rgba(220, 53, 69, 0.1) !important;
  color: var(--admin-red) !important;
  border: 1px solid rgba(220, 53, 69, 0.2) !important;
}

/* Service Tabs for Media Manager */
.service-tabs {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  border-bottom: 2px solid #ccd1d9;
  padding-bottom: 5px;
  margin-bottom: 20px;
  scrollbar-width: thin;
}

.service-tab {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 6px 6px 0 0;
  color: var(--admin-text-muted);
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.service-tab:hover {
  background-color: #f1f3f5;
  color: var(--admin-text-dark);
}

.service-tab.active {
  color: #d1a13b;
  border: 1px solid #ccd1d9;
  border-bottom-color: var(--admin-card-bg);
  background-color: var(--admin-card-bg);
  margin-bottom: -7px;
  position: relative;
  z-index: 1;
}

/* =================================================================
   ADMIN RESPONSIVE & OVERFLOW FIXES
   ================================================================= */

/* Fix drag-drop zone: constrain width and prevent overflow */
.drag-drop-zone {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  word-wrap: break-word;
}

.drag-drop-text {
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  display: block;
}

/* Fix portfolio edit grid: always stay inside card */
.portfolio-edit-grid {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.portfolio-edit-card {
  box-sizing: border-box;
  min-width: 0; /* Prevent flex item from overflowing */
}

/* Fix portfolio-edit-img: always show and contain */
.portfolio-edit-img-container {
  box-sizing: border-box;
  background-color: #f0f0f0;
}

.portfolio-edit-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* Show broken image area in gold tint */
  background-color: #e5a93c22;
}

/* Fix service tabs: horizontal scroll without full-page overflow */
.service-tabs {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--color-gold) #e9ecef;
  max-width: 100%;
  box-sizing: border-box;
}

.service-tabs::-webkit-scrollbar {
  height: 4px;
}
.service-tabs::-webkit-scrollbar-track {
  background: #e9ecef;
  border-radius: 2px;
}
.service-tabs::-webkit-scrollbar-thumb {
  background: var(--color-gold);
  border-radius: 2px;
}

/* Fix admin card body: prevent overflow */
.admin-card {
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.admin-card-body {
  box-sizing: border-box;
  max-width: 100%;
  overflow: hidden;
}

/* Responsive admin table: always scrollable horizontally */
.admin-table-container {
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* Admin header: wrap on very small screens */
@media (max-width: 768px) {
  .admin-header {
    flex-wrap: wrap;
    padding: 15px 20px;
    gap: 12px;
  }

  .admin-header h1 {
    font-size: 1.1rem;
  }

  .admin-nav {
    flex-wrap: wrap;
    gap: 8px;
  }

  .admin-nav-link {
    font-size: 0.8rem;
    padding: 6px 10px;
  }

  .admin-main {
    margin: 15px auto;
    padding: 0 12px;
  }

  .admin-card-body {
    padding: 15px;
  }

  .hero-preview-container {
    flex-direction: column;
    align-items: flex-start;
  }

  .hero-preview-img {
    width: 100%;
    height: auto;
    max-height: 120px;
  }

  .portfolio-edit-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }

  .api-config-row {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 480px) {
  .admin-stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .admin-stat-card {
    padding: 15px;
  }

  .admin-stat-val {
    font-size: 1.6rem;
  }

  .portfolio-edit-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 10px;
  }

  .service-tab {
    font-size: 0.75rem;
    padding: 8px 12px;
  }
}

/* =================================================================
   SAFARI / IOS ADMIN FIXES
   ================================================================= */
@supports (-webkit-touch-callout: none) {
  /* Fix sticky position on iOS Safari for admin header if needed */
  .admin-header {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  /* iOS Safari: fix gap in flex containers */
  .admin-nav > * + * {
    margin-left: 0;
  }

  /* Fix drag-drop on iOS */
  .drag-drop-zone {
    -webkit-user-select: none;
    user-select: none;
  }
}
