/* ============================================================
   THOUT COMMERCE — Design System & Shared Styles
   Covers: Admin Dashboard + Shop UI
   ============================================================ */

/* ── Custom Properties ───────────────────────────────────── */
:root {
  /* Brand Colors */
  --color-primary:        #86626E;
  --color-primary-dark:   #6B4E58;
  --color-primary-light:  #EDE7F5;
  --color-success:        #34a853;
  --color-success-light:  #e6f4ea;
  --color-danger:         #ea4335;
  --color-danger-light:   #fce8e6;
  --color-warning:        #fbbc04;
  --color-warning-light:  #fef7e0;
  --color-info:           #D4C5E2;
  --color-info-light:     #EDE7F5;

  /* Neutrals */
  --color-white:          #ffffff;
  --color-bg:             #F9F5FC;
  --color-sidebar-bg:     #F0EAF5;
  --color-surface:        #ffffff;
  --color-border:         #D4C5E2;
  --color-border-light:   #EDE7F5;

  /* Text */
  --color-text-primary:   #0F0E0E;
  --color-text-secondary: #5a4455;
  --color-text-muted:     #9E8896;
  --color-text-inverse:   #ffffff;

  /* Sidebar (Admin) */
  --sidebar-width:        240px;
  --sidebar-bg:           #0F0E0E;
  --sidebar-text:         #D4C5E2;
  --sidebar-text-active:  #ffffff;
  --sidebar-accent:       #86626E;

  /* Shop Category Sidebar */
  --cat-sidebar-width:    200px;

  /* Topbar */
  --topbar-height:        60px;

  /* Typography */
  --font-family:          system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-xs:         0.70rem;
  --font-size-sm:         0.813rem;
  --font-size-base:       0.938rem;
  --font-size-md:         1rem;
  --font-size-lg:         1.125rem;
  --font-size-xl:         1.375rem;
  --font-size-2xl:        1.75rem;
  --font-weight-normal:   400;
  --font-weight-medium:   500;
  --font-weight-semibold: 600;
  --font-weight-bold:     700;

  /* Spacing */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;

  /* Border Radius */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.06);
  --shadow-sm:  0 1px 4px rgba(0,0,0,0.08), 0 0 1px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.10), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-xl:  0 16px 40px rgba(0,0,0,0.14), 0 4px 12px rgba(0,0,0,0.08);

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition-base:   250ms ease;
  --transition-slow:   400ms ease;

  /* Z-Index Scale */
  --z-sidebar:     100;
  --z-topbar:      200;
  --z-cart:        300;
  --z-chat:        400;
  --z-toast:       500;
  --z-lightbox:    600;
  --z-overlay:     700;
  --z-login:       800;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

ul, ol { list-style: none; }

h1,h2,h3,h4,h5,h6 {
  font-weight: var(--font-weight-semibold);
  line-height: 1.3;
  color: var(--color-text-primary);
}

/* ── Utility Classes ─────────────────────────────────────── */
.hidden     { display: none !important; }
.sr-only    { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2      { gap: var(--space-2); }
.gap-3      { gap: var(--space-3); }
.gap-4      { gap: var(--space-4); }
.w-full     { width: 100%; }
.text-sm    { font-size: var(--font-size-sm); }
.text-muted { color: var(--color-text-muted); }
.font-medium{ font-weight: var(--font-weight-medium); }
.font-bold  { font-weight: var(--font-weight-bold); }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }


/* ============================================================
   SHARED COMPONENTS
   ============================================================ */

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
  line-height: 1;
  transition: background var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-white);
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
  box-shadow: var(--shadow-sm);
}

.btn-success {
  background: var(--color-success);
  color: var(--color-white);
}
.btn-success:hover:not(:disabled) { filter: brightness(0.92); }

.btn-danger {
  background: var(--color-danger);
  color: var(--color-white);
}
.btn-danger:hover:not(:disabled) { filter: brightness(0.92); }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--color-border);
  color: var(--color-text-secondary);
}
.btn-outline:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-light);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--color-border-light);
  color: var(--color-text-primary);
}

.btn-sm  { padding: 5px 10px; font-size: var(--font-size-xs); }
.btn-lg  { padding: 12px 24px; font-size: var(--font-size-md); }
.btn-icon {
  padding: 8px;
  border-radius: var(--radius-full);
  aspect-ratio: 1;
}

/* ── Form Elements ───────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-white);
  color: var(--color-text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(134,98,110,0.15);
}
.form-control::placeholder { color: var(--color-text-muted); }

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235f6368' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Slider (Range Input) ────────────────────────────────── */
.slider-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  outline: none;
  cursor: pointer;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-white);
  box-shadow: 0 0 0 1px var(--color-primary);
  cursor: pointer;
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-white);
  box-shadow: 0 0 0 1px var(--color-primary);
  cursor: pointer;
}
.slider-value {
  min-width: 36px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-primary);
  text-align: right;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border-light);
}

.card-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
}

.card-body {
  padding: var(--space-6);
}

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.stat-card__label {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card__value {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  line-height: 1;
}

.stat-card__icon {
  margin-bottom: var(--space-2);
  display: flex;
  width: 28px;
  height: 28px;
}
.stat-card--primary .stat-card__icon { color: var(--color-primary); }
.stat-card--success .stat-card__icon { color: var(--color-success); }
.stat-card--warning .stat-card__icon { color: var(--color-warning); }
.stat-card--info    .stat-card__icon { color: var(--color-primary); }

.stat-card--primary  { border-left: 4px solid var(--color-primary); }
.stat-card--success  { border-left: 4px solid var(--color-success); }
.stat-card--warning  { border-left: 4px solid var(--color-warning); }
.stat-card--info     { border-left: 4px solid var(--color-info); }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-light);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

thead tr {
  background: var(--color-sidebar-bg);
}

thead th {
  padding: 11px 14px;
  text-align: left;
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
}

tbody tr {
  border-bottom: 1px solid var(--color-border-light);
  transition: background var(--transition-fast);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--color-sidebar-bg); }

tbody td {
  padding: 11px 14px;
  color: var(--color-text-primary);
  vertical-align: middle;
}

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
  line-height: 1.6;
}

.badge-primary { background: var(--color-primary-light);  color: var(--color-primary); }
.badge-success { background: var(--color-success-light);  color: var(--color-success); }
.badge-danger  { background: var(--color-danger-light);   color: var(--color-danger); }
.badge-warning { background: var(--color-warning-light);  color: #7d5500; }
.badge-muted   { background: var(--color-border-light);   color: var(--color-text-muted); }
.badge-info    { background: var(--color-info-light);     color: var(--color-info); }

/* ── Toggle Switch ───────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-base);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: var(--color-white);
  border-radius: 50%;
  transition: transform var(--transition-base);
  box-shadow: var(--shadow-xs);
}
.toggle input:checked + .toggle-slider {
  background: var(--color-success);
}
.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* ── Toast Notifications ─────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--color-text-primary);
  color: var(--color-white);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  min-width: 260px;
  max-width: 380px;
  animation: toastIn 0.3s ease forwards;
}
.toast.fade-out { animation: toastOut 0.3s ease forwards; }

.toast-icon { font-size: 1rem; flex-shrink: 0; }
.toast-msg  { flex: 1; }

.toast--success { background: var(--color-success); }
.toast--danger  { background: var(--color-danger); }
.toast--warning { background: #7d5500; }
.toast--info    { background: var(--color-primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  to   { opacity: 0; transform: translateY(8px) scale(0.96); }
}

/* ── Loading Spinner ─────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner--dark {
  border-color: rgba(134,98,110,0.2);
  border-top-color: var(--color-primary);
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row td {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-8) !important;
}

/* ── Section Header ──────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.section-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
}

/* ── Search Bar ──────────────────────────────────────────── */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}
.search-bar__icon {
  position: absolute;
  left: 10px;
  color: var(--color-text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
}
.search-bar input {
  padding-left: 34px;
}

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-6);
  color: var(--color-text-muted);
  text-align: center;
  gap: var(--space-3);
}
.empty-state__icon { font-size: 2.5rem; opacity: 0.5; }
.empty-state__text { font-size: var(--font-size-base); }


/* ============================================================
   ADMIN DASHBOARD LAYOUT
   ============================================================ */

/* ── Admin Shell ─────────────────────────────────────────── */
.admin-body {
  background: var(--color-bg);
}

.admin-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Admin Sidebar ───────────────────────────────────────── */
.admin-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-logo__mark {
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: var(--font-weight-bold);
  font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-logo__text {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-white);
  line-height: 1.2;
}
.sidebar-logo__sub {
  font-size: var(--font-size-xs);
  color: var(--sidebar-text);
  font-weight: var(--font-weight-normal);
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-4) 0;
}

.sidebar-nav__section {
  padding: var(--space-3) var(--space-4) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--sidebar-text);
  opacity: 0.5;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-5);
  color: var(--sidebar-text);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  border-radius: 0;
  transition: background var(--transition-fast), color var(--transition-fast);
  cursor: pointer;
  text-decoration: none;
  border-left: 3px solid transparent;
}
.nav-link:hover {
  background: rgba(255,255,255,0.06);
  color: var(--color-white);
  text-decoration: none;
}
.nav-link.active {
  background: rgba(134,98,110,0.15);
  color: var(--sidebar-text-active);
  border-left-color: var(--sidebar-accent);
}
.nav-link__icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.85;
}

.sidebar-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: var(--font-size-xs);
  color: var(--sidebar-text);
  opacity: 0.5;
}

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

/* ── Admin Topbar ────────────────────────────────────────── */
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  box-shadow: var(--shadow-xs);
}

.topbar-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.topbar-avatar {
  width: 32px;
  height: 32px;
  background: var(--color-primary-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-sm);
}

/* ── Admin Content ───────────────────────────────────────── */
.admin-content {
  flex: 1;
  padding: var(--space-6);
  max-width: 1400px;
}

/* ── Admin Sections ──────────────────────────────────────── */
.admin-section {
  display: none;
}
.admin-section.active {
  display: block;
}

/* ── Scrape Log / Recent Table ───────────────────────────── */
.recent-log {
  margin-top: var(--space-6);
}

/* ── Source Status Indicator ─────────────────────────────── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: var(--space-1);
}
.status-dot--active   { background: var(--color-success); }
.status-dot--inactive { background: var(--color-text-muted); }
.status-dot--error    { background: var(--color-danger); }

/* ── Add Source Form ─────────────────────────────────────── */
.add-source-form {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  margin-top: var(--space-6);
}
.add-source-form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: var(--space-4);
  align-items: end;
}

/* ── Ranking Config Form ─────────────────────────────────── */
.ranking-form {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  max-width: 640px;
}
.ranking-form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-4);
}
.ranking-form .weight-section {
  margin-bottom: var(--space-6);
}
.ranking-form .weight-section h4 {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-4);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ranking-form .weight-item {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.ranking-form .weight-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
}

/* ── Login Overlay ───────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #86626E 0%, #6B4E58 60%, #0F0E0E 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-login);
}
.login-overlay.hidden { display: none !important; }

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-xl);
}
.login-card__logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.login-card__logo-mark {
  width: 40px;
  height: 40px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: var(--font-weight-bold);
  font-size: 1.25rem;
}
.login-card__title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
}
.login-card__sub {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.login-card .form-group {
  margin-bottom: var(--space-4);
}
.login-error {
  color: var(--color-danger);
  font-size: var(--font-size-sm);
  margin-top: var(--space-2);
  display: none;
}

/* ── Scraping Overlay ────────────────────────────────────── */
.scrape-cell {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}


/* ============================================================
   SHOP UI LAYOUT
   ============================================================ */

/* ── Shop Body ───────────────────────────────────────────── */
.shop-body {
  background: var(--color-bg);
}

/* ── Shop Header ─────────────────────────────────────────── */
.shop-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-topbar);
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  gap: var(--space-4);
  box-shadow: var(--shadow-xs);
}

.shop-header__logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-primary);
  white-space: nowrap;
  text-decoration: none;
}
.shop-header__logo:hover { text-decoration: none; }
.shop-header__logo-mark {
  width: 30px;
  height: 30px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: var(--font-weight-bold);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.shop-header__search {
  flex: 1;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
}
.shop-header__search-icon {
  position: absolute;
  left: 12px;
  color: var(--color-text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
}
.shop-header__search input {
  width: 100%;
  padding: 8px 16px 8px 36px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-sidebar-bg);
  color: var(--color-text-primary);
  transition: border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  font-size: var(--font-size-sm);
}
.shop-header__search input:focus {
  border-color: var(--color-primary);
  background: var(--color-white);
  box-shadow: 0 0 0 3px rgba(134,98,110,0.12);
}

.shop-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

/* Cart Button */
.cart-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 14px;
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.cart-btn:hover { background: #E0D5EE; }
.cart-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--color-danger);
  color: white;
  font-size: 10px;
  font-weight: var(--font-weight-bold);
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--color-white);
}
.cart-count.hidden { display: none; }

/* ── Shop Layout ─────────────────────────────────────────── */
.shop-layout {
  display: flex;
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
}

/* ── Category Sidebar ────────────────────────────────────── */
.category-sidebar {
  position: fixed;
  top: var(--topbar-height);
  bottom: 0;
  left: 0;
  width: var(--cat-sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border-light);
  overflow-y: auto;
  padding: var(--space-5) 0;
  z-index: 50;
}

.category-sidebar__title {
  padding: 0 var(--space-4) var(--space-3);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.category-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  border-left: 3px solid transparent;
}
.category-link:hover {
  background: var(--color-sidebar-bg);
  color: var(--color-text-primary);
}
.category-link.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-left-color: var(--color-primary);
  font-weight: var(--font-weight-medium);
}
.category-link__count {
  font-size: var(--font-size-xs);
  background: var(--color-border-light);
  color: var(--color-text-muted);
  padding: 1px 7px;
  border-radius: var(--radius-full);
}
.category-link.active .category-link__count {
  background: rgba(134,98,110,0.15);
  color: var(--color-primary);
}

/* ── Shop Main Content ───────────────────────────────────── */
.shop-main {
  margin-left: var(--cat-sidebar-width);
  flex: 1;
  padding: var(--space-5) var(--space-6);
  max-width: 1200px;
}

.shop-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.product-count {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* ── Product Grid ────────────────────────────────────────── */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: var(--space-4);
}

/* ── Product Card ────────────────────────────────────────── */
.product-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow var(--transition-base), transform var(--transition-base);
  cursor: default;
}
.product-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.product-card__image-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--color-sidebar-bg);
  overflow: hidden;
  cursor: zoom-in;
}
.product-card__image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow);
}
.product-card:hover .product-card__image-wrap img {
  transform: scale(1.04);
}

.product-card__badges {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.product-card__body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: var(--space-1);
}

.product-card__category {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.product-card__name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-card__desc {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.product-card__desc-toggle {
  font-size: var(--font-size-xs);
  color: var(--color-primary);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}
.product-card__desc-toggle:hover { text-decoration: underline; }

.product-card__footer {
  margin-top: auto;
  padding-top: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.product-card__price {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
}

.product-card__price-orig {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  text-decoration: line-through;
}

.product-card__add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  font-size: 1.1rem;
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
  border: none;
  flex-shrink: 0;
}
.product-card__add:hover { background: var(--color-primary-dark); transform: scale(1.1); }
.product-card__add:active { transform: scale(0.95); }

/* Loading skeleton */
.product-card--skeleton .product-card__image-wrap,
.product-card--skeleton .product-card__name,
.product-card--skeleton .product-card__price,
.product-card--skeleton .product-card__category {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
  color: transparent;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── Cart Sidebar ────────────────────────────────────────── */
.cart-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  background: var(--color-surface);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-cart);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-base);
}
.cart-sidebar.open { transform: translateX(0); }

.cart-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-5);
  border-bottom: 1px solid var(--color-border-light);
}
.cart-sidebar__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
}

.cart-sidebar__close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--color-text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.cart-sidebar__close:hover { background: var(--color-border-light); }

.cart-sidebar__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.cart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-3);
  color: var(--color-text-muted);
  text-align: center;
}
.cart-empty__icon { font-size: 2.5rem; opacity: 0.4; }

/* Cart Item */
.cart-item {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-sidebar-bg);
  border: 1px solid var(--color-border-light);
}

.cart-item__img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--color-border-light);
}

.cart-item__info {
  flex: 1;
  min-width: 0;
}
.cart-item__name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cart-item__price {
  font-size: var(--font-size-sm);
  color: var(--color-primary);
  font-weight: var(--font-weight-semibold);
  margin-top: 2px;
}

.cart-item__controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.qty-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border);
  background: var(--color-white);
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.qty-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
.qty-display {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  min-width: 20px;
  text-align: center;
}

.cart-item__remove {
  color: var(--color-text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
  flex-shrink: 0;
}
.cart-item__remove:hover { color: var(--color-danger); }

.cart-sidebar__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: var(--font-weight-semibold);
}
.cart-total-row .total-label { color: var(--color-text-secondary); }
.cart-total-row .total-amount {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
}

/* Cart Overlay Scrim */
.cart-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: calc(var(--z-cart) - 1);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.cart-scrim.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── Chat Widget ─────────────────────────────────────────── */
.chat-fab {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-chat);
  transition: background var(--transition-fast), transform var(--transition-fast);
  border: none;
}
.chat-fab:hover {
  background: var(--color-primary-dark);
  transform: scale(1.06);
}

.chat-panel {
  position: fixed;
  bottom: calc(var(--space-6) + 64px);
  right: var(--space-6);
  width: 340px;
  height: 480px;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-chat);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.85) translateY(24px);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom right;
  transition: transform var(--transition-base), opacity var(--transition-base);
  border: 1px solid var(--color-border-light);
}
.chat-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.chat-panel__header {
  padding: 14px var(--space-4);
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.chat-panel__title {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.chat-online-dot {
  width: 8px;
  height: 8px;
  background: var(--color-success);
  border-radius: 50%;
  display: inline-block;
  border: 2px solid white;
}
.chat-panel__close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background var(--transition-fast);
}
.chat-panel__close:hover { background: rgba(255,255,255,0.35); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 80%;
}
.chat-msg--user { align-self: flex-end; align-items: flex-end; }
.chat-msg--bot  { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  font-size: var(--font-size-sm);
  line-height: 1.4;
  word-break: break-word;
}
.chat-msg--user .chat-bubble {
  background: var(--color-primary);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}
.chat-msg--bot .chat-bubble {
  background: var(--color-sidebar-bg);
  color: var(--color-text-primary);
  border-bottom-left-radius: var(--radius-sm);
  border: 1px solid var(--color-border-light);
}

.chat-time {
  font-size: 10px;
  color: var(--color-text-muted);
  padding: 0 4px;
}

.chat-typing {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 8px 12px;
  background: var(--color-sidebar-bg);
  border-radius: 16px;
  border-bottom-left-radius: var(--radius-sm);
  width: fit-content;
  border: 1px solid var(--color-border-light);
}
.chat-typing span {
  width: 6px;
  height: 6px;
  background: var(--color-text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); }
}

.chat-panel__input {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border-light);
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}
.chat-panel__input input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-full);
  outline: none;
  font-size: var(--font-size-sm);
  transition: border-color var(--transition-fast);
}
.chat-panel__input input:focus { border-color: var(--color-primary); }
.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  flex-shrink: 0;
  border: none;
  transition: background var(--transition-fast);
}
.chat-send-btn:hover { background: var(--color-primary-dark); }

/* ── Lightbox ────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: var(--z-lightbox);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.lightbox.open {
  opacity: 1;
  pointer-events: auto;
}
.lightbox__img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  transform: scale(0.9);
  transition: transform var(--transition-base);
}
.lightbox.open .lightbox__img { transform: scale(1); }
.lightbox__close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  border: none;
  transition: background var(--transition-fast);
}
.lightbox__close:hover { background: rgba(255,255,255,0.3); }

/* ── Availability Indicator ──────────────────────────────── */
.avail-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
  flex-shrink: 0;
}
.avail-dot--in   { background: var(--color-success); }
.avail-dot--low  { background: var(--color-warning); }
.avail-dot--out  { background: var(--color-danger); }


/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1024px) {
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
  .add-source-form .form-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
    --cat-sidebar-width: 0px;
  }

  /* Admin: hide sidebar on mobile, show topbar menu */
  .admin-sidebar {
    transform: translateX(-240px);
    width: 240px;
    transition: transform var(--transition-base);
  }
  .admin-sidebar.mobile-open {
    transform: translateX(0);
    --sidebar-width: 240px;
  }
  .admin-main { margin-left: 0; }
  .admin-content { padding: var(--space-4); }

  /* Shop: hide category sidebar */
  .category-sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition-base);
  }
  .category-sidebar.mobile-open { transform: translateX(0); }
  .shop-main { margin-left: 0; }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-3);
  }

  .cart-sidebar { width: 100%; }

  .chat-panel {
    width: calc(100vw - 24px);
    right: 12px;
  }

  .stat-cards { grid-template-columns: 1fr 1fr; }

  .add-source-form .form-row {
    grid-template-columns: 1fr;
  }
  .ranking-form .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .stat-cards { grid-template-columns: 1fr; }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .shop-header__search { display: none; }
}
