:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --ink: #17201b;
  --muted: #647066;
  --line: #d9ded6;
  --panel: #ffffff;
  --accent: #246b55;
  --accent-dark: #174b3c;
  --warn: #b24a2e;
  --warn-bg: #fff1eb;
  --ok-bg: #eaf6ef;
  --shadow: 0 12px 32px rgba(23, 32, 27, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC",
    "Microsoft JhengHei", sans-serif;
  background: linear-gradient(180deg, #edf2ee 0, var(--bg) 260px);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary,
.save-btn {
  color: var(--accent);
  border: 1px solid var(--line);
  background: #fff;
}

button.secondary:hover,
.save-btn:hover {
  color: var(--accent-dark);
  background: #f4f8f5;
}

.delete-btn {
  color: var(--warn);
  border: 1px solid #e0a38e;
  background: #fff;
}

.delete-btn:hover {
  color: #8f321e;
  background: var(--warn-bg);
}

.reject-btn {
  color: var(--warn);
  border: 1px solid #e0a38e;
  background: #fff;
}

.reject-btn:hover {
  color: #8f321e;
  background: var(--warn-bg);
}

.submit-claim-btn,
.complete-claim-btn {
  background: #7a9b8b;
}

.submit-claim-btn:hover,
.complete-claim-btn:hover {
  background: #527766;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 22px 16px 48px;
}

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

h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 42px);
  line-height: 1.08;
  letter-spacing: 0;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

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

.logout-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.8);
  font-weight: 800;
  text-decoration: none;
}

.logout-link:hover {
  color: var(--accent-dark);
  background: #fff;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  padding: 0;
  font-size: 24px;
}

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

.upload-panel {
  padding: 16px;
}

.ai-warning {
  margin-bottom: 14px;
  border: 1px solid #e0a38e;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--warn);
  background: var(--warn-bg);
  font-weight: 700;
}

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

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

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

input:focus,
select:focus {
  outline: 3px solid rgba(36, 107, 85, 0.18);
  border-color: var(--accent);
}

.upload-strip {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 12px;
  align-items: stretch;
  margin-top: 14px;
}

.file-drop {
  min-height: 74px;
  border: 1px dashed #aeb8af;
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
  cursor: pointer;
}

.file-drop input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.file-drop span {
  color: var(--ink);
  font-size: 16px;
}

.file-drop strong {
  font-size: 13px;
  color: var(--muted);
}

.upload-progress {
  margin: 10px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--accent-dark);
  background: var(--ok-bg);
  font-weight: 800;
}

.photo-preview-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.photo-preview-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.photo-preview-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #edf2ee;
}

.photo-preview-meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
}

.photo-preview-meta span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-preview-meta button {
  min-height: 32px;
  padding: 0 10px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 12px;
  margin: 18px 0 12px;
}

.stats,
.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.actions select,
.actions input {
  width: auto;
  min-width: 132px;
}

.stat-filter {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.76);
}

.stat-filter:hover,
.stat-filter.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.selection-summary {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.draft-list {
  display: grid;
  gap: 12px;
}

.receipt-card {
  position: relative;
  display: grid;
  grid-template-columns: 220px 1fr;
  overflow: hidden;
}

.receipt-card.flagged {
  border-color: #e0a38e;
}

.receipt-photo {
  width: 100%;
  height: 100%;
  min-height: 250px;
  object-fit: cover;
  background: #edf0eb;
}

.select-box {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 14px rgba(23, 32, 27, 0.12);
}

.select-box input {
  width: 18px;
  height: 18px;
  min-height: auto;
  padding: 0;
}

.select-box span {
  font-size: 13px;
  white-space: nowrap;
}

.select-box.disabled {
  opacity: 0.42;
}

.receipt-body {
  padding: 14px;
}

.receipt-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 8px;
}

.receipt-title {
  display: block;
  font-size: 18px;
}

.receipt-source {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.badge,
.flag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge {
  color: var(--accent-dark);
  background: var(--ok-bg);
}

.badge.pending {
  color: var(--warn);
  background: var(--warn-bg);
}

.flag-row {
  display: flex;
  gap: 6px;
  min-height: 28px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.flag {
  color: var(--warn);
  background: var(--warn-bg);
}

.ai-error {
  display: none;
  margin: 0 0 10px;
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--warn);
  background: var(--warn-bg);
  font-size: 13px;
  font-weight: 700;
}

.ai-error.show {
  display: block;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.export-meta,
.rejection-meta {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.rejection-meta {
  color: var(--warn);
  font-weight: 800;
}

.receipt-card.exported .edit-grid input,
.receipt-card.exported .edit-grid select {
  background: #f8faf7;
}

.empty {
  display: none;
  margin-top: 36px;
  text-align: center;
  color: var(--muted);
}

.empty h2 {
  color: var(--ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(120%);
  width: min(520px, calc(100vw - 32px));
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: rgba(23, 32, 27, 0.92);
  transition: transform 180ms ease;
  z-index: 5;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 760px) {
  .app-shell {
    padding-inline: 12px;
  }

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

  .upload-strip,
  .receipt-card {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .actions select,
  .actions input {
    width: 100%;
  }

  .receipt-photo {
    max-height: 320px;
  }
}

@media (max-width: 430px) {
  .field-grid,
  .edit-grid,
  .actions {
    grid-template-columns: 1fr;
  }

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