:root {
  --desktop: #d8f0f1;
  --chrome: #f3f6f9;
  --chrome-dark: #b7c7d7;
  --chrome-line: #9aaab8;
  --panel: #f4f6f8;
  --field: #fff4cf;
  --code: #c7f6ff;
  --name: #d7ffd2;
  --grid-head: #e7edf3;
  --grid-line: #b7c0c8;
  --blue: #126fb2;
  --text: #111827;
  --red: #b42318;
  --green: #137333;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0) 190px),
    var(--desktop);
  font-family: "Microsoft JhengHei", "PMingLiU", "MingLiU", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.25;
}

button,
input {
  font: inherit;
}

.desktop-shell {
  min-height: 100vh;
}

.system-title {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  color: #0f2437;
  background: linear-gradient(#e9f3fb, #bfd5e9);
  border-bottom: 1px solid #8fa6ba;
  white-space: nowrap;
  overflow: hidden;
}

.app-icon {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #5c7992;
  border-radius: 5px;
  background: #ffffff;
  color: #0b5f8a;
  font-size: 12px;
  font-weight: 900;
}

.login-text {
  margin-left: 12px;
  font-size: 13px;
}

.menu-bar {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  background: var(--chrome);
  border-bottom: 1px solid #c3ccd5;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: thin;
}

.nav-item {
  flex: 0 0 auto;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #102a43;
  cursor: pointer;
  white-space: nowrap;
}

.nav-item:hover,
.nav-item.active {
  border-color: #9ab6d1;
  background: #e5f1fb;
}

.nav-item.active {
  box-shadow: inset 0 -2px 0 var(--blue);
}

.nav-item span {
  white-space: nowrap;
}

.nav-icon {
  color: #0064ad;
  font-weight: 900;
}

.nav-count {
  color: #555;
  font-size: 12px;
}

.icon-strip {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  background: var(--chrome);
  border-bottom: 1px solid #c3ccd5;
  overflow-x: auto;
  white-space: nowrap;
}

.icon-strip button,
.form-toolbar button,
.table-tools button,
.action-row button,
.segmented button {
  min-height: 28px;
  border: 1px solid #a8b4bf;
  border-radius: 6px;
  background: linear-gradient(#ffffff, #e9eef3);
  color: #102a43;
  padding: 3px 9px;
  cursor: pointer;
}

.icon-strip button:hover,
.form-toolbar button:hover,
.table-tools button:hover,
.action-row button:hover,
.segmented button:hover {
  border-color: #6f9fc5;
  background: #eaf5ff;
}

.icon-strip button:active,
.form-toolbar button:active,
.table-tools button:active,
.action-row button:active,
.segmented button:active {
  transform: translateY(1px);
}

.form-toolbar button.primary,
.action-row button.primary,
.action-row button.success,
.segmented button.active,
.table-tools button.active {
  background: #dcecff;
  color: #003b73;
  font-weight: 900;
}

.action-row button.danger {
  color: #8a0000;
  background: #ffe0d9;
}

.system-state {
  margin-left: 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}

.signal-dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 50%;
  background: #18a034;
  border: 1px solid #08661d;
}

.mdi-area {
  padding: 10px;
  display: grid;
  gap: 8px;
}

.legacy-window {
  background: var(--panel);
  border: 1px solid #7f8d99;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(31, 41, 55, 0.14);
  overflow: hidden;
}

.window-title {
  min-height: 34px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  color: #0f2437;
  background: linear-gradient(#edf6ff, #b8d2ea);
  border-bottom: 1px solid #8ba5ba;
  font-weight: 900;
}

.window-title.small {
  min-height: 24px;
  font-weight: 700;
}

.window-controls {
  color: #333;
  font-size: 13px;
}

.form-toolbar {
  padding: 7px 9px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid #d4dbe3;
  background: #f8fafc;
}

.form-tabs {
  display: flex;
  padding: 7px 10px 0;
  gap: 4px;
  overflow-x: auto;
  white-space: nowrap;
}

.form-tabs button {
  flex: 0 0 auto;
  border: 1px solid #a8b4bf;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: #edf2f7;
  padding: 4px 14px;
  color: #102a43;
  cursor: pointer;
}

.form-tabs button.active {
  background: #ffffff;
  color: #0b5f8a;
  font-weight: 900;
}

.work-header {
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.doc-label {
  margin-right: 8px;
  color: #333;
}

#recordTitle {
  font-size: 17px;
}

.status-pill,
.mini-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid #a8b4bf;
  border-radius: 999px;
  background: #f7f7f7;
  padding: 2px 8px;
  white-space: nowrap;
}

.status-pill.submitted,
.mini-pill.good {
  color: var(--green);
  background: #e9ffe7;
}

.status-pill.pending,
.mini-pill.warn {
  color: #8a4b00;
  background: #fff4cf;
}

.status-pill.failed,
.mini-pill.bad {
  color: var(--red);
  background: #ffe6e0;
}

.form-body {
  padding: 2px 10px 8px;
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 300px;
  gap: 10px;
  align-items: start;
}

.field-grid {
  display: grid;
  grid-template-columns: 86px minmax(120px, 1fr) 86px minmax(120px, 1fr) 86px minmax(120px, 1fr);
  gap: 4px 6px;
  align-items: center;
}

.field {
  display: contents;
}

.field label {
  text-align: right;
  white-space: nowrap;
}

.field input {
  width: 100%;
  min-height: 26px;
  border: 1px solid #a0aab4;
  border-radius: 4px;
  padding: 3px 6px;
  background: var(--field);
  color: #000;
}

.field:nth-child(2n) input {
  background: var(--name);
}

.field input:read-only {
  background: #f5f5f5;
  color: #222;
}

.check-panel {
  border: 1px solid #c4ccd4;
  border-radius: 6px;
  background: #ffffff;
  padding: 8px;
}

.section-title,
.detail-titlebar {
  font-weight: 900;
}

.scan-meter {
  margin-top: 5px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.scan-meter span {
  color: #004a98;
  font-size: 24px;
  font-weight: 900;
}

.scan-meter small {
  color: #555;
}

.scan-meter strong {
  font-size: 13px;
  text-align: right;
}

.scan-bar {
  height: 8px;
  margin: 6px 0;
  background: #d7d7d7;
  border: 1px solid #a8b4bf;
  border-radius: 999px;
  overflow: hidden;
}

.scan-bar span {
  height: 100%;
  display: block;
  width: 0;
  background: #1d77b8;
}

.alert-box {
  min-height: 34px;
  padding: 5px 6px;
  border: 1px solid #c4ccd4;
  border-radius: 5px;
  background: #fff;
  font-size: 13px;
}

.alert-box.warn {
  color: #7a4b00;
  background: #fff4cf;
}

.alert-box.bad {
  color: var(--red);
  background: #ffe6e0;
}

.alert-box.good {
  color: var(--green);
  background: #efffed;
}

.dashboard-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
}

.metric-tile {
  min-height: 92px;
  border: 1px solid #c7d2df;
  border-radius: 10px;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff, #f4f8fb);
  box-shadow: 0 8px 18px rgba(31, 41, 55, 0.08);
  display: grid;
  gap: 5px;
}

.metric-tile span {
  color: #52616f;
  font-size: 13px;
  font-weight: 800;
}

.metric-tile strong {
  color: #0f2f4a;
  font-size: 28px;
  line-height: 1;
}

.metric-tile small {
  font-weight: 900;
}

.metric-tile.good small {
  color: var(--green);
}

.metric-tile.warn small {
  color: #9a5b00;
}

.metric-tile.bad small {
  color: var(--red);
}

.bar-list {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px;
}

.bar-row {
  border: 1px solid #c7d2df;
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.bar-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.bar-track {
  height: 10px;
  margin: 8px 0 5px;
  border-radius: 999px;
  background: #e5edf3;
  overflow: hidden;
}

.bar-track i {
  height: 100%;
  display: block;
  border-radius: 999px;
  background: linear-gradient(90deg, #126fb2, #21a67a);
}

.bar-row small {
  color: #5d6b78;
}

.alert-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.alert-item {
  width: 100%;
  border: 1px solid #d5b36a;
  border-radius: 8px;
  background: #fff7dc;
  color: #593a00;
  padding: 9px;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 4px 8px;
  text-align: left;
  cursor: pointer;
}

.alert-item.bad {
  border-color: #ef9a90;
  background: #fff0ed;
  color: #8a1c12;
}

.alert-item span {
  grid-row: span 2;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
  font-weight: 900;
}

.alert-item small {
  color: inherit;
  opacity: 0.78;
}

.flow-rail {
  padding: 4px 8px 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.flow-step {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid #b8c2cc;
  border-radius: 999px;
  background: #f8f8f8;
  padding: 3px 8px;
  color: #444;
}

.flow-step.active {
  color: #fff;
  background: #1682c4;
  border-color: #075f95;
}

.flow-step.done {
  color: #00591d;
  background: #e7ffe7;
}

.flow-index {
  font-size: 12px;
}

.flow-text {
  font-weight: 900;
}

.detail-titlebar {
  min-height: 32px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 6px 10px;
  border-top: 1px solid #d4dbe3;
  background: #f8fafc;
}

.table-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.table-wrap {
  margin: 0 10px 8px;
  border: 1px solid #8f9aa5;
  border-radius: 6px;
  overflow: auto;
  background: #fff;
}

.data-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  padding: 3px 6px;
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  background: var(--grid-head);
  font-weight: 900;
}

.data-table tbody tr:first-child td,
.record-item.active {
  background: var(--blue);
  color: #fff;
}

.data-table tr.diff-row td {
  color: #910000;
  background: #fff0cf;
}

.qty-cell {
  text-align: right;
}

.row-input {
  width: 100%;
  min-width: 70px;
  border: 1px solid #a0aab4;
  border-radius: 4px;
  background: #fff;
  padding: 2px 4px;
}

.row-input.qty {
  text-align: right;
}

.action-row {
  padding: 6px 10px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.next-step {
  margin: 0;
  padding: 7px 10px;
  border-top: 1px solid #d4dbe3;
  color: #003b73;
  background: #f6f6f6;
  font-weight: 900;
}

.queue-panel {
  order: 2;
}

.segmented {
  padding: 5px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.record-list {
  max-height: 190px;
  overflow: auto;
  background: #fff;
  border-top: 1px solid #8f9aa5;
}

.record-item {
  width: 100%;
  min-height: 28px;
  border: 0;
  border-bottom: 1px solid var(--grid-line);
  background: #fff;
  display: grid;
  grid-template-columns: 220px minmax(260px, 1fr) 300px;
  gap: 8px;
  align-items: center;
  padding: 3px 8px;
  text-align: left;
  cursor: pointer;
}

.record-main {
  display: flex;
  gap: 8px;
  align-items: center;
}

.record-no {
  min-width: 110px;
  font-weight: 900;
}

.record-title {
  font-weight: 700;
}

.record-meta {
  color: inherit;
  font-size: 13px;
}

.summary-bar {
  order: 3;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.summary-item {
  border: 1px solid #a8b4bf;
  border-radius: 6px;
  background: #ffffff;
  padding: 5px 8px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.summary-label {
  color: #333;
}

.summary-value {
  color: #003b73;
  font-weight: 900;
}

.toast {
  position: fixed;
  right: 12px;
  bottom: 12px;
  border: 1px solid #333;
  background: #ffffdd;
  color: #000;
  padding: 8px 12px;
  opacity: 0;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

@media (max-width: 980px) {
  .form-body,
  .field-grid,
  .record-item,
  .summary-bar,
  .dashboard-grid,
  .bar-list {
    grid-template-columns: 1fr;
  }

  .field {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 4px;
  }

  .menu-bar,
  .icon-strip,
  .form-toolbar {
    overflow-x: auto;
    flex-wrap: nowrap;
  }
}
