:root {
  --paper: #f5f1ea;
  --ink: #23211e;
  --muted: #706b63;
  --line: #d8d0c2;
  --panel: #fffaf2;
  --panel-strong: #fff6e6;
  --green: #2e6d58;
  --green-dark: #174a3b;
  --amber: #b77a21;
  --red: #a34737;
  --blue: #315b7d;
  --shadow: 0 18px 50px rgba(51, 42, 30, 0.16);
  font-family: "Avenir Next", "Noto Sans TC", "PingFang TC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(46, 109, 88, 0.1), transparent 34%),
    linear-gradient(225deg, rgba(183, 122, 33, 0.14), transparent 30%),
    var(--paper);
  color: var(--ink);
}

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

.app-shell {
  min-height: 100vh;
}

.is-hidden {
  display: none !important;
}

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

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.94);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-mark {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.7rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 8px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf8;
  color: var(--ink);
  min-height: 42px;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(46, 109, 88, 0.25);
  outline-offset: 2px;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  min-height: 42px;
}

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

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button {
  display: grid;
  place-items: center;
  background: var(--green);
  color: #fff;
}

.ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.52);
  color: var(--ink);
  padding: 0 14px;
}

.command-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #efe4d4;
  color: var(--ink);
  padding: 0 16px;
  font-weight: 800;
}

.command-button.primary {
  background: var(--green);
  color: #fff;
}

.workspace {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

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

.work-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(360px, 1.1fr);
  gap: 16px;
}

.camera-panel,
.form-panel {
  border: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.92);
  box-shadow: var(--shadow);
  padding: 14px;
}

.camera-frame {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  min-height: 480px;
  background: #191a18;
  color: #fff;
  border-radius: 6px;
}

video,
canvas {
  width: 100%;
  height: 100%;
  min-height: 480px;
  object-fit: cover;
}

.receipt-frame,
.scan-frame {
  position: absolute;
  display: grid;
  place-items: center;
}

.camera-frame.is-qr-mode .receipt-frame,
.camera-frame.is-receipt-mode .scan-frame {
  display: none;
}

.receipt-frame {
  inset: 5%;
  border: 2px dashed rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.18);
}

.receipt-frame span {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 280px;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.9);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
  padding: 6px 10px;
}

.scan-frame {
  width: min(54%, 260px);
  min-width: 170px;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.82);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.12);
}

.scan-frame::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 3px solid rgba(244, 191, 91, 0.9);
}

.scan-frame span {
  position: absolute;
  bottom: -34px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 220px;
  border-radius: 999px;
  background: rgba(25, 26, 24, 0.78);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 6px 10px;
}

.qr-feedback {
  position: absolute;
  top: 64px;
  left: 50%;
  z-index: 4;
  transform: translate(-50%, -8px);
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 32px);
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 999px;
  background: rgba(45, 124, 94, 0.96);
  box-shadow: 0 14px 34px rgba(10, 34, 28, 0.28);
  color: #fff;
  font-size: 0.98rem;
  font-weight: 900;
  line-height: 1.25;
  opacity: 0;
  padding: 10px 14px;
  pointer-events: none;
  text-align: center;
  transition: opacity 160ms ease, transform 160ms ease;
}

.qr-feedback::before {
  content: "✓";
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}

.qr-feedback.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.camera-empty {
  position: absolute;
  color: rgba(255, 255, 255, 0.82);
  font-weight: 800;
}

.camera-actions,
.submit-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.scan-status,
.message {
  color: var(--muted);
  font-size: 0.9rem;
}

.scan-status.is-error {
  color: var(--red);
}

.scan-status.is-success {
  color: var(--green-dark);
  font-weight: 800;
}

.manual-qr {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.manual-qr summary {
  cursor: pointer;
  color: var(--blue);
  font-weight: 800;
}

.manual-qr textarea {
  margin: 10px 0;
}

.preview-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 14px;
}

.photo-preview {
  display: grid;
  place-items: center;
  min-height: 140px;
  background: var(--panel-strong);
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 6px;
  overflow: hidden;
  text-align: center;
  font-weight: 800;
}

.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.summary-strip {
  display: grid;
  gap: 8px;
  align-content: center;
  border-left: 4px solid var(--green);
  background: #fffdf8;
  padding: 14px;
}

.summary-strip strong {
  font-size: 2rem;
  line-height: 1;
}

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

.wide-field {
  grid-column: 1 / -1;
}

.message {
  min-height: 20px;
  margin: 0;
}

.message.is-error {
  color: var(--red);
}

.message.is-success {
  color: var(--green-dark);
}

@media (max-width: 860px) {
  .workspace {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

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

  .camera-frame,
  video,
  canvas {
    min-height: 58vh;
  }
}

@media (max-width: 560px) {
  .field-grid,
  .preview-row {
    grid-template-columns: 1fr;
  }

  .camera-actions .command-button,
  .submit-row .command-button {
    width: 100%;
  }

  .summary-strip strong {
    font-size: 1.7rem;
  }
}
