@font-face {
  font-family: system;
  src: local('Avenir Next'), local('Segoe UI');
}
:root {
  --paper: #f6f4ee;
  --ink: #253a32;
  --muted: #788079;
  --line: #e4e5dc;
  --green: #315b46;
  --orange: #c67a4b;
  --white: #fff;
  --red: #ad433a;
  font-family: system, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
button,
input,
select,
textarea {
  font: inherit;
}
button,
a {
  -webkit-tap-highlight-color: transparent;
}
button {
  cursor: pointer;
  border: 0;
}
button:disabled {
  opacity: 0.5;
  cursor: wait;
}
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 3px;
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #6b927a;
  outline-offset: 1px;
}
button.primary {
  background: var(--green);
  color: white;
  padding: 15px 22px;
  border-radius: 13px;
  font-weight: 600;
}
button.secondary {
  background: #e8ece3;
  color: var(--ink);
  padding: 13px 18px;
  border-radius: 12px;
}
button.quiet {
  padding: 10px;
  background: transparent;
  color: var(--green);
}
button.danger {
  background: #f7e5df;
  color: var(--red);
  padding: 12px;
  border-radius: 10px;
}
.brand {
  display: flex;
  gap: 11px;
  align-items: center;
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -1px;
}
.logo {
  display: grid;
  place-items: center;
  background: var(--green);
  color: #fff;
  width: 38px;
  height: 42px;
  border-radius: 11px;
  font-size: 24px;
}
.brand small {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 2px;
  display: block;
  color: var(--muted);
  margin-top: 1px;
}
.shell {
  max-width: 1180px;
  margin: auto;
  padding: 32px 36px 100px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 25px;
}
.account {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.avatar {
  background: #e5eadf;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-weight: bold;
}
.eyebrow {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
  text-transform: uppercase;
  margin: 0 0 12px;
}
.heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin: 40px 0 26px;
}
h1 {
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -1.6px;
  margin: 0 0 10px;
}
h2 {
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.6px;
  margin: 0 0 18px;
}
p {
  line-height: 1.6;
  margin: 8px 0;
  color: var(--muted);
}
.heading p {
  font-size: 14px;
}
.actions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.metric {
  padding: 23px;
  border: 1px solid var(--line);
  background: #fff9;
  border-radius: 15px;
}
.metric label {
  font-size: 12px;
  color: var(--muted);
}
.metric strong {
  font-size: 30px;
  font-weight: 500;
  display: block;
  margin-top: 10px;
  letter-spacing: -1px;
}
.metric small {
  font-size: 11px;
  color: var(--muted);
}
.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin: 25px 0 16px;
}
.tabs {
  display: flex;
  gap: 5px;
  background: #eaece4;
  padding: 5px;
  border-radius: 12px;
}
.tabs button {
  background: transparent;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 12px;
}
.tabs button.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 2px 4px #253a320a;
}
.search {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  padding: 12px;
  min-width: 220px;
}
.card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
}
.receipts {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.receipt {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  background: white;
  text-align: left;
  padding: 20px 23px;
  border-bottom: 1px solid var(--line);
}
.receipt:last-child {
  border-bottom: 0;
}
.receipt:hover {
  background: #fafaf6;
}
.receipt-icon {
  width: 45px;
  height: 49px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: #f2f1e9;
  color: #8b8c70;
  border-radius: 11px;
  font-size: 23px;
}
.receipt-main {
  flex: 1;
  min-width: 0;
}
.receipt-main strong {
  font-size: 14px;
  font-weight: 600;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.receipt-main small {
  font-size: 11px;
  color: var(--muted);
  display: block;
  margin-top: 5px;
}
.receipt-end {
  text-align: right;
  flex-shrink: 0;
}
.receipt-end b {
  font-size: 14px;
  font-weight: 600;
  display: block;
  margin-bottom: 7px;
}
.badge {
  display: inline-block;
  font-size: 10px;
  padding: 5px 8px;
  border-radius: 6px;
  font-weight: 600;
  background: #f5eadb;
  color: #8b6638;
}
.badge.approved {
  background: #e7f0e5;
  color: #3d6847;
}
.badge.processing,
.badge.pending {
  background: #e8edf4;
  color: #56718e;
}
.empty {
  text-align: center;
  padding: 56px 24px;
}
.empty-icon {
  font-size: 45px;
  color: var(--orange);
  margin-bottom: 14px;
}
.empty h2 {
  margin-bottom: 10px;
}
.empty p {
  max-width: 320px;
  margin: 0 auto 22px;
  font-size: 14px;
}
.bottom {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  margin-top: 23px;
}
.nav {
  display: flex;
  gap: 8px;
}
.nav button {
  background: transparent;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}
.nav button.active {
  color: var(--green);
  font-weight: 700;
}
.back {
  margin-bottom: 20px;
  background: transparent;
  color: var(--green);
  padding: 0;
  font-size: 13px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.preview {
  background: #e8e7df;
  border-radius: 13px;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.preview img {
  max-width: 100%;
  max-height: 620px;
  object-fit: contain;
}
.preview iframe {
  width: 100%;
  height: 560px;
  border: 0;
}
.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.field.full {
  grid-column: 1/-1;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 7px;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fcfcf9;
  padding: 12px;
  min-width: 0;
  color: var(--ink);
}
.field textarea {
  resize: vertical;
  min-height: 85px;
}
.field small {
  font-size: 10px;
  color: var(--muted);
  display: block;
  margin-top: 5px;
}
.check {
  display: flex;
  gap: 9px;
  align-items: center;
  font-size: 12px;
}
.check input {
  width: auto;
}
.notice {
  font-size: 12px;
  padding: 14px;
  border-radius: 10px;
  background: #f8efdf;
  color: #856442;
  line-height: 1.6;
  margin: 16px 0;
}
.notice.error {
  background: #f7e5df;
  color: var(--red);
}
.notice.success {
  background: #e7f0e5;
  color: var(--green);
}
.detail-actions {
  display: flex;
  gap: 9px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.history {
  margin-top: 18px;
  font-size: 12px;
}
details {
  padding: 16px 0;
  border-top: 1px solid var(--line);
  margin-top: 18px;
}
summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
pre {
  font-size: 11px;
  white-space: pre-wrap;
  max-height: 300px;
  overflow: auto;
  color: var(--muted);
}
.auth {
  max-width: 430px;
  margin: 8vh auto;
  padding: 0 22px;
}
.auth .brand {
  margin-bottom: 45px;
}
.auth h1 {
  font-size: 33px;
}
.auth .card {
  margin: 25px 0;
}
.auth .field {
  margin-bottom: 16px;
}
.auth button.primary {
  width: 100%;
}
.auth .server-toggle {
  margin-top: 20px;
  width: 100%;
  text-align: center;
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.settings-grid .card {
  margin-bottom: 20px;
}
.user-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.user-row small {
  color: var(--muted);
  display: block;
  font-size: 11px;
  margin-top: 4px;
}
.statusline {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.statusline span {
  color: var(--muted);
}
#toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 14px 22px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: 0 10px 30px #0002;
  max-width: 90vw;
  display: none;
  z-index: 9;
}
.queue {
  background: #edf0e7;
  border: 1px solid var(--line);
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 18px;
  font-size: 12px;
}
.scan-canvas {
  width: 100%;
  max-height: 450px;
  object-fit: contain;
  background: #e8e7df;
  touch-action: none;
  display: block;
  border-radius: 10px;
}
.scan-toolbar {
  flex-wrap: wrap;
  display: flex;
  gap: 8px;
  margin: 12px 0;
}
.scan-toolbar button {
  font-size: 12px;
}
.inline-error {
  color: var(--red);
  font-size: 13px;
  min-height: 20px;
}
.modal {
  position: fixed;
  inset: 0;
  background: #253a3290;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal .card {
  max-width: 460px;
  width: 100%;
}
/* Capture quality feedback */
.quality-ok {
  color: #3a7d44;
  font-weight: 600;
}
.quality-warn {
  color: #b55000;
  font-weight: 600;
}
.scan-parts {
  background: #f5f4ee;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 10px;
  font-size: 13px;
}
.muted {
  color: var(--muted);
  font-size: 12px;
}
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #ffffff60;
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 8px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
/* ── Live camera page ─────────────────────────────────────────────────────── */
.camera-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #000;
  overflow: hidden;
}
.camera-wrap {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
#camera-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.camera-status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 16px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.5));
}
#camera-status {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  display: block;
  min-height: 18px;
  text-align: center;
}
#camera-status.cam-ok {
  color: #7de5a0;
}
#camera-status.cam-warn {
  color: #f5a35a;
}
.camera-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px));
  background: #181e1b;
}
.camera-bar button.secondary,
.camera-bar button.quiet {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}
.camera-bar button.quiet {
  font-size: 12px;
}
.capture-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid rgba(255, 255, 255, 0.5);
  color: #000;
  font-size: 28px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.15);
  transition: transform 0.1s;
}
.capture-btn:active {
  transform: scale(0.94);
}
.camera-parts-count {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
  min-width: 60px;
}
/* ── Scan review ──────────────────────────────────────────────────────────── */
.scan-actions-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.scan-actions-row .primary {
  flex: 1 1 auto;
}
/* ── Display filter (grayscale/contrast overlay for review only) ─────────── */
.scan-canvas.filter-grayscale {
  filter: grayscale(1);
}
.scan-canvas.filter-contrast {
  filter: grayscale(1) contrast(1.6) brightness(1.1);
}
@media (max-width: 700px) {
  .shell {
    padding: 22px 18px 95px;
  }
  .topbar {
    padding-bottom: 18px;
  }
  .brand {
    font-size: 21px;
  }
  .account .username {
    display: none;
  }
  .heading {
    margin: 28px 0 22px;
    display: block;
  }
  .heading .actions {
    margin-top: 20px;
  }
  h1 {
    font-size: 31px;
  }
  .metrics {
    gap: 8px;
  }
  .metric {
    padding: 15px 12px;
  }
  .metric strong {
    font-size: 25px;
  }
  .metric label {
    font-size: 10px;
  }
  .metric small {
    font-size: 9px;
  }
  .toolbar {
    display: block;
  }
  .search {
    width: 100%;
    margin-top: 12px;
  }
  .tabs {
    width: 100%;
  }
  .tabs button {
    flex: 1;
    padding: 10px 5px;
  }
  .receipt {
    padding: 17px 14px;
    gap: 11px;
  }
  .receipt-main strong {
    font-size: 13px;
  }
  .receipt-icon {
    width: 37px;
    height: 43px;
  }
  .receipt-end b {
    font-size: 12px;
  }
  .bottom {
    font-size: 10px;
  }
  .nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fffffff5;
    border-top: 1px solid var(--line);
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
    justify-content: space-around;
    z-index: 3;
    backdrop-filter: blur(10px);
  }
  .nav button {
    font-size: 12px;
    padding: 8px 16px;
  }
  .detail-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .card {
    padding: 20px;
  }
  .preview {
    min-height: 200px;
  }
  .preview img {
    max-height: 340px;
  }
  .preview iframe {
    height: 350px;
  }
  .detail-actions button {
    flex: 1;
  }
  .fields {
    gap: 13px;
  }
  .auth {
    margin-top: 5vh;
  }
  .auth .brand {
    margin-bottom: 30px;
  }
  .scan-canvas {
    max-height: 360px;
  }
}

.language-picker {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  letter-spacing: 0;
  float: right;
}
.topbar .language-picker {
  float: none;
  margin-right: 14px;
}
.auth > .language-picker {
  margin-bottom: 12px;
}
.toolbar #uploader-filter {
  width: auto;
  min-width: 165px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}
@media (max-width: 700px) {
  .toolbar #uploader-filter {
    width: 100%;
    margin-top: 12px;
  }
}
.role-form {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.role-form label {
  flex: 1;
  min-width: 160px;
}
.role-form select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}
.role-form button {
  white-space: nowrap;
}

.product-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 85px 110px;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.product-row details {
  grid-column: 1/-1;
}
.product-row pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
@media (max-width: 500px) {
  .product-row {
    grid-template-columns: 1fr 1fr;
  }
  .product-row label:first-child {
    grid-column: 1/-1;
  }
}
.expense-panel h3 {
  margin-bottom: 4px;
}
.expense-panel select {
  min-width: 0;
  flex: 1 1 220px;
}
button.link {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

/* --- Drop overlay (drag & drop) --- */
#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(37, 58, 50, 0.82);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  z-index: 100;
  pointer-events: none;
  border: 4px dashed rgba(255, 255, 255, 0.6);
  border-radius: 0;
  letter-spacing: 0.02em;
}
#drop-overlay[hidden] {
  display: none;
}
body.drag-over #drop-overlay {
  display: flex;
}

/* --- Multi-upload page --- */
.multi-upload-list {
  list-style: none;
  padding: 0;
  margin: 0 0 18px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.multi-upload-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 13px;
}
.multi-upload-item .item-icon {
  font-size: 22px;
  flex-shrink: 0;
}
.multi-upload-item .item-name {
  flex: 1 1 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.multi-upload-item .item-status {
  flex-shrink: 0;
}
.multi-upload-item .item-error {
  color: #c0392b;
  font-size: 11px;
  display: block;
}
.multi-upload-progress {
  height: 3px;
  background: #c5c9b8;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.multi-upload-progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

/* --- PDF embed preview --- */
.preview embed {
  width: 100%;
  height: 560px;
  border: 0;
}
@media (max-width: 760px) {
  .preview embed {
    height: 380px;
  }
}

/* --- U7: Status chips --- */
.badge.ready {
  background: #e3eaf8;
  color: #2855a0;
}
.badge.preliminary {
  background: #fff3cd;
  color: #7a5c0e;
  font-style: italic;
}

/* --- U7: Day grouping --- */
.day-group {
  margin-bottom: 4px;
}
.day-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted, #888);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 12px 4px 4px;
  margin: 0;
}

/* --- U8: Confirm cards --- */
.confirm-cards {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.confirm-cards .eyebrow {
  margin-bottom: 10px;
}
.confirm-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.confirm-card:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}
.confirm-card-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.confirm-card-info strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}
.confirm-card-info small {
  font-size: 11px;
  color: var(--muted, #888);
}
.confirm-card-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
@media (max-width: 480px) {
  .confirm-card {
    flex-direction: column;
    align-items: flex-start;
  }
  .confirm-card-actions {
    width: 100%;
  }
  .confirm-card-actions button {
    flex: 1;
  }
}

/* --- PWA iOS install hint --- */
#pwa-hint {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9000;
  padding: 0 0 env(safe-area-inset-bottom, 0);
}
.pwa-hint-inner {
  background: var(--ink);
  color: var(--white);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.4;
}
.pwa-hint-inner span {
  flex: 1;
}
.pwa-hint-close {
  background: none;
  border: none;
  color: var(--white);
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  flex-shrink: 0;
}
