:root {
  --bg: #f7f5f1;
  --paper: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665e;
  --brand: #8b5a2b;
  --brand-dark: #6b4421;
  --accent: #2f6e8b;
  --danger: #b3261e;
  --line: #e5e0d6;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin:0; padding:0; }
body { font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar { display:flex; justify-content:space-between; align-items:center; padding:14px 32px; background:var(--paper); border-bottom:1px solid var(--line); position:sticky; top:0; z-index:50; }
.brand { font-size:18px; font-weight:700; color:var(--brand); text-decoration:none; }
.topbar nav a { margin-left:18px; color:var(--text); }

main { max-width: 1200px; margin: 0 auto; padding: 24px 32px 80px; }

.hero { padding: 30px 0 18px; }
.hero h1 { margin: 0 0 4px; font-size: 28px; }
.hero p { margin: 0; color: var(--muted); }

.filters { display:grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap:10px; margin: 18px 0 24px; background:var(--paper); padding:14px; border:1px solid var(--line); border-radius:var(--radius); }
.filters input, .filters select { padding:8px 10px; border:1px solid var(--line); border-radius:6px; font:inherit; background:#fff; }
.filters button { background:var(--brand); color:#fff; border:0; border-radius:6px; padding:8px 16px; cursor:pointer; }
.filters button:hover { background:var(--brand-dark); }

.grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap:18px; }
.card { background:var(--paper); border:1px solid var(--line); border-radius:var(--radius); overflow:hidden; transition:transform .15s, box-shadow .15s; color:inherit; text-decoration:none !important; box-shadow:var(--shadow); display:block; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.10); }
.card img { width:100%; height:180px; object-fit:cover; display:block; background:#eee; }
.card .noimg, .noimg { background:#eee; color:var(--muted); display:flex; align-items:center; justify-content:center; height:180px; }
.noimg.big { height:360px; }
.noimg.s { display:inline-flex; height:auto; padding:6px 8px; border-radius:4px; }
.card-body { padding:12px 14px; }
.cat { font-size:11px; text-transform:uppercase; color:var(--muted); letter-spacing:.6px; }
.card h3 { margin:4px 0 6px; font-size:15px; line-height:1.3; }
.price { font-size:16px; font-weight:700; color:var(--brand-dark); }
.price.big { font-size:24px; margin: 6px 0 14px; }

.dots { display:flex; gap:6px; margin-top:8px; }
.dot { width:14px; height:14px; border-radius:50%; border:1px solid rgba(0,0,0,.15); display:inline-block; }
.dot.lg { width:24px; height:24px; }

.empty { grid-column:1/-1; padding:40px; text-align:center; color:var(--muted); }

.foot { text-align:center; color:var(--muted); padding:24px 0 40px; font-size:12px; }

.back { display:inline-block; margin-bottom:10px; }

/* Detail */
.detail { display:grid; grid-template-columns: 1.1fr 1fr; gap:32px; background:var(--paper); padding:24px; border-radius:var(--radius); border:1px solid var(--line); }
.detail-gallery img { width:100%; max-height:420px; object-fit:cover; border-radius:8px; background:#eee; }
.thumbs { display:flex; gap:8px; margin-top:10px; flex-wrap:wrap; }
.thumb { width:64px; height:64px; object-fit:cover; cursor:pointer; border-radius:6px; opacity:.8; }
.thumb:hover { opacity:1; outline:2px solid var(--brand); }
.detail-info h1 { margin: 4px 0 0; font-size:24px; }
.desc { color:var(--text); white-space:pre-wrap; }
.block { margin-top:18px; }
.block h4 { margin:0 0 6px; color:var(--brand-dark); font-size:14px; text-transform:uppercase; letter-spacing:.5px; }
.kv { padding-left:18px; margin:6px 0; }
.kv li { margin:2px 0; }
.comp-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap:10px; }
.comp-card { background:#fff; border:1px solid var(--line); border-radius:8px; overflow:hidden; padding:8px; display:flex; flex-direction:column; gap:8px; align-items:center; text-align:center; color:inherit; }
.comp-card img { width:100%; height:80px; object-fit:cover; border-radius:4px; }

@media (max-width: 760px) {
  .detail { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
}

/* Chat widget */
.chat-fab { position:fixed; right:24px; bottom:24px; padding:12px 18px; background:var(--brand); color:#fff; border:0; border-radius:30px; font-size:14px; cursor:pointer; box-shadow:0 4px 14px rgba(139,90,43,.4); z-index:60; }
.chat-fab:hover { background:var(--brand-dark); }
.chat-panel { position:fixed; right:24px; bottom:80px; width:360px; max-height:520px; background:var(--paper); border:1px solid var(--line); border-radius:12px; box-shadow:0 10px 30px rgba(0,0,0,.18); display:flex; flex-direction:column; z-index:60; }
.chat-panel[hidden] { display:none !important; }
.chat-panel header { padding:12px; border-bottom:1px solid var(--line); display:flex; justify-content:space-between; align-items:center; }
.chat-panel header button { background:none; border:0; font-size:22px; cursor:pointer; line-height:1; }
.chat-log { flex:1; overflow-y:auto; padding:12px; display:flex; flex-direction:column; gap:8px; }
.msg { padding:8px 12px; border-radius:14px; max-width:85%; line-height:1.35; }
.msg.user { background:var(--accent); color:#fff; align-self:flex-end; border-bottom-right-radius:4px; }
.msg.bot { background:#f1ecdf; color:var(--text); align-self:flex-start; border-bottom-left-radius:4px; }
.msg.bot.thinking { font-style:italic; color:var(--muted); }
#chatForm { display:flex; border-top:1px solid var(--line); padding:8px; gap:6px; }
#chatForm input { flex:1; border:1px solid var(--line); border-radius:6px; padding:8px; font:inherit; }
#chatForm button { background:var(--brand); color:#fff; border:0; border-radius:6px; padding:0 14px; cursor:pointer; }

@media (max-width: 480px) {
  .chat-panel { right:8px; left:8px; width:auto; }
}

/* Admin */
.admin-bar { display:flex; justify-content:space-between; align-items:center; margin-bottom:14px; }
.btn { display:inline-block; padding:6px 12px; border:1px solid var(--line); background:#fff; border-radius:6px; cursor:pointer; font:inherit; color:var(--text); text-decoration:none; }
.btn:hover { background:#fafafa; text-decoration:none; }
.btn.primary { background:var(--brand); color:#fff; border-color:var(--brand); }
.btn.primary:hover { background:var(--brand-dark); }
.btn.danger { background:#fff; color:var(--danger); border-color:#e3b9b6; }
.btn.danger:hover { background:#fdecea; }
.admin-table { width:100%; border-collapse:collapse; background:var(--paper); border:1px solid var(--line); border-radius:var(--radius); overflow:hidden; }
.admin-table th, .admin-table td { padding:10px 12px; border-bottom:1px solid var(--line); text-align:left; vertical-align:middle; }
.admin-table tbody tr:last-child td { border-bottom:0; }
.row-thumb { width:50px; height:50px; object-fit:cover; border-radius:4px; }

.prod-form { background:var(--paper); border:1px solid var(--line); border-radius:var(--radius); padding:20px; max-width:880px; }
.prod-form .row { display:grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap:14px; }
.prod-form label { display:block; margin-bottom:14px; font-size:13px; font-weight:600; }
.prod-form label.checkbox { display:flex; align-items:center; gap:8px; font-weight:500; }
.prod-form input, .prod-form textarea, .prod-form select { width:100%; padding:8px 10px; border:1px solid var(--line); border-radius:6px; font:inherit; background:#fff; margin-top:4px; }
.prod-form small { display:block; color:var(--muted); font-weight:400; margin-top:4px; }
.actions { display:flex; gap:10px; margin-top:18px; }
.hint { background:#fafafa; border:1px solid var(--line); padding:8px 12px; border-radius:6px; font-size:13px; }
.hint ul { margin:8px 0 0; padding-left:20px; }
.existing-imgs { margin:14px 0; }
.existing-imgs .imgs { display:grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap:10px; }
.img-tile { background:#fafafa; border:1px solid var(--line); border-radius:6px; padding:6px; }
.img-tile.primary { border-color:var(--brand); box-shadow:0 0 0 2px rgba(139,90,43,.15); }
.img-tile img { width:100%; height:100px; object-fit:cover; border-radius:4px; }
.img-actions { display:flex; flex-direction:column; gap:4px; margin-top:6px; }
.img-actions form { margin:0; }
.badge { background:var(--brand); color:#fff; padding:2px 8px; border-radius:10px; font-size:11px; text-align:center; }

/* Galería existente fuera del form principal */
.existing-imgs { background:var(--paper); border:1px solid var(--line); border-radius:var(--radius); padding:16px 20px; margin:18px 0; max-width:880px; }
.existing-imgs h4 { margin:0 0 10px; }

/* Flash messages */
.flash { padding:10px 14px; border-radius:8px; margin: 0 0 14px; font-weight:500; transition: opacity .4s ease; max-width:880px; }
.flash.hide { opacity:0; }
.flash-ok { background:#e8f5e9; border:1px solid #a5d6a7; color:#2e7d32; }
.flash-info { background:#fff8e1; border:1px solid #ffe082; color:#8d6e00; }
.flash-err { background:#fdecea; border:1px solid #e3b9b6; color:var(--danger); padding:10px 14px; border-radius:8px; margin: 0 0 14px; font-weight:500; }

/* Login admin */
.login-wrap {
  min-height: calc(100vh - 180px);
  display:flex; align-items:center; justify-content:center;
  padding: 24px 16px;
  background:
    radial-gradient(circle at 20% 0%, rgba(139,90,43,.10), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(47,110,139,.08), transparent 50%);
}
.login-card {
  background: var(--paper);
  border:1px solid var(--line);
  border-radius:16px;
  padding: 36px 34px 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 18px 50px rgba(0,0,0,.10);
  position:relative;
  overflow:hidden;
}
.login-card::before {
  content:""; position:absolute; top:0; left:0; right:0; height:4px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}
.login-brand { font-size:30px; line-height:1; margin-bottom:12px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; color: var(--text); }
.login-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card label {
  display:block; font-size:13px; font-weight:600; color: var(--text);
  margin-bottom: 14px;
}
.login-card input[type="text"],
.login-card input[type="password"],
.login-card input:not([type]) {
  width:100%; padding:11px 12px; border:1px solid var(--line);
  border-radius:8px; font:inherit; background:#fff;
  margin-top:6px; transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus {
  outline:none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(139,90,43,.15);
}
.login-btn {
  width:100%; padding: 12px 18px; font-weight:600; font-size:15px;
  margin-top: 6px; border-radius:8px; cursor:pointer;
}
.login-foot { color: var(--muted); font-size:12px; text-align:center; margin: 18px 0 0; }
.logout-form { margin: 0; display:inline-block; }

/* Tira "Sesión iniciada" en barra admin */
.admin-bar .who { font-size:13px; color: var(--muted); margin-right:10px; }
.admin-bar .right { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }

/* ===== Inventario de Materia Prima ===== */
.inv-kpis { display:grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap:14px; margin-bottom:24px; }
.kpi-card { background:var(--paper); border:1px solid var(--line); border-radius:var(--radius); padding:18px 20px; text-align:center; box-shadow:var(--shadow); }
.kpi-card.kpi-warn { border-color:#e67e22; background:#fffbf5; }
.kpi-card.kpi-danger { border-color:var(--danger); background:#fdecea; }
.kpi-num { font-size:36px; font-weight:700; line-height:1.1; color:var(--brand-dark); }
.kpi-warn .kpi-num { color:#e67e22; }
.kpi-danger .kpi-num { color:var(--danger); }
.kpi-label { font-size:12px; color:var(--muted); margin-top:4px; text-transform:uppercase; letter-spacing:.5px; }

.inv-section { margin-bottom:28px; }
.inv-section-title { font-size:16px; font-weight:700; margin:0 0 10px; color:var(--text); }

.badge-stock { display:inline-block; padding:3px 10px; border-radius:10px; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; }
.badge-stock.ok { background:#e8f5e9; color:#2e7d32; border:1px solid #a5d6a7; }
.badge-stock.bajo { background:#fff8e1; color:#8d6e00; border:1px solid #ffe082; }
.badge-stock.critico { background:#fdecea; color:var(--danger); border:1px solid #e3b9b6; }

.badge-mov { display:inline-block; padding:2px 8px; border-radius:8px; font-size:11px; font-weight:700; text-transform:uppercase; }
.badge-mov.entrada { background:#e8f5e9; color:#2e7d32; }
.badge-mov.salida { background:#fdecea; color:var(--danger); }

.stock-bar-wrap { background:#eee; border-radius:4px; height:6px; width:80px; display:inline-block; vertical-align:middle; margin-right:6px; overflow:hidden; }
.stock-bar { height:100%; border-radius:4px; transition:width .3s; }

.row-bajo td { background:#fffbf5; }
.row-critico td { background:#fdecea; }

.inv-search { display:flex; gap:8px; margin-bottom:16px; }
.inv-search input { padding:8px 12px; border:1px solid var(--line); border-radius:6px; font:inherit; width:280px; }

.inv-filters { display:flex; gap:8px; margin-bottom:14px; }

.inline-form { display:flex; gap:6px; align-items:center; }
.input-sm { width:70px; padding:5px 8px; border:1px solid var(--line); border-radius:6px; font:inherit; text-align:center; }

.pager { display:flex; gap:6px; margin-top:16px; }

/* Widget alertas inventario en panel de productos */
.inv-alert-widget { background:#fff8e1; border:1px solid #ffe082; border-radius:var(--radius); padding:12px 16px; margin-bottom:16px; }
.inv-alert-header { display:flex; align-items:center; gap:10px; margin-bottom:8px; flex-wrap:wrap; }
.inv-alert-icon { font-size:18px; }
.inv-alert-link { margin-left:auto; font-size:13px; color:var(--accent); }
.inv-alert-pills { display:flex; flex-wrap:wrap; gap:6px; }
.inv-alert-pill { font-size:12px; padding:3px 10px; border-radius:10px; }
.inv-alert-pill.critico { background:#fdecea; color:var(--danger); border:1px solid #e3b9b6; }
.inv-alert-pill.bajo { background:#fff3e0; color:#8d6e00; border:1px solid #ffcc80; }
.inv-alert-pill.mas { background:#f5f5f5; color:var(--muted); border:1px solid var(--line); }
.inv-alert-pill b { margin-left:4px; font-weight:700; }

/* ================================================================
   SITE TOPBAR (nuevo header global - reemplaza .topbar/.brand viejos)
   Coherente con la paleta y tipografía de auth/app.css
   ================================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }

.site-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 32px;
  background: rgba(247, 241, 230, 0.85);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid rgba(139, 90, 43, 0.14);
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none !important;
  color: #2a1f15;
  flex-shrink: 0;
}
.site-brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #8b5a2b 0%, #5a3a1a 60%, #2f8b85 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 6px 14px -3px rgba(139, 90, 43, 0.45),
              inset 0 1px 0 rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}
.site-brand:hover .site-brand-mark { transform: rotate(-3deg) scale(1.04); }
.site-brand-text {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, #5a3a1a 0%, #8b5a2b 60%, #2f8b85 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.site-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 500;
  color: rgba(42, 31, 21, 0.7);
  text-decoration: none !important;
  transition: all 0.15s ease;
}
.site-nav-link:hover {
  background: rgba(139, 90, 43, 0.08);
  color: #5a3a1a;
}
.site-nav-cta {
  background: linear-gradient(135deg, #8b5a2b 0%, #5a3a1a 100%);
  color: #fff !important;
  font-weight: 600;
  box-shadow: 0 4px 12px -3px rgba(139, 90, 43, 0.5),
              inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.site-nav-cta:hover {
  background: linear-gradient(135deg, #8b5a2b 0%, #5a3a1a 100%);
  color: #fff !important;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px -3px rgba(139, 90, 43, 0.55);
}
.site-nav-cta svg { width: 14px; height: 14px; }

.site-foot {
  text-align: center;
  color: rgba(42, 31, 21, 0.55);
  padding: 28px 0 36px;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

@media (max-width: 600px) {
  .site-topbar { padding: 12px 16px; gap: 12px; }
  .site-brand-mark { width: 38px; height: 38px; }
  .site-brand-mark svg { width: 19px; height: 19px; }
  .site-brand-text { font-size: 1.2rem; }
  .site-nav-link { padding: 7px 11px; font-size: 0.85rem; }
  .site-nav-cta span,
  .site-nav-link:not(.site-nav-cta) { display: inline; }
}
