:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #6c7786;
  --line: #dde3ea;
  --primary: #146c63;
  --primary-dark: #0d4e49;
  --accent: #b9475d;
  --soft-green: #e5f3ef;
  --soft-rose: #fae8ec;
  --soft-gold: #f7efd9;
  --shadow: 0 12px 30px rgba(24, 33, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  color: var(--text);
  background: var(--bg);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 18px;
  background: #17202a;
  color: #ffffff;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.brand-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  padding: 8px 4px 24px;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #ffffff;
  text-align: left;
  background: transparent;
}

.brand-mark {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  overflow: hidden;
  background: #f1c6cf;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-block h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.3;
  font-weight: 800;
}

.brand-entry:hover {
  background: rgba(255, 255, 255, 0.06);
}

.nav-tabs {
  display: grid;
  gap: 8px;
  margin-top: 22px;
  padding-bottom: 28px;
}

.nav-tab {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  text-align: left;
  color: rgba(255, 255, 255, 0.76);
  background: transparent;
}

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

.nav-subtabs {
  display: none;
  gap: 2px;
  margin: -4px 0 2px 14px;
  padding-left: 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.14);
}

.nav-subtabs.show {
  display: grid;
}

.nav-direct-tab {
  width: 100%;
  min-height: 28px;
  border: 0;
  border-radius: 6px;
  padding: 0 8px;
  color: rgba(255, 255, 255, 0.62);
  background: transparent;
  text-align: left;
  font-size: 12px;
}

.nav-direct-tab:hover,
.nav-direct-tab.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.app-shell {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topbar h2 {
  margin: 4px 0 0;
  font-size: 28px;
  letter-spacing: 0;
}

.top-actions,
.form-actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cloud-sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  background: #edf2f5;
  font-size: 12px;
  white-space: nowrap;
}

.cloud-sync-status.synced {
  color: var(--primary-dark);
  background: var(--soft-green);
}

.cloud-sync-status.syncing {
  color: #725819;
  background: var(--soft-gold);
}

.cloud-sync-status.offline {
  color: #8f2639;
  background: var(--soft-rose);
}

.primary-button,
.ghost-button,
.icon-button,
.danger-button {
  min-height: 38px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 0 14px;
  white-space: nowrap;
}

.primary-button {
  color: #ffffff;
  background: var(--primary);
}

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

.danger-button {
  color: #ffffff;
  background: var(--accent);
}

.danger-button:hover {
  background: #92364a;
}

.ghost-button,
.icon-button {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 18px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel,
.table-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.metric.warning strong {
  color: var(--accent);
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 18px;
}

.dashboard-flow-panel {
  margin-bottom: 18px;
}

.flow-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 18px;
}

.flow-placeholder {
  min-height: 96px;
}

.flow-item {
  min-height: 74px;
  display: grid;
  align-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
  text-align: center;
}

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

.flow-item strong {
  font-size: 22px;
}

.company-hero-panel {
  margin-bottom: 18px;
}

.company-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: left;
}

.company-hero img {
  width: 92px;
  height: 92px;
  border: 1px solid var(--line);
  border-radius: 12px;
  object-fit: contain;
  background: #ffffff;
}

.company-hero h3 {
  margin: 6px 0 0;
  font-size: 28px;
}

.company-info-grid,
.company-doc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}

.company-info-card {
  min-height: 100%;
}

.info-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0 18px 18px;
}

.info-list div {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.info-list div:last-child {
  border-bottom: 0;
}

.info-list dt {
  color: var(--muted);
  font-weight: 600;
}

.info-list dd {
  margin: 0;
  color: var(--text);
  font-weight: 700;
  word-break: break-word;
}

.document-actions {
  display: grid;
  gap: 12px;
  padding: 0 18px 18px;
}

.doc-link {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.document-card {
  overflow: hidden;
}

.document-frame {
  width: 100%;
  height: 560px;
  display: block;
  border: 0;
  border-top: 1px solid var(--line);
  background: #f8fafb;
}

.document-image-wrap {
  height: 560px;
  display: grid;
  place-items: center;
  border-top: 1px solid var(--line);
  padding: 14px;
  background: #f8fafb;
}

.document-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 8px 24px rgba(23, 32, 42, 0.12);
}

.ranking-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfd;
}

.ranking-card h4 {
  margin: 0 0 14px;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.35;
}

.ranking-list {
  display: grid;
  gap: 10px;
}

.ranking-row {
  display: grid;
  grid-template-columns: 28px 54px minmax(0, 1fr) minmax(96px, auto);
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff;
}

.ranking-index {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: #e8f2ef;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.ranking-thumb {
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  object-fit: cover;
}

.ranking-main {
  min-width: 0;
}

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

.ranking-title strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

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

.ranking-bar {
  height: 6px;
  margin-top: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ecef;
}

.ranking-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.ranking-row em {
  color: var(--ink);
  font-size: 13px;
  font-style: normal;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.ranking-empty {
  min-height: 164px;
  display: grid;
  place-items: center;
}

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

.direct-grid {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 16px;
  padding: 0;
}

.direct-grid-single {
  grid-template-columns: 1fr;
}

.direct-subnav {
  display: grid;
  align-content: start;
  gap: 8px;
}

.direct-subnav button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.direct-subnav button.active {
  border-color: var(--primary);
  color: #fff;
  background: var(--primary);
}

.direct-workspace {
  min-width: 0;
  display: grid;
  gap: 12px;
  padding: 0;
}

.direct-workspace-head {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: center;
  gap: 10px;
}

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

.direct-workspace h4 {
  margin: 5px 0 0;
  color: var(--ink);
  font-size: 26px;
  line-height: 1.15;
}

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

.direct-stat-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.direct-stat-grid span {
  color: var(--muted);
  font-size: 12px;
}

.direct-stat-grid strong {
  display: block;
  margin-top: 6px;
  color: var(--primary);
  font-size: 20px;
}

.direct-section-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.direct-period-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-column: 1 / span 3;
  gap: 10px;
}

.direct-period-tabs button {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  font-weight: 800;
  cursor: pointer;
}

.direct-period-tabs button.active {
  border-color: var(--primary);
  color: #fff;
  background: var(--primary);
}

.direct-date-panel {
  display: grid;
  grid-template-columns: auto minmax(150px, 190px) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  grid-column: 4 / span 3;
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #fff;
}

.direct-date-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.direct-date-input {
  min-height: 38px;
  border-color: transparent;
  background: #f6f8fa;
}

.direct-range-badge {
  justify-self: end;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.direct-section-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.direct-section-card h5 {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
}

.direct-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.direct-section-card > h5 {
  margin-bottom: 12px;
}

.direct-detail-date-control {
  width: 220px;
  min-height: 38px;
}

.direct-table-wrap table {
  min-width: 1160px;
}

.direct-table-wrap th,
.direct-table-wrap td {
  text-align: center;
}

.direct-table-wrap td:first-child {
  text-align: left;
}

.direct-expense-form {
  display: grid;
  gap: 14px;
  border-radius: 8px;
  background: #fbfcfd;
}

.direct-expense-fields {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.direct-expense-bottom {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.direct-expense-date-field {
  grid-column: span 2;
}

.direct-expense-type-field {
  grid-column: span 2;
}

.direct-expense-product-field {
  grid-column: span 6;
}

.direct-expense-amount-field {
  grid-column: span 2;
}

.direct-expense-note-field {
  grid-column: span 10;
}

.direct-expense-form .primary-button {
  grid-column: span 2;
  min-height: 42px;
  align-self: end;
}

.direct-mini-list {
  display: grid;
  gap: 8px;
}

.direct-mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.direct-mini-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.direct-mini-row strong,
.direct-mini-row span {
  display: block;
}

.direct-mini-row strong {
  color: var(--ink);
  font-size: 13px;
}

.direct-mini-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.direct-mini-row em {
  color: var(--primary);
  font-size: 13px;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}

.direct-mini-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel,
.table-panel {
  margin-bottom: 18px;
}

.panel-heading {
  padding: 18px 18px 0;
}

.panel-heading.flat {
  padding-bottom: 14px;
}

.panel-heading h3 {
  margin: 0;
  font-size: 17px;
}

.panel-heading p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.import-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  padding: 18px;
}

.import-upload-box {
  min-height: 112px;
  align-content: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fbfcfd;
  cursor: pointer;
}

.import-upload-box span {
  color: var(--muted);
  font-size: 13px;
}

.import-upload-box strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 18px;
  word-break: break-all;
}

.import-upload-box input {
  display: none;
}

.import-actions {
  display: grid;
  align-content: center;
  gap: 10px;
}

.import-actions p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.module-import-dialog {
  width: min(680px, calc(100vw - 32px));
}

.module-import-dialog > p {
  margin: 6px 0 14px;
  color: var(--muted);
  line-height: 1.6;
}

.module-import-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.module-import-fields span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  color: var(--primary-dark);
  background: var(--soft-green);
  font-size: 12px;
}

.module-import-upload {
  display: block;
  min-height: 96px;
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
  padding: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: #3a4654;
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  color: var(--text);
  background: #ffffff;
}

textarea {
  min-height: 86px;
  padding: 10px 11px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(20, 108, 99, 0.18);
  border-color: var(--primary);
}

input[readonly] {
  color: #41505f;
  background: #f5f7f9;
}

.checkbox-list {
  min-height: 48px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: #ffffff;
}

.checkbox-option {
  width: 82px;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: #3a4654;
  background: #fbfcfd;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.checkbox-option input {
  width: 14px;
  min-height: 14px;
  accent-color: var(--primary);
}

.checkbox-option:has(input:checked) {
  color: var(--primary-dark);
  border-color: rgba(20, 108, 99, 0.35);
  background: var(--soft-green);
}

.checkbox-option:has(input:checked)::after {
  content: "✓";
  font-weight: 700;
}

.checkbox-option:has(input:disabled) {
  cursor: default;
}

#customerChannel.checkbox-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

#customerChannel .checkbox-option {
  width: 100%;
  min-width: 0;
  gap: 4px;
  padding: 0 6px;
  font-size: 12px;
}

#customerChannel .checkbox-option input {
  width: 13px;
  min-height: 13px;
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 0.8fr) auto;
  gap: 8px;
}

.compact-button {
  min-width: 58px;
  padding: 0 10px;
}

.form-actions {
  align-self: end;
  justify-content: flex-end;
}

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

.supplier-form {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  align-items: end;
}

.supplier-form .wide-field {
  grid-column: 1 / 4;
}

.supplier-form .address-field {
  grid-column: 1 / -1;
}

.supplier-actions {
  grid-column: 4;
  align-self: stretch;
  display: grid;
  align-content: end;
  gap: 10px;
  padding: 0;
  background: transparent;
}

.supplier-actions .primary-button,
.supplier-actions .ghost-button {
  width: 100%;
}

.purchase-form {
  grid-template-columns: repeat(3, minmax(170px, 1fr)) minmax(190px, 0.78fr);
  align-items: end;
}

.order-form {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  align-items: end;
}

.order-meta-field,
.order-wide-field {
  grid-column: span 2;
}

.order-party-card {
  grid-column: span 2;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-self: stretch;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.order-party-card h4 {
  grid-column: 1 / -1;
  margin: 0 0 2px;
  color: var(--text);
  font-size: 16px;
}

.order-party-card label:nth-of-type(2),
.order-party-card label:nth-of-type(5) {
  grid-column: 1 / -1;
}

.order-terms-card {
  grid-column: 1 / -1;
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.order-terms-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.order-terms-heading h4 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
}

.order-terms-heading span {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--primary-dark);
  background: var(--soft-green);
  font-size: 12px;
  font-weight: 700;
}

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

.fixed-term-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-height: 42px;
  border: 1px solid #e8edf2;
  border-radius: 7px;
  padding: 10px 12px;
  background: #fbfcfd;
}

.fixed-term-item.is-wide {
  grid-column: 1 / -1;
}

.fixed-term-item span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.fixed-term-item p {
  margin: 0;
  color: #3a4654;
  font-size: 13px;
  line-height: 1.65;
}

.fixed-term-item strong {
  color: var(--text);
}

.order-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-self: end;
  align-content: end;
}

.order-actions .primary-button,
.order-actions .ghost-button {
  width: 100%;
}

.order-lines-card {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.order-entry-table-wrap {
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow-x: hidden;
}

.order-entry-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.order-entry-table th,
.order-entry-table td {
  padding: 10px 8px;
  text-align: center;
  vertical-align: middle;
}

.order-entry-table th:nth-child(1),
.order-entry-table td:nth-child(1) {
  width: 52px;
}

.order-entry-table th:nth-child(2),
.order-entry-table td:nth-child(2) {
  width: 146px;
}

.order-entry-table th:nth-child(3),
.order-entry-table td:nth-child(3) {
  width: auto;
  white-space: nowrap;
}

.order-entry-table td:nth-child(3) {
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-entry-table th:nth-child(4),
.order-entry-table td:nth-child(4) {
  width: 76px;
}

.order-entry-table th:nth-child(5),
.order-entry-table td:nth-child(5) {
  width: 70px;
}

.order-entry-table th:nth-child(6),
.order-entry-table td:nth-child(6) {
  width: 90px;
}

.order-entry-table th:nth-child(7),
.order-entry-table td:nth-child(7) {
  width: 102px;
}

.order-entry-table th:nth-child(8),
.order-entry-table td:nth-child(8) {
  width: 76px;
}

.order-entry-table th:nth-child(9),
.order-entry-table td:nth-child(9) {
  width: 68px;
}

.order-entry-row input {
  min-height: 36px;
  padding: 0 6px;
  text-align: center;
}

#saleOrderProductNamePreview {
  padding: 0 10px;
  text-align: left;
  font-size: 12px;
}

.order-entry-row input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

.order-entry-row input[type="number"]::-webkit-outer-spin-button,
.order-entry-row input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.order-inline-image {
  display: grid;
  place-items: center;
  min-height: 64px;
  color: var(--muted);
  font-size: 12px;
}

.order-inline-image img {
  display: none;
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.order-inline-image.has-image img {
  display: block;
}

.order-inline-image.has-image span {
  display: none;
}

.order-item-thumb {
  width: 54px;
  height: 54px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.order-line-editor {
  display: grid;
  grid-template-columns: minmax(280px, 2fr) repeat(4, minmax(110px, 1fr)) minmax(120px, 0.7fr);
  gap: 12px;
  align-items: end;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.order-line-editor .primary-button {
  width: 100%;
  min-height: 46px;
}

.order-total-strip {
  display: flex;
  justify-content: flex-end;
  gap: 28px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  color: #3a4654;
  background: #fbfcfd;
}

.order-total-strip strong {
  color: var(--primary-dark);
  font-size: 18px;
}

.product-form {
  grid-template-columns: repeat(3, minmax(170px, 1fr)) minmax(190px, 0.78fr);
  align-items: end;
}

.product-name-field {
  grid-column: span 2;
}

.purchase-side-panel {
  grid-column: 4;
  grid-row: 1 / span 4;
  align-self: stretch;
  display: grid;
  grid-template-rows: minmax(116px, 1fr) auto;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.product-side-panel {
  grid-template-rows: auto minmax(116px, 1fr) auto;
}

.side-panel-title {
  color: #3a4654;
  font-size: 13px;
}

.purchase-actions {
  display: grid;
  gap: 10px;
}

.purchase-actions .primary-button,
.purchase-actions .ghost-button {
  width: 100%;
}

.toolbar {
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.toolbar input {
  max-width: 360px;
}

.brand-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-chip {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #3a4654;
  background: #ffffff;
  white-space: nowrap;
}

.filter-chip:hover,
.filter-chip.active {
  color: #ffffff;
  border-color: var(--primary);
  background: var(--primary);
}

.image-upload-preview {
  position: relative;
  align-self: end;
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px dashed #cbd4df;
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfd;
  font-size: 13px;
}

.image-upload-preview img {
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  display: none;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.image-upload-preview.has-image img {
  display: block;
}

.product-side-panel .image-upload-preview {
  align-self: stretch;
  flex-direction: column;
  justify-content: center;
  min-height: 146px;
  text-align: center;
}

.product-side-panel .image-upload-preview img {
  width: 76px;
  height: 76px;
  flex-basis: 76px;
}

.product-side-panel .image-upload-preview.has-image #productImageHint {
  display: none;
}

.upload-trigger {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--primary-dark);
  background: #ffffff;
  font-size: 13px;
  cursor: pointer;
}

.upload-trigger input {
  display: none;
}

.remove-image-button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  color: #ffffff;
  background: var(--accent);
  font-size: 16px;
  line-height: 1;
  padding: 0;
}

.image-upload-preview.has-image .remove-image-button {
  display: flex;
}

.purchase-product-preview {
  min-height: 116px;
  align-self: stretch;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.purchase-product-preview img {
  width: 76px;
  height: 76px;
  flex-basis: 76px;
}

.compact-date-filter {
  width: auto;
  min-width: 220px;
  display: flex;
  align-items: center;
  grid-template-columns: none;
  gap: 8px;
  white-space: nowrap;
}

.compact-date-filter input {
  width: 160px;
  min-width: 160px;
}

.sale-order-list-table {
  min-width: 0;
  table-layout: fixed;
}

.sale-order-list-table th,
.sale-order-list-table td {
  padding: 10px 8px;
  text-align: center;
  vertical-align: middle;
}

.sale-order-list-table th:nth-child(1),
.sale-order-list-table td:nth-child(1) {
  width: 170px;
}

.sale-order-list-table th:nth-child(2),
.sale-order-list-table td:nth-child(2) {
  width: 150px;
}

.sale-order-list-table th:nth-child(3),
.sale-order-list-table td:nth-child(3) {
  width: 110px;
}

.sale-order-list-table th:nth-child(4),
.sale-order-list-table td:nth-child(4),
.sale-order-list-table th:nth-child(5),
.sale-order-list-table td:nth-child(5) {
  width: 76px;
}

.sale-order-list-table th:nth-child(6),
.sale-order-list-table td:nth-child(6) {
  width: 130px;
}

.sale-order-list-table th:nth-child(7),
.sale-order-list-table td:nth-child(7) {
  width: 96px;
}

.sale-order-list-table th:nth-child(8),
.sale-order-list-table td:nth-child(8) {
  width: 360px;
}

.sale-order-actions {
  display: inline-grid;
  grid-template-columns: repeat(4, max-content);
  justify-content: center;
  align-items: center;
  gap: 0 60px;
  white-space: nowrap;
}

.sale-order-actions .link-button {
  min-height: 28px;
  line-height: 1;
}

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

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

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

th {
  color: var(--muted);
  background: #f9fbfc;
  font-weight: 700;
  text-align: center;
}

tbody tr:hover {
  background: #fbfcfd;
}

tbody tr.highlight-row {
  background: #fff3c6;
  box-shadow: inset 4px 0 0 #d39b16;
}

.product-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 230px;
}

.product-thumb {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 8px;
  object-fit: cover;
  background:
    radial-gradient(circle at 30% 20%, #ffffff 0 12%, transparent 13%),
    linear-gradient(135deg, #e7f2ef, #f5dce2 52%, #f5edcf);
  border: 1px solid var(--line);
}

.product-name {
  display: block;
  font-weight: 700;
}

.product-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--soft-green);
  font-size: 12px;
}

.badge.danger {
  color: #8f2639;
  background: var(--soft-rose);
}

.badge.gold {
  color: #725819;
  background: var(--soft-gold);
}

.badge.green {
  color: var(--primary-dark);
  background: var(--soft-green);
}

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

.compact-actions {
  gap: 6px;
  white-space: nowrap;
}

.supplier-short {
  display: inline-block;
  min-width: 3em;
  max-width: 3em;
  line-height: 1.45;
  word-break: keep-all;
  text-align: center;
}

#purchaseTable td,
#purchasesView th {
  padding: 9px 8px;
}

.stacked-th {
  display: inline-block;
  min-width: 2.2em;
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
}

#purchasesView table {
  min-width: 1000px;
}

#salesView table {
  min-width: 1680px;
}

#reportsView table {
  min-width: 1180px;
}

.cost-detail-cell {
  min-width: 210px;
  max-width: 260px;
  color: var(--muted);
  line-height: 1.55;
  white-space: normal;
}

.cost-summary {
  display: grid;
  gap: 3px;
  min-width: 140px;
  color: var(--muted);
  line-height: 1.35;
}

.link-button {
  border: 0;
  padding: 0;
  color: var(--primary);
  background: transparent;
}

.danger-link {
  color: var(--accent);
}

.compact-list {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.compact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.compact-item strong {
  display: block;
  font-size: 14px;
}

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

#inventoryView table {
  min-width: 980px;
}

.batch-summary {
  min-width: 180px;
  text-align: center;
}

.batch-summary strong {
  display: block;
  margin-bottom: 5px;
}

.batch-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
}

.batch-summary-cell {
  text-align: center;
}

.batch-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  color: #3a4654;
  background: #f2f5f7;
  font-size: 12px;
  white-space: nowrap;
}

.inventory-brand {
  display: inline-grid;
  gap: 2px;
  min-width: 4.5em;
  text-align: center;
  line-height: 1.35;
}

.inventory-brand strong {
  font-size: 13px;
}

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

.inventory-status {
  justify-content: center;
  min-width: 42px;
  min-height: 38px;
  line-height: 1.25;
  text-align: center;
}

.stacked-action {
  min-width: 3.2em;
  line-height: 1.35;
  text-align: center;
}

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

.switch {
  display: flex;
  grid-template-columns: auto;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.switch input {
  width: 16px;
  min-height: 16px;
}

.empty {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  min-width: 240px;
  max-width: 360px;
  padding: 13px 15px;
  border-radius: 8px;
  color: #ffffff;
  background: #17202a;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

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

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(23, 32, 42, 0.42);
}

.confirm-modal.show {
  display: flex;
}

.confirm-dialog {
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(23, 32, 42, 0.24);
}

.batch-detail-dialog {
  width: min(860px, 100%);
}

.sale-order-preview-dialog {
  width: min(1180px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  display: grid;
  gap: 14px;
}

.preview-modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-modal-actions .ghost-button {
  min-height: 38px;
  padding: 0 18px;
}

.sale-order-preview-shell {
  width: 100%;
  aspect-ratio: 297 / 210;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.sale-order-preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

.modal-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.modal-table-wrap {
  max-height: 56vh;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.modal-table-wrap table {
  min-width: 680px;
}

.modal-table-wrap th,
.modal-table-wrap td {
  text-align: center;
}

.modal-table-wrap .stacked-th {
  min-width: 3.2em;
}

.confirm-dialog h3 {
  margin: 0;
  font-size: 18px;
}

.confirm-dialog p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

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

@media (max-width: 1020px) {
  body {
    grid-template-columns: 212px minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    height: 100vh;
    padding: 20px 14px;
  }

  .nav-tabs {
    grid-template-columns: 1fr;
  }

  .nav-tab {
    text-align: left;
  }

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

  .company-info-grid,
  .company-doc-grid {
    grid-template-columns: 1fr;
  }

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

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

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

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

  .direct-period-tabs,
  .direct-date-panel {
    grid-column: 1;
    justify-self: stretch;
    width: 100%;
  }

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

  .direct-section-grid {
    grid-template-columns: 1fr;
  }

  .direct-expense-fields {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .direct-expense-date-field,
  .direct-expense-type-field,
  .direct-expense-amount-field {
    grid-column: span 2;
  }

  .direct-expense-product-field {
    grid-column: 1 / -1;
  }

  .direct-expense-bottom {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .direct-expense-note-field {
    grid-column: span 4;
  }

  .direct-expense-form .primary-button {
    grid-column: span 2;
  }

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

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

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

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

  .order-meta-field,
  .order-wide-field,
  .order-party-card,
  .order-lines-card,
  .order-actions {
    grid-column: 1 / -1;
  }

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

  .order-line-editor label:first-child,
  .order-line-editor .primary-button {
    grid-column: 1 / -1;
  }

  .product-name-field {
    grid-column: 1 / -1;
  }

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

  .supplier-form .wide-field {
    grid-column: 1;
  }

  .supplier-form .address-field {
    grid-column: 1 / -1;
  }

  .supplier-actions {
    grid-column: 2;
    grid-row: auto;
    grid-template-columns: 1fr;
  }

  .purchase-side-panel {
    grid-column: 1 / -1;
    grid-row: auto;
    grid-template-columns: minmax(0, 1fr) minmax(170px, 0.4fr);
    grid-template-rows: none;
    align-items: stretch;
  }

  .product-side-panel .side-panel-title,
  .product-side-panel .image-upload-preview {
    grid-column: 1;
  }

  .product-side-panel .purchase-actions {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: end;
  }
}

@media (max-width: 680px) {
  body {
    grid-template-columns: 86px minmax(0, 1fr);
  }

  .sidebar {
    padding: 14px 10px;
  }

  .brand-block {
    justify-content: center;
    padding-bottom: 14px;
    gap: 0;
  }

  .brand-block > div:not(.brand-mark) {
    display: none;
  }

  .brand-mark {
    width: 54px;
    height: 54px;
  }

  .app-shell {
    padding: 14px;
  }

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

  .nav-tabs {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .nav-tab {
    min-height: 44px;
    padding: 0 6px;
    text-align: center;
    font-size: 13px;
  }

  .nav-subtabs {
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }

  .nav-direct-tab {
    min-height: 30px;
    padding: 0 4px;
    text-align: center;
    font-size: 10px;
    overflow-wrap: anywhere;
  }

  .metric-grid,
  .split-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .company-hero {
    flex-direction: column;
    text-align: center;
  }

  .company-hero h3 {
    font-size: 22px;
  }

  .info-list div {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .document-frame,
  .document-image-wrap {
    height: 420px;
  }

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

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

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

  .order-form,
  .order-line-editor {
    grid-template-columns: 1fr;
  }

  .order-meta-field,
  .order-wide-field,
  .order-party-card,
  .order-lines-card,
  .order-actions,
  .order-line-editor label:first-child,
  .order-line-editor .primary-button {
    grid-column: 1;
  }

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

  .order-actions {
    grid-template-columns: 1fr;
  }

  .fixed-term-list {
    grid-template-columns: 1fr;
  }

  .order-total-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

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

  .direct-date-panel {
    grid-template-columns: 1fr;
  }

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

  .direct-card-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .direct-detail-date-control {
    width: 100%;
  }

  .direct-date-input {
    width: 100%;
  }

  .direct-range-badge {
    justify-self: start;
    max-width: 100%;
  }

  .direct-stat-grid,
  .direct-section-grid,
  .direct-expense-fields,
  .direct-expense-bottom {
    grid-template-columns: 1fr;
  }

  .import-panel {
    grid-template-columns: 1fr;
  }

  .direct-expense-date-field,
  .direct-expense-type-field,
  .direct-expense-product-field,
  .direct-expense-amount-field,
  .direct-expense-note-field,
  .direct-expense-form .primary-button {
    grid-column: 1;
  }

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

  .supplier-actions {
    grid-column: 2;
    grid-template-columns: 1fr;
  }

  .purchase-side-panel {
    grid-column: auto;
    grid-template-columns: minmax(0, 1fr) minmax(132px, 0.42fr);
  }

  .product-side-panel {
    grid-template-columns: 1fr;
  }

  .product-side-panel .side-panel-title,
  .product-side-panel .image-upload-preview,
  .product-side-panel .purchase-actions {
    grid-column: auto;
    grid-row: auto;
  }

  .top-actions,
  .toolbar,
  .form-actions,
  .purchase-actions {
    width: 100%;
    justify-content: stretch;
  }

  .primary-button,
  .ghost-button,
  .danger-button {
    flex: 1;
  }
}

@media (max-width: 460px) {
  .ranking-row {
    grid-template-columns: 24px 46px minmax(0, 1fr);
  }

  .ranking-thumb {
    width: 46px;
    height: 46px;
  }

  .ranking-row em {
    grid-column: 3;
    text-align: left;
  }

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

  .supplier-form .wide-field,
  .supplier-actions {
    grid-column: 1;
  }
}
