:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-strong: #eef7f5;
  --ink: #232323;
  --muted: #626b68;
  --line: #d8e2df;
  --teal: #0f766e;
  --teal-soft: #dff5f1;
  --green: #16803d;
  --green-soft: #e4f7eb;
  --cyan: #087f95;
  --cyan-soft: #e3f7fb;
  --amber: #b77905;
  --amber-soft: #fff4d8;
  --red: #c92a3c;
  --red-soft: #ffe7ea;
  --nav: #242826;
  --shadow: 0 18px 45px rgba(32, 38, 35, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px;
  background: var(--nav);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 22px;
  z-index: 20;
}

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

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

.brand strong,
.brand span,
.tenant-panel strong,
.tenant-panel span {
  display: block;
}

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

.brand span,
.tenant-panel span {
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
}

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

.nav-link {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.nav-link.active,
.nav-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.tenant-panel {
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.tenant-panel img {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
}

.workspace {
  min-width: 0;
  padding-bottom: 34px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: auto auto minmax(220px, 1fr) auto auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.menu-button {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--surface-strong);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
}

.menu-button span {
  width: 18px;
  height: 2px;
  background: var(--ink);
}

.page-title span,
.eyebrow {
  display: block;
  color: var(--teal);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
}

.page-title strong {
  display: block;
  font-size: 18px;
}

.global-search {
  position: relative;
}

.global-search label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.global-search input,
.topbar select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.global-search input {
  padding: 0 14px;
}

.topbar select {
  min-width: 135px;
  padding: 0 10px;
}

.session-clock {
  min-width: 112px;
  padding: 9px 10px;
  border-radius: 8px;
  text-align: center;
  color: var(--red);
  background: var(--red-soft);
  font-weight: 700;
}

.avatar-button {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-strong);
  cursor: pointer;
}

.avatar-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

main {
  display: grid;
  gap: 22px;
  padding: 22px;
}

.status-strip,
.split-section,
.qms-section,
.module-section,
.erp-workspace {
  border-radius: 8px;
  padding: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

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

h1 {
  max-width: 820px;
  margin-bottom: 0;
  font-size: 32px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.section-copy p:last-child,
.operation-board p:last-child {
  margin-bottom: 0;
}

.iso-badge {
  min-width: 230px;
  padding: 14px;
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal);
}

.iso-badge span,
.iso-badge strong {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(145px, 1fr));
  gap: 14px;
}

.metric-card {
  min-height: 118px;
  padding: 16px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  align-content: space-between;
}

.metric-card span {
  color: var(--muted);
  font-weight: 700;
}

.metric-card strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}

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

.work-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.9fr);
  gap: 22px;
}

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

.panel-heading {
  min-height: 82px;
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  border-radius: 8px;
}

.table-wrap {
  overflow-x: auto;
}

.approval-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

.approval-table th,
.approval-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.approval-table th {
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.status-pill,
.risk-pill,
.module-status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pending {
  color: var(--amber);
  background: var(--amber-soft);
}

.status-approved {
  color: var(--green);
  background: var(--green-soft);
}

.status-returned {
  color: var(--red);
  background: var(--red-soft);
}

.status-saved {
  color: var(--cyan);
  background: var(--cyan-soft);
}

.risk-pill {
  color: var(--cyan);
  background: var(--cyan-soft);
}

.row-actions {
  display: flex;
  gap: 8px;
}

.action-button,
.primary-button,
.secondary-button {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 12px;
  cursor: pointer;
  font-weight: 800;
}

.action-button,
.primary-button {
  background: var(--teal);
  color: #fff;
}

.action-button.reject {
  background: var(--red);
}

.secondary-button {
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.score {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  background: var(--teal);
  color: #fff;
}

.score span {
  font-size: 18px;
  font-weight: 900;
}

.score small {
  font-size: 10px;
}

.qms-list,
.control-grid,
.module-grid {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.qms-item,
.control-item,
.module-card,
.audit-list li {
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.qms-item {
  padding: 14px;
}

.qms-item header,
.control-item header,
.module-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.qms-item strong,
.control-item strong,
.module-card strong {
  display: block;
}

.qms-item small,
.control-item small,
.module-card small {
  color: var(--muted);
}

.progress-bar {
  height: 8px;
  margin-top: 12px;
  border-radius: 8px;
  background: #e6eeeb;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  background: var(--teal);
}

.split-section {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(320px, 1.2fr);
  gap: 22px;
  align-items: center;
}

.operation-board {
  display: grid;
  gap: 12px;
}

.operation-line {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) auto;
  gap: 8px 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.operation-line meter {
  grid-column: 1 / -1;
  width: 100%;
  height: 12px;
}

.tool-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
}

.tool-strip button {
  min-height: 82px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 800;
}

.tool-strip img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  border-radius: 8px;
}

.qms-section,
.module-section {
  display: grid;
  grid-template-columns: minmax(220px, 0.72fr) minmax(0, 1.6fr);
  gap: 22px;
}

.erp-workspace {
  display: grid;
  gap: 18px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(0, 1.35fr);
  gap: 18px;
  align-items: start;
}

.transaction-form {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.form-grid {
  display: grid;
  gap: 12px;
}

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

.field-group label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field-group input,
.field-group select,
.field-group textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
}

.field-group textarea {
  min-height: 78px;
}

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

.transaction-register {
  box-shadow: none;
}

.empty-register {
  padding: 18px;
  color: var(--muted);
}

.register-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

.control-item,
.module-card {
  padding: 16px;
  min-height: 142px;
  display: grid;
  align-content: space-between;
}

.module-status {
  color: var(--green);
  background: var(--green-soft);
}

.reports-section .panel {
  box-shadow: var(--shadow);
}

.audit-list {
  list-style: none;
  margin: 0;
  padding: 18px;
  display: grid;
  gap: 10px;
}

.audit-list li {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(110px, 0.35fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.audit-list time {
  color: var(--teal);
  font-weight: 800;
}

.mobile-nav {
  display: none;
}

.approval-dialog {
  width: min(560px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.approval-dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

.approval-dialog form {
  padding: 22px;
}

.dialog-close {
  float: right;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--surface-strong);
  cursor: pointer;
}

.approval-dialog dl {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 9px 12px;
}

.approval-dialog dt {
  color: var(--muted);
  font-weight: 800;
}

.approval-dialog dd {
  margin: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: 8px;
  background: var(--nav);
  color: #fff;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.noscript-alert {
  margin: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 800;
}

.approval-dialog.dialog-open {
  display: block;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }

  .work-grid,
  .split-section,
  .qms-section,
  .module-section,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

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

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(310px, 86vw);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

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

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

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

  .global-search {
    grid-column: 1 / -1;
  }

  .topbar select,
  .session-clock {
    display: none;
  }

  main {
    padding: 16px;
    padding-bottom: 84px;
  }

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

  h1 {
    font-size: 26px;
  }

  .metric-grid,
  .tool-strip,
  .control-grid,
  .module-grid {
    grid-template-columns: 1fr;
  }

  .audit-list li {
    grid-template-columns: 1fr;
  }

  .mobile-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 16;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow);
  }

  .mobile-nav button {
    min-height: 40px;
    border-radius: 8px;
    background: var(--surface-strong);
    color: var(--ink);
    font-weight: 800;
  }

  .mobile-nav button.active {
    background: var(--teal);
    color: #fff;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

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

  .status-strip,
  .split-section,
  .qms-section,
  .module-section,
  .erp-workspace {
    padding: 18px;
  }

  .approval-dialog dl {
    grid-template-columns: 1fr;
  }
}
