/* Saravic OS · diseño inspirado en las interfaces actuales de Meta:
   superficies limpias, grises neutros, esquinas redondeadas, botones "píldora",
   navegación con iconos y barras translúcidas. Color de marca: el ciruela/magenta de Saravic. */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --hover: rgba(0, 0, 0, .05);
  --text: #1c1e21;
  --muted: #65676b;
  --border: #e4e6eb;
  --brand: #a3195b;
  --brand-2: #d6368f;
  --brand-soft: #fbe7f1;
  --accent: #0866ff;
  --good: #1a8d4a;
  --bad: #e41e3f;
  --warn: #c77700;
  --shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 2px 10px rgba(0, 0, 0, .04);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, .16), 0 2px 4px rgba(0, 0, 0, .08);
  --radius: 16px;
  --glass: rgba(255, 255, 255, .78);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18191a;
    --surface: #242526;
    --surface-2: #3a3b3c;
    --hover: rgba(255, 255, 255, .06);
    --text: #e4e6eb;
    --muted: #b0b3b8;
    --border: #3e4042;
    --brand: #f06aad;
    --brand-2: #ff7ab8;
    --brand-soft: rgba(240, 106, 173, .16);
    --accent: #4e9bff;
    --good: #45bd62;
    --bad: #ff6b7f;
    --warn: #f7b928;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 28px rgba(0, 0, 0, .5);
    --glass: rgba(36, 37, 38, .78);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: inherit; }
a:hover { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2, h3 { font-weight: 700; margin: 0; letter-spacing: -.015em; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* Marca */
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 800; letter-spacing: -.02em; padding: 0 8px; }
.brand em { font-style: normal; font-weight: 600; color: var(--muted); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #fff; font-size: 17px; font-weight: 800;
  box-shadow: 0 4px 12px rgba(163, 25, 91, .35);
}
.brand-lg { font-size: 26px; justify-content: center; margin-bottom: 20px; }
.brand-lg .brand-mark { width: 52px; height: 52px; font-size: 24px; border-radius: 16px; }

/* Botones tipo píldora */
.btn {
  border: 0; background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 9px 16px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: background .15s, transform .08s, box-shadow .15s;
}
.btn:hover { background: color-mix(in srgb, var(--surface-2) 80%, var(--text) 8%); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 2px 8px rgba(163, 25, 91, .25); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); color: #fff; }

/* Login */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background:
    radial-gradient(900px 500px at 10% -10%, color-mix(in srgb, var(--brand-2) 22%, transparent), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    var(--bg);
}
.login-card {
  background: var(--glass); backdrop-filter: blur(20px) saturate(1.4); -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow-lg);
  padding: 36px 28px; width: 100%; max-width: 420px; text-align: center;
}
.login-code {
  font: 700 42px/1 ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace; letter-spacing: .2em;
  background: var(--brand-soft); border-radius: 16px; padding: 22px 10px 22px 18px; margin: 20px 0 12px; color: var(--brand);
}

/* Layout */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 18px 12px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 22px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 12px;
  text-decoration: none; color: var(--text); font-weight: 600; font-size: 15px; transition: background .15s;
}
.nav a svg {
  width: 36px; height: 36px; padding: 8px; border-radius: 50%; fill: var(--muted); flex: none;
  background: var(--surface-2); transition: background .15s, fill .15s;
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav a.active svg { background: var(--brand); fill: #fff; }
.user-box {
  margin-top: auto; display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
  padding: 12px; border-radius: 14px; background: var(--surface-2);
}
.user-name { font-weight: 700; }
.user-box .btn { margin-top: 8px; background: var(--surface); }
.main { min-width: 0; padding: 0 28px 60px; }
.topbar {
  position: sticky; top: 0; z-index: 5; margin: 0 -28px 18px; padding: 16px 28px 14px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(16px) saturate(1.5); -webkit-backdrop-filter: blur(16px) saturate(1.5);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border-bottom: 1px solid transparent;
}
.topbar h1 { flex: 1; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-actions input, .page-actions select, .search {
  border: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  border-radius: 999px; padding: 9px 14px; font: inherit; font-size: 14px;
}
.search { min-width: 200px; }

/* Tarjetas */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two { grid-template-columns: 2fr 1fr; }
.halves { grid-template-columns: 1fr 1fr; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; min-width: 0; border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; gap: 8px; }
.kpis .card { position: relative; overflow: hidden; }
.kpis .card::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px; border-radius: 50%;
  background: var(--brand-soft); opacity: .7;
}
.kpi-label { color: var(--muted); font-size: 13px; font-weight: 600; position: relative; z-index: 1; }
.kpi-value { font-size: 27px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; margin: 8px 0 6px; font-variant-numeric: tabular-nums; position: relative; z-index: 1; }
.delta { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.delta.up { color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.delta.down { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.chart-box { position: relative; height: 260px; }

/* Listas y tablas */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 8px 8px; margin: 0 -8px; border-radius: 12px; }
.list li:hover { background: var(--hover); }
.list .grow { flex: 1; min-width: 0; }
.list .num { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.list a { text-decoration: none; font-weight: 600; }
.thumb {
  width: 44px; height: 44px; border-radius: 12px; object-fit: cover; background: var(--surface-2); flex: none;
  display: grid; place-items: center; color: var(--muted); font-size: 18px;
}
.table-wrap { overflow-x: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .02em; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--hover); }
tr.click { cursor: pointer; }
td a { font-weight: 600; text-decoration: none; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge.activo { color: var(--good); background: color-mix(in srgb, var(--good) 13%, transparent); }
.badge.inactivo, .badge.bajo { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.badge.prospecto { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.nuevo { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* Inventario */
.products { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.product { padding: 0; overflow: hidden; display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; }
.product:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.product-img {
  aspect-ratio: 1 / 1; width: 100%; object-fit: contain; background: #fff; padding: 10px;
  display: grid; place-items: center; font-size: 42px; color: var(--muted);
}
.product-body { padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.stock-bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.stock-bar span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--brand-2), var(--brand)); }
.stock-bar.low span { background: var(--bad); }
.row { display: flex; justify-content: space-between; gap: 4px 8px; align-items: baseline; flex-wrap: wrap; }

.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.loading::before {
  content: ""; display: block; width: 28px; height: 28px; margin: 0 auto 10px; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--brand); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.back { text-decoration: none; color: var(--muted); font-weight: 600; padding: 8px 12px; border-radius: 999px; }
.back:hover { background: var(--hover); }

.mobile-only { display: none; }

/* Formularios y ventanas */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade .15s ease-out;
  display: grid; place-items: center; padding: 16px; overflow-y: auto;
}
.modal {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 18px;
  width: 100%; max-width: 560px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; border-radius: 20px;
  animation: pop .18s ease-out;
  max-height: calc(100vh - 32px);
}
.modal-wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 8px; }
.modal-body { padding: 8px 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; font-weight: 500; color: var(--muted); }
.field input, .field select, .field textarea, .line input, .line select {
  font: inherit; font-size: 15px; color: var(--text); background: var(--surface-2); border: 1px solid transparent;
  border-radius: 12px; padding: 10px 12px; width: 100%; transition: border-color .15s, background .15s;
}
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--border); }
.field input:focus, .field select:focus, .field textarea:focus, .line input:focus, .line select:focus {
  outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.lines { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.line { display: grid; grid-template-columns: 1fr 80px 110px auto; gap: 8px; align-items: center; }
.sale-total { text-align: right; font-size: 17px; margin: 12px 0 4px; }
.form-error { margin: 0 18px 8px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); font-weight: 500; }
.alert { padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 14%, transparent); margin: 8px 0; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.steps { padding-left: 20px; margin: 4px 0 12px; display: flex; flex-direction: column; gap: 8px; }
.card-actions { display: flex; gap: 6px; margin-top: 6px; }
.product.inactive { opacity: .55; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  animation: pop .2s ease-out;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px);
}

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-head h2 { font-size: 19px; }
.modal-foot { border-top: 0; }


/* Mapa de check-ins */
.map-layout { grid-template-columns: 1fr 360px; align-items: start; }
.map-card { padding: 0; overflow: hidden; position: relative; min-height: 560px; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.map-empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 500; max-width: 320px;
  background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 16px 18px; border-radius: 16px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 4px; text-align: center;
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 10px; font-size: 13px; font-weight: 600; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.timeline li { cursor: pointer; }
.timeline .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: 0 0 0 3px var(--surface); }
.leaflet-popup-content-wrapper { border-radius: 14px !important; box-shadow: var(--shadow-lg) !important; font: 14px/1.4 Inter, system-ui, sans-serif; }
.leaflet-container { font-family: Inter, system-ui, sans-serif; }

/* Selector segmentado */
.seg { display: inline-flex; background: var(--surface); border-radius: 999px; padding: 3px; box-shadow: var(--shadow); }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 14px; font-weight: 600; padding: 7px 14px; border-radius: 999px; cursor: pointer; }
.seg button.on { background: var(--brand-soft); color: var(--brand); }

/* Compras */
.supplier-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.gauge { margin: 14px 0 10px; }
.gauge-val { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.gauge.good .gauge-val { color: var(--good); }
.gauge.warn .gauge-val { color: var(--warn); }
.gauge.bad .gauge-val { color: var(--bad); }
.gauge.good .stock-bar span { background: var(--good); }
.gauge.warn .stock-bar span { background: var(--warn); }
.gauge.bad .stock-bar span { background: var(--bad); }
.gauge .stock-bar { margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.stats div { display: flex; flex-direction: column; font-size: 14px; }
.stats span { color: var(--muted); font-size: 12px; }
.po-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.qty-in { width: 80px; text-align: right; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid transparent; border-radius: 10px; padding: 6px 8px; }
.qty-in:focus { outline: none; border-color: var(--accent); background: var(--surface); }
td.diff.neg { color: var(--bad); font-weight: 700; }
td.diff.pos { color: var(--warn); font-weight: 700; }
.btn.danger { color: var(--bad); margin-top: 8px; }

/* Tablet y móvil */
@media (max-width: 1100px) {
  .app { grid-template-columns: 84px 1fr; }
  .sidebar { padding: 18px 10px; align-items: center; }
  .sidebar .brand span:not(.brand-mark), .user-box, .nav a span { display: none; }
  .nav a { padding: 6px; justify-content: center; }
  .mobile-only { display: inline-flex; }
}
@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .map-layout { grid-template-columns: 1fr; }
  .map-card { min-height: 420px; }
  .two, .halves { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 20;
    flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
    background: var(--glass); backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
  }
  .sidebar .brand { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10px; padding: 4px 0; min-width: 0; flex: 1; background: transparent !important; }
  .nav a span { display: none !important; }
  .nav a.active span { display: block !important; }
  .nav a svg { width: 40px; height: 28px; padding: 5px 10px; border-radius: 999px; background: transparent; }
  .nav { gap: 0; }
  .nav a.active svg { background: var(--brand-soft); fill: var(--brand); }
  .main { padding: 0 14px 96px; }
  .topbar { margin: 0 -14px 14px; padding: 14px 14px 10px; }
  .topbar h1 { flex: 1; }
  h1 { font-size: 23px; }
  .kpi-value { font-size: 21px; }
  .chart-box { height: 220px; }
  .products { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .product-body { padding: 10px; font-size: 13px; }
  .product-img { font-size: 30px; }
  .page-actions { width: 100%; }
  .page-actions .search { flex: 1; min-width: 0; }
  .mobile-only { display: inline-flex; }
  .form-grid { grid-template-columns: 1fr; }
  .line { grid-template-columns: 1fr 1fr auto; }
  .line select { grid-column: 1 / -1; }
  .toast { bottom: 90px; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { border-radius: 22px 22px 0 0; max-height: 92vh; animation: sheet .22s ease-out; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: .6; } }
