/* Farmacia Balassi — panel de control (ADR-0023). No external assets (CSP: self). */

:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-2: #f1f3f4;
  --border: rgba(23, 32, 42, .09);
  --border-strong: rgba(23, 32, 42, .16);
  --text: #17202a;
  --text-2: #4a5561;
  --muted: #66717d;
  --brand: #0b7a6f;
  --brand-strong: #075c54;
  --brand-soft: #e6f2f0;
  --ok: #1d7f47;
  --ok-soft: #e7f4ec;
  --warn: #965600;
  --warn-soft: #fbf0e0;
  --bad: #b42335;
  --bad-soft: #fbe9ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --radius: 12px;
  --radius-control: 8px;
  --sidebar: 248px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111416;
    --surface: #171b1e;
    --surface-2: #1f2427;
    --border: rgba(231, 237, 242, .08);
    --border-strong: rgba(231, 237, 242, .16);
    --text: #e7edf2;
    --text-2: #b0bbc4;
    --muted: #8d98a2;
    --brand: #2bb5a6;
    --brand-strong: #6fd3c7;
    --brand-soft: #16302d;
    --ok: #4cc283;
    --ok-soft: #15291e;
    --warn: #e9a447;
    --warn-soft: #33260f;
    --bad: #ef6f82;
    --bad-soft: #36181e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--brand); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--brand-strong); text-decoration: underline; text-underline-offset: 3px; }

h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 26px; line-height: 1.2; }
h2 { font-size: 17px; line-height: 1.3; }
h3 { font-size: 15px; line-height: 1.4; }
p { margin: 0 0 12px; }
strong { font-weight: 600; }
small, .muted { color: var(--muted); }
small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Layout --------------------------------------------------------------------- */

.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; color: var(--text); }
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 17px; flex: none;
}
.brand-name { font-weight: 600; line-height: 1.2; }
.brand-name small { display: block; font-weight: 400; font-size: 12px; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: 12px; font-weight: 500; color: var(--muted); padding: 24px 12px 8px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 36px; padding: 0 12px; border-radius: var(--radius-control); color: var(--text-2);
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 500; }
.nav .count { font-size: 12px; color: var(--bad); font-variant-numeric: tabular-nums; }

.sidebar-foot { margin-top: auto; padding: 16px 12px 4px; border-top: 1px solid var(--border); font-size: 13px; line-height: 1.4; }
.sidebar-foot strong { font-weight: 500; }
.sidebar-foot form { display: inline; }

.main { min-width: 0; width: 100%; max-width: 1440px; padding: 24px 32px 64px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 32px; flex-wrap: wrap; }
.search { flex: 1 1 320px; max-width: 520px; display: flex; gap: 8px; }
.search input { flex: 1; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { margin-bottom: 4px; }
.page-head p { margin: 0; color: var(--text-2); max-width: 68ch; }

/* --- Pieces ----------------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 24px;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head a { font-size: 14px; }
.cancel-all { text-align: right; max-width: 360px; }
.cancel-all summary { list-style: none; cursor: pointer; display: inline-block; }
.cancel-all summary::-webkit-details-marker { display: none; }
.cancel-all[open] summary { opacity: .6; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat { display: block; color: var(--text); }
a.stat { transition: border-color .15s var(--ease); }
a.stat:hover { color: var(--text); text-decoration: none; border-color: var(--border-strong); }
.stat .label { color: var(--text-2); font-size: 14px; }
.stat .value { font-size: 32px; line-height: 1; font-weight: 500; font-variant-numeric: tabular-nums; margin: 12px 0 8px; }
.stat .hint { font-size: 13px; line-height: 1.4; color: var(--muted); }
.stat.attention .value { color: var(--bad); }

/* Status: a dot and its words, like a shelf label. Wraps when the words are long. */
.badge {
  display: inline-flex; align-items: baseline; gap: 8px; font-size: 13px; font-weight: 500; line-height: 1.35;
  padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2);
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  flex: none; transform: translateY(-1px);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.plain::before { display: none; }
/* A product's situation is a sentence: dot and words, no box, room to read. */
.badge.status { display: flex; background: none; padding: 0; min-width: 20ch; max-width: 32ch; font-weight: 400; }
.badge.status:not(.ok):not(.warn):not(.bad) { color: var(--text-2); }

.situation { padding: 12px 16px; border-radius: var(--radius-control); font-weight: 500; }
.situation.ok { background: var(--ok-soft); color: var(--ok); }
.situation.warn { background: var(--warn-soft); color: var(--warn); }
.situation.bad { background: var(--bad-soft); color: var(--bad); }
.situation.muted { background: var(--surface-2); color: var(--text-2); }

.flash { padding: 12px 16px; border-radius: var(--radius-control); margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.bad { background: var(--bad-soft); color: var(--bad); }

.help {
  border-left: 2px solid var(--brand); padding: 4px 0 4px 16px; margin: 16px 0 20px;
  color: var(--text-2); max-width: 96ch;
}

/* --- Tabs --------------------------------------------------------------------------- */

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 20px; }
.tabs a {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: var(--radius-control);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: 14px;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.tabs a:hover { text-decoration: none; color: var(--text); border-color: var(--border-strong); }
.tabs a.active { background: var(--brand-soft); border-color: transparent; color: var(--brand-strong); font-weight: 500; }
.tabs .n { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tabs a.active .n { color: inherit; }

/* --- Tables ------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; margin: 0 -24px; padding: 0 24px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
th { font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; padding-top: 4px; }
tbody tr { transition: background-color .15s var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.right, th.right { text-align: right; }
td .actions { flex-wrap: nowrap; }

.product-cell { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.thumb {
  width: 48px; height: 48px; border-radius: 8px; object-fit: contain; background: #fff;
  border: 1px solid var(--border); flex: none;
}
.thumb.empty { display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 11px; line-height: 1.2; background: var(--surface-2); }
.thumb.big { width: 160px; height: 160px; border-radius: 12px; font-size: 13px; }
.product-name { font-weight: 500; color: var(--text); }
a.product-name:hover { color: var(--brand-strong); }
.product-meta { font-size: 13px; line-height: 1.4; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

.up { color: var(--bad); font-weight: 500; }
.down { color: var(--ok); font-weight: 500; }

.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.pagination a, .pagination span {
  min-width: 32px; height: 32px; padding: 0 8px; display: inline-grid; place-items: center;
  border-radius: var(--radius-control); font-size: 14px; font-variant-numeric: tabular-nums; color: var(--text-2);
}
.pagination a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.pagination .current { background: var(--brand-soft); color: var(--brand-strong); font-weight: 500; }

.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 24px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

pre { white-space: pre-wrap; font: 13px/1.5 var(--mono); background: var(--surface-2); padding: 12px 16px; border-radius: var(--radius-control); margin: 0; }

/* --- Forms ------------------------------------------------------------------------- */

input[type=text], input[type=email], input[type=password], input[type=search], input[type=file], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-control); padding: 8px 12px; min-width: 0;
  transition: border-color .15s var(--ease);
}
input:hover, select:hover { border-color: color-mix(in srgb, var(--text) 28%, transparent); }
input::placeholder { color: var(--muted); }
input:focus, select:focus { border-color: var(--brand); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 1px;
}
label { display: block; font-weight: 500; margin-bottom: 8px; }
.field { margin-bottom: 16px; }
.field input { width: 100%; }
.field small { display: block; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 500;
  height: 36px; padding: 0 16px; border-radius: var(--radius-control); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; font-size: 14px;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .12s var(--ease);
}
.btn:hover { text-decoration: none; color: var(--text); background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }
.btn.approve { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.approve:hover { background: color-mix(in srgb, var(--ok) 85%, #000); color: #fff; }
.btn.reject { color: var(--bad); }
.btn.reject:hover { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.link { height: auto; border: 0; background: none; padding: 0; color: var(--brand); font-weight: 400; }
.btn.link:hover { color: var(--brand-strong); text-decoration: underline; text-underline-offset: 3px; }
.btn.link:active { transform: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin: 0; }

@media (prefers-color-scheme: dark) {
  .btn.primary, .btn.primary:hover, .btn.approve, .btn.approve:hover { color: #0b1210; }
}

/* --- Login ------------------------------------------------------------------------- */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth .card { width: 100%; max-width: 400px; padding: 32px; }
.auth .brand { padding: 0 0 24px; }
.auth .btn { width: 100%; height: 40px; margin-top: 4px; }

/* --- Responsive --------------------------------------------------------------------- */

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 4px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0 8px 0 0; }
  .nav-section, .sidebar-foot { display: none; }
  .nav { display: contents; }
  .nav a { height: 32px; padding: 0 8px; font-size: 14px; }
  .main { padding: 16px 16px 48px; }
  .topbar { margin-bottom: 24px; }
  h1 { font-size: 22px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .grid-2, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .product-cell { min-width: 220px; }
}
.foot-actions { margin-top: 8px; }
.stack > * + * { margin-top: 16px; }
.stack p { margin: 0; }
.mt { margin-top: 16px; }
.auth-card { max-width: 460px; }
.card ul { padding-left: 20px; margin: 0 0 12px; }
.card li + li { margin-top: 4px; }
section[id] { scroll-margin-top: 16px; }
