:root {
  --ink: #17231d;
  --ink-soft: #53615a;
  --muted: #7c8881;
  --line: #dedfd8;
  --paper: #f5f4ee;
  --card: #fffef9;
  --sidebar: #17251e;
  --sidebar-soft: #223329;
  --accent: #e8683c;
  --accent-dark: #c94e28;
  --green: #2b7d5b;
  --green-soft: #e6f2ec;
  --blue: #3a67b1;
  --blue-soft: #eaf0fb;
  --amber: #a66b1f;
  --amber-soft: #fff2d9;
  --red: #ba493b;
  --red-soft: #fae9e5;
  --shadow: 0 16px 45px rgba(22, 35, 29, 0.08);
  --radius: 18px;
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.inline-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.inline-icon svg {
  width: 18px;
  height: 18px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 18px 18px;
  color: #f8f5ec;
  background:
    radial-gradient(circle at 20% 10%, rgba(83, 125, 99, 0.25), transparent 25%),
    var(--sidebar);
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
}

.brand strong {
  display: block;
  font-size: 18px;
  letter-spacing: -0.03em;
}

.brand small {
  color: #aebbb4;
  font-size: 10px;
  letter-spacing: 0.19em;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: 3px;
  padding: 8px;
  border-radius: 11px;
  background: var(--accent);
}

.brand-mark span {
  border-radius: 2px 2px 1px 1px;
  background: #fff9ef;
}

.brand-mark span:nth-child(1) { height: 45%; }
.brand-mark span:nth-child(2) { height: 100%; }
.brand-mark span:nth-child(3) { height: 70%; }

.nav-list {
  margin-top: 45px;
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  padding: 0 12px;
  color: #aebbb4;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  text-align: left;
  transition: 160ms ease;
}

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

.nav-item.active {
  color: #fff;
  background: var(--sidebar-soft);
  box-shadow: inset 3px 0 var(--accent);
}

.nav-icon,
.warehouse-icon {
  display: inline-grid;
  place-items: center;
}

.nav-icon svg,
.warehouse-icon svg,
.icon-button svg,
.primary-button svg,
.user-card svg,
.table-icon svg,
.button-icon svg,
.modal-close svg {
  width: 19px;
  height: 19px;
}

.nav-count {
  margin-left: auto;
  min-width: 24px;
  padding: 3px 7px;
  border-radius: 999px;
  color: #f8d2c6;
  background: rgba(232, 104, 60, 0.17);
  font-size: 11px;
  text-align: center;
}

.nav-dot {
  margin-left: auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(232, 104, 60, 0.12);
}

.sidebar-bottom {
  margin-top: auto;
}

.warehouse-card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.035);
}

.warehouse-card-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 13px;
}

.live-dot {
  width: 8px;
  height: 8px;
  margin-top: 4px;
  border-radius: 50%;
  background: #5acb8c;
  box-shadow: 0 0 0 4px rgba(90, 203, 140, 0.1);
}

.warehouse-card strong,
.warehouse-card span {
  display: block;
}

.warehouse-card > span {
  margin-top: 4px;
  color: #94a49c;
  font-size: 11px;
}

.capacity-row {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  color: #9ead9f;
  font-size: 10px;
}

.capacity-row span,
.capacity-row strong {
  display: inline;
}

.capacity-track {
  height: 4px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.09);
}

.capacity-track i {
  display: block;
  width: 64%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.user-card {
  width: 100%;
  margin-top: 13px;
  padding: 10px 8px;
  border: 0;
  color: white;
  background: transparent;
  display: grid;
  grid-template-columns: 38px 1fr 18px;
  gap: 10px;
  align-items: center;
  text-align: left;
}

.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #173025;
  background: #dce8df;
  font-size: 12px;
  font-weight: 800;
}

.user-card strong,
.user-card small {
  display: block;
}

.user-card strong { font-size: 12px; }
.user-card small { margin-top: 3px; color: #8fa097; font-size: 10px; }

.main {
  min-width: 0;
}

.topbar {
  min-height: 100px;
  padding: 24px clamp(24px, 4vw, 52px);
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid rgba(23, 35, 29, 0.08);
}

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

.topbar-title p {
  margin: 0 0 5px;
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.topbar-title h1 {
  margin: 0;
  font-family: Georgia, "Noto Serif TC", serif;
  font-size: clamp(22px, 2.3vw, 30px);
  font-weight: 600;
  letter-spacing: -0.035em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.connection-pill {
  height: 38px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.55);
  font-size: 11px;
}

.connection-pill span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
}

.connection-pill.live span { background: var(--green); }

.icon-button {
  position: relative;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.notification-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 6px;
  height: 6px;
  border: 1px solid var(--paper);
  border-radius: 50%;
  background: var(--accent);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 42px;
  border-radius: 11px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  transition: 160ms ease;
}

.primary-button {
  border: 1px solid var(--accent);
  color: #fff;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(232, 104, 60, 0.2);
}

.primary-button:hover { background: var(--accent-dark); transform: translateY(-1px); }

.secondary-button {
  border: 1px solid var(--ink);
  color: #fff;
  background: var(--ink);
}

.ghost-button {
  border: 1px solid var(--line);
  background: transparent;
}

.ghost-button:hover { border-color: #aab0ab; background: #fff; }

.danger-button {
  border: 1px solid #e2b4ac;
  color: var(--red);
  background: var(--red-soft);
}

.workspace {
  padding: 34px clamp(24px, 4vw, 52px) 60px;
}

.mobile-menu { display: none; }

.section-head {
  margin-bottom: 22px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.section-head h2 {
  margin: 0;
  font-family: Georgia, "Noto Serif TC", serif;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.035em;
}

.section-head p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 15px;
}

.stat-card {
  min-height: 145px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 3px 18px rgba(22, 35, 29, 0.035);
}

.stat-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-card-head span:first-child {
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.stat-card .metric {
  margin-top: 18px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.metric strong {
  font-family: Georgia, serif;
  font-size: 36px;
  font-weight: 600;
  line-height: 1;
}

.metric small { color: var(--muted); }

.trend {
  padding: 4px 7px;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 9px;
  font-weight: 800;
}

.trend.alert { color: var(--red); background: var(--red-soft); }

.stat-card footer {
  margin-top: 16px;
  color: var(--muted);
  font-size: 10px;
}

.dashboard-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.8fr);
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 3px 18px rgba(22, 35, 29, 0.035);
  overflow: hidden;
}

.panel-head {
  min-height: 68px;
  padding: 17px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  border-bottom: 1px solid #e7e7e1;
}

.panel-head h3 {
  margin: 0;
  font-size: 14px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 10px;
}

.text-button {
  padding: 5px 0;
  border: 0;
  color: var(--accent-dark);
  background: transparent;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.order-list {
  display: grid;
}

.order-row {
  width: 100%;
  min-height: 79px;
  padding: 13px 20px;
  border: 0;
  border-bottom: 1px solid #ecece6;
  background: transparent;
  display: grid;
  grid-template-columns: 42px minmax(120px, 1.4fr) minmax(120px, 1fr) 100px 88px 20px;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
}

.order-row:last-child { border-bottom: 0; }
.order-row:hover { background: #faf9f4; }

.channel-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-size: 10px;
  font-weight: 900;
}

.channel-icon.shopify { color: #2d6649; background: #e8f1eb; }
.channel-icon.shopee { color: #b64c2d; background: #faeae5; }

.order-main strong,
.order-customer strong {
  display: block;
  font-size: 12px;
}

.order-main span,
.order-main small,
.order-customer span,
.order-customer small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-amount {
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.order-amount strong,
.order-amount small {
  display: block;
}

.order-amount small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.status-badge {
  width: fit-content;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.status-new,
.status-allocated { color: var(--blue); background: var(--blue-soft); }
.status-picking,
.status-picked,
.status-packed,
.status-pending { color: var(--amber); background: var(--amber-soft); }
.status-shipped,
.status-success { color: var(--green); background: var(--green-soft); }
.status-failed,
.status-sync_failed,
.status-on_hold { color: var(--red); background: var(--red-soft); }
.status-cancelled { color: var(--muted); background: #eceeea; }

.activity-list {
  padding: 8px 20px 18px;
}

.activity-item {
  position: relative;
  min-height: 68px;
  padding: 15px 0 10px 27px;
  border-bottom: 1px solid #ecece6;
}

.activity-item:last-child { border-bottom: 0; }

.activity-item::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 21px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.activity-item.failed::before {
  background: var(--red);
  box-shadow: 0 0 0 4px var(--red-soft);
}

.activity-item strong {
  display: block;
  font-size: 11px;
}

.activity-item span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 9px;
}

.toolbar {
  margin-bottom: 15px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.search-box {
  min-width: min(340px, 100%);
  height: 43px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  display: flex;
  align-items: center;
  gap: 9px;
}

.search-box svg { width: 17px; height: 17px; color: var(--muted); }

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 12px;
}

.filter-select,
.form-field input,
.form-field select {
  height: 43px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0 13px;
  outline: 0;
  color: var(--ink);
  background: var(--card);
  font-size: 11px;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 850px;
}

.data-table th {
  padding: 14px 17px;
  color: var(--muted);
  background: #f8f7f1;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: left;
}

.data-table td {
  padding: 16px 17px;
  border-top: 1px solid #e9e9e3;
  font-size: 11px;
}

.data-table tr { cursor: pointer; }
.data-table tbody tr:hover { background: #fbfaf5; }

.table-order {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-order strong { display: block; }
.table-order small { display: block; margin-top: 3px; color: var(--muted); }

.low-stock { color: var(--red); font-weight: 800; }

.available-stock strong {
  display: block;
  font-size: 14px;
}

.available-stock small { color: var(--muted); }

.stock-bar {
  width: 90px;
  height: 5px;
  margin-top: 7px;
  border-radius: 9px;
  background: #e8e8e1;
  overflow: hidden;
}

.stock-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.stock-bar i.low { background: var(--red); }

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

.ops-column {
  min-width: 0;
}

.ops-column-head {
  margin-bottom: 10px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ops-column-head h3 {
  margin: 0;
  font-size: 12px;
}

.ops-count {
  min-width: 25px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--ink-soft);
  background: #e7e8e2;
  font-size: 9px;
  text-align: center;
}

.ops-stack {
  display: grid;
  gap: 10px;
}

.ops-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--card);
  box-shadow: 0 3px 14px rgba(22, 35, 29, 0.03);
}

.ops-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ops-card h4 {
  margin: 14px 0 4px;
  font-size: 13px;
}

.ops-card p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
}

.ops-progress {
  margin: 14px 0;
  display: flex;
  gap: 4px;
}

.ops-progress i {
  height: 4px;
  flex: 1;
  border-radius: 6px;
  background: #e5e7e1;
}

.ops-progress i.done { background: var(--accent); }

.ops-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 9px;
}

.ops-card footer button {
  border: 0;
  color: var(--accent-dark);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.empty-state {
  padding: 45px 20px;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
}

.drawer-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 15, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
  z-index: 60;
}

.drawer-backdrop.open,
.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.order-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(470px, 100%);
  background: var(--card);
  transform: translateX(102%);
  transition: 240ms ease;
  z-index: 70;
  overflow-y: auto;
  box-shadow: -25px 0 70px rgba(15, 24, 19, 0.14);
}

.order-drawer.open { transform: translateX(0); }

.drawer-head {
  padding: 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-head h2 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 23px;
}

.drawer-section {
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.drawer-section h3 {
  margin: 0 0 15px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.detail-grid div span {
  display: block;
  color: var(--muted);
  font-size: 9px;
}

.detail-grid div strong {
  display: block;
  margin-top: 5px;
  font-size: 11px;
}

.drawer-item {
  padding: 12px 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border-bottom: 1px solid #ecece6;
}

.drawer-item:last-child { border-bottom: 0; }
.drawer-item strong { display: block; font-size: 11px; }
.drawer-item span { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; }
.drawer-item b { font-size: 11px; }

.drawer-actions {
  padding: 22px 24px 30px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.drawer-actions .primary-button:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.modal-backdrop {
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 80;
}

.modal {
  position: relative;
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  border-radius: 20px;
  background: var(--card);
  box-shadow: 0 30px 90px rgba(15, 24, 19, 0.25);
  transform: translateY(10px) scale(0.98);
  transition: 180ms ease;
}

.modal-backdrop.open .modal { transform: none; }

.modal-close {
  position: absolute;
  top: 17px;
  right: 17px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.modal h2 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 24px;
}

.modal-lead {
  margin: 8px 0 22px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

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

.form-field label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 800;
}

.form-field input,
.form-field select {
  width: 100%;
}

.modal-actions {
  margin-top: 22px;
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.toast-region {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: min(360px, calc(100% - 44px));
  display: grid;
  gap: 8px;
  z-index: 100;
}

.toast {
  padding: 14px 16px;
  border: 1px solid #d7ded9;
  border-radius: 13px;
  background: #fff;
  box-shadow: var(--shadow);
  animation: toast-in 220ms ease both;
}

.toast strong { display: block; font-size: 11px; }
.toast span { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .operations-grid { grid-template-columns: 1fr; }
  .ops-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .connection-pill { display: none; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-102%);
    transition: 220ms ease;
    width: min(280px, 88vw);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: grid; flex: 0 0 auto; }
  .topbar { padding: 18px; min-height: 84px; }
  .topbar-title p { display: none; }
  .topbar-title h1 { font-size: 19px; }
  .topbar-actions .icon-button { display: none; }
  .primary-button { padding: 0 12px; }
  #importOrderButton { font-size: 0; width: 42px; padding: 0; }
  #importOrderButton svg { width: 19px; height: 19px; }
  .workspace { padding: 24px 18px 45px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { min-height: 125px; padding: 15px; }
  .metric strong { font-size: 30px; }
  .order-row {
    grid-template-columns: 38px minmax(120px, 1fr) 80px 20px;
  }
  .order-customer,
  .order-amount { display: none; }
  .ops-stack { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .section-head { align-items: start; flex-direction: column; }
  .drawer-actions { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
