:root {
  --bg: #f7f3ed;
  --panel: #fffdfa;
  --line: #eadfce;
  --line-strong: #d9c5aa;
  --text: #442c20;
  --muted: #806c5d;
  --blue: #df8731;
  --blue-dark: #bf681e;
  --red: #d94b52;
  --green: #16866e;
  --disabled: #b7aa9d;
  --shadow: 0 2px 9px rgba(80, 49, 28, 0.08);
  font-family: "Microsoft JhengHei UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top, #fff8df 0, var(--bg) 48%);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(16, 35, 63, 0.16);
  padding: 32px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #f3c477;
  background: #fff8dc;
}

.login-logo {
  width: 82px;
  height: 82px;
  border-width: 3px;
  box-shadow: 0 8px 22px rgba(112, 65, 24, 0.16);
}

.login-panel h1 {
  margin: 18px 0 6px;
  font-size: 24px;
}

.login-panel p {
  margin: 0 0 22px;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

label span,
.form-label {
  display: block;
  margin-bottom: 8px;
  color: #624737;
  font-weight: 650;
}

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

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(223, 135, 49, 0.16);
}

textarea {
  min-height: 210px;
  resize: vertical;
  line-height: 1.45;
}

.primary {
  min-height: 46px;
  border-radius: 7px;
  color: white;
  background: var(--blue);
  font-weight: 800;
  padding: 0 18px;
  box-shadow: 0 4px 10px rgba(191, 104, 30, 0.2);
}

.primary:hover:not(:disabled) {
  background: var(--blue-dark);
}

.primary:disabled {
  background: var(--disabled);
  box-shadow: none;
}

.secondary,
.ghost,
.danger,
.icon-button {
  min-height: 38px;
  border-radius: 7px;
  padding: 0 14px;
  background: #f7efe4;
  color: #5c402f;
  border: 1px solid var(--line);
  font-weight: 700;
}

.danger {
  color: #b4233b;
  background: #fff1f3;
}

.form-error {
  padding: 10px 12px;
  background: #fff1f3;
  color: #b4233b;
  border-radius: 7px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fffdfa;
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  width: min(940px, calc(100% - 32px));
  min-height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 22px;
}

.brand,
.user-box,
.tabs {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  white-space: nowrap;
}

.brand-copy {
  display: grid;
  line-height: 1.1;
}

.brand-copy span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.tabs {
  flex: 1;
  height: 64px;
  overflow-x: auto;
}

.tabs button {
  height: 64px;
  padding: 0 20px;
  color: #52647c;
  background: transparent;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-weight: 700;
}

.tabs button.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
  background: #fff7e9;
}

.user-box {
  gap: 10px;
  white-space: nowrap;
}

#userBadge {
  padding: 7px 13px;
  border-radius: 999px;
  color: #77451f;
  background: #fff1d8;
  font-weight: 800;
  font-size: 13px;
}

.notice {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 45;
  transform: translateX(-50%);
  width: min(940px, calc(100% - 32px));
  margin: 0;
  padding: 12px 14px;
  border-radius: 7px;
  background: #ecfdf5;
  color: #096346;
  border: 1px solid #b7ead2;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(80, 49, 28, 0.18);
}

.notice.error {
  background: #fff1f3;
  color: #b4233b;
  border-color: #ffc7d1;
}

.page {
  width: min(940px, calc(100% - 32px));
  margin: 22px auto 100px;
}

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

.compact-title {
  justify-content: flex-start;
}

.page-title h2 {
  margin: 0;
  font-size: 20px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: #e6edf6;
  border-radius: 8px;
}

.page-segment {
  margin-bottom: 16px;
}

.import-page-head {
  width: min(100%, 560px);
  margin: 0 auto 16px;
}

.import-page-head .page-title {
  margin-bottom: 12px;
}

.import-page-head .page-segment {
  margin-bottom: 0;
}

.segmented button {
  min-height: 32px;
  padding: 0 14px;
  border-radius: 6px;
  background: transparent;
  color: #53647d;
  font-weight: 800;
}

.segmented button.active {
  color: var(--blue);
  background: white;
  box-shadow: 0 1px 4px rgba(20, 42, 70, 0.08);
}

.withdraw-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
}

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

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

.product-card,
.combo-card,
.panel,
.cost-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.product-card {
  min-height: 186px;
  padding: 14px 12px 12px;
}

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

.combo-card {
  padding: 16px;
}

.combo-card-head {
  min-height: 98px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.combo-card h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.combo-components {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.combo-components span {
  padding: 5px 7px;
  border-radius: 5px;
  background: #faf4ea;
  color: #6c513f;
  font-size: 12px;
  font-weight: 700;
}

.combo-card .primary {
  width: 100%;
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  font-size: 18px;
}

.empty-state.small {
  min-height: 110px;
}

.product-head {
  min-height: 49px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid #edf1f6;
  padding-bottom: 12px;
}

.product-head h3 {
  margin: 3px 0 0;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.28;
  overflow-wrap: anywhere;
}

.count {
  display: flex;
  align-items: baseline;
  gap: 3px;
  white-space: nowrap;
}

.count strong {
  font-size: 32px;
  line-height: 1;
  color: #111827;
}

.count.low strong {
  color: var(--red);
}

.count.empty strong {
  color: var(--disabled);
}

.count span {
  color: #6f86a1;
  font-size: 12px;
}

.stepper {
  height: 44px;
  margin: 22px 0 12px;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  border: 1px solid var(--line);
  background: #faf4ea;
  border-radius: 7px;
  overflow: hidden;
}

.stepper button {
  height: 42px;
  color: #5c7697;
  background: transparent;
  font-size: 24px;
  font-weight: 600;
}

.stepper button:disabled {
  color: #cbd5e1;
}

.stepper output {
  text-align: center;
  font-size: 18px;
  font-weight: 500;
}

.product-card .primary {
  width: 100%;
}

.panel {
  padding: 18px;
}

.cart-panel {
  position: sticky;
  top: 88px;
  align-self: start;
}

.cart-list {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.cart-item,
.mini-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px;
  border-radius: 7px;
  background: #fbf6ee;
}

.combo-management {
  max-width: 760px;
  margin: 0 auto;
}

.combo-management-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.combo-management-head h3 {
  margin: 0;
}

.combo-editor {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.combo-editor-head {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.combo-layer-icon {
  color: var(--blue);
  font-size: 24px;
}

.combo-editor-head .primary {
  min-height: 40px;
}

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

.combo-product-input {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 62px;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border-radius: 7px;
  background: #fbf6ee;
}

.combo-product-input span {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 13px;
}

.combo-product-input input {
  padding: 7px;
  text-align: center;
}

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

.combo-management-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.combo-management-row .muted {
  margin-top: 5px;
  font-size: 12px;
}

.combo-available {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

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

.denom-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.denom-list button {
  min-height: 36px;
  padding: 0 13px;
  border-radius: 7px;
  background: #faf4ea;
  color: #604635;
  border: 1px solid var(--line);
  font-weight: 700;
}

.denom-list button.active {
  color: white;
  background: var(--blue);
  border-color: var(--blue);
}

.import-panel {
  width: min(100%, 560px);
  margin: 0 auto;
}

.import-panel textarea {
  min-height: 172px;
}

.selected-import {
  padding: 13px 16px;
  border: 1px solid #edcf9f;
  border-radius: 7px;
  background: #fff6e7;
  font-size: 16px;
  color: #604635;
}

.import-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.import-actions .primary {
  width: 100%;
}

.import-actions .muted {
  align-self: flex-end;
}

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

.toolbar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.toolbar label {
  flex: 1 1 220px;
}

.settings-page {
  max-width: 620px;
  margin: 0 auto;
}

.settings-head {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.settings-head h3 {
  margin: 0;
  font-size: 20px;
}

.back-link {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: transparent;
  color: #0f2340;
  font-size: 26px;
}

.dark-save {
  min-height: 38px;
  border-radius: 7px;
  padding: 0 18px;
  color: white;
  background: #40506a;
  font-weight: 800;
}

.settings-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.denom-add {
  display: grid;
  grid-template-columns: 1fr 76px;
  gap: 10px;
  margin-bottom: 12px;
}

.denom-add .primary {
  min-height: 40px;
  box-shadow: none;
}

.variable-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #233956;
  margin-bottom: 16px;
}

.variable-check input {
  width: auto;
}

.denom-settings-list {
  display: grid;
  gap: 9px;
}

.denom-row {
  min-height: 50px;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.denom-row.dragging {
  opacity: 0.5;
  border-color: var(--blue);
  box-shadow: 0 5px 16px rgba(112, 65, 24, 0.16);
}

.drag-dots {
  color: #b89269;
  font-size: 20px;
  cursor: grab;
  user-select: none;
}

.drag-dots:active {
  cursor: grabbing;
}

.denom-row-actions {
  display: flex;
  gap: 10px;
}

.icon-light {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: transparent;
  color: #9a775d;
  font-size: 18px;
}

.icon-light:hover {
  background: #faf0e1;
  color: var(--blue-dark);
}

.delete-product {
  color: #c65a62;
}

.delete-product:hover {
  color: #a52d39;
  background: #fff0f1;
}

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

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

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid #edf1f6;
  text-align: left;
  vertical-align: top;
}

th {
  color: #624737;
  font-size: 13px;
  background: #fbf5eb;
}

.compact-table {
  min-width: 0;
  margin-top: 14px;
}

.compact-table th,
.compact-table td {
  padding: 9px 8px;
}

.status-pill,
.action-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #ecfdf5;
  color: #096346;
  font-weight: 800;
  font-size: 12px;
}

.status-pill.off {
  background: #eef2f7;
  color: #64748b;
}

.action-pill.take {
  background: #eff6ff;
  color: #1d4ed8;
}

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

.logs-toolbar select {
  width: auto;
  min-width: 112px;
}

.logs-toolbar #logLimit {
  min-width: 88px;
}

.log-search {
  width: auto;
  min-width: 160px;
  flex: 1 1 220px;
  min-height: 42px;
}

.select-column {
  width: 48px;
  text-align: center;
}

.log-checkbox {
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  border-radius: 4px;
  accent-color: var(--blue);
  cursor: pointer;
}

.batch-toolbar {
  min-height: 48px;
  margin: 0 0 12px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff9ed;
}

.batch-toolbar span {
  margin-right: auto;
  color: var(--muted);
}

.batch-toolbar button {
  min-height: 34px;
}

.privacy-note {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 7px;
  color: #6c513f;
  background: #fff5e4;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
}

.code-cell {
  font-family: Consolas, "Microsoft JhengHei", monospace;
  font-size: 13px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1.5fr;
  gap: 16px;
  margin-bottom: 16px;
}

.cost-card {
  padding: 18px;
}

.cost-card h3 {
  margin: 0 0 12px;
  font-size: 17px;
}

.cost-card strong {
  display: block;
  margin: 10px 0 14px;
  font-size: 34px;
}

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

.user-count-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

.user-count-card > span {
  display: block;
  margin: 4px 0 10px;
  color: var(--muted);
}

.user-count-card div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid #eef2f7;
  font-size: 13px;
}

.user-panel h3 {
  margin: 22px 0 12px;
}

.account-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #624737;
}

.check-line input {
  width: auto;
}

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

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(32, 43, 58, 0.48);
}

.result-modal {
  position: relative;
  width: min(346px, calc(100vw - 36px));
  background: white;
  border-radius: 8px;
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.24);
  border: 1px solid var(--line);
  padding: 18px 16px 14px;
  text-align: center;
}

.result-modal footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.result-modal footer button {
  flex: 1;
}

.modal-x {
  position: absolute;
  right: 16px;
  top: 14px;
  width: 28px;
  height: 28px;
  background: transparent;
  color: #b6c4d6;
  font-size: 32px;
  line-height: 1;
}

.result-kicker {
  color: #93a3b9;
  font-weight: 800;
  font-size: 14px;
}

.result-modal h2 {
  margin: 2px 34px 12px;
  color: #e11d2f;
  font-size: 28px;
  font-weight: 500;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.result-codes {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.result-code-row {
  min-height: 54px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 38px;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  text-align: left;
}

.result-code-row span {
  color: #53647d;
  background: #faf4ea;
  border: 1px solid #dce5f1;
  border-radius: 5px;
  padding: 7px 9px;
  font-size: 12px;
}

.result-code-row strong {
  font-family: "Cascadia Mono", Consolas, "Microsoft JhengHei UI", monospace;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.copy-one {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  background: #fff5e5;
  color: var(--blue);
  border: 1px solid #cfe0ff;
  font-size: 0;
  position: relative;
}

.copy-one::before,
.copy-one::after {
  content: "";
  position: absolute;
  width: 11px;
  height: 13px;
  border: 2px solid var(--blue);
  border-radius: 2px;
  background: #fff5e5;
}

.copy-one::before {
  left: 12px;
  top: 9px;
}

.copy-one::after {
  left: 16px;
  top: 13px;
}

.result-modal .primary,
.result-modal .secondary {
  min-height: 50px;
  font-size: 16px;
}

.copy-all {
  background: #e8eef6;
  color: #253a56;
  border: 0;
}

@media (max-width: 1100px) {
  .topbar-inner,
  .page,
  .notice {
    width: min(100% - 32px, 940px);
  }

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

@media (max-width: 900px) {
  .topbar-inner {
    flex-wrap: wrap;
    padding: 10px 0;
  }

  .tabs {
    order: 3;
    width: 100%;
    flex-basis: 100%;
    height: 52px;
  }

  .tabs button {
    height: 52px;
  }

  .withdraw-layout,
  .grid-2,
  .account-form {
    grid-template-columns: 1fr;
  }

  .product-grid,
  .product-grid.mini,
  .combo-withdraw-grid,
  .combo-product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cart-panel {
    position: static;
  }

  .logs-toolbar {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .page,
  .notice,
  .topbar-inner {
    width: min(100% - 20px, 940px);
  }

  .product-grid,
  .product-grid.mini,
  .combo-withdraw-grid,
  .combo-product-grid {
    grid-template-columns: 1fr;
  }

  .logs-toolbar select,
  .log-search {
    width: 100%;
  }

  .page-title,
  .account-row,
  .combo-management-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .combo-editor-head {
    grid-template-columns: 30px 1fr;
  }

  .combo-editor-head .primary {
    grid-column: 1 / -1;
    width: 100%;
  }
}
