:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #f0eeeb;
  --text: #1d1b19;
  --muted: #6b665f;
  --border: #dedad4;
  --accent: #d9232a;
  --accent-ink: #ffffff;
  --accent-soft: #fbeaea;
  --ok: #1e7a45;
  --ok-soft: #e3f3e9;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --warn: #a15c07;
  --warn-soft: #fdf0dc;
  --na: #5f6b7a;
  --na-soft: #eceff3;
  --info: #1f5fa8;
  --info-soft: #e5eefa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412;
    --surface: #1f1d1b;
    --surface-2: #2a2825;
    --text: #efece8;
    --muted: #a39d95;
    --border: #3a3733;
    --accent: #e0524a;
    --accent-ink: #1a0b0a;
    --accent-soft: #3a1e1c;
    --ok: #5cc98a;
    --ok-soft: #173325;
    --bad: #f07268;
    --bad-soft: #3b1d1a;
    --warn: #e7a547;
    --warn-soft: #3a2a12;
    --na: #9aa6b4;
    --na-soft: #262b31;
    --info: #7fb0ea;
    --info-soft: #1a2838;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.hidden { display: none !important; }

/* ---------- topo ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; white-space: nowrap; }
.brand img { height: 28px; width: auto; max-width: 90px; object-fit: contain; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin-left: auto; }
.topbar nav a {
  padding: 7px 11px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; font-weight: 500;
}
.topbar nav a.on { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 520px) {
  .topbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .brand span { display: none; }
  .topbar nav { gap: 0; }
  .topbar nav a { padding: 7px 6px; font-size: .9rem; }
}

.container { max-width: 980px; margin: 0 auto; padding: 18px 16px 80px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; font-size: .85rem; margin-bottom: 4px; text-decoration: none; }

/* ---------- componentes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card h2 { margin-bottom: 12px; }
.grid { display: grid; gap: 12px; }
@media (min-width: 640px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }

.btn, button {
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; font-weight: 600;
}
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger, button.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.ghost, button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.block, button.block { width: 100%; }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

label.field { display: block; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; min-height: 42px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: auto; min-height: 0; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700;
  background: var(--na-soft); color: var(--na); white-space: nowrap;
}
.st-agendada { background: var(--info-soft); color: var(--info); }
.st-em_andamento { background: var(--warn-soft); color: var(--warn); }
.st-concluida { background: var(--ok-soft); color: var(--ok); }
.st-cancelada { background: var(--na-soft); color: var(--na); }
.b-C { background: var(--ok-soft); color: var(--ok); }
.b-NC { background: var(--bad-soft); color: var(--bad); }
.b-AUS { background: var(--warn-soft); color: var(--warn); }
.b-NA { background: var(--na-soft); color: var(--na); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { min-height: 36px; padding: 6px 12px; border-radius: 999px; font-weight: 500; }
.chips button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1 1 200px; }

.list { display: grid; gap: 10px; }
.item-card {
  display: block; color: inherit; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
}
.item-card:hover { border-color: var(--accent); }
.item-card .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.item-card .title { font-weight: 700; margin-top: 4px; }
.item-card .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .85rem; color: var(--muted); margin-top: 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

dl.kv { display: grid; grid-template-columns: minmax(110px, max-content) 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .88rem; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); }
table.data th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }

/* ---------- tarefa ---------- */
.tabs {
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border); margin-bottom: 16px;
  position: sticky; top: 52px; z-index: 10; background: var(--bg);
}
.tabs button {
  border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent;
  color: var(--muted); padding: 10px 12px; white-space: nowrap; min-height: 46px;
}
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { font-size: .75rem; background: var(--surface-2); color: var(--muted); padding: 1px 7px; border-radius: 999px; }

.field-log { display: grid; gap: 12px; }
@media (min-width: 640px) { .field-log { grid-template-columns: 1fr 1fr; } }
.log-box { border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px; }
.log-box h3 { margin-bottom: 8px; }
.dist-ok { color: var(--ok); font-weight: 600; }
.dist-far { color: var(--bad); font-weight: 600; }
.note { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 8px; font-size: .9rem; }

.summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.summary .badge { font-size: .85rem; padding: 4px 11px; }

.group { margin-bottom: 18px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hint { font-size: .85rem; color: var(--muted); margin: 4px 0 10px; }
.check-item {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
}
.check-item.s-C { border-left-color: var(--ok); }
.check-item.s-NC { border-left-color: var(--bad); }
.check-item.s-AUS { border-left-color: var(--warn); }
.check-item.s-NA { border-left-color: var(--na); }
.check-title { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; margin-bottom: 8px; }
.check-title button { min-height: 28px; padding: 0 8px; font-size: .8rem; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 8px; }
.seg button { min-height: 40px; padding: 4px; font-size: .82rem; font-weight: 600; }
.seg button.on[data-status=C] { background: var(--ok); border-color: var(--ok); color: #fff; }
.seg button.on[data-status=NC] { background: var(--bad); border-color: var(--bad); color: #fff; }
.seg button.on[data-status=AUS] { background: var(--warn); border-color: var(--warn); color: #fff; }
.seg button.on[data-status=NA] { background: var(--na); border-color: var(--na); color: #fff; }
.check-item textarea { min-height: 44px; }

.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; cursor: zoom-in; border: 1px solid var(--border); }
.upload-btn { position: relative; overflow: hidden; }
.upload-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.photo-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.photo-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; cursor: zoom-in; background: var(--surface-2); }
.photo-card .body { padding: 10px; display: grid; gap: 8px; }
.photo-card .row { display: flex; gap: 6px; align-items: center; }
.photo-card .row select { flex: 1; }

.sig-wrap { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
canvas.sig-pad { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.sig-img { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; max-width: 420px; }
.sig-img img { display: block; width: 100%; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth-brand img { width: 40px; height: 40px; }
.auth form { display: grid; gap: 12px; }
.error { color: var(--bad); font-size: .9rem; min-height: 1em; }

/* ---------- toast e lightbox ---------- */
#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 100;
  max-width: calc(100% - 32px); pointer-events: none;
}
#toast div {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}
#toast div.err { background: var(--bad); color: #fff; }
.lightbox {
  position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .88);
  display: grid; place-items: center; padding: 16px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: 6px; }

/* Identidade Prevebras */
.brand img { height: 34px; max-width: 140px; background: #fff; border-radius: 6px; padding: 2px 4px; }
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo img { width: 200px; max-width: 70%; height: auto; display: block; margin: 0 auto 12px; }
