:root {
  --bg: #fff7e9;
  --panel: #fffdf5;
  --ink: #33261b;
  --muted: #735f4d;
  --brand: #78953a;
  --brand-dark: #4f6c28;
  --red: #9f3426;
  --red-dark: #762518;
  --line: #eadcc8;
  --gold: #e5a93b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.topbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 4px solid var(--brand);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 12px clamp(14px, 4vw, 48px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  align-items: center;
  color: var(--ink);
  display: flex;
  gap: 12px;
  min-width: 230px;
  text-decoration: none;
}

.brand img {
  border: 2px solid var(--line);
  border-radius: 50%;
  height: 54px;
  object-fit: contain;
  width: 54px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  color: var(--red);
  font-size: 18px;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.topbar nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.topbar nav form {
  margin: 0;
}

.topbar nav a {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-weight: 700;
  padding: 9px 11px;
  text-decoration: none;
}

.topbar nav a.active,
.topbar nav a:hover {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.shell {
  margin: 0 auto;
  max-width: 1260px;
  padding: 24px 16px 56px;
}

.module-head {
  align-items: end;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 16px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  color: var(--red);
  font-size: 34px;
}

.eyebrow {
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(118, 37, 24, .07);
  margin-top: 16px;
  padding: 18px;
}

.panel-head,
.actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.actions {
  justify-content: flex-end;
  margin: 16px 0 0;
}

.notice {
  background: #fff2c8;
  border: 1px solid var(--gold);
  border-radius: 6px;
  margin-bottom: 16px;
  padding: 12px 14px;
}

.notice span {
  display: block;
  margin-top: 4px;
}

.error {
  background: #ffe7e1;
  border-color: #d48778;
}

button {
  background: var(--red);
  border: 0;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-weight: 900;
  min-height: 40px;
  padding: 10px 14px;
}

button:hover {
  background: var(--red-dark);
}

.ghost,
.button-link {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--red);
}

.button-link {
  border-radius: 6px;
  display: inline-flex;
  font-weight: 900;
  min-height: 40px;
  padding: 10px 14px;
  text-decoration: none;
}

.small {
  font-size: 12px;
  min-height: 30px;
  padding: 6px 8px;
}

.danger {
  background: var(--red-dark);
}

.hidden-field {
  display: none !important;
}

.price-mode {
  background: #efe6d2;
  border: 1px solid #d6c2a1;
  border-radius: 999px;
  color: #4d371f;
  display: inline-flex;
  font-size: 11px;
  font-weight: 900;
  justify-content: center;
  letter-spacing: 0;
  padding: 5px 8px;
  text-transform: uppercase;
  white-space: nowrap;
}

.price-mode.global {
  background: #e7f0df;
  border-color: #b8cf9f;
  color: #33541d;
}

.price-mode.margen_personalizado {
  background: #fff1ce;
  border-color: #e4c874;
  color: #72530e;
}

.price-mode.precio_fijo {
  background: #f5dfdc;
  border-color: #dfa099;
  color: #8f271e;
}

.computed-price {
  align-items: center;
  background: #f6fbf0;
  border: 1px solid #c9ddb4;
  border-radius: 6px;
  color: var(--green-dark);
  display: flex;
  font-size: 13px;
  font-weight: 900;
  min-height: 42px;
  padding: 8px 10px;
}

input,
select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}

.create-list {
  display: grid;
  gap: 10px;
  grid-template-columns: 210px 150px auto;
}

.list-selector {
  min-width: min(420px, 100%);
}

.list-meta,
.party-form,
.product-form,
.invoice-meta {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.settings-form {
  display: grid;
  gap: 14px;
}

.settings-tabs {
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-tabs button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px 6px 0 0;
  color: var(--muted);
  min-height: 38px;
}

.settings-tabs button.active,
.settings-tabs button:hover {
  background: #fff;
  border-color: var(--line);
  border-bottom-color: #fff;
  color: var(--red);
}

.settings-panel {
  display: none;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-panel.active {
  display: grid;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 940px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td input[type="number"] {
  min-width: 96px;
}

.promo-cell {
  display: grid;
  gap: 6px;
  grid-template-columns: 110px 84px;
}

.promo-cell label {
  align-items: center;
  display: flex;
  gap: 6px;
}

.promo-cell input[type="checkbox"] {
  min-height: auto;
  width: auto;
}

.two-col {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(280px, 390px) 1fr;
}

.stacked-form,
.invoice-form,
.stock-list,
.compact-list,
.party-list,
.flyer-grid {
  display: grid;
  gap: 10px;
}

.invoice-grid {
  display: grid;
  gap: 0;
  grid-template-columns: 110px 100px minmax(220px, 1fr) 140px 150px;
}

.invoice-form.breakdown-active .invoice-grid {
  grid-template-columns: 110px 90px minmax(220px, 1fr) 140px 110px 140px 150px;
}

.breakdown-col {
  display: none;
}

.invoice-form.breakdown-active .breakdown-col {
  display: block;
}

.invoice-grid > * {
  border: 1px solid #ddd5c8;
  border-radius: 0;
  min-height: 34px;
}

.invoice-grid-head {
  background: #f3c3a8;
  font-weight: 900;
  margin-top: 10px;
  text-align: center;
}

.invoice-grid-head strong {
  border-color: #d19a7d;
  padding: 8px;
}

.stock-list div,
.compact-list div,
.flyer,
.party-row {
  background: #fffaf0;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.product-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.product-row {
  background: #fffaf0;
  border: 1px solid var(--line);
  border-radius: 6px 6px 0 0;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  padding: 10px;
}

.product-actions {
  align-items: center;
  background: #fffdf5;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 6px 6px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-bottom: 8px;
  padding: 8px 10px;
}

.product-actions form {
  margin: 0;
}

.invoice-grand-total {
  align-items: center;
  background: #d9ead3;
  border: 1px solid #8b6d4c;
  display: flex;
  font-size: 18px;
  font-weight: 900;
  justify-content: space-between;
  margin-top: 0;
  padding: 10px 14px;
}

.invoice-breakdown {
  background: #fffaf0;
  border: 1px solid var(--line);
  border-top: 0;
  display: none;
  gap: 14px;
  justify-content: flex-end;
  padding: 9px 14px;
}

.invoice-breakdown.active {
  display: flex;
  flex-wrap: wrap;
}

.invoice-volume-check {
  align-self: end;
  min-height: 40px;
}

.volume-ranges {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  margin: 0;
  padding: 12px;
}

.volume-ranges legend {
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 900;
  padding: 0 6px;
}

.volume-ranges-head,
#volume-ranges {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(100px, 1fr)) 90px;
}

.volume-ranges-head {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.stock-list div,
.compact-list div,
.flyer {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: 12px;
}

.compact-list div {
  gap: 10px;
}

.row-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row-actions form {
  margin: 0;
}

.row-actions a {
  color: var(--red);
  font-weight: 900;
}

.party-row {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(6, minmax(0, 1fr)) auto;
  padding: 10px;
}

.client-filter {
  margin-bottom: 18px;
  max-width: 420px;
}

.invoice-filters {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(240px, 420px) minmax(260px, 520px);
  margin-bottom: 18px;
}

.invoice-filters .client-filter,
.invoice-filters .list-selector {
  margin-bottom: 0;
  max-width: none;
}

.price-up {
  background-color: #fce1e8;
  color: #8b2447;
}

.price-down {
  background-color: #e0f2e4;
  color: #246439;
}

.price-trend-arrow {
  display: inline-block;
  width: 1em;
  font-weight: 700;
}

.price-up > .price-trend-arrow::before { content: "\2191"; }
.price-down > .price-trend-arrow::before { content: "\2193"; }

.invoice-price-cell {
  position: relative;
  min-width: 0;
}

.invoice-price-cell input {
  width: 100%;
  height: 100%;
  padding-right: 28px;
  background: transparent;
  color: inherit;
}

.invoice-price-cell .price-trend-arrow {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.login-page {
  align-items: center;
  display: flex;
  min-height: 100vh;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(118, 37, 24, .12);
  display: grid;
  gap: 14px;
  max-width: 380px;
  padding: 24px;
  width: 100%;
}

.login-card img {
  height: 90px;
  justify-self: center;
  object-fit: contain;
  width: 90px;
}

.login-card h1 {
  text-align: center;
}

.check {
  align-items: center;
  display: flex;
  gap: 6px;
}

.check input {
  min-height: auto;
  width: auto;
}

.flyer {
  color: var(--ink);
  text-decoration: none;
}

.flyer a {
  color: var(--ink);
  display: grid;
  gap: 4px;
  text-decoration: none;
}

.flyer small {
  color: var(--muted);
}

@media (max-width: 920px) {
  .topbar,
  .module-head,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar nav {
    justify-content: flex-start;
  }

  .create-list,
  .list-meta,
  .party-form,
  .product-form,
  .party-row,
  .product-row,
  .two-col,
  .invoice-meta,
  .settings-form,
  .settings-panel {
    grid-template-columns: 1fr;
  }

  .invoice-grid {
    grid-template-columns: 1fr;
  }

  .invoice-filters {
    grid-template-columns: 1fr;
  }

  .volume-ranges-head,
  #volume-ranges {
    grid-template-columns: 1fr;
  }
}
