:root {
  color-scheme: light;
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-soft: #eef3f6;
  --ink: #152536;
  --muted: #667789;
  --line: #d9e2e8;
  --nav: #102b42;
  --nav-2: #163a59;
  --accent: #0f6b58;
  --accent-soft: #def3ec;
  --danger: #b42318;
  --danger-soft: #fde7e4;
  --warning: #b76e00;
  --warning-soft: #fff4d8;
  --info: #1a5fb4;
  --shadow: 0 18px 45px rgba(16, 43, 66, 0.11);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

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

button {
  border: 0;
}

button,
label,
select,
input[type="checkbox"],
input[type="file"] {
  cursor: pointer;
}

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

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
[contenteditable="true"]:focus {
  border-color: #2b7fb7;
  box-shadow: 0 0 0 3px rgba(43, 127, 183, 0.15);
}

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
}

a {
  color: var(--info);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  background: var(--nav);
  color: #fff;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.11);
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
}

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

.brand strong {
  font-size: 15px;
}

.brand span {
  margin-top: 2px;
  color: #b8c9d9;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.nav-item {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 6px;
  padding: 0 12px;
  color: #d7e2ec;
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: var(--nav-2);
  color: #fff;
}

.nav-item svg,
button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.fallback-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 20px;
  color: #b8c9d9;
  display: grid;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.11);
}

.save-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  color: #fff;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #96a7b6;
}

.dot.ok {
  background: #55d991;
}

.dot.dirty {
  background: #f4b740;
}

.dot.error {
  background: #ff7c6e;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(22px, 2.5vw, 30px);
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 11px;
  font-weight: 800;
}

.topbar-actions,
.button-row,
.inline-actions,
.table-tools,
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

.view-stack {
  display: grid;
  gap: 18px;
}

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 8px 24px rgba(16, 43, 66, 0.05);
}

.section.flush {
  padding: 0;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-header h2,
.section-header h3 {
  margin: 0;
}

.section-header p,
.muted {
  color: var(--muted);
}

.section-header p {
  margin: 4px 0 0;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

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

.action-tile {
  min-height: 132px;
  display: grid;
  align-content: start;
  gap: 10px;
  text-align: left;
  padding: 18px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.action-tile:hover {
  border-color: #9ac7d9;
  box-shadow: var(--shadow);
}

.action-tile svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.action-tile strong {
  font-size: 18px;
}

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

.primary,
.secondary,
.ghost,
.danger,
.icon-button,
.mini-button,
.link-button {
  min-height: 38px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  font-weight: 750;
  white-space: nowrap;
}

.primary {
  color: #fff;
  background: var(--accent);
}

.primary:hover {
  background: #0b5749;
}

.secondary {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

.secondary:hover,
.ghost:hover {
  background: var(--surface-soft);
}

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

.danger,
.danger-soft {
  color: var(--danger);
}

.danger {
  background: var(--danger-soft);
}

.danger-soft {
  background: #fff;
  border: 1px solid #f4c5bf;
}

.icon-button,
.mini-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.mini-button {
  width: 30px;
  min-width: 30px;
  min-height: 30px;
}

.mini-button.text-mini {
  width: auto;
  min-width: 0;
  padding: 0 8px;
}

.link-button {
  padding: 0;
  background: transparent;
  color: var(--info);
  min-height: auto;
}

.mobile-menu {
  display: none;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.check-field span,
.table-tools label {
  color: #30475e;
  font-size: 12px;
  font-weight: 800;
}

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

.check-field {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab {
  min-height: 38px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  font-weight: 800;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.table-shell {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

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

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  vertical-align: top;
}

.data-table th:last-child,
.data-table td:last-child {
  border-right: 0;
}

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

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  min-width: 150px;
  background: #eaf1f5;
  padding: 8px;
}

.data-table th.actions,
.data-table td.actions {
  position: sticky;
  right: 0;
  z-index: 3;
  min-width: 142px;
  background: #f7fafc;
}

.data-table td {
  min-width: 150px;
  padding: 0;
  background: #fff;
}

.column-head {
  display: grid;
  gap: 6px;
}

.column-head input {
  min-height: 32px;
  padding: 5px 6px;
  font-size: 12px;
  font-weight: 750;
  background: #fff;
}

.column-actions {
  display: flex;
  gap: 4px;
}

.cell-editor {
  min-height: 42px;
  width: 100%;
  padding: 9px 10px;
  outline: none;
  overflow-wrap: anywhere;
}

.cell-editor[contenteditable="false"] {
  background: #f3f6f8;
  color: #53677a;
}

.cell-error,
.field-error {
  background: #fff1ef !important;
  border-color: #f0a59a !important;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
}

.photo-box {
  display: grid;
  gap: 8px;
  padding: 8px;
  min-width: 190px;
}

.photo-box img {
  width: 96px;
  height: 72px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef2f5;
}

.photo-box input {
  min-height: auto;
  padding: 6px;
}

.totals-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

.totals-panel strong {
  font-size: 17px;
}

.quality-panel,
.validation-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius);
  background: #f7fafc;
  border: 1px solid var(--line);
}

.validation-panel.error {
  background: #fff7f6;
  border-color: #f3b7af;
}

.validation-panel.success {
  background: #f0fbf6;
  border-color: #bdebd5;
}

.error-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.error-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.document-card,
.product-card,
.template-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.document-card h3,
.product-card h3,
.template-card h3 {
  margin: 0;
}

.meta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-soft);
  color: #30475e;
}

.pill.green {
  background: var(--accent-soft);
  color: var(--accent);
}

.pill.warn {
  background: var(--warning-soft);
  color: var(--warning);
}

.preview-page {
  max-width: 980px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 34px;
  color: #111827;
}

.preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 2px solid #132f48;
  padding-bottom: 14px;
  margin-bottom: 18px;
}

.preview-title {
  margin: 18px 0;
  text-align: center;
  font-size: 22px;
  text-transform: uppercase;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 18px;
  font-size: 12px;
}

.preview-table th,
.preview-table td {
  border: 1px solid #b8c3cc;
  padding: 6px;
  vertical-align: top;
}

.preview-table th {
  background: #e8eef3;
}

.preview-page:has(.unified-preview-table) {
  max-width: 1280px;
  overflow-x: auto;
}

.unified-preview-table {
  min-width: 1500px;
  table-layout: fixed;
}

.unified-preview-table th,
.unified-preview-table td {
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.preview-photo {
  width: 80px;
  height: 62px;
  object-fit: cover;
  border: 1px solid #cbd5dd;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}

.modal-root.active {
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 24, 37, 0.45);
}

.modal {
  position: relative;
  width: min(920px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  margin: 14px auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 28px 80px rgba(11, 24, 37, 0.25);
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
}

.modal:has(.pdf-stepper) {
  width: min(1120px, calc(100vw - 28px));
}

.pdf-stepper {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.pdf-step {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.pdf-step span {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 12px;
}

.pdf-step.active {
  border-color: #94c7b7;
  background: var(--accent-soft);
  color: var(--accent);
}

.pdf-step.done span,
.pdf-step.active span {
  background: var(--accent);
  color: #fff;
}

.pdf-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

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

.pdf-status-grid span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.pdf-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.pdf-progress span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.18s ease;
}

.pdf-page,
.pdf-line-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.pdf-page summary,
.pdf-line-panel summary {
  padding: 10px 12px;
  font-weight: 800;
}

.pdf-page textarea {
  min-height: 150px;
  max-height: 320px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.pdf-preview-shell {
  max-height: 420px;
}

.pdf-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pdf-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.pdf-tabs button.active {
  border-color: #94c7b7;
  background: var(--accent-soft);
  color: var(--accent);
}

.pdf-tabs button span {
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 12px;
}

.pdf-select-col {
  min-width: 64px !important;
  text-align: center;
}

.pdf-preview-table th {
  min-width: 180px;
}

.pdf-preview-table th.actions,
.pdf-preview-table td.actions {
  min-width: 230px;
}

.pdf-empty-cell {
  background: #fff9e8 !important;
}

.pdf-row-util td:first-child {
  border-left: 4px solid var(--accent);
}

.pdf-row-revisar td:first-child {
  border-left: 4px solid var(--warning);
}

.pdf-row-descartado td:first-child {
  border-left: 4px solid var(--danger);
  opacity: 0.72;
}

.pdf-row-no-ofertado td:first-child {
  border-left: 4px solid var(--danger);
  background: #fff1ef;
}

.pdf-row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 6px;
}

.pdf-line-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.pdf-line-list > div {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.pdf-map-row {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdfe;
}

.matrix-shell {
  max-height: 560px;
}

.matrix-table th {
  min-width: 170px;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  min-width: 170px;
  background: #f7fafc;
}

.matrix-table select {
  min-width: 150px;
}

.matrix-actions {
  flex-wrap: wrap;
}

.matrix-status-completo td:first-child {
  border-left: 4px solid var(--accent);
}

.matrix-status-pendiente-de-ofertar td:first-child,
.matrix-status-falta-cantidad td:first-child,
.matrix-status-falta-precio td:first-child,
.matrix-status-falta-foto td:first-child,
.matrix-status-revisar-manualmente td:first-child {
  border-left: 4px solid var(--warning);
}

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: grid;
  gap: 8px;
}

.toast {
  width: min(390px, calc(100vw - 36px));
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  color: #122132;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.warn {
  border-left-color: var(--warning);
}

.fatal-error {
  position: fixed;
  inset: 16px 16px auto;
  z-index: 100;
  padding: 14px;
  background: var(--danger-soft);
  border: 1px solid #f1aea6;
  border-radius: var(--radius);
  color: var(--danger);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 36px 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed #b8c3cc;
  border-radius: var(--radius);
  background: #fbfdfe;
}

.empty-state svg {
  width: 34px;
  height: 34px;
}

.hidden {
  display: none !important;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    z-index: 20;
    transform: translateX(-104%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-flex;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 820px) {
  .topbar,
  .main-content {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .stat-grid,
  .hero-actions {
    grid-template-columns: 1fr;
  }

  .section-header {
    display: grid;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions > button {
    flex: 1 1 170px;
  }

  .primary,
  .secondary,
  .ghost,
  .danger {
    white-space: normal;
    min-height: 40px;
  }

  .preview-page {
    padding: 18px;
  }

  .pdf-stepper,
  .pdf-status-grid,
  .pdf-map-row {
    grid-template-columns: 1fr;
  }

  .pdf-step {
    justify-content: flex-start;
    padding: 0 10px;
  }
}
