/* ---------- Schneider-inspired tokens ---------- */
:root {
  --se-green: #3DCD58;
  --se-green-dark: #2FA847;
  --charcoal: #333333;
  --charcoal-2: #4A4A4A;
  --grey-100: #F5F5F5;
  --grey-200: #E6E6E6;
  --grey-400: #9FA0A4;
  --grey-600: #626469;
  --white: #FFFFFF;

  --low: #3DCD58;
  --low-bg: #E8F9EC;
  --medium: #F5A623;
  --medium-bg: #FFF3DF;
  --high: #DC0A0A;
  --high-bg: #FDE7E7;

  --radius: 12px;
  --tap: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--grey-100); color: var(--charcoal); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px; line-height: 1.35;
  min-height: 100vh; min-height: 100dvh;
  padding-bottom: calc(76px + var(--safe-bottom));
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
h1 { font-size: 24px; margin: 0 0 8px; font-weight: 700; }
h2 { font-size: 18px; margin: 0; }
.muted { color: var(--grey-600); }
code { background: var(--grey-200); padding: 1px 6px; border-radius: 4px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center;
  background: var(--charcoal); color: var(--white);
  padding: calc(8px + var(--safe-top)) 8px 8px;
  min-height: 52px;
  border-bottom: 4px solid var(--se-green);
}
.topbar-title { flex: 1; text-align: center; font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.topbar-back, .topbar-spacer { width: 48px; }
.topbar-back {
  background: none; border: 0; color: var(--white); font-size: 34px; line-height: 1;
  height: 44px; padding: 0; cursor: pointer;
}

/* ---------- Screens ---------- */
.screen { padding: 16px; max-width: 640px; margin: 0 auto; }
.screen-center { text-align: center; padding-top: 48px; }
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--grey-600); margin: 24px 0 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 28px; }
.row { display: flex; gap: 12px; }
.row .field { flex: 1; min-width: 0; }
.card { background: var(--white); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.kv { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--grey-200); }
.kv:last-of-type { border-bottom: 0; margin-bottom: 8px; }

/* ---------- Setup ---------- */
.setup-hero { text-align: center; padding: 24px 0 16px; }
.logo-mark {
  width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 14px;
  background: var(--se-green); color: var(--white);
  font-size: 44px; font-weight: 800; line-height: 72px;
}

/* ---------- Fields ---------- */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.field .opt { font-weight: 400; color: var(--grey-400); font-style: normal; }
.field input, .field textarea {
  width: 100%; font: inherit; font-size: 18px;
  padding: 14px; min-height: var(--tap);
  border: 2px solid var(--grey-200); border-radius: var(--radius);
  background: var(--white); color: var(--charcoal);
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--se-green); }
.hint { display: block; margin-top: 6px; color: var(--grey-600); font-size: 14px; }
.form-error { color: var(--high); font-weight: 600; margin: 0 0 12px; }
.saved-msg { color: var(--se-green-dark); font-weight: 700; margin: 10px 0 0; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -8px 0 16px; }
.chip {
  font: inherit; font-size: 14px; padding: 8px 12px; min-height: 40px;
  border: 1.5px solid var(--grey-200); background: var(--white); color: var(--charcoal-2);
  border-radius: 999px; cursor: pointer;
}
.chip:active { background: var(--grey-200); }

/* ---------- Buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: var(--tap); padding: 12px 16px;
  font: inherit; font-size: 17px; font-weight: 700;
  border: 2px solid transparent; border-radius: var(--radius); cursor: pointer;
  transition: transform .06s;
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--se-green); color: var(--white); }
.btn-primary:active { background: var(--se-green-dark); }
.btn-dark { background: var(--charcoal); color: var(--white); }
.btn-outline { background: var(--white); color: var(--charcoal); border-color: var(--grey-200); }
.btn-danger { background: var(--white); color: var(--high); border-color: var(--high); }
.btn-xl { min-height: 60px; font-size: 18px; }
.btn-hero { min-height: 76px; font-size: 21px; letter-spacing: .5px; box-shadow: 0 4px 12px rgba(61,205,88,.35); }
.btn-hero .plus { font-size: 32px; font-weight: 800; line-height: 1; }
.btn .ico { width: 26px; height: 26px; fill: currentColor; }
.ico { width: 22px; height: 22px; fill: currentColor; }
.btn-row { display: flex; gap: 12px; }

/* ---------- Photos ---------- */
.block { margin-bottom: 18px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 10px; }
.photo-grid:empty { display: none; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--grey-200); }
.photo-thumb:first-child { grid-column: 1 / -1; aspect-ratio: 4 / 3; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .rm {
  position: absolute; top: 6px; right: 6px; width: 36px; height: 36px;
  border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 20px; cursor: pointer;
}
.photo-actions { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Severity ---------- */
.severity-row { display: flex; gap: 10px; }
.sev {
  flex: 1; min-height: 78px; font: inherit; font-size: 15px; font-weight: 800; line-height: 1.5;
  border: 3px solid var(--grey-200); border-radius: var(--radius); background: var(--white); color: var(--charcoal);
  cursor: pointer;
}
.sev-low.active { border-color: var(--low); background: var(--low-bg); }
.sev-medium.active { border-color: var(--medium); background: var(--medium-bg); }
.sev-high.active { border-color: var(--high); background: var(--high-bg); }

.sev-panel { margin-top: 10px; border-radius: var(--radius); border-left: 6px solid; overflow: hidden; font-size: 15px; }
.sev-panel.low { background: var(--low-bg); border-color: var(--low); }
.sev-panel.medium { background: var(--medium-bg); border-color: var(--medium); }
.sev-panel.high { background: var(--high-bg); border-color: var(--high); }
.sev-panel-head {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  font: inherit; font-size: 16px; padding: 12px 14px; background: none; border: 0; color: inherit; cursor: pointer; text-align: left;
}
.sev-panel-head .chev { transition: transform .15s; }
.sev-panel.collapsed .chev { transform: rotate(-90deg); }
.sev-panel.collapsed .sev-panel-body { display: none; }
.sev-panel-body { padding: 0 14px 12px; }
.sev-panel-body p { margin: 0 0 8px; }
.sev-panel-body ul { margin: 0 0 8px; padding-left: 20px; }
.sev-panel-body li { margin: 2px 0; }

/* ---------- Report list ---------- */
.report-list { display: flex; flex-direction: column; gap: 10px; }
.report-card {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  background: var(--white); border: 0; border-radius: var(--radius); padding: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06); cursor: pointer; font: inherit; color: inherit;
  border-left: 6px solid var(--grey-200);
}
.report-card.low { border-left-color: var(--low); }
.report-card.medium { border-left-color: var(--medium); }
.report-card.high { border-left-color: var(--high); }
.report-card .thumb {
  width: 68px; height: 68px; flex: none; border-radius: 8px; background: var(--grey-200);
  object-fit: cover; display: flex; align-items: center; justify-content: center; color: var(--grey-400); font-size: 28px;
}
.report-card .body { flex: 1; min-width: 0; }
.report-card .loc { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.report-card .meta { font-size: 14px; color: var(--grey-600); margin-top: 2px; }
.report-card .badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--grey-600); padding: 32px 16px; }

.badge {
  display: inline-block; font-size: 12px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px; color: var(--white);
}
.badge.low { background: var(--low); }
.badge.medium { background: var(--medium); }
.badge.high { background: var(--high); }
.badge.status { background: var(--grey-200); color: var(--charcoal); }
.badge.status.open { background: var(--charcoal); color: var(--white); }
.badge.status.in_progress { background: #1E90FF; color: var(--white); }
.badge.status.closed { background: var(--grey-400); color: var(--white); }

.badge.sync { text-transform: none; letter-spacing: 0; font-weight: 700; }
.badge.sync.ok { background: var(--low-bg); color: var(--se-green-dark); }
.badge.sync.pending { background: var(--medium-bg); color: #9A5B00; }
.sync-note { max-width: 420px; margin: 8px auto 0; padding: 10px 14px; border-radius: var(--radius); font-weight: 600; font-size: 15px; }
.sync-note.ok { background: var(--low-bg); color: var(--se-green-dark); }
.sync-note.pending { background: var(--medium-bg); color: #9A5B00; }
.btn:disabled { opacity: .6; }

.badge.sync.resp { background: #E6F0FB; color: #1E78D2; }
.response-box { background: #E6F0FB; border-left: 5px solid #1E78D2; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.response-box .rb-head { font-weight: 800; color: #1E78D2; font-size: 14px; margin-bottom: 4px; }
.response-box p { margin: 4px 0; }
.response-box .rb-meta { font-size: 14px; color: var(--charcoal-2); }

/* ---------- Done ---------- */
.done-tick {
  width: 88px; height: 88px; border-radius: 50%; margin: 0 auto 20px;
  background: var(--se-green); color: var(--white); font-size: 52px; font-weight: 800; line-height: 88px;
}
.ref-big { font-size: 34px; font-weight: 800; letter-spacing: 1px; margin: 4px 0 8px; font-variant-numeric: tabular-nums; }

/* ---------- Detail ---------- */
.detail-photos { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px 14px; padding: 0 16px; }
.detail-photos img { height: 260px; max-width: 100%; border-radius: var(--radius); scroll-snap-align: start; flex: none; object-fit: cover; }
.detail-photos img:only-child { width: 100%; }
.detail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.detail-head .ref { font-size: 22px; font-weight: 800; }
.detail-table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius); overflow: hidden; }
.detail-table td { padding: 11px 14px; border-bottom: 1px solid var(--grey-200); vertical-align: top; }
.detail-table tr:last-child td { border-bottom: 0; }
.detail-table td:first-child { color: var(--grey-600); width: 36%; font-size: 14px; }
.detail-table td:last-child { font-weight: 600; word-break: break-word; }
.detail-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.status-select { font: inherit; font-size: 16px; font-weight: 700; padding: 8px 10px; border-radius: 8px; border: 2px solid var(--grey-200); background: var(--white); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--white);
  border-top: 1px solid var(--grey-200);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 64px; font: inherit; font-size: 12px; font-weight: 600;
  background: none; border: 0; color: var(--grey-600); cursor: pointer;
}
.tab.active { color: var(--charcoal); }
.tab .ico { width: 24px; height: 24px; }
.tab-report { color: var(--white); }
.tab-report .tab-ico {
  width: 40px; height: 40px; border-radius: 50%; background: var(--se-green);
  font-size: 30px; font-weight: 800; line-height: 40px; margin-top: -4px;
}
.tab-report { color: var(--se-green-dark); }
.tab-report.active .tab-ico { background: var(--se-green-dark); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--charcoal); color: var(--white); padding: 12px 18px; border-radius: 999px;
  font-weight: 600; z-index: 20; max-width: 90vw; text-align: center;
}

@media (min-width: 640px) {
  .photo-actions { flex-direction: row; }
}
