:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #182230;
  --muted: #667085;
  --line: #d9e0e9;
  --line-strong: #b9c4d4;
  --brand: #b42318;
  --brand-soft: #fff1f0;
  --accent: #0b6bcb;
  --accent-soft: #eaf4ff;
  --success: #087443;
  --success-soft: #eaf8ef;
  --warning: #b54708;
  --warning-soft: #fff4e5;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --teal: #0e7c7b;
  --teal-soft: #e8f7f7;
  --shadow: 0 18px 48px rgba(24, 34, 48, 0.08);
  --sidebar: 260px;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #fbfcff 0, var(--bg) 240px), var(--bg);
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.96);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 14px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

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

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

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-button {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #344054;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: var(--brand-soft);
  border-color: #ffd0cc;
  color: var(--brand);
}

.nav-button svg,
.icon,
.btn svg,
.search-box svg,
.toast svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke-width: 2;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(245, 247, 251, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.page-heading h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.25;
}

.page-heading span {
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search-box,
.control {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search-box {
  min-width: 280px;
}

.search-box input,
.control input,
.control select {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.role-switch {
  display: flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.role-switch button {
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.role-switch button.active {
  background: #182230;
  color: #fff;
}

.content {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 22px 24px 44px;
}

.screen {
  display: none;
  gap: 18px;
}

.screen.active {
  display: grid;
}

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

.band-header {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.band-title {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.band-title strong {
  font-size: 15px;
}

.band-title span {
  color: var(--muted);
  font-size: 12px;
}

.band-body {
  padding: 16px;
}

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

.grid-2 {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.45fr);
}

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

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

.kpi {
  min-height: 116px;
  display: grid;
  gap: 8px;
  padding: 16px;
}

.kpi small {
  color: var(--muted);
  font-weight: 600;
}

.kpi strong {
  display: block;
  font-size: 30px;
  line-height: 1;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: #344054;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.btn.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.btn.success {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
}

.btn.danger {
  border-color: #fecdca;
  background: var(--danger-soft);
  color: var(--danger);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

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

.form-field label {
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
}

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

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: #475467;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #fbfdff;
}

.source-data-wrap {
  max-height: 560px;
}

.khmh-table {
  min-width: 1720px;
}

.khmh-table th,
.khmh-table td {
  white-space: normal;
}

.khmh-table th:nth-child(2),
.khmh-table th:nth-child(6),
.khmh-table th:nth-child(7),
.khmh-table td:nth-child(2),
.khmh-table td:nth-child(6),
.khmh-table td:nth-child(7) {
  white-space: nowrap;
}

.khmh-table th:nth-child(8),
.khmh-table th:nth-child(9),
.khmh-table th:nth-child(10),
.khmh-table td:nth-child(8),
.khmh-table td:nth-child(9),
.khmh-table td:nth-child(10) {
  white-space: nowrap;
}

.text-right {
  text-align: right;
}

.mono {
  font-family: Consolas, "Cascadia Mono", monospace;
}

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

.strong {
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: #475467;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.draft {
  border-color: #c8d7ef;
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.pending {
  border-color: #fedf89;
  background: var(--warning-soft);
  color: var(--warning);
}

.badge.approved,
.badge.ready {
  border-color: #b7e5c4;
  background: var(--success-soft);
  color: var(--success);
}

.badge.rejected,
.badge.error {
  border-color: #fecdca;
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.po {
  border-color: #a7e6e3;
  background: var(--teal-soft);
  color: var(--teal);
}

.approval-layout,
.po-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.document-preview {
  min-height: 640px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.excel-approval {
  padding: 22px;
}

.excel-source-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.excel-sheet-wrap {
  overflow: auto;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #ffffff;
}

.excel-sheet {
  min-width: 1180px;
  padding: 24px 26px 30px;
  background: #ffffff;
  color: #111827;
  font-family: "Times New Roman", Times, serif;
  zoom: 0.76;
}

.excel-header-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.excel-header-grid span {
  display: block;
  margin-top: 5px;
  font-weight: 700;
  text-transform: none;
}

.excel-title {
  margin: 18px 0 14px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
}

.excel-info-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 160px;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
}

.excel-info-row .order-label {
  text-align: right;
}

.excel-intro {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.45;
}

.excel-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  table-layout: fixed;
}

.excel-table th,
.excel-table td {
  padding: 5px 6px;
  border: 1px solid #1f2937;
  color: #111827;
  font-size: 11px;
  line-height: 1.25;
  vertical-align: middle;
}

.excel-table th {
  position: static;
  background: #ffffff;
  font-weight: 700;
  text-align: center;
  text-transform: none;
}

.excel-table td {
  background: #ffffff;
}

.excel-table .col-tt {
  width: 34px;
  text-align: center;
}

.excel-table .col-code {
  width: 82px;
}

.excel-table .col-name {
  width: 190px;
}

.excel-table .col-origin {
  width: 86px;
}

.excel-table .col-unit {
  width: 56px;
  text-align: center;
}

.excel-table .col-number {
  width: 90px;
  text-align: right;
}

.excel-table .col-small {
  width: 78px;
  text-align: center;
}

.excel-table .col-contract {
  width: 118px;
}

.excel-table .col-category {
  width: 120px;
}

.excel-total-row td {
  font-weight: 700;
}

.excel-total-label,
.excel-empty {
  text-align: center;
}

.excel-post-lines {
  display: grid;
  margin-top: 8px;
  border: 1px solid #1f2937;
  border-bottom: 0;
  font-size: 13px;
}

.excel-post-lines div {
  min-height: 27px;
  padding: 6px 8px;
  border-bottom: 1px solid #1f2937;
  line-height: 1.35;
}

.excel-date {
  margin-top: 8px;
  padding-right: 92px;
  text-align: right;
  font-size: 13px;
  font-style: italic;
}

.excel-signatures {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  min-height: 118px;
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.excel-signatures div {
  display: grid;
  align-content: start;
  gap: 56px;
  padding-top: 8px;
}

.excel-signatures span {
  min-height: 18px;
  font-weight: 400;
  text-transform: none;
}

.doc-title {
  margin: 22px 0 18px;
  text-align: center;
}

.doc-title h2 {
  margin: 0;
  font-size: 21px;
  text-transform: uppercase;
}

.doc-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  margin-bottom: 18px;
  font-size: 13px;
}

.doc-meta div {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 8px;
}

.doc-meta span:first-child {
  color: var(--muted);
}

.summary {
  width: 340px;
  display: grid;
  gap: 6px;
  margin: 14px 0 0 auto;
}

.summary div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.summary .total {
  color: var(--brand);
  font-size: 16px;
  font-weight: 900;
  border-bottom: 0;
}

.side-stack,
.queue,
.timeline {
  display: grid;
  gap: 12px;
}

.source-card {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.source-line,
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.status-strip {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stack-toolbar {
  display: grid;
}

.detail-timeline {
  display: grid;
  gap: 12px;
}

.detail-timeline div {
  display: grid;
  gap: 3px;
  padding-left: 12px;
  border-left: 2px solid var(--line-strong);
  font-size: 13px;
}

.detail-timeline span,
.detail-timeline small,
.empty-compact {
  color: var(--muted);
  font-size: 12px;
}

.warning-box,
.locked-box {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}

.warning-box {
  border: 1px solid #fedf89;
  background: var(--warning-soft);
  color: #7a2e0e;
}

.locked-box {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #475569;
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  padding: 28px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  min-width: 260px;
  max-width: 420px;
  display: none;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.toast.show {
  display: flex;
}

.toast strong {
  display: block;
  margin-bottom: 3px;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .approval-layout,
  .po-layout,
  .form-grid,
  .filter-row {
    grid-template-columns: 1fr;
  }

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

  .search-box {
    min-width: 100%;
  }
}
