/* =====================================================================
   StockFácil PY — hoja de estilos principal
   Paleta, tipografía y componentes en un solo lugar. Los nombres de clase
   (.panel, .card, .btn, .badge, .field, ...) son los que usan las plantillas.
   ===================================================================== */

/* ---------- 1. Variables de diseño (tema claro) ---------- */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cdd5df;
  --text: #0f1b2a;
  --text-2: #4a5a6c;
  --text-3: #7a8899;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8efff;
  --primary-text: #1e40af;

  --success: #15803d;  --success-soft: #e7f6ec;
  --warning: #b45309;  --warning-soft: #fff4e0;
  --danger:  #b91c1c;  --danger-soft:  #fdeaea;
  --info:    #0e7490;  --info-soft:    #e3f5f8;

  --sidebar-bg: #0f1b2a;
  --sidebar-text: #b4c0cf;
  --sidebar-text-strong: #ffffff;
  --sidebar-hover: #1a2a3e;
  --sidebar-active: #22344c;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 27, 42, .05), 0 4px 14px rgba(15, 27, 42, .05);
  --shadow-lg: 0 10px 30px rgba(15, 27, 42, .12);
  --sidebar-w: 248px;
  --topbar-h: 60px;

  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color-scheme: light;
}

/* ---------- 2. Tema oscuro automático (según el sistema operativo) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1320;
    --surface: #121c2b;
    --surface-2: #172234;
    --border: #233147;
    --border-strong: #31425c;
    --text: #e6edf6;
    --text-2: #a9b6c7;
    --text-3: #7f8ea3;

    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: #1b2b49;
    --primary-text: #93b8ff;

    --success: #4ade80;  --success-soft: #12301f;
    --warning: #fbbf24;  --warning-soft: #33270d;
    --danger:  #f87171;  --danger-soft:  #3a1717;
    --info:    #22d3ee;  --info-soft:    #0e2c35;

    --sidebar-bg: #08101b;
    --sidebar-hover: #121c2b;
    --sidebar-active: #1a2638;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

/* ---------- 3. Base ---------- */
*, *::before, *::after { 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); }
h1 { font-size: 1.55rem; line-height: 1.25; margin: 0 0 4px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 14px; font-weight: 650; }
h3 { font-size: .95rem; margin: 0 0 10px; font-weight: 650; }
small { font-size: .8rem; }
.muted { color: var(--text-2); }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 4. Estructura: menú lateral + contenido ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  z-index: 40;
  transition: transform .2s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 20px;
  color: var(--sidebar-text-strong); text-decoration: none;
  font-weight: 750; font-size: 1.05rem; letter-spacing: -.01em;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  color: #fff;
}
.brand-mark .icon { width: 18px; height: 18px; }
.brand-sub { display: block; font-size: .7rem; font-weight: 500; color: var(--sidebar-text); letter-spacing: .02em; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: #6b7d93; padding: 14px 10px 6px; font-weight: 650;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text); text-decoration: none; font-weight: 520;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
.nav-link.active { background: var(--sidebar-active); color: var(--sidebar-text-strong); box-shadow: inset 3px 0 0 #3b82f6; }
.nav-link.active .icon { color: #60a5fa; }

.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255, 255, 255, .06); font-size: .78rem; color: #6b7d93; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.icon-btn.menu-toggle { display: none; }

.business-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); text-decoration: none; font-weight: 600; font-size: .88rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px;
}
.business-chip:hover { border-color: var(--border-strong); }
.business-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex: none; }
.business-chip .change { color: var(--text-3); font-weight: 500; }

.user-menu { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary-text);
  font-weight: 700; font-size: .85rem; text-transform: uppercase;
}
.user-meta { line-height: 1.2; }
.user-meta strong { display: block; font-size: .88rem; }
.user-meta span { font-size: .74rem; color: var(--text-3); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid var(--border); color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 28px; }

.backdrop { display: none; }

/* ---------- 5. Encabezado de página ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 22px;
}
.panel .page-head { align-items: center; margin-bottom: 14px; }
.panel .page-head h2 { margin: 0; }
.page-head > div:last-child:not(:first-child) { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 6. Tarjetas y paneles ---------- */
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.panel + .panel, section.panel + section.panel { margin-top: 18px; }
.grid {
  display: grid; gap: 16px; margin-bottom: 22px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.card { position: relative; overflow: hidden; }
.card > .muted:first-child { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.metric { font-size: 1.75rem; font-weight: 750; margin-top: 6px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* Tarjetas de indicadores con ícono y color de acento */
.stat { display: flex; gap: 14px; align-items: flex-start; }
.stat-icon {
  width: 42px; height: 42px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary);
}
.stat-icon .icon { width: 22px; height: 22px; }
.stat.ok .stat-icon { background: var(--success-soft); color: var(--success); }
.stat.warn .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat.info .stat-icon { background: var(--info-soft); color: var(--info); }
.stat-label { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.stat .metric { margin-top: 2px; }
.stat-note { font-size: .78rem; color: var(--text-3); margin-top: 2px; }

.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.two-col > .panel + .panel { margin-top: 0; }

/* ---------- 7. Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; min-height: 38px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff;
  font: inherit; font-weight: 600; font-size: .9rem; line-height: 1.2;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .input:focus-visible, .nav-link:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); outline-offset: 2px;
}
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn.danger, .btn.btn-danger { background: var(--danger); color: #fff; }
.btn.danger:hover, .btn.btn-danger:hover { filter: brightness(.92); background: var(--danger); }
.btn.ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm, td .btn { padding: 6px 10px; min-height: 32px; font-size: .82rem; }
.btn.block { width: 100%; }
td form { display: inline; }
td .btn + .btn, td form + .btn, td .btn + form { margin-left: 4px; }

/* ---------- 8. Tablas ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 12px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
th {
  font-size: .74rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); background: var(--surface-2);
}
thead th:first-child { border-top-left-radius: var(--radius-sm); }
thead th:last-child { border-top-right-radius: var(--radius-sm); }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td small.muted, td .muted { color: var(--text-3); }

/* ---------- 9. Insignias de estado ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; line-height: 1.5;
  background: var(--success-soft); color: var(--success);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.neutral { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.primary { background: var(--primary-soft); color: var(--primary-text); }

/* ---------- 10. Formularios ---------- */
.field { margin-bottom: 16px; }
.field label, form > p > label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; color: var(--text); }
.input,
.field input:not([type=checkbox]):not([type=radio]),
.field select, .field textarea,
form > p > input:not([type=checkbox]):not([type=radio]), form > p > select, form > p > textarea {
  display: block; width: 100%;
  padding: 9px 12px; min-height: 40px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .93rem;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .field input:focus, .field select:focus, .field textarea:focus,
form > p > input:focus, form > p > select:focus, form > p > textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--primary); vertical-align: middle; }
.helptext, form > p > .helptext { display: block; font-size: .8rem; color: var(--text-3); margin-top: 5px; }
form > p { margin: 0 0 16px; }
.errorlist { list-style: none; margin: 6px 0; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: .85rem; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.form-error { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: .9rem; margin-bottom: 14px; }

/* ---------- 11. Mensajes del sistema ---------- */
.messages { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 8px; }
.messages li {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--success-soft); color: var(--success);
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  font-weight: 550; font-size: .92rem;
}
.messages li.error { background: var(--danger-soft); color: var(--danger); }
.messages li.warning { background: var(--warning-soft); color: var(--warning); }
.messages li.info { background: var(--info-soft); color: var(--info); }

/* ---------- 11b. Paginación ---------- */
.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); font-size: .88rem;
}
.pagination-links { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.page-current { padding: 0 8px; color: var(--text-2); font-weight: 600; }

/* ---------- 12. Estados vacíos ---------- */
.empty { text-align: center; padding: 28px 12px; color: var(--text-3); }
.empty .icon { width: 34px; height: 34px; margin-bottom: 8px; opacity: .6; }

/* ---------- 13. Pantalla de ingreso ---------- */
.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr;
  background: var(--bg);
}
.auth-hero {
  position: relative; overflow: hidden;
  padding: 48px; color: #e6edf6;
  background:
    radial-gradient(1200px 500px at -10% 110%, rgba(6, 182, 212, .35), transparent 60%),
    radial-gradient(900px 500px at 110% -10%, rgba(59, 130, 246, .45), transparent 60%),
    #0f1b2a;
  display: flex; flex-direction: column; justify-content: space-between;
}
.auth-hero .sidebar-brand { padding: 0; height: auto; border: 0; font-size: 1.2rem; }
.auth-hero h2 { font-size: 2rem; line-height: 1.2; font-weight: 750; letter-spacing: -.02em; margin: 0 0 14px; max-width: 460px; }
.auth-hero p { color: #b4c0cf; max-width: 440px; margin: 0; }
.auth-points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.auth-points li { display: flex; gap: 10px; align-items: center; color: #cfd8e3; }
.auth-points .icon { color: #60a5fa; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 1.6rem; }
.auth-card .btn { width: 100%; min-height: 44px; margin-top: 6px; }
.auth-foot { font-size: .8rem; color: var(--text-3); margin-top: 22px; }

/* ---------- 14. Responsivo ---------- */
@media (max-width: 1080px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 16, 27, .45); z-index: 35; }
  .main { margin-left: 0; }
  .icon-btn.menu-toggle { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .container { padding: 20px 16px; }
  .user-meta { display: none; }
  .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
}
@media (max-width: 560px) {
  h1 { font-size: 1.3rem; }
  .metric { font-size: 1.45rem; }
  .business-chip { max-width: 170px; }
  .business-chip .change { display: none; }
  .page-head > div:last-child:not(:first-child) { width: 100%; }
}

/* ---------- 15. Impresión ---------- */
@media print {
  .sidebar, .topbar, .btn, .messages { display: none !important; }
  .main { margin: 0; }
  .card, .panel { box-shadow: none; border-color: #ccc; }
  body { background: #fff; }
}
