:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #d9e2ef;
  --accent: #1d4ed8;
  --accent-dark: #1e40af;
  --accent-soft: #eff6ff;
  --warn: #b45309;
  --warn-bg: #fff7ed;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --ok: #047857;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 64px 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: 280px 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #1d4ed8, #4f46e5);
  font-weight: 800;
  font-size: 18px;
}

.brand-name {
  font-weight: 800;
  letter-spacing: 0;
}

.brand-subtitle,
.run-label,
.panel-label {
  color: var(--muted);
  font-size: 12px;
}

.run-meta {
  margin-top: 2px;
  font-weight: 700;
  color: #334155;
}

.topbar-actions,
.toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.primary-button,
.ghost-button,
.approve-button {
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--line);
  padding: 0 14px;
  font-weight: 700;
  background: var(--surface);
  color: var(--text);
}

.primary-button,
.approve-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.primary-button:hover,
.approve-button:hover {
  background: var(--accent-dark);
}

.ghost-button:hover {
  background: var(--accent-soft);
}

.inline-button {
  border: 1px solid #bfd0e7;
  background: #eff6ff;
  color: var(--accent);
  border-radius: 6px;
  padding: 4px 8px;
  font-weight: 700;
}

.inline-button:hover {
  background: #dbeafe;
}

.workspace {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 292px;
  gap: 14px;
  padding: 14px;
  min-height: calc(100vh - 64px);
}

.filter-rail,
.approval-panel,
.main-surface {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.filter-rail,
.approval-panel {
  padding: 14px;
  align-self: start;
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 92px);
  overflow: auto;
}

.field-group {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

label,
.rail-title {
  font-size: 12px;
  font-weight: 800;
  color: #334155;
}

select,
input[type="search"],
input[type="number"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

select,
input[type="search"] {
  height: 36px;
  padding: 0 10px;
}

.segment {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segment-button {
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  height: 34px;
  font-size: 12px;
  font-weight: 800;
  color: #475569;
}

.segment-button:last-child {
  border-right: 0;
}

.segment-button.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.check-list {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 700;
  color: #475569;
}

.rail-block,
.panel-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.rail-copy {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.4;
}

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

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

.kpi {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: var(--surface-soft);
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.kpi strong {
  font-size: 18px;
}

.kpi-total {
  background: var(--accent-soft);
  border-color: #bfdbfe;
}

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

h1 {
  margin: 0;
  font-size: 18px;
}

.table-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: calc(100vh - 228px);
}

.purchase-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1400px;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eaf1ff;
  color: #1e3a8a;
  text-align: left;
  font-size: 11px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 7px 8px;
  border-bottom: 1px solid #e8edf5;
  vertical-align: top;
  font-size: 12px;
}

tr:hover td {
  background: #f8fbff;
}

.product-cell {
  min-width: 320px;
  max-width: 410px;
  line-height: 1.25;
}

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

.number {
  text-align: right;
  white-space: nowrap;
}

.rotation {
  display: inline-flex;
  align-items: center;
  min-width: 58px;
  justify-content: center;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
  background: #edf2f7;
}

.rotation.alta {
  color: var(--ok);
  background: #ecfdf5;
}

.rotation.media {
  color: #0369a1;
  background: #e0f2fe;
}

.rotation.baja {
  color: var(--warn);
  background: var(--warn-bg);
}

.adjust-input {
  width: 76px;
  height: 30px;
  text-align: right;
  padding: 0 7px;
  font-weight: 800;
  background: var(--warn-bg);
}

.notes-input {
  width: 160px;
  min-height: 30px;
  resize: vertical;
  padding: 6px;
}

.alert-text {
  color: var(--danger);
  font-weight: 800;
}

.approval-title {
  font-size: 16px;
  font-weight: 800;
  margin-top: 4px;
}

.order-id {
  margin-top: 8px;
  padding: 8px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: #334155;
  font-weight: 800;
  font-size: 12px;
}

.totals-list {
  display: grid;
  gap: 9px;
}

.totals-list div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

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

.total-row {
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.warnings ul {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
}

.warnings li {
  border-radius: 6px;
  padding: 8px;
  background: var(--warn-bg);
  color: #7c2d12;
  font-size: 12px;
  line-height: 1.35;
}

.approve-button {
  width: 100%;
  margin-top: 16px;
  height: 42px;
}

.approve-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.approval-message {
  color: var(--ok);
  font-weight: 800;
  font-size: 12px;
  min-height: 18px;
  margin-top: 10px;
}

.notes-box p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    padding: 12px;
  }

  .app-shell {
    grid-template-rows: auto 1fr;
  }

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

  .filter-rail,
  .approval-panel {
    position: static;
    max-height: none;
  }

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

  .table-toolbar {
    align-items: start;
    flex-direction: column;
  }
}
