/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-900: #1b5e20;
  --green-700: #2e7d32;
  --green-500: #4caf50;
  --green-100: #e8f5e9;
  --green-50:  #f1f8f2;
  --sidebar-w: 240px;
  --topbar-h:  64px;
  --bg:        #f4f6f8;
  --card:      #ffffff;
  --border:    #e0e0e0;
  --text:      #1a1a2e;
  --text-2:    #555e6e;
  --text-3:    #9aa0ab;
  --shadow:    0 2px 12px rgba(0,0,0,.06);
  --radius:    12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

/* ── Loading screen ─────────────────────────────────────────────────────────── */
.loading-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #1b5e20, #2e7d32);
  display: grid; place-items: center;
  z-index: 9999;
}
.loading-box {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  color: #fff;
}
.loading-spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-box p { font-size: .95rem; font-weight: 500; color: rgba(255,255,255,.8); }

/* ── Login screen ───────────────────────────────────────────────────────────── */
.login-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #1b5e20 0%, #2e7d32 50%, #1a3a1c 100%);
  display: grid; place-items: center;
  z-index: 1000;
  overflow: hidden;
}
.login-screen::before {
  content: '';
  position: absolute; inset: 0;
  background-image: url('login_bg.png');
  background-size: cover;
  background-position: center;
  opacity: 0.15;
  z-index: -1;
  pointer-events: none;
}
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%; max-width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
  display: flex; flex-direction: column; gap: 16px;
}
.login-logo { display: flex; justify-content: center; margin-bottom: 8px; }
.login-logo img { width: 80px; height: 80px; border-radius: 16px; object-fit: cover; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.login-card h2 { font-size: 1.4rem; font-weight: 800; text-align: center; color: #1b5e20; }
.login-subtitle { font-size: .85rem; color: #777; text-align: center; }
.login-error {
  background: #ffebee; color: #c62828;
  border: 1px solid #ffcdd2;
  border-radius: 8px; padding: 10px 14px;
  font-size: .83rem; font-weight: 500;
}

#app { display: flex; width: 100%; min-height: 100vh; }

body {

  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
}

body.dark {
  --bg:    #0f1117;
  --card:  #1a1d27;
  --border:#2d3142;
  --text:  #e8eaf0;
  --text-2:#9aa0ab;
  --text-3:#5a6070;
  --shadow:0 2px 12px rgba(0,0,0,.3);
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: linear-gradient(175deg, #1b5e20 0%, #2e7d32 60%, #1a3a1c 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 200;
  transition: transform var(--transition), width var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.logo-icon { display: flex; align-items: center; justify-content: center; }
.logo-icon img { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; background: #fff; }
.logo-text  { display: flex; flex-direction: column; }
.logo-main  { font-size: .95rem; font-weight: 700; color: #fff; }
.logo-sub   { font-size: .7rem; color: rgba(255,255,255,.6); }

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}
.nav-section-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.45);
  padding: 4px 8px 8px;
  margin-top: 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  margin-bottom: 2px;
}
.nav-item:hover  { background: rgba(255,255,255,.12); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.2); color: #fff; font-weight: 600; }
.nav-icon { font-size: 1.1rem; width: 22px; text-align: center; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.admin-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  color: #fff;
  font-weight: 700;
  display: grid; place-items: center;
  font-size: .9rem;
  flex-shrink: 0;
}
.admin-info { flex: 1; display: flex; flex-direction: column; }
.admin-name { color: #fff; font-size: .82rem; font-weight: 600; }
.admin-role { color: rgba(255,255,255,.55); font-size: .7rem; }
.logout-btn {
  background: none; border: none;
  color: rgba(255,255,255,.6);
  font-size: 1.1rem; cursor: pointer;
  transition: color var(--transition);
}
.logout-btn:hover { color: #fff; }

/* ── Main content ───────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}

/* ── Topbar ─────────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  z-index: 100;
  box-shadow: 0 1px 8px rgba(0,0,0,.04);
}
.menu-toggle {
  background: none; border: none;
  font-size: 1.4rem; cursor: pointer;
  color: var(--text-2); display: none;
}
.topbar-title { font-size: 1.1rem; font-weight: 700; flex: 1; color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.topbar-search {
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 14px 7px 36px;
  font-size: .85rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 200px;
  transition: border-color var(--transition), width var(--transition);
}
.topbar-search:focus { border-color: var(--green-500); width: 260px; }
.search-icon {
  position: absolute; left: 12px;
  font-size: .85rem; color: var(--text-3);
  pointer-events: none;
}
.notif-btn {
  position: relative;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: background var(--transition);
}
.notif-btn:hover { background: var(--green-100); }
.badge {
  position: absolute; top: 0; right: 0;
  background: #e53935; color: #fff;
  font-size: .6rem; font-weight: 700;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: grid; place-items: center;
}

/* ── Pages ──────────────────────────────────────────────────────────────────── */
.page { display: none; padding: 28px; }
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 1.55rem; font-weight: 800; margin-bottom: 4px; }
.page-header p  { color: var(--text-2); font-size: .9rem; }

/* ── Stats ──────────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.1); }
.stat-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.7rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: .78rem; color: var(--text-2); margin: 4px 0 6px; }
.stat-delta { font-size: .72rem; font-weight: 600; }
.stat-delta.positive { color: #2e7d32; }
.stat-delta.neutral  { color: var(--text-3); }
.stat-delta.negative { color: #c62828; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.card-header h3 { font-size: 1rem; font-weight: 700; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width:900px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table, .mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table th, .mini-table th {
  background: var(--green-50);
  color: var(--green-900);
  font-weight: 700;
  padding: 12px 16px;
  text-align: left;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 2px solid var(--green-100);
  white-space: nowrap;
}
body.dark .data-table th, body.dark .mini-table th {
  background: #1f2933; color: #6bcf7f;
}
.data-table td, .mini-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.data-table tr:last-child td, .mini-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--green-50); }
body.dark .data-table tr:hover td { background: rgba(255,255,255,.03); }

.table-search {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: .85rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 240px;
}
.table-search:focus { border-color: var(--green-500); }

.filter-row { display: flex; gap: 10px; flex-wrap: wrap; }
.filter-row select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: .82rem;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  outline: none;
}

/* ── Action buttons ─────────────────────────────────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, #2e7d32, #4caf50);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn-primary:hover { opacity: .9; transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: #c62828;
  color: #ffffff;
  border: 1px solid #c62828;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
}
.btn-danger:hover { opacity: .9; }

.btn-sm {
  background: var(--green-100);
  color: var(--green-700);
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-sm:hover { background: var(--green-500); color: #fff; }

.action-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: .78rem;
  cursor: pointer;
  color: var(--text-2);
  transition: all var(--transition);
  margin-right: 4px;
}
.action-btn.edit:hover  { border-color: #1565c0; color: #1565c0; background: #e3f2fd; }
.action-btn.delete:hover{ border-color: #c62828; color: #c62828; background: #ffebee; }

.chip {
  background: var(--green-100);
  color: var(--green-700);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: .72rem;
  font-weight: 700;
  display: inline-flex; align-items: center; gap: 4px;
}
.chip::before { content: '●'; font-size: .5rem; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Retailers grid ─────────────────────────────────────────────────────────── */
.retailers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}
.retailer-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform var(--transition), box-shadow var(--transition);
}
.retailer-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.1); }
.retailer-icon {
  width: 56px; height: 56px;
  border-radius: var(--radius-sm);
  background: var(--green-100);
  display: grid; place-items: center;
  font-size: 1.6rem;
}
.retailer-name  { font-size: 1.05rem; font-weight: 700; }
.retailer-url   { font-size: .8rem; color: var(--green-700); text-decoration: none; }
.retailer-url:hover { text-decoration: underline; }
.retailer-meta  { font-size: .78rem; color: var(--text-2); }
.retailer-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ── Price summary ──────────────────────────────────────────────────────────── */
.price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.price-row:last-child { border-bottom: none; }
.price-product { font-size: .88rem; font-weight: 600; }
.price-retailer { font-size: .78rem; color: var(--text-2); }
.price-amount {
  font-size: .95rem; font-weight: 800;
  color: var(--green-700);
  background: var(--green-100);
  padding: 3px 10px;
  border-radius: 20px;
}

/* ── Analytics ──────────────────────────────────────────────────────────────── */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}
.bar-chart { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.bar-item { display: flex; flex-direction: column; gap: 4px; }
.bar-label { font-size: .8rem; color: var(--text-2); display: flex; justify-content: space-between; }
.bar-track {
  background: var(--green-50);
  border-radius: 20px;
  height: 10px;
  overflow: hidden;
}
body.dark .bar-track { background: #2d3142; }
.bar-fill {
  height: 100%;
  border-radius: 20px;
  background: linear-gradient(90deg, #2e7d32, #4caf50);
  transition: width 1s ease;
}

.donut-chart {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.donut-item {
  display: flex;
  align-items: center;
  gap: 10px;
}
.donut-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.donut-name { font-size: .85rem; flex: 1; }
.donut-count {
  font-size: .8rem; font-weight: 700;
  color: var(--text-2);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 20px;
}

/* ── Settings ───────────────────────────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}
.notifications-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}
.notification-composer { grid-column: 1 / -1; }
.notification-actions {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.notification-actions .btn-primary { width: 100%; }
.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.notif-history {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: capitalize;
}
.notif-history.sent { background: #e8f5e9; color: #2e7d32; }
.notif-history.queued { background: #e3f2fd; color: #1565c0; }
.notif-history.failed { background: #ffebee; color: #c62828; }
.settings-form { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.form-group input, .form-group select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .88rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
.form-group input:focus, .form-group select:focus { border-color: var(--green-500); }
.form-group textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .88rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  resize: vertical;
  transition: border-color var(--transition);
}
.form-group textarea:focus { border-color: var(--green-500); }

.toggle-row { flex-direction: row; align-items: center; justify-content: space-between; }
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background var(--transition);
}
.slider::before {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}
.toggle input:checked + .slider { background: var(--green-500); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ── Modals ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  place-items: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: grid; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%; max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  overflow: hidden;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from{ transform:translateY(20px);opacity:0} to{transform:translateY(0);opacity:1} }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-header button {
  background: none; border: none;
  font-size: 1.1rem; cursor: pointer;
  color: var(--text-2);
  transition: color var(--transition);
}
.modal-header button:hover { color: var(--text); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 30px; right: 30px;
  background: #1b5e20;
  color: #fff;
  padding: 12px 24px;
  border-radius: 20px;
  font-size: .88rem; font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  opacity: 0; transform: translateY(12px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 999;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── Status badges ──────────────────────────────────────────────────────────── */
.badge-status {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
}
.badge-active  { background:#e8f5e9; color:#2e7d32; }
.badge-admin   { background:#e3f2fd; color:#1565c0; }
.badge-super-admin { background:#f3e5f5; color:#7b1fa2; }
.badge-inactive{ background:#fce4ec; color:#c62828; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }
  .topbar-search { width: 160px; }
  .page { padding: 16px; }
  .page-header { flex-direction: column; gap: 12px; }
}

/* ── Scraper Scheduler ──────────────────────────────────────────────────────── */
.scraper-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.scraper-stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform var(--transition), box-shadow var(--transition);
}
.scraper-stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.1); }
.scraper-stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.scraper-stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1; }
.scraper-stat-label { font-size: .75rem; color: var(--text-2); margin-top: 4px; }
