:root {
  --ink: #1a1f16;
  --muted: #5c6754;
  --paper: #f3efe6;
  --card: #fffdf8;
  --line: #d8d0c2;
  --accent: #2f6b4f;
  --accent-dark: #1f4a36;
  --danger: #9b3b2f;
  --sidebar: #1f4a36;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: var(--font); color: var(--ink); background: var(--paper); }

a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }

.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 0.55rem 1rem;
  font: inherit; font-weight: 600; font-size: 0.88rem; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn.icon { width: 2rem; height: 2rem; padding: 0; border-radius: 6px; }

/* Landing */
.landing { max-width: 960px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.landing-header { display: flex; gap: 1rem; align-items: center; margin-bottom: 2rem; }
.brand-mark {
  width: 3rem; height: 3rem; border-radius: 12px; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 1.4rem;
}
.landing h1 { margin: 0 0 0.25rem; font-size: 1.8rem; }
.landing p { margin: 0; color: var(--muted); }
.landing-actions { margin-bottom: 2rem; }
.catalog-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.catalog-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem;
}
.catalog-card h3 { margin: 0 0 0.35rem; font-size: 1.05rem; }
.card-actions { display: flex; gap: 0.5rem; margin-top: 0.85rem; }

/* Admin layout */
.admin-body { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px; background: var(--sidebar); color: #e8f0ea;
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem; border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar-head .btn { color: #fff; border-color: rgba(255,255,255,0.3); }
.catalog-nav { flex: 1; overflow-y: auto; padding: 0.5rem; }
.catalog-nav button {
  width: 100%; text-align: left; background: transparent; border: none;
  color: inherit; padding: 0.65rem 0.75rem; border-radius: 8px; cursor: pointer; font: inherit;
}
.catalog-nav button:hover { background: rgba(255,255,255,0.08); }
.catalog-nav button.active { background: rgba(255,255,255,0.15); font-weight: 600; }
.sidebar-link { padding: 1rem; color: rgba(255,255,255,0.7); text-decoration: none; font-size: 0.85rem; }

.main { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem 2rem; }
.empty-state { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.workspace-header {
  display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: flex-start;
  margin-bottom: 1.25rem;
}
.workspace-header h1 { margin: 0; font-size: 1.5rem; }
.header-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.categories-bar {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--line);
}
.categories-tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; flex: 1; }
.cat-tab {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 0.35rem 0.85rem; font-size: 0.82rem; cursor: pointer;
}
.cat-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.toolbar { display: flex; gap: 0.75rem; margin-bottom: 1rem; }
.toolbar input[type=search] {
  flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.85rem; font: inherit;
}

.product-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.85rem;
}
.product-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; position: relative;
}
.product-card.inactive { opacity: 0.5; }
.product-card.just-scraped {
  outline: 2px solid var(--green, #2f6b4f);
  box-shadow: 0 0 0 3px rgba(47, 107, 79, 0.15);
}
.scrape-live {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line, #d5cec0);
  border-radius: 10px;
  background: #f8faf7;
}
.scrape-live.hidden { display: none; }
.scrape-live-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.scrape-progress {
  height: 6px;
  background: #e6e0d4;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.65rem;
}
.scrape-progress div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2f6b4f, #4a9b6e);
  transition: width 0.25s ease;
}
.scrape-live-log {
  max-height: 140px;
  overflow: auto;
  font-size: 0.78rem;
  line-height: 1.45;
}
.scrape-log-line { padding: 0.15rem 0; color: var(--muted); }
.scrape-log-line.ok { color: #2f6b4f; }
.scrape-log-line.fail { color: #a04444; }
.product-card .thumb {
  aspect-ratio: 4/3; background: #eef2ea; display: grid; place-items: center; overflow: hidden;
}
.product-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.product-card .body { padding: 0.75rem; }
.product-card .name { font-weight: 600; font-size: 0.88rem; line-height: 1.3; margin-bottom: 0.25rem; }
.product-card .code { font-size: 0.75rem; color: var(--muted); }
.product-card .price { font-weight: 700; color: var(--accent-dark); margin-top: 0.35rem; }
.product-card .cat-label { font-size: 0.72rem; color: var(--muted); margin-top: 0.15rem; }
.product-card .actions {
  display: flex; gap: 0.35rem; padding: 0 0.75rem 0.75rem;
}
.product-card .actions button { flex: 1; font-size: 0.75rem; padding: 0.35rem; }

/* Modal */
.modal {
  border: none; border-radius: 14px; padding: 0; max-width: 480px; width: calc(100% - 2rem);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal::backdrop { background: rgba(0,0,0,0.4); }
.modal-header, .modal-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.15rem; border-bottom: 1px solid var(--line);
}
.modal-footer { border-bottom: none; border-top: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 1.15rem; display: flex; flex-direction: column; gap: 0.85rem; }
.modal-body label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; font-weight: 600; }
.modal-body input, .modal-body select {
  font: inherit; padding: 0.5rem 0.65rem; border: 1px solid var(--line); border-radius: 8px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.url-row { display: flex; gap: 0.5rem; margin-top: 0.35rem; flex-wrap: wrap; }
.url-row input { flex: 1; min-width: 160px; }
.checkbox { flex-direction: row !important; align-items: center; font-weight: 500 !important; }

.upload-zone {
  border: 2px dashed var(--line); border-radius: 10px; padding: 1.5rem;
  text-align: center; cursor: pointer; min-height: 120px; display: grid; place-items: center;
}
.upload-zone img { max-width: 100%; max-height: 140px; object-fit: contain; }
.upload-zone.dragover { border-color: var(--accent); background: #eef6f0; }

/* Public catalog */
.catalog-body { background: var(--paper); }
.pub-header {
  background: var(--accent-dark); color: #fff; padding: 1.25rem 1.5rem;
}
.pub-header-inner { max-width: 1100px; margin: 0 auto; }
.pub-header h1 { margin: 0; font-size: 1.6rem; }
.pub-header .sub { opacity: 0.85; font-size: 0.88rem; margin-top: 0.25rem; }
.pub-contact { font-size: 0.82rem; opacity: 0.75; margin-top: 0.35rem; }

.pub-main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.pub-category { margin-bottom: 2rem; }
.pub-category h2 {
  font-size: 1.1rem; color: var(--accent-dark); border-bottom: 2px solid var(--accent);
  padding-bottom: 0.4rem; margin: 0 0 1rem;
}
.pub-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.85rem;
}
.pub-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.pub-card .thumb { aspect-ratio: 4/3; background: #eef2ea; display: grid; place-items: center; }
.pub-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.pub-card .body { padding: 0.75rem; }
.pub-card .name { font-weight: 600; font-size: 0.9rem; line-height: 1.3; }
.pub-card .code { font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }
.pub-card .price { font-weight: 700; font-size: 1.05rem; color: var(--accent-dark); margin-top: 0.4rem; }

@media (max-width: 768px) {
  .admin-body { flex-direction: column; }
  .sidebar { width: 100%; max-height: 200px; }
  .row2 { grid-template-columns: 1fr; }
}
