/* ============================================================
   Feed Enricher – Main Stylesheet
   ============================================================ */

/* ── Reset & Custom Properties ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f0f4f8;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --border-focus: #3b82f6;

  --text:         #1e293b;
  --text-muted:   #64748b;
  --text-sm:      13px;

  --primary:      #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light:#dbeafe;

  --success:      #16a34a;
  --success-bg:   #dcfce7;
  --success-border:#bbf7d0;

  --danger:       #dc2626;
  --danger-bg:    #fee2e2;
  --danger-border:#fecaca;

  --warning:      #d97706;
  --warning-bg:   #fef3c7;
  --warning-border:#fde68a;

  --nav-bg:       #0f172a;
  --nav-text:     #94a3b8;
  --nav-active-bg:#1e3a8a;
  --nav-hover-bg: #1e293b;

  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 4px rgba(0,0,0,.07), 0 4px 12px rgba(0,0,0,.04);
  --shadow-sm:    0 1px 3px rgba(0,0,0,.06);
  --transition:   150ms ease;

  --sidebar-w:    256px;
  --font:         'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App shell ─────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--nav-bg);
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 200;
}

.sidebar-brand {
  padding: 20px 18px;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}
.sidebar-brand a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
}
.sidebar-brand svg { color: #60a5fa; }

.sidebar-section-label {
  padding: 18px 18px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #475569;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: var(--nav-text);
  font-size: 14px;
  text-decoration: none;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  position: relative;
}
.nav-item:hover { background: var(--nav-hover-bg); color: #e2e8f0; text-decoration: none; }
.nav-item.active {
  background: var(--nav-active-bg);
  color: #fff;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: #60a5fa;
}
.nav-icon { display: flex; align-items: center; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-user { flex: 1; display: flex; align-items: center; gap: 10px; overflow: hidden; }
.sidebar-user-avatar {
  width: 32px; height: 32px;
  background: #334155;
  color: #e2e8f0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
  flex-shrink: 0;
}
.sidebar-user-info { overflow: hidden; }
.sidebar-user-name { color: #e2e8f0; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { color: #64748b; font-size: 11px; }
.nav-item-logout { padding: 6px; border-radius: 6px; flex-shrink: 0; }

/* ── Content area ──────────────────────────────────────────── */
.content-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Page sections ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 28px 32px 0;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-narrow { max-width: 560px; }
.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 24px; }
.card-empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.card-empty h3 { color: var(--text); font-size: 16px; }
.card-empty svg { color: #cbd5e1; }

/* ── Stat grid ─────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  padding: 24px 32px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon-blue   { background: #dbeafe; color: #1d4ed8; }
.stat-icon-green  { background: #dcfce7; color: #15803d; }
.stat-icon-purple { background: #ede9fe; color: #7c3aed; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Layout helpers ────────────────────────────────────────── */
.layout-two-col {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  padding: 24px 32px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout-two-col { grid-template-columns: 1fr; }
}

.mt-6  { margin-top: 24px; }
.mb-4  { margin-bottom: 16px; }
.mt-3  { margin-top: 12px; }

/* Main page body has inner padding (for pages that don't use .stat-grid or .layout-two-col) */
.page-body { padding: 24px 32px; }

/* Page-level padding applied to common containers */
.page-header,
.feed-meta-bar,
.mass-edit-bar,
.product-toolbar,
.pagination {
  padding-left: 32px;
  padding-right: 32px;
}

.mass-edit-bar { margin-top: 16px; }
.product-toolbar { padding-top: 0; }

.content-area > .alert { margin: 16px 32px 0; }
.content-area > .card  { margin: 24px 32px; }
.products-card         { margin: 0 32px 24px; }

/* ── Tables ─────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafc; }

.col-cb    { width: 40px; }
.col-id    { width: 140px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-expand { width: 40px; text-align: right; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), box-shadow var(--transition), border-color var(--transition);
  white-space: nowrap;
  user-select: none;
}
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; text-decoration: none; }

.btn-secondary {
  background: #f1f5f9;
  color: #475569;
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; text-decoration: none; }

.btn-sm { padding: 5px 10px; font-size: 13px; gap: 4px; }
.btn-full { width: 100%; justify-content: center; }

/* Icon-only button */
.btn-expand {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background var(--transition), color var(--transition);
}
.btn-expand:hover { background: var(--border); color: var(--text); }
.product-row.is-expanded .btn-expand svg { transform: rotate(180deg); }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 5px;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 0;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
textarea,
select {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
textarea { resize: vertical; min-height: 80px; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.select-inline { width: auto; padding: 4px 28px 4px 8px; font-size: 13px; }

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border: 1px solid transparent;
  margin: 0 0 0 0;
}
.alert-success { background: var(--success-bg); color: #14532d; border-color: var(--success-border); }
.alert-error   { background: var(--danger-bg);  color: #7f1d1d; border-color: var(--danger-border); }
.alert-warning { background: var(--warning-bg); color: #78350f; border-color: var(--warning-border); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: var(--success-bg); color: #15803d; }
.badge-red    { background: var(--danger-bg);  color: #b91c1c; }
.badge-gray   { background: #f1f5f9; color: #475569; }

/* ── Typography helpers ─────────────────────────────────────── */
.fw-medium  { font-weight: 500; }
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: var(--text-sm); }
.text-right { text-align: right; }
.link-primary { color: var(--primary); font-weight: 500; }
.link-primary:hover { text-decoration: underline; }
.link-muted { color: var(--text-muted); }
.link-muted:hover { color: var(--text); }

/* ── Domain group (users by domain) ────────────────────────── */
.domain-group { border-bottom: 1px solid var(--border); }
.domain-group:last-child { border-bottom: none; }
.domain-group-header {
  padding: 10px 16px;
  background: #f8fafc;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

/* ── Inline forms ───────────────────────────────────────────── */
.inline-form { display: inline-flex; }
.inline-form button { margin: 0; }

/* ── Input copy ─────────────────────────────────────────────── */
.token-url { display: flex; align-items: center; gap: 6px; max-width: 380px; }
.input-copy {
  flex: 1;
  padding: 5px 8px;
  font-size: 12px;
  font-family: monospace;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: text;
}
.input-copy-sm { max-width: 320px; }

/* ── View toggle ────────────────────────────────────────────── */
.view-toggle { display: flex; gap: 4px; }

/* ── Auth page ──────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
}
.auth-container { width: 100%; max-width: 400px; padding: 24px; }
.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 28px;
}
.auth-brand svg { color: #60a5fa; }
.auth-card {
  background: #fff;
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.auth-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.auth-card .alert { margin-bottom: 16px; }

/* ── Feed editor ────────────────────────────────────────────── */
.feed-editor-header {
  padding-bottom: 16px;
  flex-wrap: wrap;
  row-gap: 16px;
}
.feed-header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.output-url-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.feed-meta-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 10px 0;
  padding-left: 0;
  padding-right: 0;
}

/* Mass edit bar */
.mass-edit-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--nav-bg);
  color: #e2e8f0;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 0;
  transition: opacity var(--transition), transform var(--transition);
  transform: translateY(-4px);
  opacity: 0;
  pointer-events: none;
}
.mass-edit-bar.visible { transform: translateY(0); opacity: 1; pointer-events: all; }
.mass-edit-count { font-size: 13px; font-weight: 600; white-space: nowrap; }
.mass-edit-field { display: flex; gap: 6px; }
.mass-edit-field .field-select { width: 220px; }
.mass-value-input {
  flex: 1;
  min-width: 160px;
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid #334155;
  border-radius: var(--radius-sm);
  background: #1e293b;
  color: #e2e8f0;
}
.mass-value-input::placeholder { color: #64748b; }
.mass-value-input:focus { outline: none; border-color: #60a5fa; }

/* Product toolbar */
.product-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  gap: 12px;
  flex-wrap: wrap;
}
.search-form { display: flex; gap: 6px; align-items: center; }
.search-input-wrap { position: relative; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-input { padding-left: 32px; min-width: 240px; }

/* Product table */
.products-card { overflow: visible; }
.product-row { cursor: pointer; }
.product-row:hover td { background: #f0f4f8; }
.product-row.is-expanded td { background: #f0f9ff; }
.product-title.is-overridden { color: var(--primary); }
.col-price.is-overridden { color: var(--primary); }

/* Expanded detail */
.product-detail-row { display: none; }
.product-detail-row.visible { display: table-row; }
.product-detail-cell { padding: 0 !important; }
.product-detail {
  padding: 20px 24px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.detail-add-override { width: 100%; }
.add-override-form {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
  width: 100%;
}
.add-override-form .field-select { flex: 1; min-width: 200px; }
.detail-override-value { flex: 1; min-width: 200px; }

/* Override chips (kept for potential reuse) */
.override-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Field grid */
.detail-fields { min-width: 0; width: 100%; }
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.field-cell {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  overflow: hidden;
  position: relative;
  transition: border-color var(--transition);
}
.field-cell:hover { border-color: #93c5fd; }
.field-cell.field-overridden { border-color: #bfdbfe; background: #eff6ff; }
.field-cell.field-custom     { border-color: #a5b4fc; background: #eef2ff; }
.field-cell-name {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  user-select: none;
  padding-right: 18px; /* room for delete button */
}
.field-cell:hover .field-cell-name { color: var(--primary); }

/* Delete button shown on overridden cells */
.field-cell-delete {
  position: absolute;
  top: 6px; right: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--danger);
  font-size: 16px;
  line-height: 1;
  padding: 0 3px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
}
.field-cell.field-overridden:hover .field-cell-delete,
.field-cell.field-custom:hover .field-cell-delete  { opacity: 1; }
.field-cell-delete:hover { background: var(--danger-bg); }
.field-cell-value {
  color: var(--text);
  word-break: break-word;
  max-height: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.override-value { color: var(--primary); font-weight: 500; }
.original-value { color: var(--text-muted); text-decoration: line-through; font-size: 12px; margin-top: 2px; display: block; }

/* Custom field input */
.input-custom-field { flex: 1; }
.hidden { display: none !important; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 0;
}
.pagination-info { font-size: 13px; color: var(--text-muted); }

/* ── Toast notifications ─────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #1e293b;
  color: #e2e8f0;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 320px;
  animation: toast-in .2s ease;
}
.toast.toast-success { background: #14532d; }
.toast.toast-error   { background: #7f1d1d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── Modal ───────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 1000; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(2px);
}
.modal-box {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-box p { font-size: 14px; color: var(--text-muted); margin-bottom: 10px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ── Misc ────────────────────────────────────────────────────── */
code { font-family: 'Fira Code', 'Consolas', monospace; font-size: 13px; background: #f1f5f9; padding: 2px 6px; border-radius: 4px; }
