:root {
  color-scheme: light;
  --blue: #0b5bd3;
  --blue-dark: #0847a6;
  --blue-soft: #eaf2ff;
  --ink: #14213d;
  --muted: #63708a;
  --line: #dce3ee;
  --surface: #ffffff;
  --background: #f4f7fb;
  --danger: #b42318;
  --danger-soft: #feeceb;
  --success: #137a4b;
  --shadow: 0 12px 34px rgba(27, 49, 85, 0.09);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--background); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100%; color: var(--ink); background: var(--background); }
button, input, select { font: inherit; }
button, label.button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid rgba(11, 91, 211, .25); outline-offset: 2px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 14px max(18px, env(safe-area-inset-left));
  color: white;
  background: linear-gradient(135deg, #083b83, #0b67e8);
  box-shadow: 0 8px 22px rgba(8, 59, 131, .22);
}
.topbar h1 { margin: 1px 0 0; font-size: 1.55rem; letter-spacing: -.03em; }
.eyebrow, .step { margin: 0; font-size: .7rem; font-weight: 800; letter-spacing: .14em; }
.eyebrow { color: #bad5ff; }
.step { color: var(--blue); }
.header-actions { display: flex; align-items: center; gap: 8px; }
.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 5px 10px; border: 1px solid rgba(255,255,255,.35); border-radius: 999px; font-size: .75rem; font-weight: 700; background: rgba(0,0,0,.12); }
.badge.offline { background: #77341d; }

.app-shell { width: min(980px, 100%); margin: 0 auto; padding: 18px max(14px, env(safe-area-inset-right)) calc(38px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
.card, .notice { border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.card { margin-bottom: 16px; padding: 20px; }
.notice { margin-bottom: 16px; padding: 14px 16px; color: #153b70; background: #eaf4ff; box-shadow: none; line-height: 1.5; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.section-heading h2 { margin: 4px 0 0; font-size: 1.28rem; letter-spacing: -.02em; }
.count-pill { padding: 7px 10px; border-radius: 999px; color: var(--blue); background: var(--blue-soft); font-size: .78rem; font-weight: 800; white-space: nowrap; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
label > span, legend { display: block; margin-bottom: 7px; color: #46536b; font-size: .78rem; font-weight: 800; }
select, input[type="date"], input[type="url"] { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid #cdd6e4; border-radius: 12px; color: var(--ink); background: #fff; }
select:disabled { color: #8791a5; background: #f2f4f7; }
.stage-field { min-width: 0; margin: 0; padding: 0; border: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; min-height: 48px; padding: 3px; border: 1px solid #cdd6e4; border-radius: 12px; background: #f4f6f9; }
.segmented label { position: relative; min-width: 0; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: grid; place-items: center; height: 100%; margin: 0; border-radius: 9px; color: #5d687c; font-size: .82rem; font-weight: 900; }
.segmented input:checked + span { color: white; background: var(--blue); box-shadow: 0 3px 10px rgba(11,91,211,.22); }

.master-details { margin-top: 16px; border-top: 1px solid var(--line); }
.master-details summary { padding: 16px 0 0; color: var(--blue); cursor: pointer; font-weight: 800; }
.details-body { display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 12px; padding-top: 14px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 9px 14px; border: 1px solid transparent; border-radius: 12px; cursor: pointer; font-weight: 800; text-decoration: none; transition: transform .12s ease, opacity .12s ease, background .12s ease; }
.button:active { transform: scale(.97); }
.button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.button.primary { color: white; background: var(--blue); }
.button.primary:hover { background: var(--blue-dark); }
.button.secondary { color: #174b94; border-color: #b9cceb; background: #eef5ff; }
.button.ghost { color: #42516a; border-color: var(--line); background: white; }
.topbar .button.ghost { color: white; border-color: rgba(255,255,255,.45); background: rgba(255,255,255,.1); }
.button.danger { color: var(--danger); background: var(--danger-soft); }
.button.large { min-height: 54px; }
.button.compact { min-height: 34px; padding: 6px 10px; font-size: .76rem; }
.button.full { width: 100%; }

.capture-options { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 10px; }
.helper { margin: 10px 0 0; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.helper.centered { text-align: center; }
.camera-panel { margin-top: 18px; padding: 12px; border-radius: 18px; background: #07101f; }
.camera-frame { position: relative; overflow: hidden; width: 100%; max-height: min(66vh, 720px); aspect-ratio: 4 / 3; border-radius: 13px; background: #000; }
.camera-frame video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
.camera-flash { position: absolute; inset: 0; pointer-events: none; background: white; opacity: 0; }
.camera-flash.flash { animation: camera-flash .2s ease-out; }
@keyframes camera-flash { 0% { opacity: .9; } 100% { opacity: 0; } }
.live-chip { position: absolute; top: 12px; left: 12px; display: flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; color: white; background: rgba(0,0,0,.58); font-size: .7rem; font-weight: 900; }
.live-chip span { width: 8px; height: 8px; border-radius: 50%; background: #ff3b30; box-shadow: 0 0 0 4px rgba(255,59,48,.2); }
.camera-status-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 4px 0; color: #d8e5fa; font-size: .76rem; }
.camera-status-row p { margin: 0; }
.camera-controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 14px; margin-top: 12px; }
.shutter { display: grid; place-items: center; width: 74px; height: 74px; padding: 0; border: 4px solid white; border-radius: 50%; background: transparent; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.shutter span { width: 58px; height: 58px; border-radius: 50%; background: white; transition: transform .1s ease; }
.shutter:active span { transform: scale(.86); }
.shutter:disabled { opacity: .4; }
.camera-panel .helper { color: #aebbd0; }
.message { margin-top: 12px; padding: 12px 14px; border-radius: 12px; color: #174b94; background: #eef5ff; line-height: 1.45; }
.message.error { color: #84231b; background: #feeceb; }
.message.success { color: #0c6840; background: #eaf8f1; }

.gallery-heading { align-items: center; }
.gallery-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.empty-state { padding: 30px 18px; text-align: center; color: var(--muted); border: 1px dashed #cbd6e6; border-radius: 15px; background: #f9fbfe; }
.empty-icon { margin-bottom: 8px; color: #93a6c1; font-size: 2rem; }
.empty-state h3 { margin: 0 0 5px; color: #4c5b72; font-size: 1rem; }
.empty-state p { margin: 0; font-size: .84rem; }
.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.photo-card { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: white; }
.photo-preview { position: relative; display: block; width: 100%; aspect-ratio: 4 / 3; padding: 0; border: 0; cursor: pointer; background: #0b1220; }
.photo-preview img { display: block; width: 100%; height: 100%; object-fit: contain; }
.sequence { position: absolute; top: 9px; right: 9px; padding: 5px 8px; border-radius: 999px; color: white; background: rgba(0,0,0,.64); font-size: .7rem; font-weight: 900; }
.photo-meta { padding: 11px 12px 5px; }
.photo-meta p { margin: 0; }
.filename { overflow-wrap: anywhere; font-size: .78rem; font-weight: 800; }
.dimensions { margin-top: 4px !important; color: var(--muted); font-size: .7rem; }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 8px 10px 11px; }
.photo-actions .share-photo { grid-column: 1 / -1; }
.photo-actions .button { min-height: 38px; padding: 7px 9px; font-size: .72rem; }
.tips-card { border-color: #c7d8f0; color: #294362; background: #f2f7ff; box-shadow: none; }
.tips-card h2 { margin: 0 0 10px; font-size: 1rem; }
.tips-card ol { margin: 0; padding-left: 22px; line-height: 1.65; }
.tips-card p { margin: 10px 0 0; color: #5d6d82; font-size: .8rem; line-height: 1.5; }

.dialog { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.dialog[hidden] { display: none; }
.dialog-backdrop { position: absolute; inset: 0; background: rgba(4,12,26,.78); backdrop-filter: blur(3px); }
.dialog-card { position: relative; overflow: auto; width: min(680px, 100%); max-height: 100%; padding: 14px; border-radius: 18px; background: white; box-shadow: 0 26px 60px rgba(0,0,0,.3); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.dialog-header h2 { margin: 0; font-size: 1rem; }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 50%; cursor: pointer; color: #34445d; background: #eef2f7; font-size: 1.8rem; line-height: 1; }
.dialog-card img { display: block; width: 100%; max-height: 67vh; object-fit: contain; border-radius: 12px; background: #07101f; }
.preview-name { overflow-wrap: anywhere; margin: 10px 0 0; font-size: .78rem; font-weight: 800; }

@media (max-width: 720px) {
  .card { padding: 16px; border-radius: 17px; }
  .form-grid { grid-template-columns: 1fr; }
  .details-body { grid-template-columns: 1fr; align-items: stretch; }
  .capture-options { grid-template-columns: 1fr 1fr; }
  .capture-options .primary { grid-column: 1 / -1; }
  .gallery { grid-template-columns: 1fr; }
  .gallery-heading { align-items: flex-start; flex-direction: column; }
  .gallery-actions { width: 100%; justify-content: stretch; }
  .gallery-actions .button { flex: 1; }
}

@media (max-width: 420px) {
  .topbar h1 { font-size: 1.35rem; }
  .badge { font-size: .68rem; }
  .capture-options { grid-template-columns: 1fr; }
  .capture-options .primary { grid-column: auto; }
  .camera-controls { gap: 9px; }
  .camera-controls .button { padding-inline: 9px; font-size: .72rem; }
  .shutter { width: 68px; height: 68px; }
  .shutter span { width: 52px; height: 52px; }
}
