:root {
  --bg: #e9ebe5;
  --surface: #f3f5ef;
  --text: #2c2f2a;
  --text-dim: #8a8f86;
  --green: #4f9c46;
  --green-press: #44883b;
  --on-green: #ffffff;
  --danger: #d6504a;
  --recording: #e04b45;
  --radius: 20px;
  --radius-sm: 14px;
  /* neumorphic shadows */
  --nm: 6px 6px 14px rgba(176,180,170,0.60), -6px -6px 14px rgba(255,255,255,0.95);
  --nm-sm: 3px 3px 8px rgba(176,180,170,0.55), -3px -3px 8px rgba(255,255,255,0.92);
  --nm-inset: inset 4px 4px 9px rgba(176,180,170,0.55), inset -4px -4px 9px rgba(255,255,255,0.95);
  --green-shadow: 0 9px 20px rgba(79,156,70,0.32);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
#app { position: relative; height: 100vh; height: 100dvh; width: 100%; overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
.screen { display: none; height: 100%; flex-direction: column; }
.screen.is-active { display: flex; }
.hidden { display: none !important; }

.ic { display: inline-flex; width: 20px; height: 20px; flex: 0 0 auto; }
.ic svg { width: 100%; height: 100%; display: block; }
.ic-lg { width: 38px; height: 38px; }

/* Top bar */
.topbar { position: relative; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 8px; min-height: 54px; }
.topbar-title { font-size: 17px; font-weight: 700; letter-spacing: -0.2px; }
.topbar-spacer { width: 44px; }
.icon-btn { background: none; border: none; color: var(--text); width: 44px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn .ic { width: 24px; height: 24px; }
.ed-note { margin-top: 12px; min-height: 70px; font-size: 15px; }
.text-btn { background: none; border: none; color: var(--green); font-size: 16px; font-weight: 700; cursor: pointer; padding: 8px 10px; }
.text-btn:disabled { color: var(--text-dim); }

/* Buttons */
.btn { border: none; border-radius: var(--radius-sm); font-weight: 650; font-size: 16px; padding: 15px 18px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 9px; width: 100%;
  transition: transform .06s ease, box-shadow .14s ease, opacity .12s ease; }
.btn .ic { width: 19px; height: 19px; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; }
.btn-lg { padding: 17px; font-size: 17px; }
.btn-primary { background: var(--green); color: var(--on-green); box-shadow: var(--green-shadow); }
.btn-primary:active { background: var(--green-press); }
.btn-secondary { background: var(--surface); color: var(--text); box-shadow: var(--nm-sm); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost.btn-danger { color: var(--danger); }
.btn-grow { flex: 1.4; }
.btn-inline { width: auto; }
.gen-row { display: flex; justify-content: center; margin-top: 10px; }

/* Home */
.home { flex: 1; display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 30px) 24px calc(env(safe-area-inset-bottom) + 26px); }
.home-hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.logo { width: 96px; height: 96px; border-radius: 28px; background: var(--surface); box-shadow: var(--nm);
  display: flex; align-items: center; justify-content: center; margin-bottom: 26px; color: var(--green); }
h1 { font-size: 34px; font-weight: 800; margin: 0; letter-spacing: -0.8px; color: var(--text); }
.brand-accent { color: var(--green); }
.subtitle { color: var(--text-dim); text-align: center; margin: 12px 0 0; max-width: 250px; line-height: 1.45; font-size: 16px; }
.home-actions { display: flex; flex-direction: column; gap: 14px; }
.home-foot { color: var(--text-dim); font-size: 12.5px; text-align: center; min-height: 18px; margin: 18px 0 0; line-height: 1.4; }

/* Capture */
.cap-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.capture-placeholder { flex: 1; margin: 8px 18px 0; border-radius: 24px; min-height: 0;
  background: var(--surface); box-shadow: var(--nm-inset); border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: var(--text-dim); font: inherit; padding: 24px; text-align: center; }
.capture-placeholder .ic { width: 72px; height: 72px; opacity: .55; }
.cap-ph-text { font-size: 15px; font-weight: 600; opacity: .8; }
.capture-placeholder:active { box-shadow: var(--nm-inset); color: var(--green); }
.capture-placeholder:active .ic { opacity: .8; }
.shutter-bar { display: flex; flex-direction: column; align-items: center; padding: 18px 0 calc(env(safe-area-inset-bottom) + 14px); }
.hint { color: var(--text-dim); font-size: 13px; margin: 0 0 16px; }
.shutter-row { display: flex; align-items: center; justify-content: center; gap: 44px; width: 100%; }
.round-btn { width: 50px; height: 50px; border-radius: 16px; background: var(--surface); box-shadow: var(--nm-sm);
  border: none; color: var(--text-dim); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.round-btn .ic { width: 22px; height: 22px; }
.round-btn:active { box-shadow: var(--nm-inset); }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: none; background: transparent; cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; }
.shutter-ring { width: 76px; height: 76px; border-radius: 50%; background: var(--green); border: 5px solid var(--surface);
  box-shadow: var(--green-shadow); transition: transform .08s ease; }
.shutter:active .shutter-ring { transform: scale(0.9); }
.shutter-spacer { visibility: hidden; }

.note-scroll { flex: 1; overflow-y: auto; padding: 16px 18px; -webkit-overflow-scrolling: touch; }
.photo-wrap { position: relative; width: 100%; height: 320px; border-radius: var(--radius); overflow: hidden; background: #c8ccc4; box-shadow: var(--nm-sm); touch-action: pan-y; }
#note-photo { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; transform-origin: 0 0; will-change: transform; -webkit-user-drag: none; user-select: none; }
.zoom-hint { position: absolute; bottom: 9px; left: 9px; width: 22px; height: 22px; border-radius: 7px; background: rgba(18,22,18,0.42); display: flex; align-items: center; justify-content: center; pointer-events: none; transition: opacity .25s ease; z-index: 2; }
.zoom-hint .ic { width: 13px; height: 13px; color: rgba(255,255,255,0.95); }
.zoomed .zoom-hint { opacity: 0; }
.retake { position: absolute; top: 12px; right: 12px; display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.92); color: var(--text); border: none; border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.retake .ic { width: 15px; height: 15px; }
.card { margin-top: 18px; background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--nm); }

/* Segmented Auto/Translate */
.seg { display: flex; background: var(--bg); border-radius: 13px; padding: 5px; gap: 5px; box-shadow: var(--nm-inset); }
.seg button { flex: 1; border: none; background: transparent; color: var(--text-dim); font-weight: 700; font-size: 14px;
  padding: 10px 10px; border-radius: 9px; cursor: pointer; transition: color .12s ease; }
.seg button.seg-on { background: var(--green); color: #fff; box-shadow: var(--green-shadow); }
.seg-help { color: var(--text-dim); font-size: 12.5px; margin: 10px 2px 16px; }

/* Record button */
.record { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 17px;
  border: none; border-radius: 14px; background: var(--green); color: #fff; font-size: 17px; font-weight: 700;
  cursor: pointer; margin-bottom: 14px; box-shadow: var(--green-shadow); transition: transform .06s ease; }
.record:active { transform: translateY(1px); }
.record .ic { width: 22px; height: 22px; }
.record.recording { background: var(--recording); box-shadow: 0 0 0 0 rgba(224,75,69,0.5); animation: pulse 1.3s infinite; }
.record.processing { background: var(--bg); color: var(--text-dim); box-shadow: var(--nm-inset); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(224,75,69,0.4); } 70% { box-shadow: 0 0 0 16px rgba(224,75,69,0); } 100% { box-shadow: 0 0 0 0 rgba(224,75,69,0); } }
.spinner { width: 20px; height: 20px; border: 2.5px solid rgba(140,143,134,0.3); border-top-color: var(--text-dim); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

textarea { width: 100%; background: var(--bg); color: var(--text); border: none; border-radius: 12px;
  padding: 14px; font-size: 17px; line-height: 1.45; resize: none; font-family: inherit; min-height: 96px; box-shadow: var(--nm-inset); }
textarea:focus, input:focus { outline: none; }

.action-bar, .footer { display: flex; gap: 12px; padding: 14px 18px calc(env(safe-area-inset-bottom) + 14px); background: var(--bg); }
.footer { display: block; }

/* Scroll screens */
.scroll { flex: 1; overflow-y: auto; padding: 16px 18px; -webkit-overflow-scrolling: touch; }
.field-label, .section-label { font-size: 11.5px; font-weight: 700; letter-spacing: 0.8px; color: var(--text-dim); display: block; margin-bottom: 9px; }
.section-label { margin-top: 8px; }
.title-input { width: 100%; background: var(--bg); color: var(--text); border: none; border-radius: var(--radius-sm); padding: 16px; font-size: 18px; font-weight: 650; font-family: inherit; box-shadow: var(--nm-inset);
  min-height: 0; resize: none; overflow: hidden; line-height: 1.35; display: block; }
.ed-title-small { padding: 10px 14px; font-size: 15px; font-weight: 600; border-radius: 11px; }
.muted { color: var(--text-dim); font-size: 13px; margin: 14px 0; }
.ed-meta { margin: 4px 2px 9px; }

.chip { display: inline-flex; align-items: center; gap: 7px; background: var(--surface); box-shadow: var(--nm-sm); border: none;
  color: var(--text); border-radius: 999px; padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; transition: transform .06s ease, box-shadow .12s ease; }
.chip:active { transform: translateY(1px); box-shadow: var(--nm-inset); }
.chip .ic { width: 16px; height: 16px; color: var(--green); }

.item-card { background: var(--surface); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; box-shadow: var(--nm); }
.item-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.item-label { font-size: 12px; font-weight: 800; letter-spacing: 0.5px; color: var(--green); text-transform: uppercase; }
.item-controls { display: flex; gap: 2px; }
.item-controls button { background: none; border: none; color: var(--text); width: 38px; height: 34px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 9px; }
.item-controls button:disabled { color: #c4c8be; }
.item-controls .del { color: var(--danger); }
.item-controls .ic { width: 19px; height: 19px; }

.det-actions { display: flex; flex-direction: column; gap: 12px; margin-bottom: 26px; }
.det-photo-frame { position: relative; width: 100%; height: 280px; border-radius: 14px; overflow: hidden; background: #c8ccc4; touch-action: pan-y; margin: 6px 0; }
.det-photo-frame img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; transform-origin: 0 0; will-change: transform; -webkit-user-drag: none; user-select: none; }

.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 4px; }
.empty-glyph { width: 80px; height: 80px; border-radius: 24px; background: var(--surface); box-shadow: var(--nm); display: flex; align-items: center; justify-content: center; color: var(--text-dim); margin-bottom: 12px; }
.empty .btn { width: auto; margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 26px); transform: translateX(-50%);
  background: #2c2f2a; color: #fff; padding: 13px 18px; border-radius: 12px; font-size: 14px; max-width: 84%; text-align: center; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,0.22); }

.report-row { display: flex; align-items: center; gap: 14px; background: var(--surface); border: none;
  border-radius: var(--radius); padding: 15px; margin-bottom: 14px; cursor: pointer; width: 100%; text-align: left; color: var(--text); font-family: inherit; box-shadow: var(--nm); transition: transform .06s ease, box-shadow .12s ease; }
.report-row:active { transform: scale(0.99); box-shadow: var(--nm-sm); }
.report-ic { width: 48px; height: 48px; border-radius: 14px; background: var(--bg); box-shadow: var(--nm-inset); display: flex; align-items: center; justify-content: center; color: var(--green); flex-shrink: 0; }
.report-ic .ic { width: 22px; height: 22px; }
.report-row .rtitle { font-size: 16px; font-weight: 700; }
.report-row .meta2 { color: var(--text-dim); font-size: 13px; margin-top: 3px; line-height: 1.35; }
.report-row .chev { margin-left: auto; color: var(--text-dim); }
.reports-hint { text-align: center; color: var(--text-dim); font-size: 12px; padding: 8px 0 10px; }

/* Confirm dialog */
.modal-backdrop { position: fixed; inset: 0; background: rgba(44,47,42,0.45); display: flex; align-items: center; justify-content: center; padding: 28px; z-index: 200; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 340px; box-shadow: 0 18px 50px rgba(44,47,42,0.28); }
.modal p { margin: 0 0 18px; font-size: 16px; line-height: 1.45; color: var(--text); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }
.modal-actions.stack { flex-direction: column-reverse; gap: 8px; }
.modal-actions.stack .btn { width: 100%; }
.btn-danger-solid { background: var(--danger); color: #fff; box-shadow: 0 9px 20px rgba(214,80,74,0.3); }

/* Home gear + Settings */
#screen-home { position: relative; }
.home-gear { position: absolute; top: calc(env(safe-area-inset-top) + 14px); right: 18px; width: 44px; height: 44px; border-radius: 14px;
  background: var(--surface); box-shadow: var(--nm-sm); border: none; color: var(--text-dim); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; z-index: 5; }
.home-gear:active { box-shadow: var(--nm-inset); }
.home-gear .ic { width: 22px; height: 22px; }
.settings-note { margin-top: 26px; }
.settings-note p { color: var(--text-dim); font-size: 14px; line-height: 1.5; margin: 0 0 14px; }
.settings-note strong { color: var(--text); font-weight: 700; }

/* Permission (allow) step */
.permit { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 24px 28px calc(env(safe-area-inset-bottom) + 28px); }
.permit-icon { width: 88px; height: 88px; border-radius: 26px; background: var(--surface); box-shadow: var(--nm); color: var(--green);
  display: flex; align-items: center; justify-content: center; margin-bottom: 22px; }
.permit h2 { font-size: 22px; font-weight: 800; margin: 0 0 12px; color: var(--text); }
.permit-text { color: var(--text-dim); font-size: 15px; line-height: 1.5; max-width: 320px; margin: 0 0 28px; }
.permit .btn { width: auto; min-width: 200px; }

/* ---- photo source chooser (start of a report) ---- */
.source-choice { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; padding: 24px; }
.source-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: var(--surface); border: none; border-radius: var(--radius); box-shadow: var(--nm); color: var(--text); padding: 34px 20px; font-size: 17px; font-weight: 650; font-family: inherit; cursor: pointer; }
.source-btn .ic { width: 34px; height: 34px; color: var(--green); }
.source-btn:active { box-shadow: var(--nm-inset); }
.source-btn.preferred { box-shadow: var(--nm), inset 0 0 0 2px var(--green); }

/* ---- editor item: big photo block + note (tap opens the note screen) ---- */
.item-open { display: block; width: 100%; background: none; border: none; padding: 0; text-align: left; font-family: inherit; color: var(--text); cursor: pointer; }
.item-photo { display: block; width: 100%; height: 280px; border-radius: 14px; overflow: hidden; background: #c8ccc4; }
.item-photo img { width: 100%; height: 100%; object-fit: cover; display: block; -webkit-user-drag: none; }
.item-note { display: block; width: 100%; margin-top: 12px; padding: 12px 14px; background: var(--bg); border-radius: 12px; box-shadow: var(--nm-inset); font-size: 16px; line-height: 1.45; color: var(--text); }
.item-note.is-empty { color: var(--text-dim); font-style: italic; }

/* ---- editor add controls (sticky mode primary + switch) ---- */
#ed-footer { display: flex; gap: 10px; align-items: stretch; }
.ed-add-primary { flex: 1; }
.ed-add-secondary { flex-shrink: 0; width: 56px; height: auto; background: var(--surface); box-shadow: var(--nm-sm); border-radius: 16px; color: var(--green); }
.ed-add-secondary .ic { width: 24px; height: 24px; }
.ed-add-secondary:active { box-shadow: var(--nm-inset); }
