/* =====================================================================
   ADMIN DASHBOARD & ANALYTICS STYLESHEET
   Clean, Minimalistic, Professional, Solid Gold Accents (No Gradients)
   Fully Mobile-Responsive & Touch-Optimized
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --admin-bg: #F9FAFB;
  --admin-card: #FFFFFF;
  --admin-border: #E5E7EB;
  --admin-gold: #B88E3F;
  --admin-gold-hover: #996515;
  --admin-dark: #111827;
  --admin-text: #1F2937;
  --admin-muted: #6B7280;
  --admin-danger: #DC2626;
  --admin-success: #16A34A;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--admin-bg);
  color: var(--admin-text);
  /* MOBILE FIRST: stacked layout is the default; desktop sidebar is added at >= 993px */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-wrap: break-word;
}

img, svg, video, canvas, iframe { max-width: 100%; }
img { height: auto; }
table { max-width: 100%; }
h1, h2, h3, h4, p, td, th, label, a, span, strong { overflow-wrap: break-word; }
input, select, textarea, button { max-width: 100%; font-family: inherit; }

/* Sidebar Navigation - MOBILE FIRST (sticky top bar, scrollable nav pills) */
.admin-sidebar {
  width: 100%;
  background-color: var(--admin-dark);
  color: #FFFFFF;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.sidebar-brand {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #374151;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.sidebar-brand span {
  color: var(--admin-gold);
}

.sidebar-brand .mobile-admin-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0;
  color: #F87171;
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 4px;
}

.sidebar-nav {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0.45rem 0.75rem;
  gap: 0.4rem;
  scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
  display: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  white-space: nowrap;
  padding: 0.5rem 0.8rem;
  color: #D1D5DB;
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
}

.nav-link:hover, .nav-link.active {
  background-color: #1F2937;
  color: var(--admin-gold);
}

.sidebar-footer {
  display: none;
  padding: 1rem 1.5rem;
  border-top: 1px solid #374151;
  font-size: 0.75rem;
  color: #9CA3AF;
}

/* Main Content Area */
.admin-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.admin-topbar {
  background-color: #FFFFFF;
  border-bottom: 1px solid var(--admin-border);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}

.admin-topbar > * {
  min-width: 0;
  max-width: 100%;
}

.admin-topbar input[type="text"],
.admin-topbar input[type="search"] {
  max-width: 100%;
  box-sizing: border-box;
}

.admin-page-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--admin-dark);
  margin: 0;
}

.admin-main-body {
  padding: 1rem 0.75rem;
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Filter Controls Toolbar */
.analytics-toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  background-color: #FFFFFF;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 1.25rem;
  min-width: 0;
}

.period-pills {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.25rem;
  scrollbar-width: none;
}

.period-pills::-webkit-scrollbar { display: none; }

.period-pills > * { flex-shrink: 0; white-space: nowrap; }

.pill-btn {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--admin-border);
  background-color: #FFFFFF;
  color: var(--admin-text);
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pill-btn:hover {
  border-color: var(--admin-gold);
}

.pill-btn.active {
  background-color: var(--admin-gold);
  border-color: var(--admin-gold);
  color: #FFFFFF;
  font-weight: 600;
}

.custom-range-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}

.custom-range-form input[type="date"] {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.8125rem;
}

/* Key Metrics Cards Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.metric-card {
  background-color: var(--admin-card);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  padding: 1rem;
  min-width: 0;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--admin-muted);
  margin-bottom: 0.35rem;
}

.metric-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--admin-dark);
  overflow-wrap: anywhere;
}

.metric-value.highlight-gold {
  color: var(--admin-gold);
}

.metric-value.highlight-profit {
  color: var(--admin-success);
}

.metric-sub {
  font-size: 0.75rem;
  color: var(--admin-muted);
  margin-top: 0.25rem;
}

/* Tables & CRUD Views */
.admin-card {
  background-color: var(--admin-card);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  padding: 1rem 0.85rem;
  margin-bottom: 1.25rem;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.75rem 0 0;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--admin-border);
  background: #FFFFFF;
}

.table-scroll-hint {
  display: block;
  font-size: 0.75rem;
  color: #B88E3F;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.admin-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.admin-table th {
  text-align: left;
  padding: 0.8rem 0.9rem;
  background-color: var(--admin-bg);
  border-bottom: 2px solid var(--admin-border);
  color: var(--admin-muted);
  font-weight: 700;
  font-size: 0.725rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.admin-table td {
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--admin-border);
  vertical-align: middle;
}

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

/* Badges */
.status-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-paid, .badge-delivered, .badge-active {
  background-color: #DCFCE7;
  color: #15803D;
}

.badge-pending, .badge-processing {
  background-color: #FEF3C7;
  color: #B45309;
}

.badge-cancelled, .badge-inactive {
  background-color: #FEE2E2;
  color: #B91C1C;
}

/* Admin Form Elements */
.admin-form-group {
  margin-bottom: 1.25rem;
  width: 100%;
}

.admin-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.admin-input, .admin-select, .admin-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 1rem; /* 16px: prevents iOS auto-zoom on focus */
  background-color: #FFFFFF;
}

.admin-input:focus, .admin-select:focus, .admin-textarea:focus {
  outline: none;
  border-color: var(--admin-gold);
}

.btn-admin-gold {
  background-color: var(--admin-gold);
  color: #FFFFFF;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  max-width: 100%;
  box-sizing: border-box;
  text-align: center;
}

.btn-admin-gold:hover {
  background-color: var(--admin-gold-hover);
}

/* =====================================================================
   RESPONSIVE LAYER
   Base styles above are MOBILE-FIRST. Rules below only add / adjust.
   ===================================================================== */

/* Modals must sit above the sticky top bar */
#product-form-modal, #category-modal, #banner-form-modal, #review-modal { z-index: 2000 !important; }

/* Tables always scroll inside their own box, never the page */
.table-responsive { overscroll-behavior-x: contain; }

/* Inline-styled multi-column grids collapse on phones & small tablets */
@media (max-width: 768px) {
  .admin-main-body [style*="grid-template-columns"],
  .admin-card [style*="grid-template-columns"],
  #product-form-modal [style*="grid-template-columns"],
  #category-modal [style*="grid-template-columns"],
  #banner-form-modal [style*="grid-template-columns"],
  #review-modal [style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 0.75rem !important;
  }

  .admin-main-body [style*="display: flex"],
  .admin-main-body [style*="display:flex"] {
    min-width: 0;
  }
}

/* Phones */
@media (max-width: 640px) {
  /* Filter / catalog tab rows scroll sideways inside themselves */
  .filter-tabs,
  .catalog-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.4rem;
    padding-bottom: 0.4rem;
    width: 100%;
    max-width: 100%;
    scrollbar-width: none;
  }

  .filter-tabs::-webkit-scrollbar,
  .catalog-tabs::-webkit-scrollbar { display: none; }

  .filter-tab,
  .catalog-tab-btn {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0.5rem 0.8rem;
    font-size: 0.8125rem;
  }

  /* Modals fit the screen and scroll internally */
  #product-form-modal,
  #category-modal,
  #banner-form-modal,
  #review-modal {
    padding: 0.5rem !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }

  #product-form-modal > div,
  #category-modal > div,
  #banner-form-modal > div,
  #review-modal > div {
    padding: 1.1rem 0.85rem !important;
    margin: 0.5rem auto !important;
    max-width: 100% !important;
    width: 100% !important;
    border-radius: 8px !important;
    box-sizing: border-box !important;
  }

  /* Forms: full-width controls & buttons */
  .admin-main-body form input,
  .admin-main-body form select,
  .admin-main-body form textarea,
  #product-form-modal input, #product-form-modal select, #product-form-modal textarea,
  #category-modal input, #category-modal select, #category-modal textarea,
  #banner-form-modal input, #banner-form-modal select, #banner-form-modal textarea,
  #review-modal input, #review-modal select, #review-modal textarea {
    max-width: 100%;
    box-sizing: border-box;
    font-size: 16px !important; /* no iOS zoom */
  }

  .admin-main-body input[type="file"] { width: 100%; font-size: 0.8125rem !important; }

  .btn-admin-gold { width: 100%; }

  /* ---------- Tables become stacked cards on phones (no sideways swiping) ---------- */
  .table-responsive {
    overflow: visible;
    border: 0;
    background: transparent;
    margin-top: 0.5rem;
  }

  .table-scroll-hint { display: none !important; }

  table.admin-table.is-stackable,
  table.admin-table.is-stackable tbody {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100%;
    border: 0;
  }

  table.admin-table.is-stackable thead { display: none; }

  table.admin-table.is-stackable tr {
    display: block;
    background: #FFFFFF;
    border: 1px solid var(--admin-border);
    border-radius: 10px;
    margin: 0 0 0.85rem;
    padding: 0.25rem 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    overflow: hidden;
  }

  table.admin-table.is-stackable td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    width: auto !important;
    max-width: none !important;
    padding: 0.6rem 0.85rem !important;
    border: 0;
    border-bottom: 1px dashed var(--admin-border);
    text-align: right !important;
    white-space: normal !important;
    box-sizing: border-box;
  }

  table.admin-table.is-stackable td:last-child { border-bottom: 0; }

  table.admin-table.is-stackable td::before {
    content: attr(data-label);
    flex: 0 0 34%;
    max-width: 40%;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--admin-muted);
  }

  table.admin-table.is-stackable td[data-label=""]::before { display: none; }

  table.admin-table.is-stackable td .cell-content {
    flex: 1 1 auto;
    min-width: 0;
    text-align: right;
    overflow-wrap: anywhere;
  }

  table.admin-table.is-stackable td.cell-wide {
    display: block;
    text-align: center !important;
  }

  table.admin-table.is-stackable td.cell-wide::before { display: none; }

  table.admin-table.is-stackable td .cell-content span { white-space: normal !important; max-width: 100%; }
  table.admin-table.is-stackable td img { max-width: 72px; height: auto; }
  table.admin-table.is-stackable td select,
  table.admin-table.is-stackable td .order-status-select { max-width: 100%; }
  table.admin-table.is-stackable td a,
  table.admin-table.is-stackable td button { max-width: 100%; }
  table.admin-table.is-stackable td .cell-content > div,
  table.admin-table.is-stackable td .cell-content > form { justify-content: flex-end; flex-wrap: wrap; }

  /* Order-status dropdown inside tables stays compact */
  .order-status-select { font-size: 0.75rem !important; }
}

/* Very small phones */
@media (max-width: 380px) {
  .sidebar-brand { font-size: 0.95rem; letter-spacing: 0.02em; }
  .admin-main-body { padding: 0.75rem 0.5rem; }
  .admin-card { padding: 0.85rem 0.7rem; }
  .metric-value { font-size: 1.3rem; }
}

/* ===== Tablet landscape / small laptops ===== */
@media (min-width: 641px) {
  .metrics-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
  .custom-range-form { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .custom-range-form input[type="date"] { width: auto; }
  .admin-topbar { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 1rem 1.5rem; }
  .admin-main-body { padding: 1.5rem; }
  .admin-card { padding: 1.25rem; }
  .analytics-toolbar { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; }
  .period-pills { width: auto; flex-wrap: wrap; overflow: visible; }
  .admin-page-title { font-size: 1.35rem; }
  .metric-value { font-size: 1.65rem; }
  .btn-admin-gold { width: auto; }
}

/* ===== Desktop: fixed left sidebar ===== */
@media (min-width: 993px) {
  body { flex-direction: row; }

  .admin-sidebar {
    width: 250px;
    height: 100vh;
    height: 100dvh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    box-shadow: none;
  }

  .sidebar-brand { padding: 1.5rem; font-size: 1.25rem; }
  .sidebar-brand .mobile-admin-link { display: none; }

  .sidebar-nav {
    flex-direction: column;
    overflow: visible;
    padding: 1.5rem 0.75rem;
    gap: 0.35rem;
    flex: 1;
  }

  .nav-link { padding: 0.75rem 1rem; font-size: 0.875rem; border: 0; flex-shrink: 1; white-space: normal; }
  .sidebar-footer { display: block; }
  .table-scroll-hint { display: none; }

  .admin-content { width: calc(100% - 250px); }
  .admin-topbar { padding: 1rem 2rem; }
  .admin-main-body { padding: 2rem; }
  .admin-card { padding: 1.5rem; margin-bottom: 2rem; }
  .analytics-toolbar { margin-bottom: 2rem; }
  .metrics-grid { gap: 1.25rem; margin-bottom: 2rem; }
}
