:root {
  --blue: #0b5cab;
  --blue-dark: #0a4380;
  --cyan: #0f8a9d;
  --red: #c2410c;
  --green: #18794e;
  --ink: #1f2937;
  --muted: #667085;
  --line: #d9e2ec;
  --bg: #f2f6fb;
  --panel: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

.hidden { display: none !important; }

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #d8d6cf;
  padding: 24px;
}

.login-card {
  width: min(360px, 92vw);
  background: #f8fafc;
  border: 1px solid #d6dde7;
  border-radius: 8px;
  box-shadow: 0 16px 36px rgba(15, 23, 42, .12);
  padding: 30px 28px;
}

.login-card h1 {
  text-align: center;
  color: #0078d7;
  font-size: 28px;
  margin-bottom: 16px;
}

.login-card > p {
  text-align: center;
  color: var(--muted);
  margin-bottom: 28px;
}

.login-card label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--ink);
  font-size: 14px;
}

.login-card input {
  border: 1px solid #b9c3cf;
  border-radius: 5px;
  padding: 10px 12px;
  background: #fff;
}

.remember-line {
  grid-template-columns: 16px 1fr;
  align-items: center;
  color: var(--muted) !important;
}

.remember-line input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.login-error {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
  margin-bottom: 10px;
}

.login-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.login-actions button {
  border-radius: 5px;
  padding: 10px 14px;
}

.register-toggle {
  margin-top: 8px;
  text-align: center;
}

.register-toggle button {
  border: 1px solid #d6dde7;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-weight: 400;
  padding: 10px 16px;
  font-size: 16px;
  line-height: normal;
}

.register-title {
  margin: 0 0 18px;
  color: var(--ink);
  font-size: 18px;
  text-align: center;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
  overflow: hidden;
}

.sidebar {
  background: linear-gradient(180deg, var(--blue-dark), var(--blue));
  color: #fff;
  padding: 22px 16px;
  height: 100vh;
  overflow: hidden;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 22px;
  border-bottom: 1px solid rgba(255,255,255,.22);
}

.brand span, .eyebrow, .panel-head span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.brand span { color: rgba(255,255,255,.72); margin-top: 4px; }

.emblem {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #fff;
  color: var(--blue);
  font-weight: 800;
}

.nav { display: grid; gap: 8px; margin-top: 22px; }

.nav-item {
  border: 0;
  border-radius: 6px;
  padding: 12px 14px;
  text-align: left;
  color: #e8f3ff;
  background: transparent;
}

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

.main {
  padding: 22px;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.contract-notice {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid #d9aa62;
  border-radius: 6px;
  background: #fff7e8;
  color: #7a3e0b;
  font-size: 14px;
  line-height: 1.5;
}

.contract-notice span {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.contract-notice button {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 22px;
  line-height: 1;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.year-picker {
  display: inline-flex;
  align-items: center;
  gap: 0;
  margin: 0;
  transform: none;
}

.year-picker button {
  display: none;
}

.year-picker select {
  width: 72px;
  height: 24px;
  border: 0;
  border-radius: 0;
  padding: 0 2px;
  text-align: center;
  font-weight: 700;
  color: var(--blue);
  background: transparent;
  outline: none;
  cursor: pointer;
}

.year-picker select option {
  color: var(--ink);
  font-weight: 400;
}

.topbar-right {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.user-badge button {
  border-radius: 6px;
  padding: 6px 10px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 24px; letter-spacing: 0; }
h2 { font-size: 17px; }

.searchbox {
  display: flex;
  gap: 8px;
  min-width: min(520px, 48vw);
}

.searchbox input, select, .form-grid input, .form-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
}

.searchbox button, .toolbar button, .doc-actions button {
  border-radius: 6px;
  padding: 10px 14px;
}

.view { display: none; }
.view.active {
  display: block;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

#contracts.view.active {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#inventory.view.active {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(15, 54, 92, .06);
}

.metric { padding: 16px; }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 8px; font-size: 22px; }

.layout-two {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, .65fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel { padding: 16px; }

.panel-head, .toolbar, .drawer-head, .doc-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.bar-chart { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 42px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 12px; border-radius: 999px; background: #e7eef6; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--blue), var(--cyan)); }

.risk-list, .sample-grid, .party-grid { display: grid; gap: 10px; }
.risk-item, .sample-card, .party-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #fbfdff;
}

.risk-item strong, .sample-card strong, .party-card strong { display: block; margin-bottom: 6px; }
.danger { color: var(--red); }
.ok { color: var(--green); }

.success {
  background: #5bbf5a;
  border-color: #4caf50;
  color: #fff;
}

.warning {
  background: #f0a32a;
  border-color: #e3941f;
  color: #fff;
}

.danger-button {
  background: #d9534f;
  border-color: #c9433f;
  color: #fff;
}

.sample-grid, .party-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

#contractArchive .archive-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(520px, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

#contractArchive .archive-upload-panel,
#contractArchive .archive-list-panel {
  min-width: 0;
}

.archive-tabs {
  display: inline-flex;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

#contractArchive .archive-groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.archive-group {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdff;
}

.archive-group-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  background: #edf5ff;
  line-height: 1.25;
}

.archive-group-title button,
.archive-file-main {
  border: 0;
  padding: 0;
  background: transparent;
  color: #064f9e;
  font-weight: 700;
  text-align: left;
}

.archive-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px 5px 10px;
  color: #111827;
  font-weight: 500;
  gap: 8px;
  line-height: 1.25;
}

.archive-file-row:hover {
  background: #f1f7ff;
}

.archive-file-main {
  display: flex;
  justify-content: space-between;
  min-width: 0;
  flex: 1;
  gap: 8px;
  color: #111827;
  font-weight: 500;
  font-size: 14px;
}

.archive-file-main span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archive-file-main b {
  flex: 0 0 auto;
}

.archive-delete-btn {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 13px;
}

.archive-status {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
}

#contractArchive .archive-preview-panel {
  min-height: 0;
}

#contractArchive .archive-preview {
  min-height: 760px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

#contractArchive .archive-preview iframe,
#contractArchive .archive-preview img {
  display: block;
  width: 100%;
  height: 760px;
  border: 0;
  object-fit: contain;
  background: #fff;
}

.toolbar {
  justify-content: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.toolbar select { max-width: 260px; }

#contracts #statusFilter {
  width: 110px;
  max-width: 110px;
  padding-left: 12px;
  padding-right: 28px;
}

#contracts #partyFilter {
  width: 100%;
  height: 42px;
  border: 0;
  outline: none;
  padding: 10px 34px 10px 12px;
  background: transparent;
}

.party-filter-combo {
  position: relative;
  width: 240px;
  max-width: 240px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.party-filter-combo::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 13px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #111827;
  pointer-events: none;
  transform: translateY(-35%);
}

.party-filter-menu {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  z-index: 30;
  width: max(100%, 280px);
  max-height: 260px;
  overflow: auto;
  border: 1px solid #cfd6df;
  background: #fff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .16);
}

.party-filter-menu button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 9px 12px;
  background: #fff;
  color: #111827;
  text-align: left;
  white-space: nowrap;
}

.party-filter-menu button:hover {
  background: #eaf3ff;
}

#exportContracts {
  min-width: 0;
  height: auto;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  color: #16436f;
  background: transparent;
  font-weight: 700;
}

.contract-summary {
  display: flex;
  flex: 1;
  min-width: 420px;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding-left: 10px;
  overflow-x: auto;
}

.summary-item {
  display: grid;
  gap: 6px;
  min-width: 130px;
  padding: 10px 14px;
  border: 1px solid #cfe0f5;
  background: #f8fbff;
  color: #16436f;
  text-align: left;
  white-space: nowrap;
}

.summary-item span {
  font-size: 13px;
  font-weight: 500;
}

.summary-item-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.summary-item .summary-manual-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: #d97706;
}

.summary-item strong {
  color: #0b2545;
  font-size: 14px;
  font-weight: 800;
}

.financial-detail-type {
  color: #16436f;
  font-weight: 700;
}

.financial-history-time {
  color: var(--muted);
}

.financial-negative {
  color: #b42318;
  font-weight: 700;
}

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

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.segment {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 10px 18px;
  color: #16436f;
}

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

.segment.active {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.link-button {
  border: 0;
  padding: 0;
  color: var(--blue);
  background: transparent;
  font-weight: 700;
}

.amount-link {
  border: 0;
  padding: 0;
  color: var(--blue);
  background: transparent;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.actions {
  white-space: nowrap;
}

.actions button, .drawer-actions button {
  border-radius: 6px;
  padding: 7px 10px;
  margin-right: 6px;
}

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

.party-contract-wrap {
  overflow-x: hidden;
}

#contracts .toolbar {
  flex: 0 0 auto;
}

#contracts .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
}

.inventory-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  margin-bottom: 0;
  padding: 0 0 8px;
  background: #fff;
}

.inventory-toolbar h2 {
  margin: 0 18px 0 0;
  color: #6b3f1e;
  font-size: 24px;
  font-weight: 500;
}

.inventory-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #333;
  font-size: 13px;
  white-space: nowrap;
}

.inventory-toolbar input {
  height: 30px;
  border: 1px solid #d8dde5;
  border-radius: 0;
  padding: 4px 8px;
}

.inventory-toolbar input[type="date"] {
  width: 132px;
}

.inventory-toolbar #inventoryProduct {
  width: 150px;
}

.inventory-toolbar button {
  height: 30px;
  border: 1px solid #d8dde5;
  border-radius: 0;
  padding: 0 14px;
  background: #eef1f4;
}

.inventory-wrap {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 0;
}

table { width: 100%; border-collapse: collapse; min-width: 980px; }
#contracts table {
  min-width: 1420px;
  table-layout: fixed;
}

.inventory-table {
  min-width: 760px;
  table-layout: fixed;
}

.inventory-table th,
.inventory-table td {
  border: 1px solid #a9a9a9;
  padding: 8px 6px;
  color: #1f2937;
  font-size: 13px;
}

.inventory-table th {
  background: #fff;
  color: #222;
  text-align: center;
}

.inventory-table tbody tr:nth-child(odd) {
  background: #e7f3f7;
}

.inventory-table tbody tr:hover {
  background: #dff0f7;
}

.inventory-table th:nth-child(1),
.inventory-table td:nth-child(1) { width: 27%; }

.inventory-table th:nth-child(2),
.inventory-table td:nth-child(2) { width: 9%; }

.inventory-table th:nth-child(3),
.inventory-table td:nth-child(3) { width: 7%; text-align: center; }

.inventory-table th:nth-child(4),
.inventory-table td:nth-child(4) { width: 9%; text-align: center; }

.inventory-table th:nth-child(5),
.inventory-table td:nth-child(5) { width: 14%; }

.inventory-table th:nth-child(n+6),
.inventory-table td:nth-child(n+6) { width: 11%; }

.inventory-table .num-cell {
  text-align: right;
}

.inventory-table tfoot td {
  background: #fff;
  font-weight: 700;
  text-align: right;
}

.inventory-opening td {
  font-weight: 600;
}

.empty-cell {
  text-align: center;
  color: var(--muted);
}
.party-contract-table {
  min-width: 0;
  table-layout: fixed;
}

.party-contract-table th,
.party-contract-table td {
  padding: 9px 10px;
  white-space: nowrap;
}

.party-contract-table th:nth-child(1),
.party-contract-table td:nth-child(1) { width: 132px; }

.party-contract-table th:nth-child(2),
.party-contract-table td:nth-child(2) { width: 96px; }

.party-contract-table th:nth-child(3),
.party-contract-table td:nth-child(3),
.party-contract-table th:nth-child(4),
.party-contract-table td:nth-child(4) {
  width: 110px;
  text-align: right;
}

th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
th { background: #edf5ff; color: #16436f; position: sticky; top: 0; z-index: 1; }
tbody tr:hover { background: #f7fbff; }

#contracts th,
#contracts td {
  padding: 9px 7px;
  font-size: 13px;
}

#contracts th {
  white-space: nowrap;
}

.party-contract-table th,
.party-contract-table td {
  padding: 9px 10px;
  white-space: nowrap;
}

.party-contract-table th:nth-child(3),
.party-contract-table td:nth-child(3),
.party-contract-table th:nth-child(4),
.party-contract-table td:nth-child(4) {
  text-align: right;
}

#contracts th:nth-child(2),
#contracts td:nth-child(2) {
  width: 86px;
  min-width: 86px;
  white-space: nowrap;
}

#contracts th:nth-child(3),
#contracts td:nth-child(3) {
  width: 118px;
  min-width: 118px;
  white-space: nowrap;
}

#contracts th:nth-child(4),
#contracts td:nth-child(4) {
  width: 58px;
  min-width: 58px;
  white-space: nowrap;
}

#contracts th:nth-child(5),
#contracts td:nth-child(5) {
  width: 176px;
  min-width: 176px;
  max-width: 176px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#contracts th:nth-child(6),
#contracts td:nth-child(6) {
  width: 78px;
  min-width: 78px;
  white-space: nowrap;
}

#contracts th:nth-child(1),
#contracts td:nth-child(1) { width: 42px; min-width: 42px; white-space: nowrap; }

#contracts th:nth-child(7),
#contracts td:nth-child(7) {
  width: 100px;
  min-width: 100px;
  max-width: 100px;
  white-space: nowrap;
}

.contract-terms-preview {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  vertical-align: bottom;
  cursor: help;
}

.contract-terms-tooltip {
  position: fixed;
  z-index: 10000;
  max-width: min(360px, calc(100vw - 16px));
  padding: 8px 10px;
  border-radius: 4px;
  background: #111;
  color: #fff;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .22);
}

.contract-terms-tooltip[hidden] {
  display: none;
}

#contracts th:nth-child(n+8),
#contracts td:nth-child(n+8) {
  width: 86px;
  min-width: 78px;
  white-space: nowrap;
}

#contracts th:nth-child(11),
#contracts td:nth-child(11) {
  width: 64px;
  min-width: 64px;
}

#contracts th:nth-child(15),
#contracts td:nth-child(15) {
  width: 86px;
  min-width: 86px;
}

.delivery-popover {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 10000;
  width: min(620px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border: 1px solid #cfd6df;
  border-radius: 6px;
  box-shadow: 0 18px 42px rgba(15, 23, 42, .18);
  padding: 10px;
  transform: translate(-50%, -50%);
}

.money-popover {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 10000;
  width: min(430px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border: 1px solid #cfd6df;
  border-radius: 6px;
  box-shadow: 0 18px 42px rgba(15, 23, 42, .18);
  padding: 10px;
  transform: translate(-50%, -50%);
}

.product-popover {
  width: min(980px, calc(100vw - 24px));
}

.product-popover[data-shipping-status="true"] {
  width: min(1060px, calc(100vw - 24px));
}

.delivery-edit-table {
  min-width: 0;
  width: 100%;
  border-collapse: collapse;
}

.product-edit-table {
  min-width: 920px;
  table-layout: fixed;
}

.product-popover[data-shipping-status="true"] .product-edit-table {
  min-width: 1000px;
}

.delivery-popover-title {
  padding: 4px 8px 10px;
  color: #16436f;
  font-weight: 700;
}

.delivery-edit-table th,
.delivery-edit-table td {
  padding: 8px;
  border-bottom: 1px solid #edf2f7;
}

.delivery-edit-table th {
  position: static;
  background: #fff;
  color: #111827;
  text-align: center;
  font-weight: 700;
}

.delivery-edit-table input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 6px 8px;
}

.delivery-edit-table input:focus {
  border-color: var(--blue);
  outline: none;
  background: #f8fbff;
}

.delivery-delete {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  color: var(--red);
  background: #fff1f2;
  font-weight: 700;
}

.money-edit-table {
  min-width: 0;
}

.money-edit-table th:first-child,
.money-edit-table td:first-child {
  width: 160px;
}

.money-edit-table input[type="date"] {
  min-width: 138px;
}

.money-delete {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  color: var(--red);
  background: #fff1f2;
  font-weight: 700;
}

.product-delete {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  color: var(--red);
  background: #fff1f2;
  font-weight: 700;
}

.product-shipping-status {
  min-width: 60px;
  height: 28px;
  padding: 0 4px;
  border: 1px solid #bdd6c5;
  border-radius: 4px;
  background: #edf8f0;
  color: #17653a;
  white-space: nowrap;
  cursor: pointer;
}

.product-shipping-status[data-shipped="false"] {
  border-color: #e2c9a2;
  background: #fff7e8;
  color: #8b5315;
}

.product-popover[data-shipping-status="true"] .product-edit-table th:last-child,
.product-popover[data-shipping-status="true"] .product-edit-table td:last-child {
  width: 82px;
  text-align: center;
}

.product-edit-table th:first-child,
.product-edit-table td:first-child {
  width: 42px;
  text-align: center;
  color: var(--muted);
}

.product-edit-table th:nth-child(2),
.product-edit-table td:nth-child(2) {
  width: 150px;
}

.product-edit-table th:nth-child(4),
.product-edit-table td:nth-child(4) {
  width: 52px;
}

.product-edit-table td:nth-child(4) input {
  padding-left: 6px;
  padding-right: 6px;
  text-align: center;
}

.product-edit-table input[readonly] {
  background: #f4f7fb;
  color: #111827;
}

.product-edit-table input::-webkit-outer-spin-button,
.product-edit-table input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.delivery-total {
  display: flex;
  justify-content: flex-end;
  padding: 10px 8px 2px;
  color: var(--muted);
}

.delivery-total strong {
  margin-left: 8px;
  color: var(--ink);
}

.selected-row {
  background: #d7eaff !important;
  box-shadow: inset 5px 0 0 var(--blue);
  outline: 2px solid #69a7e8;
  outline-offset: -2px;
}

.selected-row td {
  font-weight: 700;
  color: #073b70;
}

.select-indicator {
  display: inline-block;
  min-width: 48px;
  margin-right: 8px;
  color: #fff;
  background: var(--blue);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 700;
}

.account-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.account-actions button {
  min-width: 128px;
  border-radius: 5px;
  padding: 10px 18px;
  font-weight: 700;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, .22);
  padding: 24px;
  overflow: auto;
}

.modal-card {
  width: min(420px, 94vw);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border: 1px solid #cfd6df;
  border-radius: 8px;
  box-shadow: 0 22px 55px rgba(15, 23, 42, .24);
  margin: auto;
  transform: translateZ(0);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff7f7;
}

.modal-head h2 {
  font-size: 15px;
}

.modal-head button {
  border: 0;
  width: 28px;
  height: 28px;
  font-size: 20px;
  background: transparent;
}

.user-dialog-form {
  display: grid;
  gap: 16px;
  padding: 24px 26px 12px;
}

.user-dialog-form label {
  display: grid;
  grid-template-columns: 70px 1fr;
  align-items: center;
  gap: 12px;
  font-weight: 700;
}

.user-dialog-form input,
.user-dialog-form select {
  border: 1px solid #cfd6df;
  border-radius: 5px;
  padding: 10px 12px;
  font-weight: 400;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 26px 24px;
}

.modal-actions button {
  min-width: 120px;
  border-radius: 5px;
  padding: 10px 16px;
  font-weight: 700;
}

.progress {
  width: 64px;
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  margin: 0 auto;
}

.progress i { display: block; height: 100%; background: var(--green); }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 94vw);
  height: 100vh;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(15, 23, 42, .14);
  padding: 18px;
  transform: translateX(105%);
  transition: transform .2s ease;
  overflow: auto;
  z-index: 5;
}

.drawer.open { transform: translateX(0); }
.drawer-head button { width: 34px; height: 34px; border-radius: 6px; font-size: 22px; }

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

.field {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfdff;
}

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

.dropzone {
  min-height: 150px;
  border: 1px dashed #79a7d8;
  border-radius: 8px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--blue);
  background: #f7fbff;
  margin-bottom: 16px;
  padding: 22px;
}

.dropzone input { display: none; }
.dropzone span { color: var(--muted); margin-top: 6px; }

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

.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.form-grid textarea, .wide { grid-column: 1 / -1; }

.form-grid label.party-type-field {
  color: #b45309;
  font-weight: 700;
}

.form-grid label.party-type-field select {
  border-color: #f59e0b;
  background: #fff7ed;
  color: #7c2d12;
  font-weight: 700;
}

.settlement-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.settlement-field input {
  border: 0 !important;
  border-radius: 0 !important;
}

.settlement-days {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 100%;
  border-left: 1px solid var(--line);
  background: #f8fbff;
  padding-right: 10px;
}

.settlement-days input {
  min-width: 0;
  padding-right: 2px;
  text-align: right;
  background: transparent !important;
  color: var(--ink);
  font-weight: 700;
}

.settlement-days b {
  color: var(--muted);
  font-size: 13px;
}

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

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

.contract-preview {
  margin-top: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  line-height: 1.8;
}

.contract-preview h2 { text-align: center; font-size: 22px; margin-bottom: 18px; }

.generate-tabs {
  margin-bottom: 14px;
}

.contract-meta {
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.contract-doc-table {
  width: 100%;
  min-width: 0;
  margin: 14px 0;
  border: 1px solid #9ca3af;
}

.contract-doc-table th,
.contract-doc-table td {
  border: 1px solid #9ca3af;
  padding: 8px 10px;
  text-align: center;
}

.contract-doc-table th {
  position: static;
  background: #f8fafc;
  color: #111827;
}

.sign-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 28px;
}

.mini-metrics {
  grid-template-columns: repeat(2, minmax(140px, 1fr));
}

.drawer-actions {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

.drawer h3 {
  margin: 18px 0 10px;
  font-size: 16px;
}

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; overflow: visible; }
  .main { height: auto; min-height: 100vh; overflow: visible; }
  .view.active { overflow: visible; }
  #contracts.view.active { min-height: 70vh; }
  #contracts .table-wrap { max-height: 70vh; }
  .topbar, .layout-two { grid-template-columns: 1fr; display: grid; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .searchbox { min-width: 0; }
  .toolbar { flex-wrap: wrap; }
  #contractArchive .archive-layout,
  #contractArchive .archive-groups {
    grid-template-columns: 1fr !important;
  }
  .contract-summary {
    min-width: 100%;
    justify-content: flex-start;
  }
  .form-grid { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .contract-notice, .panel, .drawer { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .contract-preview { border: 0; box-shadow: none; }
}
