:root {
  --bg: #f6f3ec;
  --ink: #24201a;
  --muted: #746b5d;
  --line: #ded6ca;
  --panel: #fffaf2;
  --accent: #8b1f2d;
  --accent-dark: #641520;
  --gold: #c9953b;
  --ok: #2f7654;
  --warn: #b36b00;
  --bad: #ad3030;
  --shadow: 0 18px 50px rgba(48, 36, 22, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf2;
  color: var(--ink);
  cursor: pointer;
  min-height: 42px;
  padding: 0 14px;
}

button:hover {
  border-color: var(--gold);
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 700;
}

.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.needsSave {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
  font-weight: 800;
}

.isSaved {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
  font-weight: 800;
}

.isSaving {
  background: var(--warn);
  border-color: var(--warn);
  color: #fff;
  font-weight: 800;
}

.topActions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.topbar {
  align-items: center;
  background: #24160f;
  color: white;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 22px clamp(16px, 4vw, 44px);
}

.eyebrow {
  color: #e4bd67;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 3vw, 2.6rem);
}

h2 {
  font-size: 1.15rem;
}

main {
  margin: 0 auto;
  max-width: 1280px;
  padding: 22px clamp(14px, 3vw, 28px) 44px;
}

.stats {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.stats article,
.panel,
.cards article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.stats article {
  padding: 16px;
}

.stats span {
  color: var(--muted);
  display: block;
  font-size: 0.86rem;
  margin-bottom: 8px;
}

.stats strong {
  font-size: 1.65rem;
}

.tabs {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  margin-bottom: 18px;
  padding-bottom: 4px;
}

.tab {
  font-weight: 700;
  width: 100%;
}

.tab.active {
  background: #24160f;
  border-color: #24160f;
  color: white;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar,
.sectionHead {
  align-items: end;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.82rem;
  font-weight: 750;
  gap: 6px;
}

input,
select,
textarea {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  line-height: 1.4;
  padding: 10px 12px;
  resize: vertical;
}

.search {
  flex: 1;
  min-width: 220px;
}

.tableWrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

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

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

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

tr:last-child td {
  border-bottom: 0;
}

.status {
  border-radius: 999px;
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 5px 9px;
}

.status.ok {
  background: rgba(47, 118, 84, 0.13);
  color: var(--ok);
}

.status.warn {
  background: rgba(179, 107, 0, 0.14);
  color: var(--warn);
}

.status.bad {
  background: rgba(173, 48, 48, 0.13);
  color: var(--bad);
}

.panel {
  padding: 18px;
}

.hidden {
  display: none !important;
}

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

.formGrid h2,
.wide {
  grid-column: 1 / -1;
}

.cards {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cards article {
  padding: 14px;
}

.cards h3 {
  margin: 0 0 6px;
}

.cards p,
.log p,
.empty,
.mutedText {
  color: var(--muted);
  margin: 0;
}

.reportGrid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 1fr;
}

.manageGrid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  align-items: start;
}

.invoiceGrid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 0.95fr) minmax(360px, 1.05fr);
}

.invoicePreview {
  align-items: center;
  background: white;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  min-height: 190px;
  overflow: hidden;
}

.invoicePreview img {
  display: block;
  max-height: 360px;
  max-width: 100%;
  object-fit: contain;
}

.invoiceActions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.voiceTools {
  align-items: center;
  background: rgba(201, 149, 59, 0.1);
  border: 1px solid rgba(201, 149, 59, 0.25);
  border-radius: 8px;
  display: flex;
  gap: 12px;
  padding: 10px;
}

.voiceTools button {
  flex: 0 0 auto;
}

.invoiceActions button {
  flex: 1 1 150px;
}

.invoiceRows {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.invoiceLine {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(150px, 1.5fr) 90px 105px 110px 135px 42px;
  padding: 10px;
}

.invoiceLine button {
  min-height: 42px;
  padding: 0;
}

.newProductFields {
  border: 1px dashed var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 12px;
}

.newProductFields h3 {
  grid-column: 1 / -1;
  margin: 0;
}

.supplierList,
.warehouseList,
.priceCompare {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.supplierGroup,
.warehouseItem,
.compareGroup {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.supplierGroup h3,
.warehouseItem h3,
.compareGroup h3 {
  margin: 0 0 10px;
}

.supplierProduct,
.compareRow,
.warehouseEdit {
  align-items: center;
  display: grid;
  gap: 8px;
}

.supplierProduct,
.compareRow {
  border-top: 1px solid var(--line);
  padding: 9px 0;
}

.supplierProduct {
  grid-template-columns: minmax(0, 1fr) auto;
}

.supplierProductInfo {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.supplierProductInfo strong {
  overflow-wrap: anywhere;
}

.supplierProductInfo span {
  color: var(--muted);
}

.compareRow {
  grid-template-columns: minmax(140px, 1fr) 100px 90px;
}

.supplierProduct:first-of-type {
  border-top: 0;
}

.compareRow:first-of-type {
  border-top: 0;
}

.supplierProduct p,
.compareRow p {
  color: var(--muted);
  margin: 0;
}

.compareRow.best {
  background: rgba(47, 118, 84, 0.09);
  border-radius: 8px;
  color: var(--ok);
  font-weight: 800;
  padding-left: 8px;
  padding-right: 8px;
}

.warehouseEdit {
  grid-template-columns: minmax(130px, 1fr) 84px 84px;
}

.bestSupplier {
  background: rgba(47, 118, 84, 0.1);
  border: 1px solid rgba(47, 118, 84, 0.2);
  border-radius: 8px;
  color: var(--ok);
  font-weight: 800;
  margin-top: 10px;
  padding: 8px;
}

.movementResult {
  background: rgba(47, 118, 84, 0.1);
  border: 1px solid rgba(47, 118, 84, 0.2);
  border-radius: 8px;
  color: var(--ok);
  font-weight: 700;
  margin: 0;
  min-height: 0;
  padding: 10px;
}

.movementResult:empty {
  display: none;
}

.log {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.logItem {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.logItem strong {
  display: block;
  margin-bottom: 4px;
}

.empty {
  background: rgba(255, 250, 242, 0.78);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
}

@media (max-width: 820px) {
  .topbar,
  .toolbar,
  .sectionHead,
  .voiceTools {
    align-items: stretch;
    flex-direction: column;
  }

  .topActions {
    justify-content: stretch;
  }

  .topActions button {
    flex: 1 1 150px;
  }

  .tabs {
    display: flex;
    overflow-x: auto;
  }

  .tab {
    flex: 0 0 auto;
    width: auto;
  }

  .stats,
  .cards,
  .invoiceGrid,
  .manageGrid,
  .reportGrid {
    grid-template-columns: 1fr;
  }

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

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

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

  .supplierProduct,
  .compareRow,
  .warehouseEdit {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .supplierProduct,
  .compareRow,
  .warehouseEdit {
    grid-template-columns: 1fr;
  }
}
