:root {
  --ink: #1b2527;
  --muted: #657477;
  --soft: #f5f7f6;
  --soft-2: #f8faf9;
  --line: #dfe7e5;
  --brand: #16464b;
  --brand-2: #22747a;
  --accent: #b86a2f;
  --accent-soft: #fff4ea;
  --ok: #216b4f;
  --warn: #946022;
  --danger: #9c2f2f;
  --card: #ffffff;
  --shadow: 0 12px 28px rgba(22, 70, 75, 0.08);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  color: var(--ink);
  background: #fff;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #fff;
}

body {
  min-height: 100%;
  margin: 0;
  background: #fff;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 1040px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 14px 28px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(8px + env(safe-area-inset-top)) 2px 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-2);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  box-shadow: var(--shadow);
  font-size: 22px;
  font-weight: 800;
}

.brand-band,
.top-tabs,
.toolbar,
.summary-strip,
.order-card,
.detail-panel,
.line-item,
.record-card {
  border: 1px solid var(--line);
  background: #fff;
}

.brand-band {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 6px;
  border-radius: 8px;
}

.brand-option,
.tab-button {
  min-height: 44px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.brand-option.active,
.tab-button.active {
  color: #fff;
  background: var(--brand);
}

.top-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
  padding: 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.app-main {
  padding-top: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border-radius: 8px;
}

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

.search-field span,
.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

input:focus {
  outline: 3px solid rgba(14, 109, 114, 0.18);
  border-color: var(--brand-2);
}

.subtle-button {
  min-height: 46px;
  border-radius: 8px;
  padding: 0 14px;
  color: var(--brand);
  background: #e7efed;
  font-weight: 800;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 8px;
}

.metric {
  min-width: 0;
  padding: 12px 10px;
  background: #fff;
}

.metric b {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.metric span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.order-list,
.record-list,
.item-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.order-card,
.detail-panel,
.line-item,
.record-card {
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(18, 63, 70, 0.06);
}

.order-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  text-align: left;
}

.order-card.recommended {
  border-color: rgba(196, 107, 45, 0.5);
  background: #fffaf6;
}

.order-top,
.detail-top,
.item-top,
.record-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.order-title,
.detail-title {
  min-width: 0;
}

.order-title h2,
.detail-title h2 {
  margin: 0 0 5px;
  font-size: 19px;
  line-height: 1.25;
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  max-width: 100%;
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--brand);
  background: #e7efed;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.pill.warn {
  color: var(--warn);
  background: var(--accent-soft);
}

.pill.ok {
  color: var(--ok);
  background: #e9f5ef;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #dce5e3;
}

.progress i {
  display: block;
  height: 100%;
  width: var(--pct, 0%);
  background: linear-gradient(90deg, var(--brand-2), var(--ok));
}

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

.primary-button,
.ghost-button,
.danger-button {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 900;
}

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

.primary-button:disabled {
  color: #8a9698;
  background: #d8e0df;
  cursor: not-allowed;
}

.ghost-button {
  color: var(--brand);
  background: #e7efed;
}

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

.detail-panel {
  padding: 14px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

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

.detail-stat {
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--soft-2);
}

.detail-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-stat b {
  display: block;
  margin-top: 3px;
  font-size: 16px;
}

.line-item {
  padding: 14px;
  background: #fff;
}

.line-item.passive {
  background: #fff;
}

.item-main {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.item-code {
  display: inline-flex;
  align-items: center;
  min-width: 42px;
  min-height: 32px;
  border-radius: 8px;
  padding: 4px 9px;
  color: #fff;
  background: var(--brand-2);
  font-size: 15px;
  font-weight: 900;
}

.item-code.passive {
  color: var(--muted);
  background: #e8eeee;
}

.item-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.qty-badge {
  display: grid;
  min-width: 66px;
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--brand);
  background: #eef5f4;
  text-align: center;
}

.qty-badge span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.qty-badge b {
  font-size: 24px;
  line-height: 1.05;
}

.line-subrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.line-details summary {
  min-height: 30px;
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--brand);
  background: #eef3f2;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  list-style-position: inside;
}

.item-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.item-meta {
  min-width: 0;
  padding: 9px;
  border-radius: 8px;
  background: var(--soft-2);
}

.item-meta span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.item-meta b {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.entry-form {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.entry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.number-field {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.number-field.active {
  border-color: var(--brand-2);
  background: #eef8f6;
  box-shadow: 0 0 0 3px rgba(14, 109, 114, 0.12);
}

.code-input {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
}

.code-input b {
  display: inline-grid;
  place-items: center;
  min-width: 46px;
  min-height: 46px;
  border-radius: 8px;
  color: #fff;
  background: var(--brand-2);
  font-size: 18px;
  font-weight: 900;
}

.code-input input {
  border-color: transparent;
  background: #fff;
  font-size: 22px;
  text-align: left;
}

.code-input input[readonly] {
  cursor: pointer;
}

.number-field em {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  line-height: 1.4;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: #edf3f2;
}

.number-pad.hidden {
  display: none;
}

.number-key {
  min-height: 58px;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 25px;
  font-weight: 900;
}

.number-key:active {
  transform: translateY(1px);
  background: #f8fbfa;
}

.number-key.soft {
  color: var(--brand);
  background: #dfe9e7;
  font-size: 18px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.completed-orders {
  display: grid;
  gap: 10px;
}

.completed-orders h2 {
  margin: 4px 0 0;
  font-size: 16px;
}

.hint-line {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.error-line {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
}

.success-panel {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #cbe4d7;
  border-radius: 8px;
  background: #f0f8f4;
}

.success-panel strong {
  color: var(--ok);
}

details.more-actions {
  margin-top: 8px;
}

details.more-actions summary {
  width: fit-content;
  min-height: 34px;
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--muted);
  background: #edf2f1;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.more-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.empty-state {
  margin-top: 12px;
  padding: 24px 16px;
  border: 1px dashed #becbc8;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  text-align: center;
  font-weight: 800;
}

.record-card {
  padding: 13px;
}

.record-card h3 {
  margin: 0 0 5px;
  font-size: 17px;
}

.toast {
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: 14px;
  z-index: 20;
  display: grid;
  place-items: center;
  min-height: 48px;
  border-radius: 8px;
  padding: 10px 14px;
  color: #fff;
  background: rgba(18, 63, 70, 0.95);
  box-shadow: var(--shadow);
  font-weight: 900;
}

@media (min-width: 760px) {
  .app-shell {
    padding: 24px;
  }

  h1 {
    font-size: 34px;
  }

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

  .summary-strip {
    grid-template-columns: repeat(4, 1fr);
  }

  .toast {
    right: 24px;
    left: auto;
    min-width: 300px;
  }
}

@media (max-width: 430px) {
  .item-meta-grid {
    grid-template-columns: 1fr;
  }

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

  .number-key {
    min-height: 64px;
  }

  .summary-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}
