:root {
  --blue: #155eef;
  --blue-dark: #104bbd;
  --blue-soft: #eff4ff;
  --ink: #172033;
  --muted: #5f6b7c;
  --line: #dfe4ec;
  --surface: #ffffff;
  --background: #f5f7fb;
  --success: #087a4b;
  --success-soft: #e9f8f0;
  --warning: #8a4b08;
  --warning-soft: #fff5db;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --shadow: 0 10px 30px rgba(23, 32, 51, .08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--background); }
button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(21, 94, 239, .32);
  outline-offset: 2px;
}

.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; padding: 10px 14px; color: #fff; background: var(--ink); border-radius: 8px; }
.skip-link:focus { top: 12px; }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.app-header {
  position: sticky; top: 0; z-index: 20; min-height: 68px; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: rgba(255, 255, 255, .94); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; flex: 0 0 auto; color: var(--blue); }
.brand-title, .brand-subtitle { display: block; }
.brand-title { font-weight: 750; font-size: 17px; }
.brand-subtitle { margin-top: 2px; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.network-badge { padding: 6px 9px; color: var(--success); background: var(--success-soft); border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.network-badge.offline { color: var(--warning); background: var(--warning-soft); }

main { padding: 20px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.pilot-warning { width: min(1120px, 100%); margin: 0 auto 16px; padding: 12px 16px; border: 1px solid #f0b429; border-radius: 12px; background: #fff8df; color: #6b4600; font-size: .92rem; line-height: 1.4; }
.screen { width: min(1120px, 100%); margin: 0 auto; }
.centered { min-height: calc(100vh - 130px); display: grid; place-items: center; }
.loader { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-panel { width: min(470px, 100%); padding: 30px; }
.security-icon, .receipt-check { display: grid; place-items: center; width: 46px; height: 46px; color: #fff; background: var(--success); border-radius: 50%; font-weight: 900; font-size: 24px; }
.eyebrow { margin: 18px 0 6px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(24px, 5vw, 34px); line-height: 1.13; }
h2 { margin: 0; font-size: 20px; line-height: 1.25; }
.lead { color: var(--muted); line-height: 1.55; }

label { display: block; margin: 18px 0 7px; font-size: 14px; font-weight: 700; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 11px 12px; color: var(--ink); background: #fff;
  border: 1px solid #cbd2dd; border-radius: 10px;
}
textarea { resize: vertical; }
input:disabled, select:disabled, textarea:disabled { color: var(--muted); background: #f3f4f7; }
.field-hint { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.privacy-note { margin: 22px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; text-align: center; }
.optional { color: var(--muted); font-weight: 400; }

.button { min-height: 44px; padding: 10px 16px; border: 0; border-radius: 10px; font-weight: 750; cursor: pointer; }
.button:disabled { opacity: .52; cursor: not-allowed; }
.button-primary { color: #fff; background: var(--blue); box-shadow: 0 4px 12px rgba(21, 94, 239, .22); }
.button-primary:hover:not(:disabled) { background: var(--blue-dark); }
.button-secondary { color: var(--blue); background: var(--blue-soft); }
.button-quiet { color: var(--muted); background: transparent; }
.button-wide { width: 100%; margin-top: 20px; }
.text-button { min-height: 44px; padding: 4px 0; color: var(--blue); background: none; border: 0; font-weight: 700; cursor: pointer; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 20px; align-items: start; }
.main-column, .side-column { display: grid; gap: 18px; min-width: 0; }
.organisation-card { padding: 4px 2px; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.field-caption { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 650; }
.verified-badge { padding: 7px 10px; color: var(--success); background: var(--success-soft); border-radius: 999px; font-size: 12px; font-weight: 700; text-align: center; }
.upload-panel { padding: 24px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading .eyebrow { margin-top: 0; }
.section-heading.compact { align-items: start; }
.count-badge { padding: 6px 10px; color: var(--muted); background: #f0f2f6; border-radius: 999px; font-size: 12px; font-weight: 700; }

.capture-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 20px; }
.capture-button { min-height: 92px; padding: 13px; display: flex; align-items: center; gap: 11px; text-align: left; color: var(--ink); background: #fafbfc; border: 1px solid var(--line); border-radius: 13px; cursor: pointer; }
.capture-button:hover { border-color: #aebdf0; background: var(--blue-soft); }
.capture-button:disabled { opacity: .52; cursor: not-allowed; }
.capture-camera { background: var(--blue-soft); border-color: #c9d8ff; }
.capture-icon { width: 34px; height: 34px; flex: 0 0 auto; display: grid; place-items: center; color: var(--blue); background: #fff; border: 1px solid #d7e0f8; border-radius: 9px; font-size: 10px; font-weight: 850; }
.capture-button strong, .capture-button small { display: block; }
.capture-button strong { font-size: 13px; line-height: 1.25; }
.capture-button small { margin-top: 4px; color: var(--muted); font-size: 11px; }

.empty-state { min-height: 118px; margin-top: 16px; display: grid; place-content: center; justify-items: center; color: var(--muted); background: #fbfcfe; border: 1px dashed #cbd2dd; border-radius: 13px; text-align: center; }
.empty-state span { font-size: 28px; color: #9aa5b5; }
.empty-state p { margin: 5px 16px 0; font-size: 13px; }
.file-queue { margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; list-style: none; }
.file-card { min-width: 0; overflow: hidden; background: #fafbfc; border: 1px solid var(--line); border-radius: 12px; }
.preview { position: relative; height: 118px; display: grid; place-items: center; overflow: hidden; background: #eef1f5; }
.preview img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.file-glyph { display: grid; place-items: center; width: 54px; height: 64px; color: var(--danger); background: #fff; border: 1px solid #d9dee6; border-radius: 7px; box-shadow: 0 3px 8px rgba(0,0,0,.06); font-weight: 850; font-size: 12px; }
.file-glyph.generic { color: var(--blue); }
.file-meta { padding: 9px; }
.file-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 750; }
.file-size { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.file-actions { padding: 0 7px 8px; display: flex; justify-content: space-between; gap: 4px; }
.icon-button { min-width: 44px; min-height: 44px; display: inline-grid; place-items: center; color: var(--muted); background: transparent; border: 0; border-radius: 8px; cursor: pointer; }
.icon-button:hover { color: var(--blue); background: var(--blue-soft); }
.icon-button.danger:hover { color: var(--danger); background: var(--danger-soft); }

.form-grid { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.full-width { grid-column: 1 / -1; }
.message { margin-top: 16px; padding: 12px 14px; border-radius: 10px; font-size: 13px; line-height: 1.45; }
.message-warning { color: var(--warning); background: var(--warning-soft); border: 1px solid #f2d791; }
.message-error { color: var(--danger); background: var(--danger-soft); border: 1px solid #f4c3bd; }
.message-success { color: var(--success); background: var(--success-soft); border: 1px solid #b9e7cf; }
.progress-area { margin-top: 18px; padding: 14px; background: #f7f9fc; border-radius: 12px; }
.progress-copy { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
progress { width: 100%; height: 9px; margin-top: 10px; overflow: hidden; border: 0; border-radius: 999px; accent-color: var(--blue); }
progress::-webkit-progress-bar { background: #dde3ed; border-radius: 999px; }
progress::-webkit-progress-value { background: var(--blue); border-radius: 999px; }
.submit-row { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; }

.help-card, .history-card { padding: 18px; box-shadow: none; }
.help-card ul { margin: 14px 0 0; padding-left: 20px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.help-card li + li { margin-top: 8px; }
.history-list { margin: 12px 0 0; padding: 0; list-style: none; }
.history-item { padding: 10px 0; display: grid; grid-template-columns: 1fr auto; gap: 5px 8px; border-top: 1px solid #eef0f4; }
.history-item:first-child { border-top: 0; }
.history-main { font-size: 13px; font-weight: 700; }
.history-meta { color: var(--muted); font-size: 11px; }
.history-status { align-self: center; grid-row: 1 / 3; grid-column: 2; color: var(--success); font-size: 12px; font-weight: 750; }
.device-card { padding: 4px 2px; display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }

.receipt-card { padding: 24px; grid-template-columns: auto 1fr; gap: 16px; align-items: start; border-color: #bce6d0; background: linear-gradient(135deg, #fff, #f4fcf7); }
.receipt-card:not(.hidden) { display: grid; }
.receipt-card .eyebrow { margin-top: 4px; }
.success-text { color: var(--success); }
.receipt-security-status { display: inline-block; margin: 8px 0 0; padding: 6px 9px; color: var(--warning); background: var(--warning-soft); border-radius: 999px; font-size: 12px; font-weight: 700; }
.receipt-details { margin: 16px 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.receipt-details div { min-width: 0; }
.receipt-details dt { color: var(--muted); font-size: 11px; }
.receipt-details dd { margin: 4px 0 0; font-size: 13px; font-weight: 750; overflow-wrap: anywhere; }

dialog { width: min(430px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 16px; box-shadow: 0 20px 70px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(23, 32, 51, .5); }
.dialog-card { position: relative; padding: 24px; }
.dialog-card ol { color: var(--muted); line-height: 1.6; }
.dialog-close { position: absolute; right: 12px; top: 10px; width: 38px; height: 38px; color: var(--muted); background: transparent; border: 0; border-radius: 50%; font-size: 24px; cursor: pointer; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 80; max-width: calc(100% - 32px); padding: 11px 16px; transform: translateX(-50%); color: #fff; background: var(--ink); border-radius: 999px; box-shadow: var(--shadow); font-size: 13px; text-align: center; }
noscript { display: block; padding: 20px; text-align: center; }

@media (max-width: 880px) {
  .content-grid { grid-template-columns: 1fr; }
  .side-column { grid-template-columns: 1fr 1fr; }
  .device-card { grid-column: 1 / -1; }
}

@media (max-width: 650px) {
  .app-header { min-height: 60px; }
  .brand-subtitle, .network-badge { display: none; }
  main { padding-top: 14px; }
  .auth-panel { padding: 22px 18px; }
  .organisation-card { align-items: start; }
  .verified-badge { max-width: 110px; }
  .upload-panel { padding: 17px 14px; border-radius: 14px; }
  .capture-actions { grid-template-columns: 1fr; }
  .capture-button { min-height: 70px; }
  .file-queue { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
  .submit-row { position: sticky; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 8; margin: 20px -5px -5px; padding: 7px; background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(10px); }
  .submit-row .button-primary { flex: 1; }
  .side-column { grid-template-columns: 1fr; }
  .device-card { grid-column: auto; }
  .receipt-details { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
