/* Control de Stock — estilos (mobile-first, sin dependencias) */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #16202c;
  --muted: #667085;
  --primary: #0f766e;
  --primary-600: #0d6660;
  --primary-50: #e6f4f2;
  --normal: #15803d;
  --normal-bg: #e8f6ed;
  --low: #b45309;
  --low-bg: #fdf3e2;
  --out: #c2410c;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --info-bg: #eaf2fd;
  --info: #1d4ed8;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .05);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 14px; letter-spacing: -.005em; }
p { margin: 0 0 10px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; word-break: break-word; }
pre.code { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: var(--radius-sm); overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.text-danger { color: var(--danger); }
.text-success { color: var(--normal); }
.inline { display: inline; }
.icon { flex: none; vertical-align: middle; }
.truncate { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .icon { color: var(--primary); }
.brand span { display: none; }
.nav { display: flex; gap: 2px; flex: 1; justify-content: center; }
.nav-link {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 10px; border-radius: 12px; color: var(--muted); font-size: .72rem; font-weight: 600;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav-link.is-active { color: var(--primary); background: var(--primary-50); }
.nav-badge {
  position: absolute; top: 0; right: 2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: .68rem; line-height: 18px; text-align: center;
}
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover, .icon-btn.is-active { background: var(--surface-2); color: var(--text); }

/* ---------- Layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head .muted { margin: 0; }
.head-actions { display: flex; gap: 8px; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 12px; }
.section-head h2 { margin: 0; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: .9rem; margin-bottom: 8px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + * { margin-top: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.empty { text-align: center; color: var(--muted); padding: 36px 18px; display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }

/* ---------- Tarjetas de estadísticas ---------- */
.cards-3, .cards-4 { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 16px; }
.cards-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-card {
  display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text);
}
a.stat-card:hover { text-decoration: none; border-color: #cfd5dd; }
.stat-card.is-active { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.stat-label { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.2; }
.stat-sub { font-size: .78rem; color: var(--muted); }
.stat-low .stat-value { color: var(--low); }
.stat-out .stat-value { color: var(--danger); }
.big-number { font-size: 2.4rem; font-weight: 750; letter-spacing: -.02em; color: var(--primary); }
.stock-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.stock-row > div { display: flex; flex-direction: column; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; font-weight: 600; }
.field small { font-weight: 400; }
.field-inline { min-width: 0; }
input[type=text], input[type=password], input[type=number], input[type=search], select, input[type=file] {
  width: 100%; font: inherit; font-weight: 400; color: var(--text);
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  min-height: 44px;
}
input[type=file] { padding: 8px; background: var(--surface-2); }
input:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50);
}
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--primary); }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { width: 140px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 9px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: .92rem;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: #f3c7c2; }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.btn-small { min-height: 34px; padding: 5px 12px; font-size: .84rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn.is-disabled { opacity: .45; pointer-events: none; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* ---------- Mensajes ---------- */
.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: .92rem; border: 1px solid transparent; }
.flash-success { background: var(--normal-bg); color: #14532d; border-color: #c6e9d2; }
.flash-error { background: var(--danger-bg); color: #7a1a12; border-color: #f5c9c3; }
.flash-info { background: var(--info-bg); color: #1e3a8a; border-color: #cddcf8; }
.notice {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; margin-bottom: 16px; color: inherit;
}
.notice span { flex: 1; }
.notice:hover { text-decoration: none; filter: brightness(.98); }
.notice-warning { background: var(--low-bg); color: #7c3a06; border: 1px solid #f5d9a8; }

/* ---------- Badges ---------- */
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: .76rem; font-weight: 650; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.badge .icon { width: 14px; height: 14px; }
.badge-normal { background: var(--normal-bg); color: var(--normal); }
.badge-low { background: var(--low-bg); color: var(--low); }
.badge-out, .badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-cancelled, .badge-hidden, .badge-inactive { background: #eef0f3; color: #5b6472; }
.badge-visible { background: var(--info-bg); color: var(--info); }
.pill { font-size: .76rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; }
.pill-low { background: var(--low-bg); color: var(--low); }
.pill-out { background: var(--danger-bg); color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.chip { padding: 4px 12px; border-radius: 999px; background: var(--surface-2); font-size: .82rem; font-weight: 600; }
.chip-normal { background: var(--normal-bg); color: var(--normal); }
.chip-low { background: var(--low-bg); color: var(--low); }
.chip-out { background: var(--danger-bg); color: var(--danger); }

/* ---------- Filtros y buscador ---------- */
.filters { display: flex; flex-direction: column; gap: 12px; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.filter-actions { display: flex; gap: 8px; grid-column: 1 / -1; }
.search-box { position: relative; display: flex; align-items: center; }
.search-box > .icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search-box input { padding-left: 40px; font-size: 1rem; }
.suggestions {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 15; list-style: none; margin: 0; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 12px 32px rgba(16, 24, 40, .14);
  max-height: 360px; overflow-y: auto;
}
.suggestions li { padding: 10px 12px; border-radius: 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.suggestions li[aria-selected=true], .suggestions li:hover { background: var(--primary-50); }
.suggestions .s-meta { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.suggestions mark { background: none; color: var(--primary); font-weight: 700; }
.segmented { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 12px; gap: 2px; margin-bottom: 14px; }
.section-head .segmented { margin-bottom: 0; }
.segmented a { padding: 6px 12px; border-radius: 9px; color: var(--muted); font-size: .85rem; font-weight: 600; }
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

/* ---------- Carpetas ---------- */
.folder-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.folder-card {
  display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text);
  transition: transform .12s, border-color .12s;
}
.folder-card:hover { text-decoration: none; border-color: #c7ced8; transform: translateY(-1px); }
.folder-top { display: flex; gap: 10px; align-items: flex-start; }
.folder-icon { display: inline-flex; padding: 8px; border-radius: 12px; background: var(--primary-50); color: var(--primary); }
.folder-name { font-weight: 650; line-height: 1.35; padding-top: 5px; overflow-wrap: anywhere; }
.folder-meta { display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: .84rem; }
.folder-meta .dot::before { content: "·"; margin-right: 6px; }
.folder-stats { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .86rem; color: var(--muted); }
.folder-stats strong { color: var(--text); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 20px 0; }

/* ---------- Tablas ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .74rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; overflow-wrap: anywhere; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; }

/* Tablas → cards en pantallas chicas (sin scroll horizontal) */
@media (max-width: 719px) {
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { border: 1px solid var(--border); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; background: var(--surface); }
  .table.responsive td { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); text-align: right; }
  .table.responsive td:last-child { border-bottom: 0; }
  .table.responsive td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: .82rem; text-align: left; }
  .table.responsive td.actions { justify-content: flex-end; }
  .table.responsive td.actions:not([data-label])::before { content: none; }
  .truncate { max-width: 60vw; }
}

/* ---------- Ficha / detalle ---------- */
.details { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 8px 16px; margin: 0; }
.details dt { color: var(--muted); font-size: .86rem; }
.details dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }

/* ---------- Alertas ---------- */
.alert-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.alert-item {
  display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap;
  padding: 14px 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--danger); box-shadow: var(--shadow);
}
.alert-item.alert-low { border-left-color: var(--low); }
.alert-item.alert-out { border-left-color: var(--danger); }
.alert-item.is-read { opacity: .62; box-shadow: none; }
.alert-main { flex: 1; min-width: 220px; }
.alert-top { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.alert-product { font-weight: 650; display: block; margin-bottom: 2px; color: var(--text); }
.alert-main p { margin: 0; color: #394150; font-size: .92rem; }

/* ---------- Revisión y sincronización ---------- */
.review-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.review-head h2 { margin: 0; font-size: 1.2rem; }
.review-actions { display: flex; gap: 6px; align-items: flex-start; }
.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.result-list li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.result-list li:last-child { border-bottom: 0; }
.onboarding .steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.onboarding .steps li.is-done { color: var(--muted); text-decoration: line-through; }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #eef6f5, #f5f6f8 60%); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 28px 24px; box-shadow: 0 20px 48px rgba(16, 24, 40, .1); }
.login-card h1 { text-align: center; margin-bottom: 20px; }
.login-logo { display: flex; justify-content: center; margin-bottom: 10px; }
.login-logo .icon { width: 44px; height: 44px; color: var(--primary); background: var(--primary-50); padding: 9px; border-radius: 14px; }

/* ---------- Tablet / desktop ---------- */
@media (min-width: 560px) {
  .folder-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat-value { font-size: 1.9rem; }
  .filter-row { grid-template-columns: repeat(3, minmax(0, 1fr)) auto; }
  .filter-actions { grid-column: auto; }
}
@media (min-width: 720px) {
  .nav-link { flex-direction: row; font-size: .9rem; padding: 8px 12px; gap: 8px; }
  .nav-badge { position: static; margin-left: 2px; }
  .brand span { display: inline; }
  .nav { justify-content: flex-start; margin-left: 16px; }
  .container { padding: 28px 24px 72px; }
  h1 { font-size: 1.75rem; }
  .card { padding: 22px; }
}
@media (min-width: 960px) {
  .folder-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 380px) {
  .nav-link { padding: 6px 7px; }
  .stat-card { padding: 12px 10px; }
  .stat-value { font-size: 1.35rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
