:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #64736c;
  --line: #dbe4df;
  --surface: #ffffff;
  --soft: #f4f7f5;
  --green: #196f53;
  --green-dark: #0f513b;
  --gold: #b2812d;
  --red: #b42318;
  --blue: #2563eb;
  --shadow: 0 16px 40px rgba(21, 35, 29, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #eef3f0;
  font-family: Arial, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  padding: 8px clamp(14px, 3vw, 28px);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.header-title {
  min-width: 0;
}

.app-header h1,
.section-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.app-header h1 {
  overflow: hidden;
  font-size: clamp(18px, 2vw, 24px);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  white-space: nowrap;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 9px;
  color: var(--green-dark);
  background: #edf8f4;
  border: 1px solid #b8d8cb;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.env-pill {
  padding: 7px 8px;
  color: var(--red);
  background: #fff1f0;
  border: 1px solid #ffd1cc;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.icon-button,
.secondary-button,
.primary-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  color: var(--green-dark);
  background: var(--soft);
  border-color: var(--line);
  font-size: 18px;
}

.action-menu {
  position: relative;
}

.action-menu summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  color: var(--green-dark);
  background: #edf8f4;
  border: 1px solid #b8d8cb;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  list-style: none;
  cursor: pointer;
}

.action-menu summary::-webkit-details-marker {
  display: none;
}

.action-menu summary::after {
  content: "▾";
  margin-left: 8px;
  font-size: 11px;
}

.action-menu[open] summary::after {
  content: "▴";
}

.action-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  display: grid;
  min-width: 160px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.action-menu-list a,
.action-menu-list button,
.menu-status {
  min-height: 38px;
  padding: 0 10px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.action-menu-list a,
.menu-status {
  display: inline-flex;
  align-items: center;
}

.menu-status {
  color: var(--red);
  background: #fff1f0;
  cursor: default;
}

.action-menu-list a:hover,
.action-menu-list button:hover {
  background: var(--soft);
}

.primary-button {
  width: 100%;
  color: #fff;
  background: var(--green);
  font-weight: 700;
}

.secondary-button,
.row-button {
  color: var(--green-dark);
  background: #edf8f4;
  border: 1px solid #b8d8cb;
  font-weight: 700;
}

.full-button {
  width: 100%;
}

.text-button {
  min-height: 44px;
  padding: 0;
  color: var(--green-dark);
  background: transparent;
  border: 0;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.layout {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 3vw, 28px) 48px;
}

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

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

.metric {
  min-height: 88px;
  padding: 14px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  letter-spacing: 0;
}

.panel {
  padding: 18px;
}

.create-panel {
  margin-bottom: 18px;
  padding: 0;
  overflow: hidden;
}

.create-panel summary {
  display: flex;
  align-items: center;
  min-height: 54px;
  padding: 0 18px;
  color: var(--green-dark);
  font-size: 16px;
  font-weight: 700;
  list-style: none;
  cursor: pointer;
}

.create-panel summary::-webkit-details-marker {
  display: none;
}

.create-panel summary::after {
  content: "▾";
  margin-left: auto;
  font-size: 12px;
}

.create-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.create-panel[open] summary::after {
  content: "▴";
}

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

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-heading h2 {
  font-size: 20px;
}

.shipment-form {
  display: grid;
  gap: 14px;
}

.divider {
  height: 1px;
  margin: 20px 0;
  background: var(--line);
}

.compact-heading {
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 76px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 6px;
  min-width: 58px;
  min-height: 32px;
  color: var(--green-dark);
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.checkbox-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 500;
}

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

textarea {
  min-height: 82px;
  padding-top: 10px;
  resize: vertical;
}

.guardrails {
  margin-top: 18px;
  padding: 14px;
  background: #fff8eb;
  border: 1px solid #eed3a1;
  border-radius: 8px;
}

.guardrails h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.guardrails p {
  margin: 0;
  color: #6d4f17;
  line-height: 1.6;
}

.shipment-panel {
  overflow: visible;
}

.table-wrap {
  overflow: visible;
  max-height: 560px;
  overflow-y: auto;
  position: relative;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
}

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

th {
  color: var(--muted);
  font-size: 13px;
}

td {
  font-size: 14px;
  overflow-wrap: anywhere;
}

th:nth-child(1),
td:nth-child(1) {
  width: 21%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 22%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 18%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 13%;
}

th:nth-child(5),
td:nth-child(5) {
  width: 15%;
}

th:nth-child(6),
td:nth-child(6) {
  width: 11%;
}

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

.status {
  display: inline-flex;
  min-width: 96px;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.status-ready_to_ship,
.status-shipped,
.status-prepared,
.status-label_created {
  color: #7a4c00;
  background: #fff1c7;
}

.status-in_transit {
  color: #164e9f;
  background: #dbeafe;
}

.status-reviewing {
  color: #7c2d12;
  background: #ffedd5;
}

.status-delivered,
.status-completed,
.status-signed,
.status-preparing,
.status-pending {
  color: #166145;
  background: #d8f3e7;
}

.status-failed,
.status-exception,
.status-returning,
.status-returned,
.status-refunding,
.status-refunded {
  color: var(--red);
  background: #fee4e2;
}

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

.row-button {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 6px;
  cursor: pointer;
}

.row-action-menu {
  position: relative;
  width: max-content;
}

.row-action-menu summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  color: var(--green-dark);
  background: #edf8f4;
  border: 1px solid #b8d8cb;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  list-style: none;
  cursor: pointer;
}

.row-action-menu summary::-webkit-details-marker {
  display: none;
}

.row-action-menu summary::after {
  content: "▾";
  margin-left: 6px;
  font-size: 10px;
}

.row-action-menu[open] summary::after {
  content: "▴";
}

.row-action-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 200;
  display: grid;
  min-width: 152px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.row-action-menu-list button {
  min-height: 36px;
  padding: 0 10px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.row-action-menu-list button:hover {
  background: var(--soft);
}

.workflow-menu {
  position: relative;
}

.workflow-menu summary {
  display: flex;
  align-items: center;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  list-style: none;
  cursor: pointer;
}

.workflow-menu summary::-webkit-details-marker {
  display: none;
}

.workflow-menu summary::after {
  content: "›";
  margin-left: auto;
  font-size: 16px;
}

.workflow-menu[open] summary,
.workflow-menu summary:hover {
  background: var(--soft);
}

.workflow-menu-list {
  display: grid;
  gap: 4px;
  padding: 4px 0 0 10px;
}

.workflow-menu-list button[disabled] {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.7;
}

.is-selected {
  background: #f8fbf9;
}

.shipment-detail-row td {
  width: auto;
  padding: 0 10px 16px;
  background: #f8fbf9;
}

.shipment-detail-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-section {
  min-width: 0;
}

.detail-section h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.detail-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.detail-section-heading h3 {
  margin: 0;
}

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

.inline-actions button {
  min-height: 36px;
  padding: 0 10px;
  color: var(--green-dark);
  background: #edf8f4;
  border: 1px solid #b8d8cb;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

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

.detail-list div {
  min-width: 0;
  padding: 10px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-list dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.item-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.item-chips span {
  padding: 6px 8px;
  color: var(--green-dark);
  background: #edf8f4;
  border: 1px solid #b8d8cb;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.print-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.print-actions button {
  min-height: 38px;
  padding: 0 8px;
  color: var(--green-dark);
  background: #edf8f4;
  border: 1px solid #b8d8cb;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

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

.event-item {
  padding: 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.event-item strong {
  display: block;
  margin-bottom: 4px;
}

.event-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.empty-state {
  min-height: 120px;
  place-items: center;
  color: var(--muted);
  background: var(--soft);
  border: 1px dashed #b8c8c0;
  border-radius: 8px;
}

.compact-empty {
  min-height: 52px;
  display: grid;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  color: #fff;
  background: var(--green-dark);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 31, 24, 0.38);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

/* ── 右側詳情 Drawer ───────────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: flex;
  justify-content: flex-end;
  background: rgba(15, 31, 24, 0.38);
}

.drawer-backdrop[hidden] {
  display: none;
}

.drawer {
  width: min(460px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: drawer-slide-in 0.22s ease;
}

@keyframes drawer-slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2 {
  margin: 4px 0 2px;
  font-size: 20px;
}

.drawer-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.drawer-tab {
  flex: 0 0 auto;
  padding: 10px 14px;
  min-height: 40px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.drawer-tab.is-active {
  color: var(--green-dark);
  border-bottom-color: var(--green);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  display: grid;
  gap: 14px;
  padding: 18px;
}

body.drawer-open {
  overflow: hidden;
}

.auth-page {
  background: #f5f1ea;
}

.auth-shell,
.public-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
}

.auth-card {
  width: min(420px, 100%);
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.auth-copy,
.notice,
.form-message {
  color: var(--muted);
  line-height: 1.6;
}

.reset-form {
  display: grid;
  gap: 14px;
  margin-top: 8px;
}

.reset-form h2 {
  margin: 0;
  font-size: 20px;
}

.public-link {
  display: inline-flex;
  margin-top: 18px;
  color: var(--green-dark);
  font-weight: 700;
}

.public-header {
  position: sticky;
  top: 0;
  z-index: 10;
}

.public-layout {
  place-items: start center;
}

.public-panel {
  width: min(980px, 100%);
}

.public-form {
  display: grid;
  gap: 22px;
}

.public-form h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

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

.span-2 {
  grid-column: span 2;
}

@media (max-width: 980px) {
  .app-header {
    align-items: center;
    flex-wrap: nowrap;
  }

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

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

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

  table {
    min-width: 760px;
  }
}

@media (max-width: 560px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-list,
  .print-actions {
    grid-template-columns: 1fr;
  }

  .drawer {
    width: 100%;
  }

  .detail-section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    width: auto;
    justify-content: flex-end;
  }

  .env-pill {
    text-align: center;
  }

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

  .span-2 {
    grid-column: span 1;
  }
}
