@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,500..800&family=Public+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #1f1424;
  --muted: #685a70;
  --plum: #7c3e90;
  --plum-hover: #692f7c;
  --plum-deep: #241129;
  --plum-mid: #a86bbc;
  --lilac: #f3eaf6;
  --paper: #faf8fb;
  --line: #e4d9e9;
  --ochre: #a8763a;
  --ochre-soft: #fbf0e0;
  --wine: #8f2f4c;
  --wine-soft: #f8e4e9;
}

* { box-sizing: border-box; }

body {
  font-family: "Public Sans", system-ui, -apple-system, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  margin: 0;
}

/* ---------- Navegación ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  min-height: 68px; padding: 10px max(5%, 28px);
  background: var(--plum-deep);
  box-shadow: 0 2px 18px #1a0d1f4a;
}
.brand {
  display: flex; align-items: center; gap: 11px; margin-right: 20px;
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-weight: 700; font-size: 19px; letter-spacing: -.3px; color: #fff;
}
.brand-logo { width: 38px; height: 38px; object-fit: contain; border-radius: 11px; background: #fff; padding: 4px; box-shadow: 0 2px 6px #00000030; }
.top a { color: #e6d8ec; padding: 9px 12px; border-radius: 8px; font-size: 13.5px; font-weight: 600; text-decoration: none; transition: background .16s ease, color .16s ease; }
.top a:hover, .top a:focus-visible { background: #ffffff1a; color: #fff; }
.top .out { margin-left: auto; background: #ffffff14; }
.top .out:hover { background: #ffffff26; }
.stock-alert { background: var(--ochre-soft) !important; color: #6b4a1f !important; margin-left: 4px; }
.stock-alert span { display: inline-grid; place-items: center; min-width: 19px; height: 19px; margin-left: 5px; border-radius: 99px; background: var(--ochre); color: #fff; font-size: 11px; font-weight: 700; }

/* ---------- Estructura ---------- */
main { max-width: 1280px; padding: 0 28px; margin: 38px auto 56px; }

h1 {
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-weight: 800; font-size: 33px; line-height: 1.1; letter-spacing: -.7px;
  margin: 0 0 8px;
}
h1::after {
  content: ""; display: block; width: 30px; height: 15px; margin-top: 14px;
  background: var(--plum);
  clip-path: polygon(50% 0%, 100% 62%, 100% 100%, 0 100%, 0 62%);
}
h1 + * { margin-top: 22px; }
h2 { font-family: "Bricolage Grotesque", system-ui, sans-serif; font-weight: 700; font-size: 19px; letter-spacing: -.2px; margin: 0 0 4px; }

.muted { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
p.muted { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13.5px; }

/* ---------- Tarjetas y formularios ---------- */
.card, form {
  background: #fff; border: 1px solid var(--line); border-radius: 15px;
  padding: 19px 20px; box-shadow: 0 6px 20px #2b0f3609;
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid > .card { position: relative; overflow: hidden; min-height: 112px; }
.grid > .card:first-child::before {
  content: ""; position: absolute; top: 0; left: 20px; width: 30px; height: 8px;
  background: var(--plum);
  clip-path: polygon(50% 0%, 100% 100%, 0 100%);
}
.metric { font-family: "IBM Plex Mono", ui-monospace, monospace; font-weight: 600; font-size: 27px; letter-spacing: -.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }
form.card { background: linear-gradient(160deg, #fff, #fdfbfe); }

.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; margin-top: 4px; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }

label { display: block; color: #3a2c40; font-size: 13px; font-weight: 650; margin: 13px 0 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  border: 1px solid #d6c9db; border-radius: 9px; padding: 10px 11px; background: #fff;
  transition: border-color .16s ease, box-shadow .16s ease;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, .button:focus-visible, a:focus-visible {
  outline: 0; border-color: var(--plum); box-shadow: 0 0 0 3px #7c3e9026;
}

button, .button {
  display: inline-block; font: inherit; font-weight: 700; font-size: 13.5px;
  background: var(--plum); color: #fff; border: 0; border-radius: 9px;
  padding: 10px 16px; margin-top: 14px; cursor: pointer; text-decoration: none;
  box-shadow: 0 4px 12px #7c3e9024; transition: transform .14s ease, background .14s ease, box-shadow .14s ease;
}
button:hover, .button:hover { background: var(--plum-hover); transform: translateY(-1px); box-shadow: 0 6px 16px #7c3e9030; }
button:active, .button:active { transform: translateY(0); }
.secondary { background: var(--lilac); color: var(--plum-deep); box-shadow: none; }
.secondary:hover { background: #e9d8ee; }
.danger { background: var(--wine); box-shadow: 0 4px 12px #8f2f4c24; }
.danger:hover { background: #7a2740; }

/* ---------- Tablas ---------- */
table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; box-shadow: 0 6px 20px #2b0f3609; }
th { text-align: left; background: var(--lilac); color: #5b3f63; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 12px 12px; }
td { text-align: left; padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fbf7fc; }
td .button, td form .danger { margin: 0; padding: 7px 11px; font-size: 12px; line-height: 1.4; border-radius: 8px; vertical-align: middle; box-shadow: none; }
td form { display: inline-block; vertical-align: middle; margin: 0 0 0 6px; padding: 0; background: transparent; border: 0; border-radius: 0; box-shadow: none; }

.row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.line { padding: 10px; background: var(--lilac); border-radius: 9px; margin: 9px 0; }
.product-photo { width: 46px; height: 46px; object-fit: cover; border-radius: 11px; background: var(--lilac); box-shadow: 0 2px 8px #2b0f3620; }
.amount { font-family: "IBM Plex Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; font-weight: 600; }

.note { border: 0; border-left: 4px solid var(--ochre); border-radius: 10px; color: #6b4a1f; background: var(--ochre-soft); padding: 12px 15px; margin: 15px 0; }
.flash { padding: 12px 15px; border-radius: 11px; margin-bottom: 16px; background: var(--lilac); color: var(--plum-deep); font-weight: 600; box-shadow: 0 4px 14px #2b0f360c; }
.flash.error { background: var(--wine-soft); color: #6e2138; }

/* ---------- Login ---------- */
.auth-shell {
  min-height: 68vh; display: grid; place-items: center;
  background: radial-gradient(circle at 22% 18%, #3a1c43 0%, var(--plum-deep) 55%, #170a1b 100%);
  border-radius: 24px; padding: 40px 24px;
}
.auth-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 20px;
  padding: 38px 34px 32px; box-shadow: 0 24px 60px #00000040; text-align: center;
}
.auth-logo { width: 64px; height: 64px; object-fit: contain; background: var(--lilac); border-radius: 16px; padding: 9px; margin-bottom: 18px; }
.auth-card h1 { font-size: 26px; text-align: center; }
.auth-card h1::after { margin-left: auto; margin-right: auto; }
.auth-sub { color: var(--muted); font-size: 13.5px; margin: 10px 0 22px; }
.auth-card form { border: 0; box-shadow: none; padding: 0; text-align: left; }
.auth-card button { width: 100%; margin-top: 20px; padding: 12px; font-size: 14px; }

/* ---------- Dashboard ---------- */
.dashboard-two { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .8fr); gap: 18px; margin-top: 22px; }
.chart-card { min-height: 360px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.section-heading h2 { margin-bottom: 4px; }
.chart-current { font-family: "IBM Plex Mono", ui-monospace, monospace; color: var(--plum); font-size: 17px; font-weight: 600; }
.chart-wrap { width: 100%; margin-top: 18px; }
.chart-wrap svg { width: 100%; display: block; overflow: visible; }
.chart-grid { stroke: #ece1f0; stroke-width: 1; }
.chart-axis { fill: #8a7a90; font: 11px "IBM Plex Mono", monospace; }
.chart-line { stroke: var(--plum); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { fill: #fff; stroke: var(--plum); stroke-width: 3; }
.chart-empty { height: 220px; display: grid; place-items: center; color: #8a7a90; background: var(--lilac); border-radius: 12px; margin-top: 18px; }
.stats-list { margin-top: 14px; }
.stats-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.stats-list strong { color: var(--ink); text-align: right; font-family: "IBM Plex Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.stats-list .top-product { display: block; border-bottom: 0; }
.stats-list .top-product strong { display: block; text-align: left; margin-top: 5px; color: var(--plum); font-family: inherit; }

.inventory-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.value-pair {
  grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px;
  padding: 18px 20px; background: linear-gradient(120deg, var(--lilac), var(--ochre-soft));
  border: 1px solid var(--line); border-radius: 16px;
}
.value-pair > div + div { border-left: 1px solid #d9c8de; padding-left: 20px; }

@media (max-width: 760px) {
  .top { padding: 10px 16px; gap: 2px; }
  .brand { width: 100%; margin-right: 0; }
  .top a { padding: 7px 8px; font-size: 12px; }
  .top .out { margin-left: 0; }
  main { padding: 0 16px; margin-top: 24px; }
  h1 { font-size: 27px; }
  .dashboard-two { grid-template-columns: 1fr; }
  .chart-card { min-height: 300px; }
  .inventory-grid { grid-template-columns: 1fr; }
  .value-pair { grid-column: auto; grid-template-columns: 1fr; }
  .value-pair > div + div { border-left: 0; border-top: 1px solid #d9c8de; padding: 14px 0 0; }
  .auth-card { padding: 30px 24px; }
}

@media (max-width: 960px) {
  table { display: block; overflow-x: auto; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  button, .button { transition: none; }
}

/* ---------- Analítica ---------- */
.analytics-filters { margin-top: 22px; }
.analytics-metrics { margin-top: 18px; }
.analytics-section { margin-top: 30px; }
.analytics-section > .muted, .analytics-pairs > section > .muted { display: block; margin: 5px 0 13px; }
.analytics-pairs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; margin-top: 30px; }
.table-scroll { overflow-x: auto; border-radius: 15px; box-shadow: 0 6px 20px #2b0f3609; }
.table-scroll table { min-width: 720px; box-shadow: none; }
.negative { color: var(--wine); font-weight: 700; }
@media (max-width: 760px) { .analytics-pairs { grid-template-columns: 1fr; } }

/* ---------- Densidad y acciones de tablas ---------- */
th, td { vertical-align: middle; }
@media (min-width: 961px) {
  th, td { white-space: nowrap; }
}
.table-actions { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
td .table-actions form { display: inline-flex; margin: 0; }
td .button, td form .danger { display: inline-flex; align-items: center; justify-content: center; min-height: 34px; }
.history-table th:nth-child(1) { width: 110px; }
.history-table th:nth-child(2) { width: 130px; }
.history-table th:nth-child(4), .history-table th:nth-child(5), .history-table th:nth-child(6) { width: 145px; }
.history-table th:nth-child(7) { width: 178px; }

/* ---------- Navegación de regreso y ayudas ---------- */
.back-bar { display: flex; align-items: center; min-height: 42px; margin: 0 0 18px; }
.back-bar a { display: inline-flex; align-items: center; gap: 7px; color: var(--plum); font-weight: 700; text-decoration: none; }
.back-bar a:hover { color: var(--plum-hover); text-decoration: underline; }
.analytics-metrics .card[title], .analytics-section th[title] { cursor: help; }

.help-icon {
  display: inline-grid; place-items: center; width: 16px; height: 16px;
  border: 1px solid currentColor; border-radius: 50%; color: var(--plum);
  font-family: system-ui, sans-serif; font-size: 11px; font-weight: 800;
  line-height: 1; vertical-align: text-bottom; cursor: help;
}
.help-icon:focus { outline: 0; box-shadow: 0 0 0 3px #7c3e9026; }
th .help-icon { color: #5b3f63; }
.dashboard-metrics .card[title], .inventory-grid .card[title], .value-pair > div[title] { cursor: help; }
