:root {
  --bg: #f5f6f4;
  --panel: #ffffff;
  --ink: #1f2528;
  --muted: #657078;
  --line: #d9dedc;
  --teal: #0f766e;
  --teal-weak: #d8f0ec;
  --amber: #9a6412;
  --amber-weak: #f8ead2;
  --red: #a33a3a;
  --red-weak: #f4dddd;
  --green: #2f7d4f;
  --green-weak: #e0efdf;
  --accent: var(--teal);
  --accent-strong: #0b5f59;
  --brand: var(--teal);
  --focus: #78b8b0;
  --shadow: 0 12px 28px rgba(31, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px;
  background: #eef3f4;
  position: relative;
  overflow: hidden;
}

.login-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(15, 118, 110, 0.08), transparent 42%, rgba(29, 78, 216, 0.06));
  pointer-events: none;
}

.login-panel {
  width: min(860px, 100%);
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(31, 37, 40, 0.12);
  padding: 0;
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(300px, 1fr);
  overflow: hidden;
}

.login-brand {
  grid-row: 1 / span 6;
  background: #f3f8f7;
  border-right: 1px solid var(--line);
  padding: 70px 42px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 28px;
  position: relative;
  z-index: 1;
}

.login-logo {
  width: 210px;
  height: auto;
  display: block;
  mix-blend-mode: multiply;
}

.login-panel h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0;
}

.login-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.login-copy {
  grid-column: 2;
  padding: 42px 42px 16px;
  display: grid;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.login-copy strong {
  font-size: 18px;
}

.login-copy span,
.login-footnote {
  color: var(--muted);
  font-size: 12px;
}

.login-panel label {
  grid-column: 2;
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  padding: 0 42px;
  position: relative;
  z-index: 1;
}

.login-panel input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fbfcfb;
}

.login-panel input:focus {
  outline: 2px solid #b8ded8;
  border-color: #78b8b0;
  background: #fff;
}

.login-error {
  grid-column: 2;
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
  padding: 0 34px;
  position: relative;
  z-index: 1;
}

.login-panel .primary {
  grid-column: 2;
  margin: 0 42px;
  min-height: 44px;
  position: relative;
  z-index: 1;
}

.login-footer {
  grid-column: 2;
  margin: 0 42px 36px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: grid;
  gap: 9px;
  position: relative;
  z-index: 1;
}

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

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  vertical-align: middle;
  line-height: 1.25;
  min-width: 0;
}

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

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

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 6px 18px;
  border-bottom: 1px solid var(--line);
}

.brand-logo {
  width: 150px;
  max-width: 100%;
  height: auto;
  display: block;
  mix-blend-mode: multiply;
}

.login-panel {
  border-color: #cddbd8;
  box-shadow: 0 24px 60px rgba(25, 60, 68, 0.14);
}

.login-brand {
  background: #f3f8f7;
}

.login-copy strong {
  color: #0f766e;
}

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

.dashboard-sales-analytics .pie3d-card {
  min-height: 200px;
}

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

.nav-btn,
button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  min-height: 36px;
  position: relative;
  transition: transform 90ms ease, box-shadow 140ms ease, filter 140ms ease, opacity 140ms ease;
  -webkit-tap-highlight-color: transparent;
}

button:not(:disabled):active,
.nav-btn:not(:disabled):active,
button.is-pressed,
td.actions button.action-primary.is-pressed,
#productionOrders td.actions button.action-primary.is-pressed,
#purchaseOrders td.actions button.action-primary.is-pressed {
  transform: translateY(3px) scale(0.965);
  box-shadow: inset 0 3px 7px rgba(18, 43, 38, 0.28), 0 1px 0 rgba(255, 255, 255, 0.5);
  filter: brightness(0.86);
}

button.is-processing {
  pointer-events: none;
  opacity: 0.78;
  box-shadow: inset 0 0 0 2px rgba(20, 125, 114, 0.28), 0 0 0 3px rgba(20, 125, 114, 0.09);
}

button.is-processing::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: button-feedback-spin 620ms linear infinite;
}

@keyframes button-feedback-spin {
  to { transform: rotate(360deg); }
}

.button-action-feedback {
  position: fixed;
  z-index: 12000;
  top: 20px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(520px, calc(100vw - 32px));
  min-height: 42px;
  padding: 10px 16px;
  color: #fff;
  background: #173e49;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  box-shadow: 0 10px 28px rgba(19, 48, 55, 0.24);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity 140ms ease, transform 160ms ease;
}

.button-action-feedback::before {
  width: 9px;
  height: 9px;
  flex: none;
  background: #5ed4bc;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(94, 212, 188, 0.14);
  content: "";
}

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

@media (prefers-reduced-motion: reduce) {
  button,
  .nav-btn {
    transition: none;
  }

  button.is-processing::after {
    animation: none;
  }

  .button-action-feedback {
    transition: none;
  }
}

.nav-btn {
  justify-content: flex-start;
  text-align: left;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 600;
}

.nav-btn:hover,
.nav-btn.active {
  background: var(--teal-weak);
  color: #0b5f59;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.sidebar-tools {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.sidebar-tools summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sidebar-tools summary::-webkit-details-marker { display: none; }
.sidebar-tools summary::before { content: "▸"; display: inline-block; width: 16px; color: var(--teal); }
.sidebar-tools[open] summary::before { content: "▾"; }
.sidebar-tools summary:hover { background: #f0f6f5; color: var(--teal); }
.sidebar-tools-body { display: grid; gap: 7px; padding-top: 5px; }

.icp-link {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  text-decoration: none;
}

.filing-links {
  display: grid;
  gap: 3px;
  justify-items: center;
}

.icp-link:hover {
  color: #0b5f59;
  text-decoration: underline;
}

.sidebar-filings {
  padding: 6px 2px 0;
}

.main {
  padding: 18px 20px 24px;
  min-width: 0;
}

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

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

h2,
h3 {
  margin: 0;
}

h2 {
  font-size: 22px;
  line-height: 1.25;
}

h3 {
  font-size: 16px;
  line-height: 1.35;
}

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

.role-switch {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.role-switch select {
  min-height: 32px;
  padding: 5px 8px;
}

.status-pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--amber-weak);
  color: var(--amber);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.safe,
.tag.good {
  background: var(--green-weak);
  color: var(--green);
}

.tag.warn {
  background: var(--red-weak);
  color: var(--red);
}

.receivable-theme h3,
.receivable-theme .form-section,
.receivable-ledger table {
  color: var(--red);
}

.receivable-theme {
  border-color: #efc7c7;
}

.receivable-ledger th {
  color: var(--red);
  background: #fff6f6;
}

.payable-theme h3,
.payable-theme .form-section,
.payable-ledger table {
  color: var(--green);
}

.payable-theme {
  border-color: #bfdcc8;
}

.payable-ledger th {
  color: var(--green);
  background: #f3faf2;
}

.view {
  display: none;
  contain: content;
}

.view.active {
  display: block;
  content-visibility: auto;
}

.module-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 0 0 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.module-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 8px 14px;
  white-space: nowrap;
}

.module-tab:hover {
  background: #eef7f5;
  color: var(--accent);
}

.module-tab.active {
  border-color: rgba(0, 107, 104, 0.2);
  background: #d9f1ee;
  color: var(--accent);
  font-weight: 700;
}

.compact-form-panel {
  align-self: start;
}

.rd-formula-form {
  padding-bottom: 16px;
}

.rd-cost-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
  padding: 12px;
}

.rd-cost-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.rd-cost-grid > div {
  min-height: 68px;
  padding: 10px;
  border: 1px solid #d9e3df;
  border-radius: 6px;
  background: #fff;
}

.rd-cost-grid span,
.rd-cost-grid strong {
  display: block;
}

.rd-cost-grid span {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.rd-cost-grid strong {
  font-size: 17px;
}

.rd-cost-grid strong.good {
  color: var(--green);
}

.rd-cost-grid strong.warn {
  color: #a86608;
}

.rd-cost-warning,
.rd-cost-note {
  margin-top: 9px;
  padding: 9px 11px;
  border-radius: 6px;
  font-size: 12px;
}

.rd-cost-warning {
  border: 1px solid #e5c07b;
  color: #7d4d00;
  background: #fff8e9;
}

.rd-cost-note {
  color: var(--muted);
  background: #eef5f3;
}

.rd-list-head {
  margin-top: 20px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
  min-height: 78px;
}

.metric .label {
  color: var(--muted);
  font-size: 12px;
}

.metric .value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dashboard-report {
  margin-bottom: 14px;
}

.module-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.module-summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
  display: grid;
  gap: 7px;
  text-align: left;
  min-height: 118px;
}

.module-summary-card:hover {
  border-color: #9bc8c1;
  background: #f6fbfa;
}

.module-summary-card strong {
  font-size: 15px;
}

.module-summary-card span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.module-summary-card b {
  color: var(--ink);
  font-size: 14px;
}

.module-summary-card em {
  font-style: normal;
}

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

.dashboard-sales-analytics {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.pie3d-card {
  min-height: 230px;
}

.pie3d-layout {
  display: grid;
  gap: 12px;
  align-items: center;
}

.pie3d-wrap {
  height: 142px;
  display: grid;
  place-items: center;
}

.pie3d {
  width: 132px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--pie));
  position: relative;
  box-shadow: 0 8px 20px rgba(31, 37, 40, 0.10);
}

.pie3d::before {
  content: "";
  position: absolute;
  inset: 36px;
  border-radius: 50%;
  background: #fbfcfb;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.pie3d::after {
  content: none;
}

.pie3d-legend {
  align-content: start;
}

.pie3d-legend strong {
  white-space: nowrap;
}

.sales-detail-card {
  min-width: 0;
}

.sales-margin-section {
  display: grid;
  gap: 12px;
}

.sales-report-actions button {
  min-width: 112px;
  white-space: nowrap;
}

.sales-report-status {
  margin: -1px 0 11px;
  padding: 7px 10px;
  border-left: 3px solid #168076;
  background: #f0f7f6;
  color: #52636b;
  font-size: 12px;
}

.sales-report-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid #bcd8d4;
  border-radius: 8px;
  background: #f4faf9;
}

.sales-report-heading span,
.sales-report-heading strong {
  display: block;
}

.sales-report-heading span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
}

.sales-report-heading strong {
  color: #0b625d;
  font-size: 19px;
}

.sales-report-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.sales-report-metrics {
  grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
}

.sales-report-section {
  display: grid;
  gap: 9px;
  min-width: 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.sales-report-section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.sales-report-section-head span,
.sales-report-section-head h4 {
  display: block;
}

.sales-report-section-head span {
  margin-bottom: 2px;
  color: #14766d;
  font-size: 11px;
  font-weight: 700;
}

.sales-report-section-head h4 {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
}

.sales-report-section-head > strong {
  color: #14766d;
  font-size: 14px;
  white-space: nowrap;
}

.receivable-report-section .sales-report-section-head span,
.receivable-report-section .sales-report-section-head > strong {
  color: var(--red);
}

.sales-report-table {
  max-height: min(48vh, 520px);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.sales-report-table table {
  min-width: 980px;
}

.sales-report-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.sales-margin-pies {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

/* Sales management dashboard */
.sales-stats-panel {
  background: #f7f9f8;
}

.sales-stats-panel > .panel-head,
.sales-stats-panel > .stats-filters,
.sales-stats-panel > .sales-report-status {
  background: #fff;
}

.sales-stats-panel > .panel-head {
  margin: -16px -16px 0;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.sales-stats-panel > .stats-filters {
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
}

.sales-stats-panel > .sales-report-status {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-top: 0;
  border-left: 3px solid #087f8c;
  border-radius: 0 0 8px 8px;
}

.sales-report-heading {
  min-height: 78px;
  padding: 16px 18px;
  border: 0;
  border-left: 5px solid #087f8c;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 7px 18px rgba(28, 54, 61, 0.06);
}

.sales-report-heading span {
  color: #087f8c;
  font-size: 12px;
  font-weight: 800;
}

.sales-report-heading strong {
  color: #172b32;
  font-size: 23px;
}

.sales-report-heading p {
  line-height: 1.65;
}

.sales-report-metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(118px, 1fr));
  gap: 10px;
}

.sales-kpi {
  position: relative;
  min-width: 0;
  min-height: 112px;
  padding: 14px 15px 13px;
  overflow: hidden;
  border: 1px solid #dce3e1;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 5px 14px rgba(28, 54, 61, 0.045);
}

.sales-kpi::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: var(--kpi-color, #2a6fbb);
}

.sales-kpi span,
.sales-kpi strong,
.sales-kpi small {
  display: block;
}

.sales-kpi span {
  color: #66757b;
  font-size: 12px;
  font-weight: 700;
}

.sales-kpi strong {
  margin: 9px 0 5px;
  color: #18262c;
  font-size: clamp(19px, 1.5vw, 26px);
  line-height: 1.05;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.sales-kpi small {
  color: #7b898e;
  font-size: 11px;
}

.sales-kpi-blue { --kpi-color: #2a6fbb; }
.sales-kpi-violet { --kpi-color: #7b61a8; }
.sales-kpi-green { --kpi-color: #35a66f; }
.sales-kpi-red { --kpi-color: #d44d5c; }
.sales-kpi-gold { --kpi-color: #e9a23b; }
.sales-kpi-slate { --kpi-color: #64748b; }

.sales-insight-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.sales-insight {
  min-width: 0;
  padding: 12px 13px;
  border-left: 3px solid var(--insight-color, #2a6fbb);
  background: #fff;
}

.sales-insight span {
  color: var(--insight-color, #2a6fbb);
  font-size: 11px;
  font-weight: 800;
}

.sales-insight p {
  margin: 5px 0 0;
  color: #3b4a50;
  font-size: 12px;
  line-height: 1.55;
}

.sales-insight-blue { --insight-color: #2a6fbb; }
.sales-insight-gold { --insight-color: #c47c12; }
.sales-insight-red { --insight-color: #c84758; }
.sales-insight-green { --insight-color: #268d5d; }

.sales-report-overview {
  display: grid;
  grid-template-columns: minmax(0, 1.85fr) minmax(280px, .75fr);
  gap: 12px;
  align-items: stretch;
}

.sales-report-rank-grid,
.sales-margin-visuals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.sales-report-chart-card {
  min-width: 0;
  min-height: 290px;
  padding: 15px;
  border: 1px solid #dce3e1;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 5px 15px rgba(28, 54, 61, 0.045);
}

.sales-chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 43px;
  margin-bottom: 10px;
}

.sales-chart-head span,
.sales-chart-head h4 {
  display: block;
}

.sales-chart-head span {
  margin-bottom: 2px;
  color: #718087;
  font-size: 11px;
  font-weight: 700;
}

.sales-chart-head h4 {
  margin: 0;
  color: #1b2d34;
  font-size: 15px;
}

.sales-chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px 10px;
  color: #66757b;
  font-size: 10px;
  white-space: nowrap;
}

.sales-dot {
  width: 8px;
  height: 8px;
  margin-top: 3px;
  border-radius: 50%;
}

.sales-dot-sales { background: #2a6fbb; }
.sales-dot-cash { background: #35a66f; }
.sales-dot-ar { background: #d44d5c; }

.sales-trend-chart {
  display: block;
  width: 100%;
  height: 244px;
}

.sales-trend-grid {
  stroke: #e6ecea;
  stroke-width: 1;
}

.sales-trend-axis {
  fill: #75838a;
  font-size: 10px;
}

.sales-trend-line {
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sales-line-sales { stroke: #2a6fbb; }
.sales-line-cash { stroke: #35a66f; }
.sales-line-ar {
  stroke: #d44d5c;
  stroke-width: 2;
  stroke-dasharray: 7 5;
}
.sales-point-sales { fill: #2a6fbb; }
.sales-point-cash { fill: #35a66f; }
.sales-point-ar { fill: #d44d5c; }
.sales-trend-point { stroke: #fff; stroke-width: 1.5; }

.sales-donut-layout {
  display: grid;
  grid-template-columns: minmax(126px, .85fr) minmax(135px, 1fr);
  gap: 15px;
  align-items: center;
  min-height: 214px;
}

.sales-donut {
  position: relative;
  width: min(164px, 100%);
  aspect-ratio: 1;
  margin: auto;
  border-radius: 50%;
  background: conic-gradient(var(--sales-donut));
}

.sales-donut::after {
  content: "";
  position: absolute;
  inset: 25%;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 1px #edf1f0;
}

.sales-donut > div {
  position: absolute;
  z-index: 1;
  inset: 25%;
  display: grid;
  place-content: center;
  text-align: center;
}

.sales-donut strong,
.sales-donut span {
  display: block;
}

.sales-donut strong {
  color: #1b2d34;
  font-size: 17px;
}

.sales-donut span {
  color: #819096;
  font-size: 9px;
}

.sales-donut-legend {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.sales-donut-legend > div {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  font-size: 11px;
}

.sales-donut-legend i {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.sales-donut-legend span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sales-donut-legend strong {
  color: #34474e;
  white-space: nowrap;
}

.sales-rank-list {
  display: grid;
  gap: 13px;
}

.sales-rank-row {
  display: grid;
  grid-template-columns: 25px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.sales-rank-row > b {
  color: #9aa6aa;
  font-size: 10px;
}

.sales-rank-label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  margin-bottom: 5px;
  font-size: 11px;
}

.sales-rank-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sales-rank-label strong {
  color: #33454c;
  white-space: nowrap;
}

.sales-rank-track {
  height: 7px;
  overflow: hidden;
  border-radius: 2px;
  background: #edf1f0;
}

.sales-rank-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--rank-color, #2a6fbb);
}

.sales-rank-blue { --rank-color: #2a6fbb; }
.sales-rank-gold { --rank-color: #e9a23b; }
.sales-rank-red { --rank-color: #d44d5c; }
.sales-rank-green { --rank-color: #35a66f; }

.sales-report-section {
  gap: 12px;
  padding-top: 18px;
}

.sales-margin-section {
  border-top-color: #d9e8df;
}

.sales-receivable-visuals {
  display: grid;
  grid-template-columns: minmax(290px, .85fr) minmax(0, 1.4fr);
  gap: 12px;
}

.sales-collection-layout {
  display: grid;
  grid-template-columns: 145px minmax(130px, 1fr);
  gap: 18px;
  align-items: center;
  min-height: 210px;
}

.sales-collection-ring {
  position: relative;
  width: 138px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(#35a66f 0 var(--collection-rate), #e8edeb var(--collection-rate) 360deg);
}

.sales-collection-ring::after {
  content: "";
  position: absolute;
  inset: 20px;
  border-radius: 50%;
  background: #fff;
}

.sales-collection-ring > div {
  position: absolute;
  z-index: 1;
  inset: 20px;
  display: grid;
  place-content: center;
  text-align: center;
}

.sales-collection-ring strong,
.sales-collection-ring span {
  display: block;
}

.sales-collection-ring strong {
  color: #238152;
  font-size: 21px;
}

.sales-collection-ring span {
  color: #7d8a8f;
  font-size: 10px;
}

.sales-collection-values {
  display: grid;
  gap: 11px;
}

.sales-collection-values > div {
  padding-left: 10px;
  border-left: 3px solid #2a6fbb;
}

.sales-collection-values > .cash { border-left-color: #35a66f; }
.sales-collection-values > .ar { border-left-color: #d44d5c; }

.sales-collection-values span,
.sales-collection-values strong {
  display: block;
}

.sales-collection-values span {
  color: #718087;
  font-size: 10px;
}

.sales-collection-values strong {
  margin-top: 2px;
  color: #263a41;
  font-size: 16px;
}

.sales-report-details {
  display: grid;
  gap: 8px;
}

.sales-report-detail {
  min-width: 0;
  border: 1px solid #dce3e1;
  border-radius: 7px;
  background: #fff;
  overflow: hidden;
}

.sales-report-detail summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 10px 13px;
  cursor: pointer;
  list-style: none;
}

.sales-report-detail summary::-webkit-details-marker {
  display: none;
}

.sales-report-detail summary::after {
  content: "+";
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border: 1px solid #ccd7d4;
  border-radius: 4px;
  color: #4d6269;
  font-size: 17px;
}

.sales-report-detail[open] summary::after {
  content: "−";
}

.sales-report-detail summary > div {
  min-width: 0;
}

.sales-report-detail summary span,
.sales-report-detail summary strong {
  display: block;
}

.sales-report-detail summary span {
  color: #087f8c;
  font-size: 10px;
  font-weight: 800;
}

.sales-report-detail summary strong {
  color: #263a41;
  font-size: 13px;
}

.sales-report-detail summary > b {
  margin-left: auto;
  color: #738188;
  font-size: 11px;
  white-space: nowrap;
}

.sales-report-detail .sales-report-table {
  margin: 0 10px 10px;
  border-radius: 5px;
}

.sales-visual-empty {
  display: grid;
  place-items: center;
  min-height: 150px;
  color: #859197;
  font-size: 12px;
  text-align: center;
}

.profit-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px;
  margin-bottom: 9px;
}

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

.profit-total strong {
  color: var(--teal);
  font-size: 20px;
}

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

.dashboard-gantt {
  display: grid;
  gap: 10px;
}

.gantt-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 9px;
  display: grid;
  grid-template-columns: minmax(140px, 0.9fr) minmax(220px, 1.4fr);
  gap: 10px;
  align-items: center;
  text-align: left;
}

.gantt-row:hover {
  border-color: #9bc8c1;
}

.gantt-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.gantt-title strong,
.gantt-title em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gantt-title em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.gantt-line {
  display: grid;
  grid-template-columns: repeat(4, minmax(42px, 1fr));
  gap: 5px;
  min-width: 0;
}

.gantt-segment {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 5px 6px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #fff;
}

.gantt-segment.done {
  border-color: #b9d8bb;
  background: var(--green-weak);
  color: var(--green);
}

.gantt-segment.current {
  border-color: #efd19f;
  background: var(--amber-weak);
  color: var(--amber);
}

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

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

.wide-panel {
  grid-column: 1 / -1;
}

.content-grid.form-list {
  grid-template-columns: minmax(360px, 500px) minmax(0, 1fr);
}

.after-sales-grid {
  grid-template-columns: minmax(420px, 0.9fr) minmax(620px, 1.5fr);
  align-items: start;
}

.after-sales-grid > .panel { min-width: 0; }
.after-sales-batch-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  align-items: end;
  min-width: 0;
  overflow: hidden;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f5f8f7;
}
.after-sales-batch-picker > label {
  grid-template-rows: 20px 36px;
  align-content: start;
  line-height: 20px;
}
.after-sales-batch-picker > .batch-issue-field { grid-column: 1 / -1; }
.after-sales-batch-picker button { align-self: end; min-height: 36px; min-width: 132px; white-space: nowrap; }
.after-sales-filters { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
.after-sales-line-detail h5 { margin: 16px 0 7px; color: var(--ink); font-size: 13px; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 7px; }
.attachment-list a { padding: 6px 9px; border-radius: 5px; color: #0d6964; background: #e2f2f0; text-decoration: none; }
.discussion-timeline { display: grid; gap: 10px; margin: 12px 0 18px; }
.discussion-entry { padding: 12px 14px; border-left: 3px solid #21867d; background: #f5f8f7; }
.discussion-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.discussion-entry p { margin: 9px 0; color: var(--ink); line-height: 1.65; white-space: pre-wrap; }
.next-action { margin-top: 8px; padding: 8px 10px; background: #fff7df; color: #72520d; }
.discussion-form { padding-top: 16px; border-top: 1px solid var(--line); }
.batch-link-field { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; }
.batch-link-field legend { padding: 0 5px; color: var(--muted); font-size: 12px; }
.batch-link-field label { display: flex; align-items: center; grid-auto-flow: column; width: auto; }
.batch-link-field input { width: auto; min-height: auto; }

/* A selected module subpage uses the full workspace; related panels stack. */
.content-grid > [data-module-page] {
  grid-column: 1 / -1;
  min-width: 0;
}

.sales-extra {
  margin-top: 12px;
}

#sales [data-sales-page] {
  display: none;
}

#sales [data-sales-page].active {
  display: block;
}

.view[data-active-page] [data-module-page] {
  display: none;
}

.view[data-active-page] [data-module-page].active {
  display: block;
}

#sales .sales-main {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.sales-entry-panel {
  position: static;
  max-height: none;
  overflow: visible;
}

.sales-list-panel .table-scroll {
  max-height: min(62vh, 650px);
}

.sales-order-table table {
  min-width: 1520px;
  table-layout: fixed;
}

.sales-order-table .compact-flow {
  min-width: 0;
}

.sales-order-table .flow-status {
  display: none;
}

#sales .form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

#sales .form-section {
  margin-top: 4px;
  padding-top: 10px;
}

#sales .form-grid button.wide {
  min-height: 40px;
  margin-top: 2px;
}

.sales-form-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}

.sales-form-actions button {
  min-width: 132px;
  min-height: 42px;
}

#salesOrders table th:nth-child(1),
#salesOrders table td:nth-child(1) {
  width: 104px;
}

#salesOrders table th:nth-child(2),
#salesOrders table td:nth-child(2) {
  width: 150px;
}

#salesOrders table th:nth-child(3),
#salesOrders table td:nth-child(3) {
  width: 210px;
}

#salesOrders table th:nth-child(4),
#salesOrders table td:nth-child(4),
#salesOrders table th:nth-child(5),
#salesOrders table td:nth-child(5),
#salesOrders table th:nth-child(6),
#salesOrders table td:nth-child(6),
#salesOrders table th:nth-child(7),
#salesOrders table td:nth-child(7),
#salesOrders table th:nth-child(8),
#salesOrders table td:nth-child(8) {
  width: 106px;
}

#salesOrders table th:nth-child(9),
#salesOrders table td:nth-child(9) {
  width: 280px;
}

#salesOrders table th:nth-child(10),
#salesOrders table td:nth-child(10) {
  width: 310px;
}

#sales .stats-filters {
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

#sales .rich-toolbar {
  gap: 8px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

#sales .rich-toolbar button,
#sales .rich-toolbar select,
#sales .rich-toolbar input[type="color"] {
  flex: 0 0 auto;
}

#sales .rich-toolbar select {
  width: auto;
  min-width: 78px;
}

#sales .rich-toolbar button {
  min-width: 36px;
}

#sales .rich-toolbar button[data-rich-command="clear"] {
  min-width: 86px;
}

#sales td.actions {
  min-width: 0;
  max-width: none;
  padding-top: 8px;
  padding-bottom: 8px;
}

#sales td.actions button,
#sales td.actions .button-link {
  min-width: 0;
  max-width: none;
  margin: 3px 5px 3px 0;
  width: auto;
}

.sales-extra {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

#sales[data-sales-subpage="service"] .sales-extra {
  grid-template-columns: minmax(0, 1fr);
}

#sales[data-sales-subpage="service"] .return-order-panel {
  grid-column: 1 / -1;
}

#sales[data-sales-subpage="service"] #returnForm {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.sales-contract-panel,
.sales-stats-panel,
.sales-price-panel {
  grid-column: 1 / -1;
}

.product-cost-panel {
  margin-top: 12px;
}

.product-extra {
  margin-top: 12px;
}

.production-extra {
  margin-top: 12px;
}

.production-orders-panel {
  min-height: 360px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
  min-width: 0;
}

.panel-head {
  min-height: 34px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 9px;
}

.panel-head > div:first-child { min-width: 0; }

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

.panel-head > div,
.panel-head h3 {
  min-width: 0;
}

.panel-head > button,
.panel-head > .primary,
.panel-head > .secondary,
.panel-head > .ghost {
  flex: 0 0 auto;
}

.panel-collapse {
  width: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #f7faf9;
  font-size: 18px;
  line-height: 1;
}

.panel-collapse:hover {
  color: var(--teal);
  border-color: #9ccbc4;
  background: #eef7f5;
}

.panel.is-collapsed > :not(.panel-head) { display: none; }

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

.panel-actions > button,
.panel-head > button { white-space: nowrap; }

.panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.panel-head h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inbound-preview {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.compact-panel-head {
  min-height: 28px;
  margin-bottom: 6px;
}

.compact-panel-head h4 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
}

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

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  min-width: 0;
}

.field-label {
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--ink);
  background: #fff;
  min-width: 0;
  width: 100%;
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  margin: 0;
  accent-color: var(--teal);
}

.long-select-search {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.long-select-search-input {
  min-height: 32px;
  padding: 6px 8px;
  font-size: 12px;
  background: #fbfcfb;
}

.long-select-search-meta {
  min-height: 15px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.16);
  border-color: #78b8b0;
}

input[readonly] {
  background: #f4f7f6;
  color: #40504d;
  cursor: default;
}

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

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

.rich-toolbar button,
.rich-toolbar select,
.rich-toolbar input[type="color"] {
  min-height: 32px;
}

.rich-toolbar button {
  padding: 5px 9px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  font-weight: 700;
}

.rich-toolbar select {
  padding: 5px 8px;
}

.rich-toolbar input[type="color"] {
  width: 42px;
  padding: 3px;
}

.rich-editor {
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 9px;
  background: #fff;
  color: var(--ink);
  outline: none;
  overflow-wrap: anywhere;
}

.rich-editor:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.rich-output {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  min-height: 38px;
  background: #fff;
  overflow-wrap: anywhere;
}

.rich-output + .rich-output {
  margin-top: 8px;
}

.wide {
  grid-column: 1 / -1;
}

.outbound-order-summary {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f4f8f6;
  color: var(--muted);
}

.outbound-order-summary strong {
  color: var(--ink);
}

.outbound-line-editor {
  min-width: 0;
}

.outbound-line-header,
.outbound-line-row {
  display: grid;
  grid-template-columns: 34px minmax(210px, 1.2fr) minmax(220px, 1.4fr) minmax(150px, .8fr) minmax(120px, .7fr);
  gap: 8px;
  align-items: center;
}

.outbound-line-header {
  padding: 7px 8px;
  color: var(--muted);
  background: #eef5f2;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
}

.outbound-line-row {
  padding: 8px;
  border: 1px solid var(--line);
  border-top: 0;
  background: #fff;
}

.outbound-line-check {
  display: flex;
  align-items: center;
  justify-content: center;
}

.outbound-line-product {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.outbound-line-product strong,
.outbound-line-product span,
.outbound-line-batch {
  overflow-wrap: anywhere;
}

.outbound-line-product strong {
  color: var(--ink);
}

.outbound-line-product span,
.outbound-line-batch {
  color: var(--muted);
  font-size: 12px;
}

.outbound-line-row input,
.outbound-line-row select {
  min-width: 0;
}

@media (max-width: 780px) {
  .outbound-line-header {
    display: none;
  }

  .outbound-line-row {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .outbound-line-row select,
  .outbound-line-row .outbound-line-batch,
  .outbound-line-row input {
    grid-column: 2;
  }
}

.form-section {
  padding-top: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  border-top: 1px solid var(--line);
}

.line-draft {
  min-width: 0;
}

.line-draft table {
  min-width: 520px;
}

.stock-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
}

.stock-card div {
  display: grid;
  gap: 4px;
}

.stock-card span,
.stock-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.stock-card strong {
  font-size: 14px;
  color: var(--ink);
}

.stock-card em {
  grid-column: 1 / -1;
}

.stock-card.good {
  border-color: #bedbc7;
  background: var(--green-weak);
}

.stock-card.warn {
  border-color: #e0b6b6;
  background: var(--red-weak);
}

.price-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  border: 1px solid #c7d7ee;
  border-radius: 8px;
  padding: 10px;
  background: #eef5ff;
}

.price-card div {
  display: grid;
  gap: 4px;
}

.price-card span,
.price-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.price-card strong {
  color: var(--ink);
  font-size: 14px;
}

.price-card em {
  grid-column: 1 / -1;
}

.margin-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px 12px;
  border: 1px solid #b9d6c3;
  border-radius: 8px;
  padding: 12px;
  background: #f1f8f3;
}

.margin-card div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.margin-card span,
.margin-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.margin-card strong {
  color: #216b43;
  font-size: 14px;
}

.margin-card em {
  grid-column: 1 / -1;
  border-top: 1px solid rgba(33, 107, 67, 0.16);
  padding-top: 8px;
}

.margin-card.negative {
  border-color: #e0b6b6;
  background: var(--red-weak);
}

.margin-card.negative strong {
  color: var(--red);
}

.sales-detail-margin {
  margin-top: 12px;
}

.trace-label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 440px);
  gap: 24px;
  align-items: center;
}

.trace-label span,
.trace-label p {
  color: var(--muted);
}

.trace-label h3 {
  margin: 5px 0;
  font-size: 22px;
}

.trace-barcode {
  display: block;
  width: 100%;
  height: 92px;
  background: #fff;
}

.trace-barcode text {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  letter-spacing: 1px;
}

.trace-detail-grid {
  margin-top: 14px;
}

.trace-code-preview {
  text-align: center;
  padding: 24px;
}

.trace-code-preview .trace-barcode {
  width: min(100%, 860px);
  height: 230px;
  margin: 12px auto 18px;
  border: 1px solid var(--line);
  padding: 12px;
}

.trace-code-preview .trace-barcode text {
  font-size: 13px;
}

.trace-preview-meta span,
.trace-preview-meta p {
  color: var(--muted);
}

.trace-preview-meta h3 {
  margin: 6px 0;
  font-size: 22px;
}

.trace-preview-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.trace-code-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  align-items: center;
  margin: 12px auto 16px;
}

.trace-code-grid.compact {
  grid-template-columns: minmax(240px, 1fr) 140px;
  margin: 0 0 10px;
}

.trace-code-grid .trace-barcode {
  margin: 0;
}

.trace-qr {
  width: 220px;
  height: 220px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.trace-qr.small {
  width: 140px;
  height: 140px;
  padding: 5px;
}

.trace-qr img,
.trace-qr canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.trace-public-link {
  display: inline-block;
  margin: 4px 0 10px;
  color: var(--accent-strong);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.trace-code-link {
  min-height: 0;
  padding: 2px 5px;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.trace-event {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.barcode-scanner {
  display: grid;
  justify-items: center;
  gap: 9px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #f7faf9;
}

.barcode-scanner video {
  width: min(100%, 560px);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #111;
}

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

.cost-subtable {
  margin-top: 12px;
}

.primary,
.secondary,
.ghost {
  padding: 7px 11px;
  font-weight: 600;
}

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

.secondary {
  background: var(--amber-weak);
  color: var(--amber);
}

.ghost {
  background: transparent;
  color: var(--teal);
}

.full {
  width: 100%;
}

.table-wrap {
  overflow: visible;
  max-width: 100%;
  min-width: 0;
}

.erp-table-shell {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.table-summary {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  padding: 0 2px;
}

.table-scroll {
  max-height: min(44vh, 430px);
  overflow: auto;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.table-scroll::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.table-scroll::-webkit-scrollbar-thumb {
  background: #c8d4d1;
  border-radius: 999px;
  border: 2px solid #fff;
}

.compact-table .table-scroll {
  max-height: 280px;
}

.roomy-table .table-scroll {
  max-height: min(52vh, 540px);
}

.cost-subtable .table-scroll {
  max-height: 320px;
}

.roomy-table table {
  min-width: 1180px;
}

.roomy-table td.actions {
  min-width: 0;
}

.roomy-table td.actions,
.finance-ledger td.actions {
  min-width: 0;
}

.roomy-table td.actions button,
.roomy-table td.actions .button-link,
.finance-ledger td.actions button,
.finance-ledger td.actions .button-link {
  max-width: 112px;
}

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

.stats-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(174px, 1fr));
  gap: 11px;
  margin-bottom: 10px;
  align-items: end;
}

.stats-filters > label { min-width: 0; }

@media (max-width: 1180px) {
  .main { padding-left: 16px; padding-right: 16px; }
  .topbar { align-items: stretch; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
}

.stats-filters button,
.form-grid button,
.detail-form button {
  justify-self: start;
}

.stats-filters button.wide,
.form-grid button.wide,
.detail-form button.wide {
  justify-self: stretch;
}

.stats-filters label,
.stats-filters input,
.stats-filters select {
  min-width: 0;
  width: 100%;
}

.inventory-filters {
  grid-template-columns: repeat(2, minmax(156px, 1fr));
  align-items: start;
}

#purchase .content-grid.two {
  grid-template-columns: minmax(0, 1fr);
}

#purchase .purchase-list-panel .table-scroll {
  max-height: min(58vh, 620px);
}

#purchase .purchase-list-panel table {
  min-width: 0;
  table-layout: fixed;
}

#purchase .purchase-list-panel th,
#purchase .purchase-list-panel td {
  white-space: normal;
  line-height: 1.35;
}

#purchase .purchase-list-panel td:not(.actions) {
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
}

#purchase .purchase-list-panel .compact-flow {
  min-width: 0;
  gap: 8px;
}

#purchase .purchase-list-panel .flow-cell {
  min-width: 0;
}

#purchase .purchase-list-panel .compact-flow .flow-steps {
  gap: 4px;
}

#purchase .purchase-list-panel .compact-flow .flow-step strong {
  max-width: 42px;
}

#purchase .purchase-list-panel .flow-status {
  display: none;
}

#purchase .purchase-list-panel td.actions {
  min-width: 0;
  max-width: none;
}

#purchase .purchase-list-panel td.actions button {
  width: auto;
  min-width: 0;
  padding-left: 6px;
  padding-right: 6px;
  margin: 3px 5px 3px 0;
}

#purchaseReqs table,
#purchaseOrders table,
#purchaseContracts table,
#demandPlans table,
#productionOrders table {
  min-width: 0;
  width: 100%;
  table-layout: fixed;
}

#demandPlans table th:nth-child(1),
#demandPlans table td:nth-child(1) { width: 17%; }
#demandPlans table th:nth-child(2),
#demandPlans table td:nth-child(2) { width: 21%; }
#demandPlans table th:nth-child(3),
#demandPlans table td:nth-child(3) { width: 15%; }
#demandPlans table th:nth-child(4),
#demandPlans table td:nth-child(4) { width: 15%; }
#demandPlans table th:nth-child(5),
#demandPlans table td:nth-child(5) { width: 20%; }
#demandPlans table th:nth-child(6),
#demandPlans table td:nth-child(6) { width: 12%; }

#demandPlans td.actions {
  min-width: 0;
  max-width: none;
  grid-template-columns: 1fr;
}

#purchaseReqs table th:nth-child(1),
#purchaseReqs table td:nth-child(1) { width: 17%; }
#purchaseReqs table th:nth-child(2),
#purchaseReqs table td:nth-child(2) { width: 22%; }
#purchaseReqs table th:nth-child(3),
#purchaseReqs table td:nth-child(3) { width: 13%; }
#purchaseReqs table th:nth-child(4),
#purchaseReqs table td:nth-child(4) { width: 25%; }
#purchaseReqs table th:nth-child(5),
#purchaseReqs table td:nth-child(5) { width: 23%; }

#purchaseOrders table th:nth-child(1),
#purchaseOrders table td:nth-child(1) { width: 17%; }
#purchaseOrders table th:nth-child(2),
#purchaseOrders table td:nth-child(2) { width: 20%; }
#purchaseOrders table th:nth-child(3),
#purchaseOrders table td:nth-child(3) { width: 14%; }
#purchaseOrders table th:nth-child(4),
#purchaseOrders table td:nth-child(4) { width: 10%; }
#purchaseOrders table th:nth-child(5),
#purchaseOrders table td:nth-child(5) { width: 21%; }
#purchaseOrders table th:nth-child(6),
#purchaseOrders table td:nth-child(6) { width: 18%; }

#purchaseContracts table th:nth-child(1),
#purchaseContracts table td:nth-child(1) { width: 18%; }
#purchaseContracts table th:nth-child(2),
#purchaseContracts table td:nth-child(2) { width: 16%; }
#purchaseContracts table th:nth-child(3),
#purchaseContracts table td:nth-child(3) { width: 19%; }
#purchaseContracts table th:nth-child(4),
#purchaseContracts table td:nth-child(4) { width: 14%; }
#purchaseContracts table th:nth-child(5),
#purchaseContracts table td:nth-child(5) { width: 12%; }
#purchaseContracts table th:nth-child(6),
#purchaseContracts table td:nth-child(6) { width: 21%; }

#purchaseContracts td.actions {
  min-width: 0;
  max-width: none;
}

#productionOrders table th:nth-child(1),
#productionOrders table td:nth-child(1) { width: 20%; }
#productionOrders table th:nth-child(2),
#productionOrders table td:nth-child(2) { width: 21%; }
#productionOrders table th:nth-child(3),
#productionOrders table td:nth-child(3) { width: 11%; }
#productionOrders table th:nth-child(4),
#productionOrders table td:nth-child(4) { width: 25%; }
#productionOrders table th:nth-child(5),
#productionOrders table td:nth-child(5) { width: 23%; }

.cell-subline {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

#productionOrders .compact-flow {
  min-width: 0;
}

#productionOrders td.actions {
  min-width: 0;
  max-width: none;
  display: table-cell;
  white-space: normal;
  vertical-align: middle;
}

#productionOrders td.actions .action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  align-items: center;
}

.batch-inbound-qty {
  width: 82px;
  min-width: 82px;
  padding: 3px 5px;
}

.batch-draft-summary {
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 13px;
}

#otherInboundDraftLines table {
  margin-bottom: 12px;
}

#productionOrders td.actions button,
#productionOrders td.actions .button-link {
  min-width: 0;
  max-width: none;
  width: 100%;
  padding-left: 5px;
  padding-right: 5px;
}

#outboundOrders table {
  min-width: 1320px;
}

#outboundOrders table th:last-child,
#outboundOrders table td:last-child {
  width: 180px;
}

#outboundOrders td.actions {
  min-width: 0;
  max-width: none;
  grid-template-columns: repeat(2, minmax(68px, 1fr));
}

.mini-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px;
}

.mini-metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fbfcfb;
}

.mini-metric span {
  color: var(--muted);
  display: block;
  font-size: 12px;
}

.mini-metric strong {
  display: block;
  margin-top: 6px;
  font-size: 16px;
}

.inventory-stats {
  margin-bottom: 12px;
}

#purchaseInboundOrders table {
  min-width: 1180px;
  table-layout: fixed;
}

#purchaseInboundOrders th,
#purchaseInboundOrders td {
  white-space: normal;
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  vertical-align: top;
}

#purchaseInboundOrders th:nth-child(1),
#purchaseInboundOrders td:nth-child(1) { width: 16%; }
#purchaseInboundOrders th:nth-child(2),
#purchaseInboundOrders td:nth-child(2) { width: 31%; }
#purchaseInboundOrders th:nth-child(3),
#purchaseInboundOrders td:nth-child(3) { width: 16%; }
#purchaseInboundOrders th:nth-child(4),
#purchaseInboundOrders td:nth-child(4) { width: 13%; }
#purchaseInboundOrders th:nth-child(5),
#purchaseInboundOrders td:nth-child(5) { width: 14%; }
#purchaseInboundOrders th:nth-child(6),
#purchaseInboundOrders td:nth-child(6) { width: 10%; }

#purchaseInboundOrders .purchase-inbound-order-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 7px;
  align-items: start;
}

#purchaseInboundOrders .purchase-inbound-order-row > input[type="checkbox"] {
  margin-top: 3px;
}

#purchaseInboundOrders .purchase-inbound-order-meta,
#purchaseInboundOrders .purchase-inbound-summary {
  display: grid;
  gap: 3px;
  min-width: 0;
}

#purchaseInboundOrders .purchase-inbound-line {
  display: grid;
  gap: 7px;
  padding: 2px 0 9px;
  margin-bottom: 8px;
  border-bottom: 1px solid #e4eae8;
}

#purchaseInboundOrders .purchase-inbound-line:last-child {
  padding-bottom: 2px;
  margin-bottom: 0;
  border-bottom: 0;
}

#purchaseInboundOrders .purchase-inbound-line-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

#purchaseInboundOrders .purchase-inbound-line-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

#purchaseInboundOrders .purchase-inbound-line-title .cell-subline {
  flex: 0 0 auto;
  white-space: nowrap;
}

#purchaseInboundOrders .purchase-inbound-line-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 108px;
  gap: 7px;
  align-items: end;
}

#purchaseInboundOrders .purchase-inbound-line-fields label {
  gap: 3px;
  min-width: 0;
  font-size: 11px;
}

#purchaseInboundOrders .purchase-inbound-line-fields input,
#purchaseInboundOrders .purchase-inbound-location {
  min-height: 34px;
  padding: 7px 8px;
}

#purchaseInboundOrders td.actions {
  min-width: 0;
  width: 10%;
  vertical-align: middle;
}

#purchaseInboundOrders td.actions button {
  width: 100%;
  margin: 0;
  padding-left: 7px;
  padding-right: 7px;
}

.inventory-adjustment-form {
  margin-bottom: 10px;
}

#inventory > .panel + .panel,
#inventory > .panel + .content-grid {
  margin-top: 14px;
}

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

.chart-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
  min-width: 0;
}

.chart-box h4 {
  margin: 0 0 10px;
  font-size: 13px;
}

.bar-chart {
  display: grid;
  gap: 7px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(72px, 120px) minmax(80px, 1fr) minmax(58px, auto);
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.bar-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: #1d4ed8;
}

.share-chart {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.donut {
  width: 86px;
  aspect-ratio: 1;
  border-radius: 50%;
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 24px;
  border-radius: 50%;
  background: #fbfcfb;
}

.legend {
  display: grid;
  gap: 6px;
  font-size: 12px;
}

.legend div {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.legend span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px 9px;
  text-align: left;
  vertical-align: middle;
  font-size: 12px;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: #fafafa;
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 1px 0 var(--line);
}

table:has(td.actions) th:last-child {
  position: sticky;
  right: 0;
  z-index: 4;
  background: #f6faf9;
  box-shadow: -1px 0 0 var(--line), 0 1px 0 var(--line);
}

td:not(.actions) {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

td .tag {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

td.actions {
  display: table-cell;
  min-width: 0;
  max-width: none;
  white-space: normal;
  vertical-align: middle;
  position: sticky;
  right: 0;
  z-index: 3;
  background: #fff;
  box-shadow: -1px 0 0 var(--line);
}

td.actions button,
td.actions .button-link {
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--teal-weak);
  color: #0b5f59;
  font-size: 12px;
  white-space: nowrap;
  width: auto;
  max-width: none;
  margin: 3px 5px 3px 0;
}

td.actions .button-link {
  font-weight: 600;
  text-decoration: none;
}

td.actions button.danger {
  background: var(--red-weak);
  color: var(--red);
}

td.actions button.action-primary,
#productionOrders td.actions button.action-primary,
#purchaseOrders td.actions button.action-primary {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
  font-weight: 700;
  box-shadow: 0 2px 7px rgba(16, 111, 103, 0.24);
}

td.actions button.action-primary:hover,
#productionOrders td.actions button.action-primary:hover,
#purchaseOrders td.actions button.action-primary:hover {
  filter: brightness(0.94);
  transform: translateY(-1px);
}

.inbound-confirm-button {
  min-height: 42px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 3px 9px rgba(16, 111, 103, 0.22);
}

td.actions .tag {
  justify-content: center;
  max-width: none;
  width: auto;
  min-height: 28px;
  border-radius: 6px;
}

td.actions > button:last-child,
td.actions > .button-link:last-child,
td.actions > .tag:last-child {
  margin-right: 0;
}

button.danger {
  background: var(--red-weak);
  color: var(--red);
  border-color: #efc7c7;
  padding: 7px 12px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.approval-rules {
  display: grid;
  gap: 10px;
}

.approval-rule {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  display: grid;
  gap: 5px;
  background: #fff;
}

.approval-rule strong {
  color: var(--ink);
  font-size: 14px;
}

.approval-rule span,
.approval-rule p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.approval-rule em {
  font-style: normal;
  color: #0b5f59;
  font-size: 13px;
}

.flow-cell {
  min-width: 220px;
  display: grid;
  gap: 6px;
}

.flow-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(54px, 1fr));
  gap: 8px;
  position: relative;
}

.flow-steps::before {
  content: "";
  position: absolute;
  left: 28px;
  right: 28px;
  top: 15px;
  height: 2px;
  background: var(--line);
}

.flow-step {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.flow-step span {
  width: 30px;
  aspect-ratio: 1;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 2px solid var(--line);
  color: var(--muted);
  font-weight: 700;
}

.flow-step.done span {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.flow-step.active span {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}

.flow-step.done strong {
  color: var(--green);
}

.flow-step.active strong {
  color: var(--amber);
}

.compact-flow {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

.compact-flow .flow-steps {
  min-width: 0;
  grid-template-columns: repeat(var(--flow-count, 4), minmax(42px, 1fr));
  gap: 5px;
}

.compact-flow .flow-steps::before {
  left: 20px;
  right: 20px;
  top: 11px;
}

.compact-flow .flow-step {
  gap: 2px;
  font-size: 11px;
  white-space: nowrap;
  min-width: 0;
}

.compact-flow .flow-step span {
  width: 22px;
  height: 22px;
  font-size: 11px;
}

.compact-flow .flow-step strong {
  max-width: 46px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flow-status {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  min-width: 0;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compact-flow .flow-status {
  display: none;
}

.ship-progress {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.ship-progress div {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--green));
}

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

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-height: 52px;
}

.list-item strong {
  display: block;
}

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

.compact .list-item {
  align-items: flex-start;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}

.compact-note {
  padding: 10px;
  text-align: left;
}

.permission-editor,
.role-permission-editor {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.permission-editor .panel-head p,
.role-permission-editor .panel-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 13px;
}

.permission-group { min-width: 0; margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.permission-group legend { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: calc(100% - 8px); padding: 0 4px; font-weight: 700; }
.permission-group-toggle { min-height: 28px; padding: 4px 9px; color: var(--brand); background: #eef7f6; font-size: 11px; }
.permission-group-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.custom-role-form { display: flex; align-items: end; gap: 12px; max-width: 620px; }
.custom-role-form label { display: grid; flex: 1; gap: 6px; color: var(--muted); font-size: 12px; }
.custom-role-form input { min-height: 40px; }

.permission-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
}

.permission-check input { flex: none; width: 16px; height: 16px; }
.permission-check span { min-width: 0; line-height: 1.3; }
.permission-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.role-template-select { display: grid; gap: 5px; max-width: 260px; color: var(--muted); font-size: 12px; }
.role-template-select select { min-height: 38px; }
.permission-tags { display: flex; flex-wrap: wrap; gap: 4px; min-width: 260px; max-width: 560px; }

@media (max-width: 1100px) {
  .after-sales-grid { grid-template-columns: 1fr; }
  .after-sales-batch-picker button { grid-column: 1 / -1; justify-self: stretch; width: 100%; }
  .permission-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .after-sales-batch-picker { grid-template-columns: 1fr; gap: 10px; }
  .after-sales-batch-picker button { grid-column: auto; }
  .permission-grid { grid-template-columns: 1fr; }
  .permission-group-grid { grid-template-columns: 1fr; }
  .custom-role-form { align-items: stretch; flex-direction: column; }
  .permission-actions { align-items: stretch; flex-direction: column-reverse; }
}

.muted-text {
  color: var(--muted);
  font-size: 12px;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

/* Customer development and AI-assisted prospecting. */
#crm {
  max-width: 1480px;
}

#crm .module-subnav {
  margin-bottom: 14px;
}

.crm-intro {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 4px 2px 14px;
}

.crm-intro.active { display: flex !important; }
.crm-intro h1 { margin: 4px 0 5px; font-size: 25px; }
.crm-intro p { margin: 0; color: var(--muted); font-size: 13px; }

.crm-mode-badge {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid #d8b765;
  border-radius: 5px;
  background: #fff8df;
  color: #775408;
  font-size: 12px;
  font-weight: 700;
}

#crmMetrics.active { display: grid !important; }
.crm-workbench.active {
  display: grid !important;
  grid-template-columns: minmax(350px, .8fr) minmax(480px, 1.2fr);
  align-items: start;
}

.crm-company-form .wide,
.crm-analysis-form .wide { grid-column: 1 / -1; }

.crm-analysis-status {
  margin-top: 11px;
  padding: 9px 11px;
  border-left: 3px solid #83908b;
  background: #f2f5f4;
  color: var(--muted);
  font-size: 12px;
}
.crm-analysis-status.success { border-color: #27825c; background: #edf8f2; color: #1b6546; }
.crm-analysis-status.error { border-color: #c44840; background: #fff1f0; color: #963029; }
.crm-analysis-status.info { border-color: #2877a8; background: #edf6fb; color: #245e80; }

.crm-analysis-result { margin-top: 12px; display: grid; gap: 12px; }
.crm-analysis-head {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  background: #f8faf9;
}
.crm-analysis-head h4 { margin: 0 0 5px; }
.crm-analysis-head p { margin: 0 0 5px; color: var(--ink); line-height: 1.5; }
.crm-analysis-head small { color: var(--muted); line-height: 1.45; }
.crm-score-ring {
  width: 78px;
  aspect-ratio: 1;
  display: grid;
  place-content: center;
  text-align: center;
  border: 7px solid #22836f;
  border-radius: 50%;
  background: #fff;
}
.crm-score-ring strong { font-size: 24px; line-height: 1; }
.crm-score-ring span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.crm-score-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(84px, 1fr));
  gap: 7px;
}
.crm-score-grid > div { padding: 9px; border: 1px solid var(--line); background: #fff; }
.crm-score-grid span { display: block; color: var(--muted); font-size: 11px; }
.crm-score-grid strong { display: block; margin-top: 3px; font-size: 18px; }
.crm-output-block { border-top: 1px solid var(--line); padding-top: 10px; }
.crm-output-block h4 { margin: 0 0 7px; font-size: 13px; }
.crm-output-block ul { margin: 0; padding-left: 20px; color: var(--ink); line-height: 1.65; }
.crm-output-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.crm-output-block pre {
  margin: 7px 0 0;
  padding: 10px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  background: #f7f9f8;
  color: var(--ink);
  font: inherit;
  line-height: 1.6;
}
.crm-recommendations { display: grid; gap: 7px; }
.crm-recommendations > div { display: grid; grid-template-columns: minmax(150px, 1fr) auto; gap: 5px 12px; padding: 9px 10px; background: #f5f8f7; }
.crm-recommendations span { color: #176f66; font-weight: 700; }
.crm-recommendations p { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 12px; }

.crm-table td small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.crm-table .table-actions { display: flex; flex-wrap: nowrap; gap: 7px; }
.crm-table .table-actions button { min-width: 58px; }
.crm-stage,
.crm-grade,
.crm-knowledge-status { display: inline-block; padding: 3px 7px; border-radius: 4px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.crm-stage { background: #e8f3f1; color: #176f66; }
.crm-grade { min-width: 27px; text-align: center; background: #edf0ef; color: #59635f; }
.crm-grade.grade-a { background: #dff4e8; color: #176a43; }
.crm-grade.grade-b { background: #e4f1fa; color: #225f86; }
.crm-grade.grade-c { background: #fff2d4; color: #79580f; }
.crm-grade.grade-d { background: #fbe4e2; color: #943b35; }
.crm-knowledge-status.approved { background: #dff4e8; color: #176a43; }
.crm-knowledge-status.pending { background: #fff2d4; color: #79580f; }

.crm-company-detail { margin-top: 16px; }
.crm-radar-panel { margin-bottom: 14px; }
.crm-radar-form { margin-bottom: 14px; }
.crm-radar-toolbar { display: grid; grid-template-columns: minmax(180px, 220px) minmax(220px, 1fr); gap: 10px; align-items: end; margin: 12px 0; padding-top: 12px; border-top: 1px solid var(--line); }
.crm-radar-toolbar label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.crm-radar-table small, .crm-radar-table a { display: block; margin-top: 4px; }
.crm-radar-table small { color: var(--muted); }
.crm-source-link { color: var(--teal); font-size: 12px; text-decoration: none; }
.crm-source-link:hover { text-decoration: underline; }
.crm-detail-sheet { padding-top: 14px; border-top: 2px solid #176f66; }
.crm-detail-grid { display: grid; grid-template-columns: repeat(4, minmax(100px, 1fr)); gap: 8px; margin-bottom: 13px; }
.crm-detail-grid > div { padding: 9px; border: 1px solid var(--line); }
.crm-detail-grid span { display: block; color: var(--muted); font-size: 11px; }
.crm-detail-grid strong { display: block; margin-top: 3px; }
.crm-detail-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.crm-quick-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; padding: 12px; border: 1px solid var(--line); background: #f8faf9; }
.crm-quick-form h4 { grid-column: 1 / -1; margin: 0 0 2px; }
.crm-quick-form button { grid-column: 1 / -1; justify-self: start; }
.crm-history { margin-top: 14px; }
.crm-history > h4 { margin: 0 0 7px; }
.crm-history > div { padding: 9px 0; border-top: 1px solid var(--line); }
.crm-history > div > span { float: right; color: var(--muted); font-size: 11px; }
.crm-history p { margin: 4px 0 0; color: var(--muted); white-space: pre-wrap; }

button.is-loading { transform: translateY(1px); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .18); }

@media (max-width: 1050px) {
  .crm-workbench.active { grid-template-columns: 1fr; }
  .crm-score-grid { grid-template-columns: repeat(3, minmax(84px, 1fr)); }
}

@media (max-width: 680px) {
  .crm-intro.active { display: grid !important; }
  .crm-mode-badge { justify-self: start; }
  .crm-score-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crm-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crm-detail-columns, .crm-quick-form { grid-template-columns: 1fr; }
  .crm-quick-form h4, .crm-quick-form button { grid-column: 1; }
  .crm-analysis-head { grid-template-columns: 1fr; }
  .crm-radar-toolbar { grid-template-columns: 1fr; }
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(31, 37, 40, 0.42);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-panel {
  width: min(1180px, 100%);
  max-height: min(90vh, 920px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.modal-body {
  padding: 12px;
  display: grid;
  gap: 10px;
}

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

.detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
  min-width: 0;
}

.detail-card h4 {
  margin: 0 0 10px;
  font-size: 13px;
}

.detail-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(72px, 92px) minmax(0, 1fr);
  gap: 7px 10px;
  font-size: 12px;
}

.detail-card dt {
  color: var(--muted);
}

.detail-card dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.workflow-hint {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent, #168a82);
  background: #eef8f6;
  color: #35645f;
  font-size: 13px;
  line-height: 1.6;
}

.pre-line {
  white-space: pre-line;
}

.button-link {
  display: inline-flex;
  margin-top: 6px;
  text-decoration: none;
}

.detail-flow {
  margin-top: 12px;
}

.detail-form {
  margin-top: 12px;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 9px;
  margin-bottom: 10px;
}

.attachment-card {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.attachment-card img,
.file-icon {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--teal-weak);
  color: #0b5f59;
}

.file-icon {
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.attachment-card strong,
.attachment-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-card span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.attachment-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 9px;
}

.preline {
  white-space: pre-line;
}

.statement-box {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.statement-preview {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

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

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

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

  .nav-btn {
    text-align: center;
  }

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

  .sidebar-tools { grid-column: 1 / -1; }

  .metric-grid,
  .chart-grid,
  .dashboard-chart-grid,
  .dashboard-sales-analytics,
  .detail-grid,
  .content-grid.two,
  .content-grid.form-list,
  .sales-extra {
    grid-template-columns: 1fr;
  }

  .sales-entry-panel {
    position: static;
    max-height: none;
  }

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

  #sales[data-sales-subpage="service"] #returnForm {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .inventory-filters {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

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

  .sales-insight-strip,
  .sales-report-rank-grid,
  .sales-margin-visuals {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sales-report-overview,
  .sales-receivable-visuals {
    grid-template-columns: 1fr;
  }
}

/* Keep short operational hints quiet and consistent across modules. */
.panel-head p,
.crm-intro p,
.table-summary,
.batch-draft-summary,
.compact-note,
.rd-cost-note,
.stock-hint {
  line-height: 1.35;
}

.panel-head p,
.crm-intro p {
  font-size: 12px;
}

@media (max-width: 760px) {
  .login-panel {
    grid-template-columns: 1fr;
  }

  .login-brand {
    grid-row: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 24px;
    gap: 18px;
  }

  .login-logo {
    width: 158px;
  }

  .login-panel h1 {
    font-size: 28px;
  }

  .login-copy,
  .login-panel label,
  .login-error {
    grid-column: 1;
    padding-left: 24px;
    padding-right: 24px;
  }

  .login-panel .primary {
    grid-column: 1;
    margin-left: 24px;
    margin-right: 24px;
  }

  .login-footer {
    grid-column: 1;
    margin-left: 24px;
    margin-right: 24px;
    margin-bottom: 24px;
  }

  .topbar,
  .panel-head,
  .profit-total,
  .sales-report-heading,
  .sales-report-section-head,
  .list-item {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-actions {
    justify-content: flex-start;
  }

  .sales-report-actions button {
    flex: 1 1 132px;
  }

  .sales-report-heading p {
    text-align: left;
  }

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

  .sales-insight-strip,
  .sales-report-rank-grid,
  .sales-margin-visuals {
    grid-template-columns: 1fr;
  }

  .sales-report-chart-card {
    min-height: 0;
    padding: 13px;
  }

  .sales-chart-head {
    display: grid;
    min-height: 0;
  }

  .sales-chart-legend {
    justify-content: flex-start;
  }

  .sales-trend-chart {
    height: 220px;
  }

  .sales-report-detail summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .sales-report-detail summary > b {
    grid-row: 2;
    margin-left: 0;
  }

  .sales-report-detail summary::after {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .stats-filters,
  .inventory-filters,
  .attachment-inputs {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  #sales .stats-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stock-card {
    grid-template-columns: 1fr;
  }

  .price-card {
    grid-template-columns: 1fr;
  }

  .margin-card {
    grid-template-columns: 1fr;
  }

  .trace-label {
    grid-template-columns: 1fr;
  }

  .trace-code-grid,
  .trace-code-grid.compact {
    grid-template-columns: 1fr;
  }

  .trace-qr,
  .trace-qr.small {
    width: min(220px, 100%);
    height: auto;
    aspect-ratio: 1;
    margin: 0 auto;
  }

  .compact-flow {
    min-width: 280px;
  }

  .table-scroll {
    max-height: 420px;
  }

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

@media (max-width: 560px) {
  .main {
    padding: 12px;
  }

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

  .sidebar-footer {
    grid-template-columns: 1fr;
  }

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

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

  #sales[data-sales-subpage="service"] #returnForm {
    grid-template-columns: 1fr;
  }

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

  .inventory-filters {
    grid-template-columns: 1fr;
  }

  .metric .value {
    font-size: 20px;
  }

  .modal {
    padding: 10px;
  }

  .modal-panel {
    max-height: 94vh;
  }
}

/* Global UI baseline: keep controls, table headers and status colors consistent. */
:where(button, .button-link) {
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}

:where(button.primary, button.secondary, button.ghost, button.danger) {
  border-width: 1px;
  border-style: solid;
}

button.primary {
  border-color: var(--teal);
}

button.secondary {
  border-color: #edd5a8;
}

button.ghost {
  border-color: transparent;
}

button:focus-visible,
.button-link:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  align-items: center;
}

.top-actions,
.panel-actions,
.permission-actions {
  gap: 8px;
}

.top-actions button {
  min-height: 34px;
  padding: 7px 11px;
}

.module-subnav {
  gap: 6px;
  padding: 6px;
}

.module-tab {
  min-height: 34px;
  padding: 7px 12px;
}

.panel-head {
  min-height: 38px;
  margin-bottom: 12px;
}

.panel-head h3,
.panel-head h4 {
  line-height: 1.35;
}

input,
select,
textarea {
  min-height: 38px;
  padding: 8px 10px;
}

.table-scroll {
  border-radius: 8px;
  overscroll-behavior: contain;
}

table {
  min-width: 880px;
}

th,
td {
  padding: 9px 10px;
  line-height: 1.35;
}

th {
  color: #405159;
  background: #f1f6f5;
  font-weight: 700;
}

tbody tr:nth-child(even) td:not(.actions) {
  background: #fbfdfd;
}

tbody tr:hover td:not(.actions) {
  background: #eff8f6;
}

td.actions {
  background: #fff;
}

tbody tr:nth-child(even) td.actions {
  background: #fbfdfd;
}

tbody tr:hover td.actions {
  background: #f4faf8;
}

td.actions button,
td.actions .button-link {
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 6px;
  line-height: 1.2;
}

.tag,
.status-pill {
  line-height: 1.25;
}

.empty {
  line-height: 1.5;
}

@media (max-width: 680px) {
  .main {
    padding: 14px;
  }

  .panel {
    padding: 12px;
  }

  .module-subnav {
    gap: 5px;
  }

  .module-tab {
    flex: 1 1 auto;
  }

  th,
  td {
    padding: 8px 9px;
  }
}
