:root {
  --ink: #17292e;
  --muted: #657477;
  --line: #d9e1df;
  --paper: #f5f7f4;
  --panel: #ffffff;
  --accent: #24515f;
  --accent-2: #d65745;
  --ok: #2e7d57;
  --warn: #b66a17;
  --shadow: 0 18px 45px rgba(23, 41, 46, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px 1fr;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.5 "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
}

button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}
button:hover { filter: brightness(1.06); }
button.ghost { color: var(--accent); background: #e7eeee; }
button.danger { background: var(--accent-2); }
button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.3);
  opacity: 0.55;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #edf3f2;
}
.login-screen.hidden { display: none; }
.login-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}
.login-card .brand-mark { margin-bottom: 4px; }
.login-card p { color: var(--muted); }
.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border-radius: 999px;
  padding: 4px 10px;
  color: #183238;
  background: #f0bd55;
  font-weight: 750;
  white-space: nowrap;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  color: #edf4f3;
  background: #183238;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #f0bd55;
  color: #183238;
  font-weight: 800;
}
.brand small { display: block; color: #b9c8c6; }
.nav { display: grid; gap: 8px; }
.nav-item {
  width: 100%;
  text-align: left;
  color: #dce9e7;
  background: transparent;
}
.nav-item.active, .nav-item:hover { background: rgba(255, 255, 255, 0.12); }

.shell { min-width: 0; padding: 28px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }
.topbar p, .panel-head p { color: var(--muted); }
.top-actions { display: flex; gap: 10px; align-items: center; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
}
textarea { min-height: 82px; resize: vertical; }

.view { display: none; }
.view.active { display: grid; gap: 18px; }
.panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.metric {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.metric span { display: block; color: var(--muted); }
.metric strong { display: block; margin-top: 6px; font-size: 28px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.form-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 5px; }
.field.wide { grid-column: span 2; }
.field.full { grid-column: 1 / -1; }
label { color: #3c5055; font-weight: 650; }
.readonly {
  background: #eef3f2;
  color: #4d6064;
}
.form-actions { grid-column: 1 / -1; display: flex; gap: 10px; }
.inline-select {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px;
}
.inline-select button { min-width: 44px; padding-inline: 0; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #40575c; background: #f0f4f3; white-space: nowrap; }
td.num, th.num { text-align: right; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  color: var(--accent);
  background: #e7eeee;
  font-size: 13px;
  font-weight: 700;
}
.badge.warn { color: #8a4a06; background: #fff0d9; }
.badge.ok { color: var(--ok); background: #e1f1e8; }
.badge.danger { color: #9a2c1d; background: #ffe1db; }
.struck { text-decoration: line-through; color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.list { display: grid; gap: 10px; }
.field.full .list {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
}
.field.full .list.check-grid {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  align-items: start;
}
.field.full .list.check-grid .row-actions,
.field.full .list.check-grid .compact-filter {
  grid-column: 1 / -1;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
}
.check-row small { color: var(--muted); }
.compact-filter {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.report-filter {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.report-filter label {
  display: grid;
  gap: 5px;
}
.list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}
.list-item small { display: block; color: var(--muted); }

.master-layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.master-tabs { display: grid; gap: 7px; align-content: start; }
.master-tab {
  color: var(--accent);
  background: #edf3f2;
}
.master-tab.active { color: #fff; background: var(--accent); }
.doc-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.doc-tab {
  color: var(--accent);
  background: #edf3f2;
}
.doc-tab.active {
  color: #fff;
  background: var(--accent);
}
.db-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.file-btn {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border-radius: 8px;
  padding: 9px 14px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}
.file-btn input { display: none; }
.note {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  padding: 14px;
  border-left: 4px solid var(--accent-2);
  background: #fff7f3;
}
.task-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.task-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}
.task-card h3 { margin: 0 0 8px; font-size: 16px; }
.task-card p { color: var(--muted); }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.task-actions {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.task-section {
  grid-column: 1 / -1;
}
.task-section h3 {
  margin: 4px 0 10px;
}
.task-priority-panel {
  border-color: #f0bd55;
  box-shadow: 0 18px 45px rgba(240, 189, 85, 0.16);
}
.print-area {
  display: grid;
  gap: 16px;
}
.print-area .doc {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.print-area table {
  min-width: 0;
  margin-top: 12px;
}
.label-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.label-card {
  width: 10cm;
  height: 5cm;
  display: grid;
  align-content: start;
  gap: 3px;
  overflow: hidden;
  padding: 4mm 4.5mm;
  border: 1px dashed var(--line);
  background: #fff;
  color: #111;
  font: 13.5px/1.15 "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
.label-card strong { font-weight: 900; }
.shipment-label .ship-main { font-size: 19px; font-weight: 850; display: grid; gap: 2mm; }
.shipment-label .ship-address { min-height: 18mm; }
.logistics-no { font-size: 11px; }
.label-card .label-title { font-size: 18px; font-weight: 900; text-align: center; }
.product-label { font-size: 14.5px; }
.product-items { min-height: 15mm; }
.label-card .label-large { font-size: 20px; font-weight: 950; text-align: center; line-height: 1.05; }
.label-card .label-line { border-top: 1px dashed #111; margin: 2px 0; }
.label-card .label-bottom { margin-top: auto; display: flex; justify-content: space-between; gap: 3mm; font-size: 10.5px; line-height: 1.12; }
.process-label { font-size: 12.5px; }
.sales-a4 {
  min-height: 287mm;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 8mm;
}
.sales-copy {
  min-height: 135mm;
}
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #17292e;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 0.18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
dialog {
  width: min(760px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(23, 41, 46, 0.42); }
.dialog-card { padding: 18px; background: #fff; }
.template-dialog {
  width: min(1120px, calc(100vw - 28px));
}
.template-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f8f7;
}
.template-tools button,
.template-tools select {
  width: auto;
  min-height: 36px;
  padding: 7px 10px;
}
.template-canvas {
  min-height: 560px;
  max-height: 68vh;
  overflow: auto;
  margin-top: 12px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: inset 0 0 0 1px #f3f5f4;
}
.template-canvas:focus {
  outline: 2px solid rgba(36, 81, 95, 0.24);
}
.template-canvas table {
  min-width: 0;
  width: 100%;
  border-collapse: collapse;
}
.template-canvas th,
.template-canvas td {
  border: 1px solid #879593;
  padding: 7px;
}
.template-canvas .doc {
  border: 1px dashed #b7c3c1;
  padding: 18px;
  background: #fff;
}
.muted { color: var(--muted); }

@media (max-width: 980px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .topbar, .panel-head { align-items: stretch; flex-direction: column; }
  .metric-grid, .two-col, .task-board { grid-template-columns: 1fr; }
  .form-grid, .form-grid.compact { grid-template-columns: 1fr 1fr; }
  .field.full .list.check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .master-layout { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .shell { padding: 18px; }
  .nav { grid-template-columns: 1fr 1fr; }
  .top-actions { flex-direction: column; align-items: stretch; }
  .form-grid, .form-grid.compact { grid-template-columns: 1fr; }
  .field.full .list.check-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
}

@media print {
  @page { size: auto; margin: 6mm; }
  body { display: block; background: #fff; }
  .label-card {
    width: 10cm;
    height: 5cm;
    break-after: page;
    page-break-after: always;
    border: 0;
    box-shadow: none;
  }
}
