/* ============================================================
   ML Dashboard — Global Styles
   ============================================================ */
:root {
  --yellow:      #FFE600;
  --yellow-dark: #e6cf00;
  --navy:        #1a1f36;
  --navy-light:  #2d3561;
  --sidebar-w:   240px;
  --topbar-h:    64px;
  --bg:          #f0f2f8;
  --card:        #ffffff;
  --border:      #e5e7eb;
  --text:        #1a1f36;
  --text-2:      #6b7280;
  --text-3:      #9ca3af;
  --green:       #10b981;
  --red:         #ef4444;
  --orange:      #f59e0b;
  --blue:        #3b82f6;
  --purple:      #8b5cf6;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg:   0 10px 30px rgba(0,0,0,0.15);
  --transition:  0.2s ease;
}

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

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo-icon {
  width: 40px; height: 40px;
  background: var(--yellow);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-logo-name {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.sidebar-logo-sub {
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
  cursor: pointer;
}

.nav-item:hover { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.9); }

.nav-item.active {
  background: var(--yellow);
  color: var(--navy);
  font-weight: 700;
}

.nav-item.active .nav-icon { filter: none; }

.nav-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-label { flex: 1; }

.nav-badge {
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  min-width: 18px;
  text-align: center;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 8px 0;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-avatar {
  width: 34px; height: 34px;
  background: var(--yellow);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-avatar img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role { font-size: 11px; color: rgba(255,255,255,0.4); }

.btn-logout {
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color var(--transition);
  flex-shrink: 0;
}
.btn-logout:hover { color: var(--red); }

/* ============================================================
   MAIN WRAPPER
   ============================================================ */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.btn-toggle-sidebar {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
  padding: 4px;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.store-selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.store-label {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
}

.store-select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}
.store-select:focus { border-color: var(--yellow); }

.topbar-refresh {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-2);
  transition: all var(--transition);
}
.topbar-refresh:hover { background: var(--yellow); color: var(--navy); }
.topbar-refresh.spinning { animation: spin 1s linear infinite; }

/* ============================================================
   CONTENT
   ============================================================ */
.content {
  flex: 1;
  padding: 24px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* ============================================================
   COMPONENTS — Page Header
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-2); margin-top: 2px; }

.page-actions { display: flex; gap: 10px; }

/* ============================================================
   COMPONENTS — Cards
   ============================================================ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

/* ============================================================
   COMPONENTS — KPI Cards
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--kpi-color, var(--yellow));
}

.kpi-label { font-size: 12px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1; }
.kpi-sub   { font-size: 12px; color: var(--text-3); }
.kpi-icon  { position: absolute; top: 18px; right: 18px; font-size: 28px; opacity: 0.15; }

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}
.kpi-trend.up   { background: #d1fae5; color: #065f46; }
.kpi-trend.down { background: #fee2e2; color: #991b1b; }

/* ============================================================
   COMPONENTS — Charts
   ============================================================ */
.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-container {
  position: relative;
  height: 280px;
}

/* ============================================================
   COMPONENTS — Tables
   ============================================================ */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-2);
  border-bottom: 1.5px solid var(--border);
  background: var(--bg);
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

.td-light { color: var(--text-2); font-size: 13px; }

/* ============================================================
   COMPONENTS — Badges / Pills
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-green  { background: #d1fae5; color: #065f46; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-gray   { background: #f3f4f6; color: #6b7280; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ============================================================
   COMPONENTS — Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--yellow);
  color: var(--navy);
}
.btn-primary:hover { background: var(--yellow-dark); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: #fee2e2; color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); }

/* ============================================================
   COMPONENTS — Search & Filters
   ============================================================ */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  color: var(--text-3);
  pointer-events: none;
}

.search-input, .filter-select, .filter-input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color var(--transition);
}
.filter-select, .filter-input { padding-left: 12px; }

.search-input:focus, .filter-select:focus, .filter-input:focus {
  border-color: var(--yellow);
}

/* ============================================================
   COMPONENTS — Listings
   ============================================================ */
.listing-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.listing-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  transition: box-shadow var(--transition);
}
.listing-card:hover { box-shadow: var(--shadow-md); }

.listing-thumb {
  width: 64px; height: 64px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  background: var(--bg);
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.listing-thumb-ph {
  width: 64px; height: 64px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border: 1px solid var(--border);
}

.listing-info { flex: 1; min-width: 0; }
.listing-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.listing-meta { font-size: 12px; color: var(--text-2); display: flex; gap: 12px; flex-wrap: wrap; }

.listing-stats {
  display: flex;
  gap: 24px;
  align-items: center;
  flex-shrink: 0;
}

.listing-stat { text-align: center; }
.listing-stat-val  { font-size: 15px; font-weight: 700; color: var(--text); }
.listing-stat-lab  { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }

.listing-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ============================================================
   COMPONENTS — Questions
   ============================================================ */
.question-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
  border-left: 4px solid var(--yellow);
}
.question-card.answered { border-left-color: var(--green); }

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.question-item {
  font-size: 12px;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: 4px;
}
.question-text { font-size: 15px; color: var(--text); font-weight: 500; }
.question-meta { font-size: 12px; color: var(--text-3); margin-top: 4px; }

.answer-text {
  background: #f0f9f4;
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 12px;
  font-size: 14px;
  color: #065f46;
  border-left: 3px solid var(--green);
}

.answer-form { margin-top: 14px; }
.answer-textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
  color: var(--text);
}
.answer-textarea:focus { border-color: var(--yellow); }

/* ============================================================
   COMPONENTS — Pagination
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 0;
  flex-wrap: wrap;
  gap: 8px;
}

.pagination-info { font-size: 13px; color: var(--text-2); }

.pagination-btns { display: flex; gap: 6px; }
.page-btn {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  transition: all var(--transition);
}
.page-btn:hover  { background: var(--yellow); border-color: var(--yellow); color: var(--navy); }
.page-btn.active { background: var(--yellow); border-color: var(--yellow); color: var(--navy); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   COMPONENTS — Empty State
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-2);
}
.empty-state-icon { font-size: 56px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.empty-state p  { font-size: 14px; max-width: 320px; margin: 0 auto; }

/* ============================================================
   COMPONENTS — Loading
   ============================================================ */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  gap: 16px;
  color: var(--text-2);
}

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   COMPONENTS — Modal
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 17px; font-weight: 700; color: var(--text); }

.modal-close {
  width: 30px; height: 30px;
  border: none;
  background: var(--bg);
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--red); color: #fff; }

.modal-body   { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ============================================================
   COMPONENTS — Form
   ============================================================ */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color var(--transition);
}
.form-control:focus { border-color: var(--yellow); }

/* ============================================================
   COMPONENTS — Toast
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  min-width: 260px;
  animation: toastIn 0.3s ease;
}
.toast.success { background: #065f46; }
.toast.error   { background: #991b1b; }
.toast.warning { background: #92400e; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   METRICS PAGE
   ============================================================ */
.metrics-period {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}
.period-btn {
  padding: 8px 20px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  color: var(--text-2);
  transition: all var(--transition);
}
.period-btn.active { background: var(--yellow); border-color: var(--yellow); color: var(--navy); }
.period-btn:hover  { border-color: var(--yellow); color: var(--navy); }

.top-products-table td:first-child { font-weight: 600; }

/* ============================================================
   STORES PAGE
   ============================================================ */
.store-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.store-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow var(--transition);
}
.store-card:hover { box-shadow: var(--shadow-md); }

.store-card-avatar {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--yellow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  flex-shrink: 0;
  overflow: hidden;
}
.store-card-avatar img { width: 100%; height: 100%; object-fit: cover; }

.store-card-info { flex: 1; }
.store-card-name { font-size: 15px; font-weight: 700; color: var(--text); }
.store-card-id   { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.add-store-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--border);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  min-height: 90px;
}
.add-store-card:hover {
  border-color: var(--yellow);
  color: var(--navy);
  background: #fffbe6;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-wrapper { margin-left: 0; }
  .btn-toggle-sidebar { display: flex; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .listing-stats { display: none; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .filters  { flex-direction: column; }
}

/* ============================================================
   UTILS
   ============================================================ */
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-bold { font-weight: 700; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.d-flex { display: flex; }
.gap-8  { gap: 8px; }
.gap-16 { gap: 16px; }
.flex-1 { flex: 1; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.color-green { color: var(--green); }
.color-red   { color: var(--red);   }
.color-text2 { color: var(--text-2);}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}
.sidebar-overlay.show { display: block; }
