:root {
  color-scheme: light;
  --bg: #f5f2ec;
  --surface: #fffdfa;
  --surface-strong: #eef4eb;
  --line: #ded8cf;
  --text: #1e2620;
  --muted: #6b716b;
  --green: #24523a;
  --green-2: #2f6b4a;
  --amber: #b67622;
  --blue: #315d7d;
  --red: #a74432;
  --shadow: 0 18px 46px rgba(35, 45, 36, 0.11);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #203428;
  color: #f7f3eb;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  align-items: center;
  background: #d9c28f;
  border-radius: 8px;
  color: #203428;
  display: inline-flex;
  font-weight: 800;
  height: 42px;
  justify-content: center;
  width: 42px;
}

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

.brand small {
  color: #c9d1c8;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #f7f3eb;
  padding: 11px 12px;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.7rem, 3vw, 2.4rem);
  line-height: 1.05;
  margin-bottom: 0;
}

h2 {
  font-size: 1.1rem;
  margin-bottom: 0;
}

h3 {
  font-size: 0.98rem;
  margin-bottom: 0;
}

.top-actions,
.section-head,
.section-actions,
.button-stack {
  align-items: center;
  display: flex;
  gap: 10px;
}

.section-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-head.compact {
  margin-bottom: 10px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.cloud-status {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  min-width: 150px;
}

.section-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.compact-action {
  min-height: 34px;
  padding: 7px 10px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel,
.kpi,
.lot-card,
.order-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.warning-panel {
  border-color: #d39b2f;
  box-shadow: 0 10px 28px rgba(114, 76, 16, 0.12);
}

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

.kpi {
  padding: 16px;
}

.kpi small {
  color: var(--muted);
  display: block;
  margin-bottom: 8px;
}

.kpi strong {
  display: block;
  font-size: 1.75rem;
}

.quick-actions {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 16px;
}

.quick-card {
  background: linear-gradient(180deg, #fffdfa 0%, #f2f6ef 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(35, 45, 36, 0.08);
  color: var(--text);
  display: grid;
  gap: 5px;
  min-height: 88px;
  padding: 14px;
  text-align: left;
}

.quick-card:hover {
  border-color: #b8c9b6;
  transform: translateY(-1px);
}

.quick-card strong {
  color: var(--green);
  font-size: 1rem;
}

.quick-card span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.25;
}

.split,
.two-col,
.report-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

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

.form {
  display: grid;
  gap: 13px;
}

.form.is-editing {
  border-color: #d1a35d;
  box-shadow: 0 0 0 3px rgba(182, 118, 34, 0.12), var(--shadow);
}

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

.inline-form {
  align-items: end;
  grid-template-columns: minmax(160px, 1.2fr) minmax(110px, 0.7fr) minmax(150px, 1fr) auto;
  margin-bottom: 14px;
}

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

input,
select,
textarea {
  background: #fff;
  border: 1px solid #cfc8bd;
  border-radius: 7px;
  color: var(--text);
  min-height: 42px;
  padding: 9px 10px;
  width: 100%;
}

input.is-estimated {
  border-color: #c0392b;
  color: #9d2419;
  font-weight: 800;
}

textarea {
  resize: vertical;
}

.primary,
.secondary,
.ghost,
.link {
  border-radius: 7px;
  min-height: 40px;
  padding: 9px 13px;
}

.primary {
  background: var(--green);
  border: 1px solid var(--green);
  color: white;
  font-weight: 800;
}

.primary:hover {
  background: var(--green-2);
}

.secondary {
  background: #edf3f6;
  border: 1px solid #c8d9df;
  color: #1d3d52;
  font-weight: 750;
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.link {
  background: transparent;
  border: 0;
  color: var(--blue);
  font-weight: 800;
  padding-left: 6px;
  padding-right: 6px;
}

.link.danger {
  color: var(--red);
}

.file-action {
  align-items: center;
  background: #fff;
  border: 1px solid #cfc8bd;
  border-radius: 7px;
  color: var(--green);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.9rem;
  font-weight: 800;
  min-height: 40px;
  padding: 9px 13px;
}

.file-action input {
  display: none;
}

.wide {
  width: 100%;
}

.form-block {
  background: var(--surface-strong);
  border: 1px solid #d8e1d5;
  border-radius: 8px;
  padding: 12px;
}

.lot-picker {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-height: 260px;
  overflow: auto;
}

.group-selector {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 1fr) auto auto;
  margin-bottom: 12px;
}

.lot-option {
  align-items: start;
  background: #fff;
  border: 1px solid #d7d1c9;
  border-radius: 8px;
  display: grid;
  gap: 2px;
  grid-template-columns: 20px 1fr;
  min-height: 58px;
  padding: 8px;
}

.lot-option input {
  min-height: auto;
  width: auto;
}

.lot-option strong {
  font-size: 0.9rem;
}

.lot-option small {
  color: var(--muted);
  display: block;
}

.product-rows {
  display: grid;
  gap: 10px;
}

.product-row {
  background: #fff;
  border: 1px solid #d7d1c9;
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(160px, 2fr) 90px 88px 88px 36px;
  padding: 10px;
}

.icon-btn {
  align-self: end;
  background: #f8e7e2;
  border: 1px solid #efc2b8;
  border-radius: 7px;
  color: var(--red);
  font-weight: 900;
  min-height: 42px;
}

.list {
  display: grid;
  gap: 10px;
}

.recent-list {
  display: grid;
  gap: 8px;
}

.recent-entry {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(110px, 0.55fr) minmax(0, 1.4fr) minmax(150px, 0.8fr) auto;
  padding: 10px 12px;
}

.recent-entry strong,
.recent-entry span {
  display: block;
}

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

.recent-type {
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.recent-detail {
  min-width: 0;
}

.recent-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.edit-note {
  background: #eef4eb;
  border: 1px solid #d8e1d5;
  border-radius: 8px;
  color: var(--green);
  font-weight: 750;
  padding: 10px 12px;
}

.order-card {
  padding: 14px;
}

.order-top {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.muted,
.subcopy {
  color: var(--muted);
}

.subcopy {
  margin-bottom: 0;
}

.pill {
  background: #dcece3;
  border-radius: 999px;
  color: var(--green);
  display: inline-flex;
  font-size: 0.75rem;
  font-weight: 850;
  padding: 5px 9px;
}

.pill.amber {
  background: #faebd2;
  color: #8b520e;
}

.pill.red {
  background: #f9ded8;
  color: var(--red);
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

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

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

th {
  background: #e9efe6;
  color: #34453a;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.filter-row th {
  background: #f8faf5;
  padding: 6px;
}

.filter-row select {
  border-radius: 6px;
  font-size: 0.78rem;
  min-height: 30px;
  padding: 5px 7px;
}

.table-filtered-out {
  display: none;
}

.num {
  text-align: right;
}

.estimated-value {
  color: #c0392b;
  font-weight: 850;
}

.estimated-tag {
  color: #c0392b;
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 850;
  margin-left: 4px;
  text-transform: uppercase;
}

.click-row {
  cursor: pointer;
}

.click-row:hover td {
  background: #f3f7ef;
}

.detail-panel {
  margin-top: 16px;
}

.row-actions {
  white-space: nowrap;
}

.row-actions .link {
  min-height: 28px;
  padding-bottom: 2px;
  padding-top: 2px;
}

.compact-table table {
  min-width: 620px;
}

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

.lot-card {
  padding: 14px;
}

.lot-card strong {
  display: block;
  font-size: 1.05rem;
}

.lot-card dl {
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr;
  margin: 12px 0 0;
}

.lot-card dt {
  color: var(--muted);
  font-size: 0.76rem;
}

.lot-card dd {
  margin: 0;
  text-align: right;
}

.search {
  max-width: 320px;
}

.check-list {
  margin: 14px 0 0;
  padding-left: 18px;
}

.check-list li {
  margin-bottom: 8px;
}

.button-stack {
  align-items: stretch;
  flex-direction: column;
  margin-top: 18px;
}

.stock-split-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  grid-column: 1 / -1;
  padding: 12px;
}

.split-rows {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.split-row {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(180px, 1fr) 120px auto;
}

.pill.warn {
  background: #f7d9d4;
  color: #7d2619;
}

.correction-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(160px, 1fr) minmax(180px, 1fr) auto;
  margin-bottom: 16px;
}

.correction-form button {
  align-self: end;
}

.query-form {
  margin-top: 18px;
}

.ai-intake-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(180px, 0.7fr) minmax(220px, 0.9fr);
}

.ai-text-field {
  grid-column: 1 / -1;
}

.draft-panel {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 14px;
}

.inline-draft {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
  padding: 12px;
}

.inline-draft h3 {
  color: #102019;
  font-size: 20px;
  margin: 0;
}

.answer-box {
  background: #f7f4ee;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 180px;
  padding: 14px;
  white-space: pre-wrap;
}

.hint-box {
  background: #eef5ee;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  margin-top: 12px;
  padding: 10px 12px;
}

.map-panel {
  overflow: hidden;
  padding: 0;
}

.map-filter {
  margin-top: 12px;
}

.map-tabs {
  background: #f6f4ed;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px;
  -webkit-overflow-scrolling: touch;
}

.map-tab {
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #183122;
  cursor: pointer;
  flex: 0 0 auto;
  font-weight: 800;
  min-height: 36px;
  padding: 8px 12px;
}

.map-tab.active {
  background: #1f573b;
  border-color: #1f573b;
  color: #fff;
}

.map-toolbar {
  background: #faf8f3;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
}

.map-toolbar button {
  min-height: 38px;
}

.map-canvas {
  background: #eef3ec;
  cursor: grab;
  display: block;
  height: min(62vh, 560px);
  touch-action: none;
  width: 100%;
}

.map-canvas.dragging {
  cursor: grabbing;
}

.map-lot {
  cursor: pointer;
  fill: #d7c78e;
  fill-opacity: 0.54;
  stroke: #17472e;
  stroke-width: 2;
}

.map-lot.linked {
  fill: #8ab57c;
  fill-opacity: 0.64;
}

.map-lot.selected {
  fill-opacity: 0.86;
  stroke: #082719;
  stroke-width: 4;
}

.map-label {
  fill: #102019;
  font-size: 18px;
  font-weight: 800;
  pointer-events: none;
  stroke: rgba(255, 255, 255, 0.78);
  stroke-width: 3px;
  paint-order: stroke;
  text-anchor: middle;
}

.map-empty {
  fill: var(--muted);
  font-size: 20px;
}

.map-legend {
  background: #fffdf9;
  border-top: 1px solid var(--line);
  padding: 12px;
}

.map-legend-title {
  color: #183122;
  font-weight: 900;
  margin-bottom: 8px;
}

.map-legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.map-legend-item {
  align-items: center;
  background: #f6f4ed;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  padding: 8px 10px;
}

.map-legend-item small {
  color: var(--muted);
}

.map-swatch {
  border: 1px solid rgba(16, 32, 25, 0.28);
  border-radius: 999px;
  display: inline-block;
  height: 16px;
  width: 16px;
}

.map-detail {
  align-items: center;
  background: #faf8f3;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  padding: 12px;
}

.map-detail > div {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.map-detail strong {
  color: #123021;
}

.voice-panel,
.ticket-panel {
  align-items: center;
  background: rgba(24, 33, 26, 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 30;
}

.ticket-panel {
  background: rgba(24, 33, 26, 0.5);
  z-index: 60;
}

.voice-card,
.ticket-card-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 680px;
  padding: 18px;
  width: min(680px, 100%);
}

.ticket-card-wrap {
  max-height: 94vh;
  overflow: auto;
}

.ticket-card {
  background: #fff;
  border: 1px solid #cfc8bd;
  border-radius: 8px;
  color: #17231b;
  margin: 14px auto;
  max-width: 520px;
  padding: 22px;
}

.ticket-head {
  border-bottom: 2px solid #203428;
  margin-bottom: 14px;
  padding-bottom: 12px;
}

.ticket-head h3 {
  font-size: 1.25rem;
  margin: 0 0 4px;
}

.ticket-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.ticket-row {
  border-bottom: 1px solid #e5ded3;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  padding: 8px 0;
}

.ticket-row strong {
  text-align: right;
}

.ticket-weight {
  background: #eef4eb;
  border-radius: 8px;
  margin: 14px 0;
  padding: 10px 14px;
}

.ticket-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.ticket-text {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.voice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

.voice-matches {
  margin-top: 12px;
}

.hidden {
  display: none;
}

@media print {
  body.printing-ticket .shell,
  body.printing-ticket .toast,
  body.printing-ticket .ticket-card-wrap > .section-head,
  body.printing-ticket .ticket-actions,
  body.printing-ticket .ticket-text {
    display: none !important;
  }

  body.printing-ticket {
    background: #fff;
  }

  body.printing-ticket .ticket-panel {
    background: #fff;
    display: block !important;
    inset: 0;
    padding: 0;
    position: static;
  }

  body.printing-ticket .ticket-card-wrap {
    border: 0;
    box-shadow: none;
    max-height: none;
    max-width: none;
    padding: 0;
    width: auto;
  }

  body.printing-ticket .ticket-card {
    border: 0;
    max-width: none;
  }
}

#view-reportes.active {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#view-reportes > .report-grid:first-child {
  order: 6;
}

#view-reportes > .report-grid:nth-of-type(2) {
  order: 1;
}

#view-reportes > section:nth-of-type(1) {
  order: 4;
}

#view-reportes > section:nth-of-type(2) {
  order: 5;
}

#view-reportes > section:nth-of-type(3) {
  order: 2;
}

#view-reportes > section:nth-of-type(4) {
  order: 3;
}

#view-reportes .detail-panel {
  margin-top: 0;
}

.toast {
  background: #1f3027;
  border-radius: 8px;
  bottom: 18px;
  box-shadow: var(--shadow);
  color: #fff;
  left: 50%;
  max-width: calc(100vw - 32px);
  opacity: 0;
  padding: 12px 14px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1080px) {
  .kpi-grid,
  .lot-grid,
  .master-grid,
  .quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-col,
  .split,
  .report-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    display: block;
    padding-bottom: 76px;
  }

  .sidebar {
    bottom: 0;
    height: auto;
    left: 0;
    padding: 8px;
    position: fixed;
    right: 0;
    top: auto;
    z-index: 10;
  }

  .brand {
    display: none;
  }

  .nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .nav-item {
    flex: 0 0 auto;
    font-size: 0.73rem;
    min-width: 86px;
    padding: 8px 4px;
    scroll-snap-align: start;
    text-align: center;
  }

  .main {
    padding: 18px 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .section-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .kpi-grid,
  .lot-grid,
  .master-grid,
  .lot-picker,
  .quick-actions {
    grid-template-columns: 1fr;
  }

  .group-selector {
    grid-template-columns: 1fr 1fr;
  }

  .group-selector button {
    width: 100%;
  }

  .product-row {
    grid-template-columns: 1fr 1fr;
  }

  .recent-entry {
    align-items: start;
    grid-template-columns: 1fr;
  }

  .correction-form {
    grid-template-columns: 1fr;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .product-row label:first-child {
    grid-column: 1 / -1;
  }

  .icon-btn {
    grid-column: 1 / -1;
  }
}
