:root {
  --bg: #f6f8f7;
  --panel: #ffffff;
  --text: #071724;
  --muted: #5d6e78;
  --line: #d8e2df;
  --teal: #087f74;
  --teal-soft: #e3f4f1;
  --danger: #c43d12;
  --danger-soft: #fff0ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft JhengHei", "Microsoft YaHei", sans-serif;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(7, 23, 36, 0.08);
}

.login-card h1 {
  margin-bottom: 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.sidebar-brand {
  display: grid;
  gap: 4px;
  margin-bottom: 24px;
}

.sidebar-brand span {
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

.sidebar-brand strong {
  font-size: 17px;
  line-height: 1.25;
}

.global-sync-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.global-sync-title {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.global-sync-panel button {
  width: 100%;
  padding: 9px 10px;
  text-align: center;
}

.global-sync-message {
  border-radius: 7px;
  padding: 9px 10px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 12px;
  line-height: 1.45;
}

.global-sync-message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  text-align: left;
  border-color: transparent;
  background: transparent;
}

.nav-button.active {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--teal);
}

.workspace {
  min-width: 0;
  width: 100%;
  padding: 18px;
}

.hero,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 8px;
  font-size: 30px;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

h3 {
  margin: 20px 0 10px;
  font-size: 16px;
}

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

.small {
  max-width: 340px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-card {
  min-width: 210px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
}

.status-card strong {
  font-size: 24px;
}

.badge {
  width: fit-content;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.65fr);
  gap: 18px;
}

.page {
  display: none;
}

.page.active {
  display: grid;
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.detail-totals {
  min-width: 280px;
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  padding-top: 22px;
  color: var(--muted);
  font-size: 12px;
}

.detail-totals span {
  white-space: nowrap;
}

.detail-totals strong {
  color: var(--text);
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  font-weight: 700;
}

label span {
  color: #334751;
  font-size: 13px;
}

.field-title {
  display: block;
  margin-bottom: 8px;
  color: #334751;
  font-size: 13px;
  font-weight: 700;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 0;
}

.checkbox-row input {
  width: auto;
}

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

.permission-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdfc;
  font-size: 13px;
}

.permission-item input {
  width: auto;
}

.permission-tags {
  max-width: 360px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.permission-tag {
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.account-actions button {
  padding: 6px 8px;
  font-size: 12px;
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.actions.compact {
  align-items: center;
  margin-top: 0;
}

.checkline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.checkline.compact {
  min-height: 34px;
}

.meta-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.detail-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.detail-tools button {
  padding: 7px 10px;
  font-size: 12px;
}

.print-list-header {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.print-list-summary,
.print-list-tools {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.print-list-summary .detail-totals {
  min-width: 0;
  padding-top: 22px;
}

.print-meta {
  max-width: 520px;
  margin-top: 24px;
  text-align: right;
}

.print-export-note {
  max-width: none;
  margin: 8px 0 0;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

.print-list-tools .detail-tools {
  flex: 1;
  justify-content: flex-start;
}

.print-list-tools .pager {
  justify-content: flex-end;
}

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

.print-job-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.print-job-card.running,
.print-job-card.queued,
.print-job-card.stopping {
  border-color: #9ccdc6;
  background: #f3fbf9;
}

.print-job-card.paused {
  border-color: #d8c38a;
  background: #fffaf0;
}

.print-job-card.failed,
.print-job-card.partial {
  border-color: #f0c36d;
  background: #fffaf0;
}

.print-job-card.stopped {
  border-color: #d5dadd;
  background: #f7f8f8;
}

.print-job-header,
.print-job-actions,
.print-job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}

.print-job-header {
  justify-content: space-between;
}

.print-job-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-weight: 800;
}

.job-select-control {
  display: inline-flex;
  align-items: center;
}

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

.print-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dbe7e4;
}

.print-progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--teal);
}

.print-job-actions button {
  padding: 7px 10px;
  font-size: 12px;
}

.print-job-detail {
  margin: 0;
}

.print-job-detail summary {
  cursor: pointer;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

.print-job-items {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.print-job-item {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) minmax(90px, 0.5fr) minmax(220px, 1.5fr);
  gap: 10px;
  align-items: start;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-size: 12px;
}

.print-job-item.failed {
  border-color: #f4b69e;
  background: var(--danger-soft);
  color: var(--danger);
}

.print-job-item.running {
  border-color: #9ccdc6;
  background: #eef9f6;
}

.print-job-item.paused {
  border-color: #d8c38a;
  background: #fffaf0;
}

.print-job-item.stopped {
  color: var(--muted);
}

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

.page-size-control {
  width: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  white-space: nowrap;
}

.page-size-control span {
  font-size: 12px;
}

.page-size-control select {
  width: 76px;
  padding: 7px 8px;
  font-size: 12px;
}

.pager button {
  padding: 7px 10px;
  font-size: 12px;
}

.column-picker {
  position: relative;
  justify-self: end;
}

.column-picker summary {
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.column-picker summary::-webkit-details-marker {
  display: none;
}

.column-picker-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 4;
  min-width: 180px;
  display: grid;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(15, 45, 55, 0.14);
}

.column-picker:not([open]) .column-picker-menu {
  display: none;
}

.column-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 12px;
  white-space: nowrap;
}

.column-picker-item:hover {
  background: #eef7f5;
}

.column-picker-item input {
  width: auto;
}

.table-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
}

.warning-list {
  display: grid;
  gap: 6px;
  margin: 10px 0 14px;
  padding: 12px 14px;
  border: 1px solid #f0c36d;
  border-radius: 7px;
  background: #fff8e5;
  color: #6f4b00;
  font-size: 13px;
  line-height: 1.5;
}

.warning-list strong {
  font-weight: 800;
}

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

.sales-filter-grid {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

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

.multi-select {
  position: relative;
}

.multi-select-control {
  min-height: 44px;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 34px 5px 7px;
  background: #fff;
  cursor: text;
}

.multi-select-control::after {
  content: "⌄";
  position: absolute;
  right: 12px;
  top: 13px;
  color: var(--muted);
  font-size: 14px;
}

.multi-select.open .multi-select-control {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(8, 127, 116, 0.12);
}

.multi-tags {
  display: contents;
}

.multi-tag {
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid #cddbd8;
  border-radius: 6px;
  background: #edf7f5;
  color: #14544e;
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
}

.multi-tag span {
  color: #56716d;
}

.multi-select input {
  min-width: 130px;
  flex: 1;
  border: 0;
  border-radius: 0;
  padding: 6px 4px;
  outline: 0;
}

.multi-dropdown {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 14px 32px rgba(7, 23, 36, 0.14);
}

.multi-option {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  background: #fff;
  color: var(--text);
  text-align: left;
  font-weight: 700;
}

.multi-option:hover,
.multi-option.selected {
  background: var(--teal-soft);
  color: var(--teal);
}

.multi-option strong {
  min-width: 16px;
  color: var(--teal);
  text-align: right;
}

.multi-empty {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

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

.summary-list > div {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdfc;
}

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

.summary-list strong {
  overflow-wrap: anywhere;
}

.message {
  margin-top: 16px;
  padding: 12px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--teal-soft);
  color: var(--teal);
  line-height: 1.5;
}

.message.error {
  border-color: #f4b69e;
  background: var(--danger-soft);
  color: var(--danger);
}

.hidden {
  display: none;
}

.logs {
  display: grid;
  gap: 8px;
}

.log-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdfc;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.log-item.failed {
  border-color: #f4b69e;
  background: var(--danger-soft);
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

table {
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th[data-key="accountingNote"],
th[data-key="invoiceNote"],
th[data-key="transportNote"],
td[data-key="accountingNote"],
td[data-key="invoiceNote"],
td[data-key="transportNote"] {
  min-width: 0;
  padding-right: 16px;
}

#salesStatsPage td[data-key="accountingNote"],
#salesStatsPage td[data-key="invoiceNote"],
#salesStatsPage td[data-key="transportNote"] {
  min-width: 220px;
  max-width: 360px;
  white-space: pre-line;
  overflow: visible;
  text-overflow: clip;
}

#salesStatsPage td[data-key="transportNote"] {
  min-width: 300px;
  max-width: 520px;
}

.cancelled-invoice-cell {
  color: #d93025;
  font-weight: 800;
}

.detail-totals .total-cancelled {
  color: #b42318;
}

.multiline-cell {
  white-space: pre-line !important;
  overflow: visible !important;
  text-overflow: clip !important;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef7f5;
  border-right: 1px solid #d5e3e0;
  color: #24424a;
  font-weight: 800;
}

th.resizable-column {
  position: sticky;
}

.sort-header {
  min-width: 0;
  width: 100%;
  display: inline-flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font-size: inherit;
  font-weight: inherit;
  overflow: hidden;
}

.sort-header > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sort-header:hover {
  color: var(--teal);
}

.sort-indicator {
  width: 9px;
  min-width: 9px;
  display: inline-grid;
  flex: 0 0 auto;
  gap: 2px;
}

.sort-triangle {
  width: 0;
  height: 0;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  opacity: 0.32;
}

.sort-up {
  border-bottom: 5px solid #6f8580;
}

.sort-down {
  border-top: 5px solid #6f8580;
}

.sort-indicator.is-asc .sort-up {
  border-bottom-color: var(--teal);
  opacity: 1;
}

.sort-indicator.is-desc .sort-down {
  border-top-color: var(--teal);
  opacity: 1;
}

.column-resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  bottom: 0;
  z-index: 3;
  width: 10px;
  cursor: col-resize;
  touch-action: none;
}

.column-resize-handle::after {
  position: absolute;
  top: 7px;
  right: 3px;
  bottom: 7px;
  width: 2px;
  border-radius: 2px;
  background: #6f918b;
  content: "";
}

.column-resize-handle:hover::after,
.column-resizing .column-resize-handle::after {
  background: var(--teal);
}

.column-resizing {
  cursor: col-resize;
  user-select: none;
}

td {
  color: #18303b;
}

.issue-cell {
  color: var(--danger);
  font-weight: 700;
}

.status-ok {
  color: var(--teal);
  font-weight: 800;
}

.status-warning {
  color: #9a6400;
  font-weight: 800;
}

.status-danger {
  color: var(--danger);
  font-weight: 800;
}

.amount-status-amount_mismatch,
.amount-status-client_mismatch,
.amount-status-sales_cancelled,
.amount-status-missing_pickup,
.amount-status-missing_sales,
.amount-status-pickup_invalid_amount {
  background: #fff9f6;
}

.amount-status-pickup_duplicate {
  background: #fffaf0;
}

.selected-row {
  background: #eef9f6;
}

tbody tr:hover {
  background: #fbfdfc;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  padding: 28px 12px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .global-sync-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
  }

  .global-sync-title,
  .global-sync-message {
    grid-column: 1 / -1;
  }

  .shell,
  .workspace {
    width: 100%;
    padding: 12px;
  }

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

  .hero {
    display: grid;
  }

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

  .wide-filter {
    grid-column: auto;
  }
}
