:root {
  color-scheme: light;
  --ink: #18283b;
  --text: #343f4c;
  --subtle: #5e6b79;
  --line: #d8dfe5;
  --paper: #fff;
  --surface: #f2f4f6;
  --blue: #26457f;
  --blue-hover: #193565;
  --sans: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  --gutter: clamp(14px, 2.5vw, 40px);
  font: 15px/1.55 var(--sans);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--surface);
}

* { box-sizing: border-box; }
body { margin: 0; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 600; text-wrap: balance; }
p { text-wrap: pretty; }
button, input, select { font: inherit; font-variant-numeric: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, a, input { touch-action: manipulation; }
button:focus-visible, a:focus-visible, .table-scroll:focus-visible {
  outline: 3px solid #5277b8;
  outline-offset: 3px;
}
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Masthead */
.shell {
  width: min(calc(100% - var(--gutter) * 2), 1584px);
  margin-inline: auto;
}
.masthead {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.masthead-inner, .brand, .header-actions, .environment {
  display: flex;
  align-items: center;
}
.masthead-inner { justify-content: space-between; min-height: 52px; gap: 10px; }
.brand { min-width: 0; gap: 8px; }
.brand-symbol { display: block; flex: none; width: 36px; height: 36px; }
.brand-name { display: grid; gap: 3px; color: #293d85; line-height: 1; white-space: nowrap; }
.brand-name strong { font-size: 21px; font-weight: 700; letter-spacing: .075em; }
.brand-name [lang="en"] { font: 650 10px/1 Arial, sans-serif; letter-spacing: .105em; }
.header-actions { gap: 17px; font-size: 13px; flex-shrink: 0; }
.environment { gap: 8px; color: var(--subtle); white-space: nowrap; }
.environment-dot {
  width: 7px;
  height: 7px;
  background: #b76a30;
  border-radius: 50%;
}
.account-id {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}
.logout {
  text-decoration: none;
  white-space: nowrap;
  padding: 6px 12px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 5px;
  background: white;
}
.logout:hover, .secondary:hover { border-color: #96a4b4; background: #f7f9fb; }

/* Shared form controls */
.field { min-width: 0; }
.field label {
  display: block;
  width: fit-content;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 5px;
}
.field input {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid #bac5cf;
  border-radius: 6px;
  color: var(--ink);
  background: var(--paper);
}
.field input:focus-visible {
  outline: 2px solid #5277b8;
  outline-offset: 1px;
  border-color: var(--blue);
}
.primary, .secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.primary { border: 1px solid var(--blue); background: var(--blue); color: white; }
.primary:hover:enabled { background: var(--blue-hover); border-color: var(--blue-hover); }
.primary:disabled { background: #e8ecf0; color: #606e7e; border-color: #d7dfe6; }
.secondary { border: 1px solid #bdc7d1; color: var(--text); background: white; }
.text-action {
  padding: 3px 0;
  border: 0;
  background: none;
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}
.text-action:hover, .password-toggle:hover { text-decoration: underline; text-underline-offset: 3px; }
.error {
  margin: 12px 0 0;
  color: #9d301f;
  font-size: 14px;
  font-weight: 500;
}

/* Compact login */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
}
.login-page .page-frame {
  width: min(100%, 400px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(24, 40, 59, .05);
}
.login-page .masthead-inner {
  width: auto;
  min-height: 58px;
  margin-inline: 24px;
}
.login-page .environment { font-size: 12px; gap: 6px; }
.login-main { padding: 20px 24px 24px; }
.login-main h1 { font-size: 24px; line-height: 1.3; }
#login-form { margin-top: 15px; }
#login-form .field + .field { margin-top: 12px; }
.field-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.field-heading .text-action { font-size: 13px; }
.password-input { position: relative; }
.password-input input { padding-right: 56px; }
.password-toggle {
  position: absolute;
  inset: 3px 4px 3px auto;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #53657a;
  font-size: 13px;
}
.login-submit { width: 100%; min-height: 40px; font-size: 15px; margin-top: 18px; }

/* Order query and line selection */
.orders-main { padding-block: 18px 24px; }
.page-title { font-size: clamp(22px, 1.8vw, 26px); line-height: 1.25; }
.query-form, .results {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.query-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: clamp(10px, 1.1vw, 18px);
  align-items: end;
  margin: 12px 0;
  padding: 10px 14px;
}
.query-form .field { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 7px; }
.query-form .field label { font-size: 13px; margin: 0; white-space: nowrap; }
.query-form .field input { height: 34px; padding-inline: 9px; font-size: 14px; }
.query-actions, .result-title, .export-tools {
  display: flex;
  align-items: center;
}
.query-actions { gap: 9px; }
.small-button, .export-button { font-size: 14px; }
.search-icon {
  position: relative;
  width: 13px;
  height: 13px;
  border: 1.7px solid currentColor;
  border-radius: 50%;
  margin: -2px 1px 0 0;
}
.search-icon::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 2px;
  top: 9px;
  left: 8px;
  background: currentColor;
  transform: rotate(45deg);
}
.results { min-width: 0; overflow: hidden; }
.result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 14px;
}
.result-title { gap: 10px; }
.result-title h2 { font-size: 17px; line-height: 1.3; }
.result-count, .export-tools output { color: var(--subtle); font-size: 13px; }
.result-count { border-left: 1px solid var(--line); padding-left: 13px; line-height: 1.3; }
.result-count strong { font-weight: 600; }
.export-tools { gap: 14px; }
.download-icon { position: relative; width: 14px; height: 14px; border-bottom: 1.6px solid currentColor; }
.download-icon::before {
  content: "";
  position: absolute;
  top: 0;
  left: 6px;
  width: 1.6px;
  height: 9px;
  background: currentColor;
}
.download-icon::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 5px;
  height: 5px;
  border: solid currentColor;
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(45deg);
}
.export-error { padding: 0 14px 10px; margin: 0; }
.table-scroll { overflow-x: auto; max-width: 100%; scrollbar-color: #9fadb9 #eef1f4; }
.table-scroll:focus-visible { outline-offset: -3px; }
table {
  width: 100%;
  min-width: 1160px;
  border-spacing: 0;
  table-layout: fixed;
  text-align: left;
  font-size: 14px;
}
.col-check { width: 38px; }
.col-contract_no { width: 11%; }
.col-line_no { width: 4.5%; }
.col-batch_number { width: 10%; }
.col-product { width: 20%; }
.col-grade { width: 11%; }
.col-drawing { width: 11%; }
.col-ordered { width: 6.5%; }
.col-delivery_date { width: 11%; }
.table-scroll .has-column-widths { min-width: 0; }
.supplier-name { max-width: 32vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th, td {
  padding: 6px 8px;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
th {
  position: relative;
  background: #eaf0f5;
  color: #3e5166;
  border-block: 1px solid #d9e2e9;
  font-weight: 600;
  line-height: 1.45;
}
td {
  height: 36px;
  border-bottom: 1px solid #e3e8ed;
  color: var(--text);
  line-height: 1.45;
  background: var(--row-fill, white);
}
.column-heading { display: block; overflow: hidden; text-overflow: ellipsis; }
.column-resizer {
  position: absolute;
  inset: 0 0 0 auto;
  width: 12px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
}
.column-resizer::after {
  content: "";
  position: absolute;
  inset: 22% 0;
  width: 1px;
  margin-left: auto;
  background: #bac6d2;
}
.column-resizer:hover::after, .column-resizer:focus-visible::after,
.column-resizer.is-dragging::after { inset-block: 0; width: 3px; background: var(--blue); }
.column-resizer:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.table-scroll th:has(.column-resizer) { padding-right: 14px; }
@media (any-pointer: coarse) {
  .column-resizer { width: 24px; }
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { --row-fill: #f7f9fb; }
tbody tr:has(input:checked) { --row-fill: #edf3fc; }
.check-cell { padding: 0; text-align: center; }
.check-target {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 30px;
  cursor: pointer;
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--blue); cursor: pointer; }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
td.cell-contract_no { color: #243d5c; }
td.cell-product { color: var(--ink); }
.cell-line_no, .cell-delivery_date { text-align: center; }
.cell-ordered { text-align: right; }
.cell-ordered, th.cell-contract_no { white-space: nowrap; }
.empty-state { padding: 24px 16px; text-align: center; }
.empty-state h3 { font-size: 17px; font-weight: 600; color: var(--text); }
.empty-state .text-action { display: inline-block; margin-top: 9px; font-size: 14px; }

/* Result navigation */
.pager, .page-links { display: flex; align-items: center; }
.pager { justify-content: flex-end; flex-wrap: wrap; gap: 12px; padding: 8px 14px; border-top: 1px solid var(--line); }
.pager select {
  height: 30px;
  padding: 0 6px;
  border: 1px solid #bdc7d1;
  border-radius: 4px;
  color: var(--text);
  background: white;
  font-size: 13px;
}
.pager select:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.page-links { gap: 4px; }
.page-link {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 5px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text);
  background: white;
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
}
.page-link:not(.page-number) { border-color: var(--line); font-size: 19px; }
a.page-link:hover { border-color: #acbfda; background: #f2f6fb; }
.page-number[aria-current="page"] { border-color: #b1c4e1; background: #eaf1fb; color: var(--blue); font-weight: 600; }
.page-link:disabled { color: #909ba7; background: #f5f7f9; }
.page-position { display: none; }
.page-gap { color: var(--subtle); padding: 0 3px; }

@media (max-width: 1160px) {
  .query-form .field { display: block; }
  .query-form .field label { margin-bottom: 4px; }
}
@media (max-width: 760px) {
  .orders-page .supplier-name { display: none; }
  .orders-page .account-id { border: 0; padding: 0; }
  .masthead-inner { min-height: 50px; }
  .header-actions { gap: 10px; }
  .query-form { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 12px; }
  .query-actions { flex-wrap: wrap; }
  .query-form .field input, .small-button { min-height: 36px; }
  .export-tools { gap: 8px; }
}
@media (max-width: 480px) {
  .orders-page .masthead-inner { flex-wrap: wrap; padding-block: 6px; }
  .orders-page .header-actions { flex-wrap: wrap; max-width: 100%; }
  .orders-page .account-id { max-width: 38vw; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
  :root { --gutter: 12px; }
  .login-page { align-items: start; padding-top: clamp(24px, 8vh, 64px); }
  .login-page .masthead-inner { margin-inline: 18px; min-height: 50px; }
  .login-main { padding: 16px 18px 19px; }
  .brand { gap: 6px; }
  .brand-symbol { width: 31px; height: 31px; }
  .brand-name strong { font-size: 18px; }
  .brand-name [lang="en"] { font-size: 8.5px; }
  .account-id, .environment { font-size: 12px; }
  .logout { padding: 4px 8px; }
  .result-title, .export-tools { gap: 6px; }
  .result-count { padding-left: 6px; }
  .result-bar { gap: 7px; padding: 8px 10px; }
  .export-button { padding-inline: 8px; gap: 6px; }
  .page-links .page-number, .page-gap { display: none; }
  .page-position { display: inline-block; min-width: 48px; text-align: center; font-size: 13px; }
}
