:root {
  color-scheme: light;
  --navy: #0b2b61;
  --blue: #0e58a8;
  --blue-light: #e8f1fb;
  --copper: #b66a2d;
  --copper-dark: #70401f;
  --ink: #142033;
  --muted: #617086;
  --surface: #ffffff;
  --line: #d8e0ea;
  --success: #14745a;
  --danger: #a52c32;
  --shadow: 0 12px 35px rgba(11, 43, 97, .12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: linear-gradient(180deg, #eef3f8 0, #f8f9fb 38%, #fff 100%); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }

.app-header { position: sticky; z-index: 10; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 70px; padding: .75rem max(1rem, env(safe-area-inset-left)); background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.brand-logo { display: block; width: 150px; max-height: 48px; object-fit: contain; object-position: left center; }
.header-actions { display: flex; align-items: center; gap: .5rem; }
.header-help-button { min-height: 38px; padding: .45rem .7rem; white-space: nowrap; }
.status-pill { border: 1px solid var(--line); border-radius: 999px; padding: .4rem .65rem; color: var(--muted); background: #fff; font-size: .78rem; white-space: nowrap; }
.status-pill.online { color: var(--success); border-color: #99cfbf; background: #effaf6; }
.status-pill.offline { color: var(--copper-dark); border-color: #dfb98e; background: #fff7ee; }

.shell { width: min(720px, 100%); margin: auto; padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom)); }
.hero { margin: .5rem 0 1rem; padding: 1.35rem; border-radius: 24px; color: #fff; background: linear-gradient(135deg, var(--navy), var(--blue)); box-shadow: var(--shadow); }
.hero h1 { margin: .2rem 0 .5rem; font-size: clamp(1.75rem, 7vw, 2.65rem); line-height: 1.05; }
.hero p:last-child { margin: 0; max-width: 55ch; line-height: 1.5; color: #e8f1fc; }
.eyebrow { margin: 0; color: var(--copper); font-size: .72rem; font-weight: 850; letter-spacing: .16em; }
.hero .eyebrow { color: #ffc88e; }

.install-card { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center; margin: 1rem 0; padding: 1rem 1.1rem; border: 1px solid #d7b48d; border-left: 5px solid var(--copper); border-radius: 16px; background: #fffaf5; box-shadow: 0 7px 22px rgba(11, 43, 97, .07); }
.install-card[hidden] { display: none; }
.install-card strong, .install-card span { display: block; }
.install-card strong { color: var(--navy); font-size: 1.05rem; }
.install-card span { margin-top: .25rem; color: var(--muted); line-height: 1.4; }

.card, .history-section { margin: 1rem 0; padding: 1.15rem; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: 0 7px 22px rgba(11, 43, 97, .07); }
.centered { text-align: center; padding: 2rem 1.2rem; }
h2 { margin: .2rem 0 .5rem; color: var(--navy); }
p { line-height: 1.45; }
label { display: grid; gap: .4rem; margin: .85rem 0; color: #263b59; font-weight: 700; }
label[hidden] { display: none; }
input, select, textarea { width: 100%; min-height: 48px; padding: .7rem .8rem; border: 1px solid #b7c4d4; border-radius: 11px; background: #fff; color: var(--ink); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid rgba(14, 88, 168, .23); outline-offset: 2px; border-color: var(--blue); }
.destination-row { display: grid; grid-template-columns: 1fr 48px; gap: .55rem; align-items: center; }

.primary-button, .quiet-button, .capture-button, .confirm-button, .icon-button { border: 0; border-radius: 12px; font-weight: 800; }
.primary-button { min-height: 48px; padding: .75rem 1rem; color: #fff; background: var(--blue); box-shadow: 0 4px 0 var(--navy); }
.quiet-button { min-height: 42px; padding: .6rem .8rem; color: var(--navy); border: 1px solid #b9c7d7; background: #fff; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; color: var(--navy); border: 1px solid var(--line); background: #fff; font-size: 1.4rem; }
.capture-button { display: grid; place-items: center; gap: .55rem; width: 100%; min-height: 185px; margin: 1rem 0; padding: 1rem; color: #fff; background: linear-gradient(145deg, var(--blue), var(--navy)); box-shadow: 0 7px 0 #071e43; font-size: 1.25rem; }
.capture-button:active, .primary-button:active { transform: translateY(2px); box-shadow: none; }
.camera-icon { display: grid; place-items: center; width: 64px; height: 52px; border: 3px solid #fff; border-radius: 10px; font-size: 2rem; }
.toggle-row, .check-row { display: flex; align-items: flex-start; gap: .65rem; font-weight: 500; }
.toggle-row input, .check-row input { width: 22px; min-width: 22px; min-height: 22px; margin: .1rem 0 0; }
.small-note { color: var(--muted); font-size: .87rem; }
.full-width { width: 100%; }

.section-heading, .dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.receipt-list { display: grid; gap: .7rem; margin-top: 1rem; }
.empty-state { padding: 1.5rem .75rem; text-align: center; color: var(--muted); border: 1px dashed #b7c4d4; border-radius: 14px; }
.receipt-item { display: grid; grid-template-columns: 68px 1fr auto; gap: .8rem; align-items: center; min-width: 0; padding: .65rem; border: 1px solid var(--line); border-radius: 14px; background: #fbfcfe; }
.receipt-thumb { width: 68px; height: 68px; border-radius: 10px; object-fit: cover; background: #e7edf4; }
.receipt-thumb-placeholder { display: grid; place-items: center; color: #fff; background: var(--success); font-size: 1.6rem; font-weight: 900; }
.receipt-copy { min-width: 0; }
.receipt-copy strong, .receipt-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.receipt-copy span { margin-top: .18rem; color: var(--muted); font-size: .82rem; }
.receipt-copy .receipt-error { overflow: visible; white-space: normal; overflow-wrap: anywhere; color: var(--danger); }
.receipt-view { margin-top: .5rem; padding: .4rem .55rem; font-size: .82rem; }
.receipt-detail-photo { width: 100%; height: auto; }
#receipt-detail-title, #receipt-detail-info, #receipt-detail-error, #receipt-detail-photo-note { overflow-wrap: anywhere; }
.upload-status { max-width: 100px; padding: .35rem .5rem; border-radius: 999px; background: var(--blue-light); color: var(--navy); font-size: .72rem; font-weight: 800; text-align: center; }
.upload-status.sent { background: #e9f8f2; color: var(--success); }
.upload-status.error { background: #fff0f0; color: var(--danger); }

dialog { border: 0; }
dialog::backdrop { background: rgba(7, 19, 36, .72); backdrop-filter: blur(3px); }
.dialog-card, .preview-dialog { width: min(620px, calc(100% - 1.25rem)); max-height: calc(100dvh - 1.25rem); margin: auto; padding: 1.1rem; border-radius: 20px; background: #fff; box-shadow: var(--shadow); overflow: auto; }
.dialog-card form { margin: 0; }
.dialog-actions, .capture-actions { display: flex; justify-content: flex-end; align-items: center; gap: .7rem; margin-top: 1rem; }
.capture-actions { flex-wrap: wrap; }
#receipt-amount-review { margin-top: 1rem; }
.quick-guide { display: grid; gap: .75rem; margin: 1rem 0; padding: 0; list-style: none; counter-reset: quick-guide; }
.quick-guide li { display: grid; grid-template-columns: 36px 1fr; gap: .15rem .7rem; align-items: start; padding: .75rem; border: 1px solid var(--line); border-radius: 14px; background: #f8fbff; counter-increment: quick-guide; }
.quick-guide li::before { content: counter(quick-guide); grid-row: 1 / 3; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 999px; color: #fff; background: var(--blue); font-weight: 900; }
.quick-guide strong, .quick-guide span { grid-column: 2; }
.quick-guide strong { color: var(--navy); }
.quick-guide span { color: var(--muted); line-height: 1.4; }
.tutorial-result { margin: 1rem 0; padding: .85rem 1rem; border-left: 5px solid var(--copper); border-radius: 12px; background: #fff7ee; }
.tutorial-result strong { color: var(--copper-dark); }
.tutorial-result p { margin: .35rem 0 0; }
.required { color: var(--danger); font-size: .75rem; }
.optional { color: var(--muted); font-size: .75rem; font-weight: 500; }
.turnstile-slot { min-height: 66px; margin: 1rem 0; }
.form-error { min-height: 1.3rem; margin: .5rem 0; color: var(--danger); font-weight: 700; }
.connection-recovery-message { padding: .75rem .85rem; border: 1px solid #d69a64; border-left: 5px solid var(--copper); border-radius: 10px; background: #fff8f0; color: #5d3516; font-weight: 700; text-align: left; }

.preview-dialog { padding: .75rem; }
.camera-dialog { width: min(720px, 100%); height: 100dvh; max-height: 100dvh; margin: auto; padding: max(.65rem, env(safe-area-inset-top)) .65rem max(.65rem, env(safe-area-inset-bottom)); border-radius: 0; color: #fff; background: #08111f; box-shadow: var(--shadow); overflow: auto; }
.camera-topbar { position: absolute; z-index: 2; top: 0; right: 0; left: 0; display: grid; gap: .35rem; padding: .65rem 4.7rem .9rem .65rem; background: linear-gradient(180deg, rgba(0,0,0,.82), transparent); }
.camera-topbar label { margin: 0; color: #fff; font-size: .72rem; }
.camera-destination-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .4rem; }
.camera-destination-row select { min-height: 40px; padding-block: .45rem; }
.camera-primary-button { min-height: 40px; padding: .45rem .55rem; border: 1px solid rgba(255,255,255,.5); border-radius: 10px; color: #fff; background: rgba(0,0,0,.48); font-size: .75rem; font-weight: 800; }
.camera-primary-button.is-primary { color: #28180a; border-color: #ffc264; background: #ffc264; }
.camera-shortcuts { position: absolute; z-index: 3; top: .55rem; right: .45rem; display: grid; gap: .4rem; }
.camera-icon-tool { display: grid; place-items: center; width: 58px; min-height: 55px; padding: .25rem; border: 1px solid rgba(255,255,255,.38); border-radius: 12px; color: #fff; background: rgba(0,0,0,.52); font-weight: 800; }
.camera-icon-tool span { font-size: 1.2rem; line-height: 1; }
.camera-icon-tool small { margin-top: .15rem; font-size: .62rem; }
.camera-tool-button { min-height: 42px; padding: .6rem .7rem; border: 1px solid rgba(255,255,255,.45); border-radius: 11px; color: #fff; background: rgba(255,255,255,.1); font-weight: 800; }
.camera-stage { position: relative; display: grid; place-items: center; height: min(66dvh, 720px); overflow: hidden; border-radius: 14px; background: #000; touch-action: none; }
.camera-stage video { width: 100%; height: 100%; object-fit: cover; }
.camera-hint { position: absolute; bottom: .65rem; left: 50%; margin: 0; padding: .4rem .65rem; border-radius: 999px; color: #fff; background: rgba(0,0,0,.62); font-size: .8rem; text-align: center; transform: translateX(-50%); white-space: nowrap; pointer-events: none; }
.focus-reticle { position: absolute; width: 58px; height: 58px; margin: -29px 0 0 -29px; border: 2px solid #ffc264; border-radius: 10px; box-shadow: 0 0 0 1px rgba(0,0,0,.35); pointer-events: none; animation: focus-pulse .55s ease-out; }
@keyframes focus-pulse { from { transform: scale(1.35); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.camera-zoom-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .75rem; margin: .55rem .15rem 0; color: #fff; }
.camera-zoom-row input { min-height: 34px; padding: 0; }
.camera-actions { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; }
.shutter-wrap { display: grid; justify-items: center; gap: .35rem; font-size: .78rem; font-weight: 800; }
.camera-action-spacer { width: 100%; }
.shutter-button { border: 6px solid #fff; border-radius: 999px; background: var(--copper); box-shadow: 0 0 0 3px rgba(255,255,255,.35); }
.preview-image-wrap { display: grid; place-items: center; height: min(58dvh, 600px); overflow: hidden; border-radius: 14px; background: #10151c; }
.preview-image-wrap img { width: 100%; height: 100%; object-fit: contain; }
.details-panel { margin-top: .7rem; padding: .75rem; border: 1px solid var(--line); border-radius: 12px; }
.details-panel summary { color: var(--navy); font-weight: 800; cursor: pointer; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }
.details-grid label:nth-last-child(-n+2) { grid-column: 1 / -1; }
.confirm-button { display: grid; place-items: center; width: 62px; height: 62px; color: #fff; background: var(--success); font-size: 2rem; box-shadow: 0 4px 0 #0c4d3b; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); width: min(500px, calc(100% - 2rem)); padding: .8rem 1rem; border-radius: 12px; color: #fff; background: var(--navy); box-shadow: var(--shadow); text-align: center; transform: translate(-50%, 140%); transition: transform .2s ease; }
.toast.visible { transform: translate(-50%, 0); }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

@media (max-width: 520px) {
  .brand-logo { width: 120px; }
  .shell { padding-inline: .7rem; }
  .hero { border-radius: 18px; }
  .card, .history-section { padding: .9rem; border-radius: 16px; }
  .receipt-item { grid-template-columns: 58px 1fr; }
  .receipt-thumb { width: 58px; height: 58px; }
  .upload-status { grid-column: 2; justify-self: start; }
  .details-grid { grid-template-columns: 1fr; }
  .details-grid label { grid-column: 1 !important; }
  .status-pill { max-width: 125px; overflow: hidden; text-overflow: ellipsis; }
  .header-help-button { padding-inline: .55rem; }
  .install-card { grid-template-columns: 1fr; }
  .install-card .primary-button { width: 100%; }
  .camera-dialog { padding-inline: .45rem; }
  .camera-stage { height: min(61dvh, 640px); }
  .camera-hint { max-width: calc(100% - 1rem); overflow: hidden; text-overflow: ellipsis; }
}

@media (display-mode: standalone) {
  .app-header { padding-top: calc(.75rem + env(safe-area-inset-top)); }
  .install-card { display: none; }
}
