/* OlivaMG: mobile-first, no framework. */
:root {
  color-scheme: light;
  --brown: #a84a2b;
  --brown-dark: #8a3a20;
  /* Page background, and text on the terracotta top bar and buttons. They are
     two tokens because dark mode changes the first and not the second. */
  --bg: #faf6ef;
  --on-accent: #faf6ef;
  /* Terracotta used as text or a link: lighter in dark mode to stay readable. */
  --accent-text: #a84a2b;
  --focus: #c89b6d;
  --press: rgba(250, 246, 239, 0.15);
  --paper: #ffffff;
  --ink: #2a1e16;
  --muted: #756559;
  --line: #e4d9cd;
  /* Hover of the outline buttons: light enough for terracotta text on it. */
  --hover: #efe6da;
  --ok: #2e6b3a;
  --ok-bg: #e6f2e8;
  --info-bg: #eaf0f6;
  --err: #9b1c1c;
  --err-bg: #fbe9e9;
  --touch: 44px;
  --nav-h: 60px;
  --radius: 10px;
}

/* Dark palette. It is written twice, with the same values: once for "follow the
   device" (no choice made, or Automática) and once for an explicit "Oscura".
   The accent (--brown, --on-accent) is the same in both themes. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1a1410;
    --paper: #241c17;
    --ink: #f3e9dc;
    --muted: #b8a898;
    --line: #3a2e26;
    --hover: #3a2e26;
    --accent-text: #e08a66;
    --ok: #7fc08b;
    --ok-bg: #1f3324;
    --info-bg: #1e2a36;
    --err: #f09a9a;
    --err-bg: #3a1d1d;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1410;
  --paper: #241c17;
  --ink: #f3e9dc;
  --muted: #b8a898;
  --line: #3a2e26;
  --hover: #3a2e26;
  --accent-text: #e08a66;
  --ok: #7fc08b;
  --ok-bg: #1f3324;
  --info-bg: #1e2a36;
  --err: #f09a9a;
  --err-bg: #3a1d1d;
}

*, *::before, *::after { box-sizing: border-box; }

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

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

body.has-nav {
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1rem;
}

h1, h2, h3 { line-height: 1.2; }
.page-title { font-size: 1.4rem; margin: 0.5rem 0 1rem; }

a { color: var(--accent-text); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--touch);
  padding: 0.25rem 1rem;
  padding-top: calc(0.25rem + env(safe-area-inset-top, 0px));
  background: var(--brown);
  color: var(--on-accent);
}
.topbar-start { display: flex; align-items: center; gap: 0.25rem; min-width: 0; }
.nav-arrows { display: flex; align-items: center; margin-left: -0.5rem; }
/* Scoped under .topbar so they beat the global button, button:hover and
   .htmx-request button rules (a sticky touch hover must not leave a dark square). */
.topbar .nav-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch);
  min-height: var(--touch);
  height: var(--touch);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  opacity: 1;
  cursor: pointer;
}
.topbar .nav-arrow:hover { background: transparent; }
.topbar .nav-arrow:active { background: var(--press); }
.topbar .nav-arrow:disabled { opacity: 0.35; cursor: default; }
.topbar .nav-arrow:disabled:hover, .topbar .nav-arrow:disabled:active { background: transparent; }
.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--touch);
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}
.topbar .brand-name {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.01em;
}
/* The seal is a square image shown as a circle. */
.seal { display: block; border-radius: 50%; flex: none; }
.topbar .seal { width: 36px; height: 36px; }
/* The global focus ring is too faint on the terracotta bar. */
.topbar :focus-visible,
.topbar a:focus-visible,
.topbar button:focus-visible { outline: 3px solid var(--on-accent); outline-offset: 2px; }
.seal-hero { width: 160px; height: 160px; margin: 0.5rem auto 1rem; }
.topbar .who { font-size: 0.9rem; opacity: 0.95; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* Bottom navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--paper);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.bottom-nav a {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 0 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
}
.bottom-nav a:hover,
.bottom-nav a:focus-visible { color: var(--accent-text); background: var(--bg); }

/* Forms and buttons: every control is at least 44px tall. */
label { display: block; margin: 0.75rem 0 0.25rem; font-weight: 600; }

input, select, textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 0.5rem 0.75rem;
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 0.5rem 1.25rem;
  font: inherit;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--brown);
  border: 0;
  border-radius: var(--radius);
  text-decoration: none;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--brown-dark); }
button[disabled], .htmx-request button { opacity: 0.6; cursor: progress; }
.btn-secondary { color: var(--accent-text); background: transparent; border: 1px solid var(--brown); }
.btn-secondary:hover { background: var(--hover); }
.btn-block { display: flex; width: 100%; }

.field-error { margin: 0.25rem 0 0; color: var(--err); font-size: 0.9rem; }

/* Flash and error messages */
#flash:empty { display: none; }
.flash {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--info-bg);
}
.flash p { margin: 0; }
.flash ul { margin: 0.25rem 0 0; padding-left: 1.25rem; }
.flash-ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.flash-error { background: var(--err-bg); border-color: var(--err); color: var(--err); }
.flash .ref { margin-top: 0.5rem; font-size: 0.85rem; color: var(--muted); }

/* Cards and tables */
.card {
  margin: 0 0 1rem;
  padding: 1rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.5rem 0.25rem; text-align: left; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

@media (min-width: 48rem) {
  main { padding: 1.5rem; }
  .page-title { font-size: 1.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Configuration screens */
.stack > :first-child { margin-top: 0; }
.stack button { margin-top: 1rem; }
.stack.card { display: block; }
.card-title { margin: 0 0 0.25rem; font-size: 1.1rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
p.muted { margin: 0.25rem 0 0.75rem; }
.badge {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.badge-off { color: var(--err); background: var(--err-bg); border-color: var(--err); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.actions form { margin: 0; }
.menu { display: grid; gap: 0.75rem; }

/* Sales: the three steps of the sale form */
.choices { display: grid; gap: 0.75rem; margin: 0.75rem 0; }
.product {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.product-info { display: grid; margin: 0; }
.product .field-error { grid-column: 1 / -1; }
.qty { display: flex; align-items: center; gap: 0.25rem; }
.qty input { width: 4rem; text-align: center; }
.qty-btn { min-width: var(--touch); padding: 0.5rem; font-size: 1.4rem; line-height: 1; }
.total { margin: 0.5rem 0; font-size: 1.6rem; font-weight: 700; }
details { margin: 0.75rem 0; }
summary { min-height: var(--touch); padding: 0.5rem 0; font-weight: 700; cursor: pointer; }

/* Stock: size buttons, movement history */
.chips { margin: 0.75rem 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chips legend { padding: 0; margin-bottom: 0.25rem; font-weight: 600; }
.chip { position: relative; }
.chip input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.chip label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  margin: 0;
  padding: 0.5rem 1rem;
  text-align: center;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}
.chip input:checked + label { color: var(--on-accent); background: var(--brown); border-color: var(--brown); }
.chip input:checked + label .muted { color: var(--on-accent); }
.chip input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
.movements { margin: 0; padding: 0; list-style: none; }
.movement p { margin: 0.25rem 0; }
.movement .mv-top { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.view-switch { margin: 0.5rem 0 1rem; }
.view-switch a[aria-current] { color: var(--ink); font-weight: 700; text-decoration: none; }
.table-scroll { overflow-x: auto; margin: 0 0 1rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.movement-table { min-width: 52rem; font-size: 0.9rem; }
.movement-table th, .movement-table td { padding: 0.5rem; vertical-align: top; }
.movement-table th { white-space: nowrap; }
.movement-table tfoot td { font-weight: 700; border-bottom: 0; }
.purchases { list-style: none; margin: 0; padding: 0; }
.purchases li { padding: 0.5rem 0; border-top: 1px solid var(--line); }
.mv-reverse { margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px solid var(--line); }
.mv-reverse button { margin-top: 0.5rem; }
.badge-ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok); }

/* Dashboards */
.progress {
  display: block;
  width: 100%;
  height: 0.9rem;
  margin: 0.5rem 0;
  accent-color: var(--ok);
}
.figure { margin: 0; font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv { display: flex; justify-content: space-between; gap: 0.75rem; margin: 0.25rem 0; }
.kv > :last-child { font-variant-numeric: tabular-nums; text-align: right; }
.summary-total { padding-top: 0.25rem; border-top: 1px solid var(--line); }
.neg { color: var(--err); }
.card-link { display: block; color: inherit; text-decoration: none; }
.card-link:hover .card-title, .card-link:focus-visible .card-title { text-decoration: underline; }
.menu-section { margin: 1.25rem 0 0.5rem; font-size: 1rem; color: var(--muted); }
.menu form { margin: 0; }

/* Supplies missing from a packing */
.shortages { margin: 0.5rem 0 0; padding: 0; list-style: none; }
.shortages li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; padding: 0.5rem 0; border-top: 1px solid var(--line); }
.shortages li:first-child { border-top: 0; }
.shortages li > span:first-child { flex: 1 1 100%; }
.shortages label { display: inline-flex; align-items: center; gap: 0.4rem; min-height: var(--touch); }

/* Product photos: thumbnails in the product list and the sale form */
.thumb { object-fit: cover; border-radius: 0.5rem; background: var(--line); flex: none; }
.thumb-large { display: block; margin-bottom: 0.25rem; }
.card-photo { display: flex; gap: 0.75rem; align-items: flex-start; }
.card-photo-body { flex: 1; min-width: 0; }
.product-info.with-photo { grid-template-columns: 3rem 1fr; column-gap: 0.75rem; align-items: center; }
.product-info.with-photo .thumb { grid-row: 1 / span 3; align-self: center; }
