:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  color: #172b22;
  background: #edf0ed;
  font-synthesis: none;
  --green: #17683e;
  --muted: #495d52;
  --line: #cbd5ce;
  --composer-height: 84px;
  --keyboard-inset: 0px;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
button { min-height: 56px; border: 1px solid transparent; border-radius: 10px; padding: 12px 18px; cursor: pointer; font-weight: 650; color: inherit; overflow-wrap: anywhere; }
button:disabled { cursor: not-allowed; background: #e1e6e2; border-color: #c7d0c9; color: #59655d; }
button:hover:not(:disabled) { filter: brightness(.96); }
:focus-visible { outline: 3px solid #195ba6; outline-offset: 3px; }
input, textarea, select { min-width: 0; width: 100%; min-height: 56px; padding: 12px; border: 1px solid #7c9183; border-radius: 8px; color: #172b22; background: #fff; }
input:focus, textarea:focus, select:focus { outline: 3px solid #195ba6; outline-offset: 1px; }
textarea { resize: vertical; line-height: 1.6; }
input[data-missing="true"] { border-color: #98682b; background: #fffaf0; }
select { appearance: none; padding-right: 38px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%23172b22' stroke-width='2'/%3E%3C/svg%3E"); background-position: right 12px center; background-repeat: no-repeat; }
label { display: block; font-weight: 650; margin-bottom: 8px; }
label span:not(.confirmation span), h3 span { color: var(--muted); font-weight: 400; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.3rem; line-height: 1.4; }
h3 { font-size: 1.1rem; line-height: 1.5; }
a { color: #165f3a; }
small, .tiny, .muted, .eyebrow, .tag, .version { font-size: 1rem; color: var(--muted); }
.tiny, .muted { line-height: 1.6; }
.primary, .record-button { color: #fff; background: var(--green); }
.secondary { background: #fff; border-color: #879c8d; color: #174c30; }
.text-button { background: transparent; border-color: #879c8d; color: #174c30; }
.wide, .add-button { width: 100%; }
.center { text-align: center; }
.topbar { max-width: 760px; margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; background: #fff; }
.brand { color: #174c30; text-decoration: none; font-size: 1.4rem; font-weight: 750; display: flex; align-items: center; gap: 10px; }
.brand small { display: block; font-size: 1rem; font-weight: 400; }
.brand-icon, .language-mark, .sound-bars { display: none; }
#connection-status { text-align: right; font-size: 1rem; }
main { max-width: 760px; margin: 0 auto; padding: 0 16px 24px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 0; }
.tab { background: #fff; border-color: #879c8d; color: #174c30; }
.tab.active { background: #17683e; border-color: #17683e; color: #fff; }
.tab b { margin-left: 6px; font-variant-numeric: tabular-nums; }
.notice { background: #e2f2e6; border: 1px solid #648971; border-radius: 10px; padding: 14px; margin: 8px 0 16px; overflow-wrap: anywhere; }
.notice.error, .error-list { background: #fff1e9; border: 1px solid #b46a43; color: #733415; }
.error-list { border-radius: 10px; padding: 14px; margin: 18px 0; }
.error-list ul { padding-left: 24px; margin: 0; }
#create-view { padding-bottom: calc(var(--composer-height) + 24px); }
#conversation, .conversation { display: flex; flex-direction: column; gap: 16px; padding: 12px 0 24px; }
.message { padding: 14px 16px; border-radius: 12px; max-width: 92%; overflow-wrap: anywhere; white-space: pre-wrap; }
.message, .chat-order { font-size: 20px; line-height: 1.65; }
.user-message { align-self: flex-end; background: #d1efc3; border: 1px solid #a0c68d; border-top-right-radius: 3px; }
.system-message { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-top-left-radius: 3px; }
.message p + p { margin-top: 8px; }
.message time, .message-source, .message-label { display: block; color: var(--muted); margin-bottom: 6px; }
.chat-date, .date-divider { text-align: center; color: var(--muted); margin: 8px 0; }
.card, .chat-order, #draft-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; min-width: 0; overflow-wrap: anywhere; }
.chat-order { width: 100%; }
.chat-order h3, #draft-card h3 { margin-bottom: 10px; }
.chat-order header, .order-heading { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.chat-order ul { padding-left: 22px; margin: 12px 0; }
.chat-order li + li { margin-top: 10px; }
.chat-order .card-total { font-size: 1.5rem; font-weight: 750; font-variant-numeric: tabular-nums; margin: 14px 0; }
#draft-card { padding: 0; border: 0; background: transparent; }
#draft-card:empty { display: none; }
.order-actions, .chat-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.order-actions > button, .chat-actions > button { flex: 1 1 150px; }
.chat-order details { margin-top: 12px; }
.chat-order details p { white-space: pre-wrap; }
.audio-message { max-width: 100%; background: #fff; border: 1px solid var(--line); padding: 16px; border-radius: 12px; }
audio { display: block; width: 100%; max-width: 100%; margin: 12px 0; }
.audio-message button { margin: 8px 8px 0 0; }
.composer { position: fixed; z-index: 10; bottom: var(--keyboard-inset); left: 50%; transform: translateX(-50%); width: min(100%, 760px); background: #f5f6f5; border-top: 1px solid #a8b9ad; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px #172b2210; max-height: 60dvh; overflow-y: auto; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer-icon { flex: 0 0 48px; width: 48px; padding: 6px; background: transparent; color: #172b22; }
.composer-icon svg { width: 30px; height: 30px; vertical-align: middle; }
#more-actions span { display: block; font-size: 32px; line-height: 1; }
.composer textarea { resize: none; min-height: 56px; height: 56px; max-height: 110px; }
.text-compose { display: flex; flex: 1; min-width: 0; align-items: flex-end; gap: 6px; }
.text-compose textarea { flex: 1; }
#send-message { flex: 0 0 auto; padding: 12px 10px; }
#record-button { flex: 1; min-width: 0; margin: 0; padding: 10px 6px; background: #fff; border-color: #b3c1b7; color: #172b22; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; font-size: 1.1rem; }
#record-button.recording { background: #8a321c; color: #fff; }
#record-button svg { width: 22px; height: 24px; vertical-align: middle; }
#record-status:not(.sr-only) { margin: 8px 0; }
#cancel-record { width: 100%; color: #812d19; border-color: #9c4633; background: #fff2ed; margin: 8px 0; }
.composer-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.composer-actions button { min-height: 72px; padding: 12px 8px; background: #fff; }
#composer-actions > p { margin-top: 12px; }
#demo-panel { margin: 12px 0; padding: 12px; border: 1px solid #9d8b5f; border-radius: 10px; background: #fffbef; }
#demo-panel select, #demo-panel button { margin-top: 10px; width: 100%; }
summary { cursor: pointer; min-height: 56px; padding: 12px 0; font-weight: 650; }
.demo-note { border-left: 4px solid #977136; padding-left: 12px; margin: 14px 0; }
.demo-note p { margin-top: 8px; }
#editor-dialog { width: min(100% - 24px, 720px); max-height: calc(100dvh - 24px); margin: auto; padding: 0; border: 1px solid #879c8d; border-radius: 14px; background: #fff; color: #172b22; overflow-y: auto; overscroll-behavior: contain; }
#editor-dialog::backdrop { background: #14271bd1; }
#editor-dialog .editor { padding: 20px; border: 0; border-radius: 0; }
.dialog-heading, .section-head { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
#close-editor { flex-shrink: 0; background: #fff; border-color: #879c8d; }
.tag { background: #edf3ef; padding: 7px 10px; border-radius: 8px; }
.two-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.items-title { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 24px 0 12px; }
.item { padding: 20px 0; border-bottom: 1px solid var(--line); }
.item-top { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.item-top label { flex: 1; min-width: 0; margin: 0; }
.item-index { flex-shrink: 0; font-weight: 700; }
.remove-item { flex-shrink: 0; background: #fff; border-color: #b36b52; color: #812d19; padding: 12px; }
.item-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.item-fields label { min-width: 0; }
.item-fields input { padding: 10px; }
.line-total { text-align: right; margin-top: 10px; font-variant-numeric: tabular-nums; }
.add-button { background: #fff; border: 2px dashed #648971; color: #174c30; margin-top: 16px; }
.payment-fields { margin-top: 24px; }
.totals { background: #edf5ef; border: 1px solid #c2d6c8; border-radius: 10px; padding: 18px; margin: 22px 0; }
.totals > div { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.totals > div + div { border-top: 1px solid #c2d6c8; padding-top: 12px; }
.totals strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.totals small { display: block; }
#overpaid, .overpay-note { color: #733415; margin: 10px 0; }
.confirmation { display: flex; align-items: flex-start; gap: 12px; padding: 14px 0; min-height: 56px; font-weight: 500; }
.confirmation input { width: 28px; min-width: 28px; min-height: 28px; height: 28px; margin-top: 3px; accent-color: var(--green); }
.confirmation small { display: block; margin-top: 6px; }
#batch-target, #draft-storage { margin: 12px 0; }
#reset { width: 100%; margin-top: 14px; }
.batch-overview { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin: 18px 0; }
.batch-heading, .batch-bottom, .history-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px; }
.batch-heading > div { flex: 1 1 260px; min-width: 0; }
.current-number { font-size: 1.2rem; font-weight: 700; margin: 16px 0 8px; overflow-wrap: anywhere; }
.batch-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 18px 0; }
.batch-stats span { display: block; }
.batch-stats strong { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.batch-bottom button { flex-shrink: 0; }
.history-head { margin: 24px 0 14px; }
.history-row { width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; background: #fff; border-color: #879c8d; margin: 12px 0; padding: 16px; }
.history-row small { display: block; margin-top: 8px; }
#history-view .history-row { font-size: 20px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; }
#history-view .history-shop { overflow-wrap: anywhere; }
#history-view .history-amount { text-align: right; }
#history-view .history-payment { grid-column: 1 / -1; font-size: 18px; overflow-wrap: anywhere; }
#history-view .history-open { grid-column: 1 / -1; font-size: 18px; color: var(--green); }
/* Page 1 keeps its current-batch count; the records page lists every batch. */
body.view-history #order-count { display: none; }
#history-view #history-tools { margin-top: 24px; }
#history-view summary { min-height: 56px; padding: 14px 8px; cursor: pointer; font-size: 20px; }
#history-view #history-tools > p { margin: 16px 0; }
#history-view #receipt { font-size: 20px; }
#history-view .record-products { list-style: none; padding: 0; margin: 0; }
#history-view .record-products li { border-bottom: 1px solid var(--line); padding: 16px 0; break-inside: avoid; }
#history-view .record-products h3 { margin-bottom: 8px; }
@media (max-width: 380px) {
  #history-view .history-row { grid-template-columns: minmax(0, 1fr); }
  #history-view .history-amount { text-align: left; }
}
.empty { text-align: center; background: #fff; border: 1px dashed #879c8d; border-radius: 10px; padding: 24px 16px; margin: 20px 0; }
#receipt { margin-top: 20px; overflow-wrap: anywhere; }
.receipt-meta { color: var(--muted); margin: 16px 0; }
.receipt-table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 8px; border-bottom: 1px solid var(--line); }
th { background: #edf3ef; font-weight: 650; }
th:last-child, td:last-child { text-align: right; }
.receipt-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.receipt-actions button { flex: 1 1 160px; }
.receipt-source { white-space: pre-wrap; padding: 14px; background: #edf3ef; border-radius: 8px; margin-top: 12px; }
.document-heading { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 16px; padding-bottom: 22px; }
.document-heading h2 { font-size: 1.5rem; }
.document-code { color: #174c30; font-weight: 650; margin-top: 10px; }
.document-date { color: var(--muted); }
.document-date strong, .document-date span { display: block; }
.document-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid #c2d6c8; border-radius: 10px; background: #edf5ef; overflow: hidden; }
.document-metrics > div { padding: 16px; }
.document-metrics > div + div { border-left: 1px solid #c2d6c8; }
.document-metrics span { display: block; margin-bottom: 8px; }
.document-metrics strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.due-metric { background: #dcecdf; }
.export-panel { padding: 20px 0; }
.export-panel p { margin-top: 6px; }
.batch-entry { border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin: 0 0 20px; }
.supplier-heading { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.supplier-heading h3 { font-size: 1.3rem; margin-top: 8px; }
.entry-code { color: var(--muted); }
.payment-badge { padding: 6px 10px; border: 1px solid #87aa90; border-radius: 8px; color: #174c30; background: #edf5ef; }
.pending-payment { border-color: #a88c51; background: #fff4d9; color: #68460f; }
.entry-payment { display: flex; flex-wrap: wrap; gap: 10px 20px; padding: 16px 0; }
.entry-payment b { margin-left: 6px; font-variant-numeric: tabular-nums; }
.delivery-note { background: #edf3ef; padding: 12px; border-radius: 8px; }
.delivery-note span { display: block; color: var(--muted); margin-bottom: 6px; }
.source-details, .backup-panel { margin-top: 14px; }
.backup-panel { padding: 12px; background: #edf5ef; border: 1px solid #c2d6c8; border-radius: 10px; }
.backup-panel p { margin: 12px 0; }
.document-footer { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 16px; }
footer { color: var(--muted); padding: 24px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.app-dialog { width: min(640px, calc(100% - 24px)); max-height: 90dvh; padding: 24px; border: 1px solid var(--line); border-radius: 12px; color: inherit; font-size: 20px; overflow-y: auto; overflow-wrap: anywhere; }
.app-dialog::backdrop { background: #172b22b3; }
.app-dialog h2, .app-dialog h3, .app-dialog p, .app-dialog ul { margin-bottom: 12px; }
.app-dialog button { margin-top: 12px; }
.dialog-warning { padding: 12px; border-left: 4px solid #b46a43; background: #fff6ef; color: #733415; }
.dialog-error:not(:empty) { padding: 12px; background: #fff0e9; color: #812d19; }
.data-summary li { margin-bottom: 6px; }
.extract-notes { margin: 0 0 16px; padding: 12px 14px; border-left: 4px solid #977136; background: #fffaf0; }
.extract-notes ul { margin: 8px 0 0; padding-left: 22px; }
.pending-shops { margin: 8px 0 16px; padding: 12px; border: 1px dashed #977136; border-radius: 10px; background: #fffaf0; }
.backup-tools { display: grid; gap: 10px; margin: 12px 0 20px; }
#setup-banner p { margin-bottom: 12px; }
#purchase-editor { width: min(720px, calc(100% - 24px)); max-height: 90dvh; padding: 24px; border: 1px solid var(--line); border-radius: 12px; color: inherit; font-size: 20px; overflow-wrap: anywhere; }
#purchase-editor::backdrop { background: #172b2280; }
#purchase-editor h2, #purchase-editor h3, #purchase-editor label { margin-top: 16px; }
#purchase-editor [role="alert"]:not(:empty) { padding: 12px; background: #fff0e9; color: #812d19; }
#purchase-editor .purchase-edit-item { padding-bottom: 16px; border-bottom: 1px solid var(--line); }
#purchase-editor .purchase-edit-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
#purchase-editor .purchase-edit-actions { display: grid; gap: 12px; margin-top: 20px; }
#purchase-editor .revision-change, #receipt .revision-change { padding: 12px 0; border-bottom: 1px solid var(--line); white-space: pre-wrap; }
#receipt .revision-entry { margin-top: 20px; }
@media (max-width: 540px) {
  #purchase-editor { padding: 16px; }
  #purchase-editor .purchase-edit-fields { grid-template-columns: 1fr; gap: 0; }
}
@media (max-width: 540px) {
  main { padding-left: 12px; padding-right: 12px; }
  .topbar { padding: 14px 12px; flex-wrap: wrap; }
  .card, .chat-order, .batch-overview { padding: 16px; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .two-cols { grid-template-columns: 1fr; }
  #editor-dialog .editor { padding: 16px; }
  .item-top { flex-wrap: wrap; }
  .item-top label { flex-basis: calc(100% - 40px); }
  .remove-item { margin-left: auto; }
  .item-fields { grid-template-columns: 1fr; }
  .batch-stats, .document-metrics { grid-template-columns: 1fr; }
  .batch-stats > div { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
  .document-metrics > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 12px 14px; }
  .document-metrics > div + div { border-left: 0; border-top: 1px solid #c2d6c8; }
  .document-metrics span { margin: 0; }
  .batch-bottom button, .history-head button { width: 100%; }
  .batch-entry { padding: 14px; }
  .message { max-width: 96%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }
@media print {
  #purchase-editor, .app-dialog, #setup-banner, .extract-notes, .pending-shops { display: none !important; }
  #history-home, #back-to-records { display: none !important; }
  :root { font-size: 12px; color: #000; background: #fff; }
  body { background: #fff; color: #000; }
  .topbar, .tabs, #notice, #create-view, .composer, #editor-dialog, .batch-overview, .history-head, #history-view > p, #history-list, footer, button, .export-panel, .backup-panel, .source-details { display: none !important; }
  main { max-width: none; padding: 0; margin: 0; }
  #history-view, #receipt { display: block !important; }
  #receipt { border: 0; padding: 0; margin: 0; }
  .document-metrics { grid-template-columns: repeat(3, 1fr); }
  .document-metrics > div { display: block; }
  .document-metrics > div + div { border-top: 0; border-left: 1px solid #aaa; }
  .document-metrics strong, .totals strong { font-size: 24px; }
  .document-metrics, .supplier-heading, .entry-payment, .delivery-note, .totals { break-inside: avoid; }
  .batch-entry { border-color: #aaa; }
  .batch-entry h3 { break-after: avoid; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
  th, td { padding: 8px; }
  .receipt-table { overflow: visible; }
}

/* One-page review of every shop recognised from a text. Yellow only where a look is needed. */
#draft-card.review-page { background: none; border: 0; padding: 0; }
.review h2 { font-size: 1.35rem; margin: 4px 0 2px; }
.rv-sub { margin: 0 0 12px; color: var(--muted); font-size: 1rem; }
.rv-box { background: #fff; border: 1px solid #9aa59c; border-radius: 12px; padding: 12px; margin-bottom: 12px; font-size: 1rem; line-height: 1.45; cursor: pointer; }
.rv-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 1.1rem; }
.rv-top span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rv-meta { margin: 4px 0 8px; color: var(--muted); font-size: .95rem; }
.rv-line { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.rv-line > span { min-width: 0; }
.rv-line b { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.rv-line small { color: #6b5200; font-size: .85rem; }
.rv-y { background: #fff1b8; border-radius: 4px; }
.rv-ignore { min-height: 40px; padding: 6px 10px; font-size: .9rem; flex: 0 0 auto; }
.rv-edit { display: block; min-height: 44px; margin-top: 6px; padding: 8px 0; background: none; color: #1f6b3a; text-align: left; }
.rv-problems { background: #fff1b8; border: 1px solid #c9a227; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: .95rem; }
.rv-problems ul { margin: 6px 0 0; padding-left: 20px; }
.rv-save { font-size: 1.1rem; margin-bottom: 6px; }
