:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --panel: #fff;
  --line: #d6d9df;
  --line-strong: #b8bec8;
  --text: #222833;
  --muted: #6b7280;
  --accent: #3f4652;
  --accent-dark: #262c35;
  --danger: #a33a3a;
  --warn: #9a5a16;
  --warn-bg: #fff4df;
  --ok: #4b5563;
  --ok-bg: #eef0f3;
  --confirmed: #1f6b4a;
  --confirmed-bg: #e8f4ee;
  --surface: #f8f9fb;
  --surface-strong: #eceff3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

.app {
  min-height: 100vh;
  padding: 18px;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; margin-bottom: 10px; }
p { color: var(--muted); margin-top: 6px; }

button {
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 650;
  min-height: 36px;
  padding: 0 12px;
}

button:hover { background: var(--accent-dark); }
button[type="button"] { background: #3f4652; }
button.active { background: #111827; box-shadow: 0 0 0 3px rgba(17, 24, 39, .14); }
button:disabled, input:disabled, select:disabled { opacity: .55; cursor: not-allowed; }

input, select {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  min-height: 34px;
  padding: 5px 8px;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: #343a43;
  border-radius: 3px;
  flex: 0 0 auto;
  height: 16px;
  min-height: 16px;
  padding: 0;
  width: 16px;
}

.topbar,
.uploadBand,
.casesPanel,
.bonusPanel,
.objectPanel,
.viewerPanel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 16px;
}

.topActions,
.uploadControls,
.viewerActions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.projectBar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  position: relative;
}

.projectBar label {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 6px;
}

.projectBar select {
  min-width: 220px;
}

.currentProjectName {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-weight: 650;
  min-height: 34px;
  padding: 6px 10px;
}

.projectListPanel {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(17, 24, 39, .14);
  left: 0;
  max-height: 420px;
  min-width: 520px;
  overflow: auto;
  padding: 8px;
  position: absolute;
  top: 42px;
  z-index: 10;
}

.projectListItem {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 8px;
}

.projectListItem:last-child { border-bottom: 0; }
.projectListItem.activeProject { background: var(--surface); }
.projectListItem span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

.projectItemActions {
  display: flex;
  gap: 6px;
}

.projectItemActions button {
  min-height: 30px;
  padding: 0 9px;
}

.uploadBand {
  margin-top: 12px;
  padding: 14px 16px;
}

.segmentControls {
  align-items: end;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(110px, 150px)) auto auto;
  margin-top: 12px;
  padding-top: 12px;
}

.segmentControls label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 4px;
}

.segmentControls input {
  min-width: 0;
  width: 100%;
}

.filePicker,
.pageLimit,
.aiToggle {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: inline-flex;
  gap: 8px;
  min-height: 36px;
  padding: 0 10px;
}

.filePicker input { max-width: 240px; }
.fileName { color: var(--muted); min-width: 160px; }
.pageLimit input { width: 82px; }
.aiToggle input {
  min-height: auto;
  width: auto;
}

.progressShell {
  background: var(--surface-strong);
  border-radius: 999px;
  height: 8px;
  margin-top: 12px;
  overflow: hidden;
}

.progressBar {
  background: var(--accent);
  height: 100%;
  transition: width .25s ease;
  width: 0;
}

.statusText {
  color: var(--muted);
  font-size: 14px;
  margin-top: 8px;
}

.statusText.error { color: var(--danger); }

.warnings {
  background: var(--warn-bg);
  border: 1px solid #f1d48d;
  border-radius: 8px;
  color: var(--warn);
  margin-top: 12px;
  padding: 10px 12px;
}

.workspace {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) minmax(430px, 500px);
  margin-top: 12px;
}

.panelHeader,
.viewerHeader {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px 14px;
}

.caseTableWrap {
  max-height: 460px;
  overflow: auto;
}

table {
  border-collapse: collapse;
  min-width: 1040px;
  width: 100%;
}

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

th {
  background: var(--surface-strong);
  color: #374151;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7f8fa; }
.selectedRow { background: #eef0f3; }
.confirmedRow { background: var(--confirmed-bg); }
.confirmedRow:hover { background: #ddede6; }
.objectSubRow { background: #fbfcfd; color: var(--muted); }
.addressCell { min-width: 260px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.toggleCase, .miniButton { min-height: 28px; padding: 0 8px; }

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  white-space: nowrap;
}
.ok { background: var(--ok-bg); color: var(--ok); }
.warn { background: var(--warn-bg); color: var(--warn); }
.confirmed { background: var(--confirmed-bg); color: var(--confirmed); }
.muted { background: #eef0f3; color: var(--muted); }
.mutedText { color: var(--muted); font-size: 12px; }

.bonusPanel { min-width: 0; }
.processEditor { padding: 12px; }
.caseCalc {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}
.caseCalc label, .boxEditor label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 4px;
}
.processRow {
  align-items: center;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: 18px minmax(72px, 96px) minmax(150px, 1fr) minmax(54px, 72px);
  min-height: 48px;
  padding: 7px 0;
}
.caseCalc input,
.processRow input,
.processRow select {
  min-width: 0;
  width: 100%;
}
.processName {
  color: var(--text);
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
}
.assigneeInput { width: 100%; }
.amountInput {
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.primaryButton {
  margin-top: 4px;
  width: 100%;
}
.bonusTotal {
  background: var(--surface);
  border-radius: 6px;
  font-weight: 700;
  margin-top: 10px;
  padding: 10px;
  text-align: right;
}

.objectPanel, .viewerPanel { margin-top: 12px; }
.objectRows {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  padding: 12px;
}
.objectCard {
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  padding: 10px;
}
.objectCard:hover { background: #f7f8fa; border-color: var(--line-strong); }
.objectCard span { color: var(--muted); font-size: 13px; }
.objectCard .draftTag {
  background: var(--warn-bg);
  border-radius: 999px;
  color: var(--warn);
  display: inline-flex;
  font-weight: 700;
  justify-self: start;
  padding: 2px 8px;
}

.viewerGrid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) 300px;
  padding: 12px;
}

.canvasScroller {
  background: #e6e9ee;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 520px;
  overflow: auto;
  padding: 10px;
}

#drawingCanvas {
  background: #fff;
  cursor: crosshair;
  display: block;
  max-width: 100%;
}

.boxEditor {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}
.boxEditor input { width: 100%; }
.boxEditor label + label { margin-top: 10px; }
.sinkInfo {
  background: #f2f3f5;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 10px;
  padding: 8px;
}

.empty,
.emptyBox {
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

@media (max-width: 1080px) {
  .topbar, .workspace, .viewerGrid { display: block; }
  .topActions, .bonusPanel, .viewerGrid .boxEditor { margin-top: 12px; }
  .caseCalc { grid-template-columns: 1fr; }
  .segmentControls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .app { padding: 10px; }
  .processRow {
    align-items: stretch;
    grid-template-columns: 18px 1fr;
  }
  .processRow .assigneeInput,
  .processRow .amount { grid-column: 1 / -1; }
  .amount { text-align: left; }
  .segmentControls { grid-template-columns: 1fr; }
}
