/* ==========================================================================
   Gerenciador de Obras — app do celular
   Mobile-first (alvo 390 px). Tema claro/escuro por prefers-color-scheme.
   ========================================================================== */

:root {
  color-scheme: light dark;

  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --surface-3: #e9ecf2;
  --text: #11151c;
  --text-2: #394150;
  --muted: #667085;
  --border: rgba(16, 24, 40, 0.08);
  --border-strong: rgba(16, 24, 40, 0.18);

  --accent: #2563eb;
  --accent-text: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --accent-soft-2: rgba(37, 99, 235, 0.18);
  --btn-primary: #2563eb;
  --btn-primary-press: #1d4ed8;
  --on-primary: #ffffff;

  --success: #16a34a;
  --success-text: #15803d;
  --success-soft: rgba(22, 163, 74, 0.12);
  --success-col: rgba(22, 163, 74, 0.07);
  --on-success: #ffffff;   /* ✓ sobre --success: 3,3:1 (ícone) */
  --warning: #f59e0b;
  --warning-text: #9a5b06;
  --warning-soft: rgba(245, 158, 11, 0.16);
  --warning-col: rgba(245, 158, 11, 0.08);
  --danger: #dc2626;
  --danger-text: #b91c1c;
  --danger-soft: rgba(220, 38, 38, 0.10);
  --on-danger: #ffffff;    /* texto sobre --danger: 4,8:1 */

  --header-bg: rgba(255, 255, 255, 0.86);
  --toast-bg: #1b1f27;
  --toast-text: #f5f7fa;
  --toast-action: #9dbcff;
  --backdrop: rgba(10, 14, 22, 0.42);

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.07);
  --shadow-md: 0 6px 16px rgba(16, 24, 40, 0.08), 0 2px 4px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 22px 48px rgba(16, 24, 40, 0.22), 0 6px 14px rgba(16, 24, 40, 0.10);

  --avatar-s: 72%;
  --avatar-l: 90%;
  --avatar-fg-l: 30%;

  --gutter: 16px;
  --pad-l: max(var(--gutter), env(safe-area-inset-left, 0px));
  --pad-r: max(var(--gutter), env(safe-area-inset-right, 0px));
  --header-h: calc(60px + env(safe-area-inset-top, 0px)); /* recalculado pelo app.js */
  --tabbar-h: calc(64px + env(safe-area-inset-bottom, 0px));
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f13;
    --surface: #171a20;
    --surface-2: #1c2027;
    --surface-3: #272c35;
    --text: #edf0f5;
    --text-2: #c7cdd8;
    --muted: #8e97a8;
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.17);

    --accent: #6f9dff;
    --accent-text: #9dbcff;
    --accent-soft: rgba(111, 157, 255, 0.14);
    --accent-soft-2: rgba(111, 157, 255, 0.24);
    --btn-primary: #3a6ff0;
    --btn-primary-press: #2f5fd6;
    --on-primary: #ffffff;

    --success: #3ccf78;
    --success-text: #74e2a2;
    --success-soft: rgba(60, 207, 120, 0.14);
    --success-col: rgba(60, 207, 120, 0.06);
    --on-success: #0d0f13;   /* branco daria só 2,0:1; escuro dá 9,5:1 */
    --warning: #f5b43f;
    --warning-text: #f8cd72;
    --warning-soft: rgba(245, 180, 63, 0.14);
    --warning-col: rgba(245, 180, 63, 0.06);
    --danger: #f06a6a;
    --danger-text: #ff9c9c;
    --danger-soft: rgba(240, 106, 106, 0.14);
    --on-danger: #0d0f13;    /* branco daria só 3,0:1; escuro dá 6,4:1 */

    --header-bg: rgba(20, 23, 29, 0.86);
    --toast-bg: #eef1f6;
    --toast-text: #12161d;
    --toast-action: #2156d9;
    --backdrop: rgba(0, 0, 0, 0.58);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.38);
    --shadow-lg: 0 22px 48px rgba(0, 0, 0, 0.6), 0 6px 14px rgba(0, 0, 0, 0.35);

    --avatar-s: 34%;
    --avatar-l: 26%;
    --avatar-fg-l: 82%;
  }
}

/* ------------------------------------------------------------------ Base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  overflow-x: hidden; /* propaga para a viewport; nada deve rolar na horizontal */
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
h1, h2, h3, p { margin: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.noscript { padding: 24px; text-align: center; }

/* Ícones SVG (traço, herdam a cor do texto) */
.i {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}
.i-xs { width: 15px; height: 15px; }
.i-sm { width: 18px; height: 18px; }
.i-lg { width: 30px; height: 30px; }

/* ------------------------------------------------------------------ Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
  transition: background-color .15s ease, color .15s ease, opacity .15s ease;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active:not(:disabled) { scale: .98; }
.btn:disabled { opacity: .45; }
.btn-block { width: 100%; }
.btn-lg { min-height: 50px; font-size: 17px; }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 14.5px; border-radius: 10px; }
.btn-primary { background: var(--btn-primary); color: var(--on-primary); }
.btn-primary:active:not(:disabled) { background: var(--btn-primary-press); }
.btn-soft { background: var(--accent-soft); color: var(--accent-text); }
.btn-soft:active:not(:disabled) { background: var(--accent-soft-2); }
.btn-secondary { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger); color: var(--on-danger); }

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-2);
  transition: background-color .15s ease;
}
.icon-btn:active:not(:disabled) { background: var(--surface-3); }
.icon-btn:disabled { opacity: .35; }

@media (hover: hover) {
  .icon-btn:hover:not(:disabled) { background: var(--surface-3); }
  .btn-soft:hover:not(:disabled) { background: var(--accent-soft-2); }
  .btn-primary:hover:not(:disabled) { background: var(--btn-primary-press); }
}

/* Spinner (botão Entrar) */
.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  animation: girar .7s linear infinite;
}
.is-busy .spinner { display: inline-block; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ Campos */
.field-label {
  display: block;
  margin: 0 0 6px 2px;
  font-size: 14px;
  font-weight: 650;
  color: var(--text-2);
}

.field {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.field-icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; width: 20px; height: 20px; }
.field input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 6px 0 42px;
  border: 0;
  background: transparent;
  font-size: 16px; /* >= 16px: evita zoom automático no iOS */
  color: var(--text);
  outline: none;
  border-radius: 12px;
}
.field input::placeholder { color: var(--muted); opacity: .9; }
.field input[type="search"]::-webkit-search-cancel-button,
.field input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.field-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
}
.field-btn:active { background: var(--surface-3); }

.select-wrap { position: relative; display: flex; align-items: center; min-width: 0; }
.select-wrap select {
  width: 100%;
  min-width: 0;
  height: 46px;
  padding: 0 36px 0 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  text-overflow: ellipsis;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.select-wrap select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.select-wrap > .i { position: absolute; right: 12px; pointer-events: none; color: var(--muted); }
.select-wrap.is-active select { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.select-wrap.is-active > .i { color: var(--accent-text); }

/* ------------------------------------------------------------------ Login */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top, 0px)) var(--pad-r) calc(24px + env(safe-area-inset-bottom, 0px)) var(--pad-l);
  background:
    radial-gradient(900px 480px at 50% -12%, var(--accent-soft-2), transparent 62%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 390px;
  padding: 30px 22px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.login-logo { display: block; margin: 0 auto 14px; border-radius: 20px; box-shadow: var(--shadow-md); }
.login-title { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; }
.login-sub { margin-top: 4px; color: var(--muted); font-size: 15px; }
.login-form { margin-top: 24px; text-align: left; display: flex; flex-direction: column; gap: 12px; }
.login-form .field-label { margin-bottom: -6px; }
.login-erro {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger-text);
  font-size: 14.5px;
  font-weight: 550;
}
.login-dica { margin-top: 18px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.login-dica strong { color: var(--text-2); font-weight: 650; }

/* ------------------------------------------------------------------ Cabeçalho fixo */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 30;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.header-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 60px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) 6px var(--pad-l);
}
.header-titles { flex: 1; min-width: 0; }
.header-title { font-size: 22px; font-weight: 800; letter-spacing: -0.025em; line-height: 1.15; }
.header-sub {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  margin-top: 2px;
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--muted);
}
.header-sub .i { margin-top: 1px; }
#sync-texto {
  min-width: 0;
  text-wrap: balance;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#btn-recarregar.is-spinning .i { animation: girar .8s linear infinite; }

.pendentes-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px var(--pad-r) 7px var(--pad-l);
  background: var(--warning-soft);
  color: var(--warning-text);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.3;
  text-wrap: balance;
}

/* ------------------------------------------------------------------ Conteúdo */
.app-main {
  padding-top: var(--header-h);
  padding-bottom: calc(var(--tabbar-h) + 28px);
  min-height: 100vh;
  min-height: 100dvh;
}
.tab-panel { max-width: 1100px; margin: 0 auto; }
#aba-engenheiros { max-width: none; }

.toolbar-sticky {
  position: sticky;
  top: var(--header-h);
  z-index: 12;
  display: flex;
  gap: 8px;
  padding: 10px var(--pad-r) 10px var(--pad-l);
  background: var(--bg);
}
.field-busca { flex: 1 1 auto; }
.select-filtro { flex: 0 1 44%; max-width: 210px; }

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px var(--pad-r) 6px var(--pad-l);
}
.hint { font-size: 13px; line-height: 1.4; color: var(--muted); }
.toolbar-row .hint { flex: 1; min-width: 0; }

.list-summary {
  padding: 0 var(--pad-r) 8px var(--pad-l);
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 var(--pad-r) 0 var(--pad-l);
}

/* ------------------------------------------------------------------ Cards */
.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  min-height: 56px;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: box-shadow .15s ease, border-color .15s ease, background-color .15s ease, scale .12s ease;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
button.card { font: inherit; }
.card[role="button"], button.card { cursor: pointer; }
.card[role="button"]:active, button.card:active { scale: .985; }
@media (hover: hover) {
  .card[role="button"]:hover, button.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
}

.card-body { flex: 1; min-width: 0; }
.card-title-row { display: flex; align-items: flex-start; gap: 8px; }
.card-title {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 6px;
  font-size: 13.5px;
  color: var(--muted);
}
.meta-item { display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; }
.meta-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta-item.is-muted { font-style: italic; }
.meta-obras { font-weight: 600; color: var(--text-2); }
.card-chev { color: var(--muted); width: 20px; height: 20px; }
.grip { display: grid; place-items: center; width: 24px; color: var(--muted); opacity: .7; flex: none; }
.grip .i { width: 20px; height: 20px; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--surface-3);
  color: var(--text-2);
}
.badge .i { width: 13px; height: 13px; stroke-width: 2.4; }
.badge-info { background: var(--accent-soft); color: var(--accent-text); }
.badge-sucesso { background: var(--success-soft); color: var(--success-text); }
.badge-aviso { background: var(--warning-soft); color: var(--warning-text); }
.badge-perigo { background: var(--danger-soft); color: var(--danger-text); }
.badge-critica { flex: none; }

/* Avatar do engenheiro (iniciais) */
.avatar {
  --hue: 220;
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: hsl(var(--hue) var(--avatar-s) var(--avatar-l));
  color: hsl(var(--hue) 55% var(--avatar-fg-l));
  font-size: 12.5px;
  font-weight: 750;
  letter-spacing: .02em;
}
.avatar-sem { background: var(--surface-3); color: var(--muted); }
.avatar-sem .i { width: 18px; height: 18px; }

/* ------------------------------------------------------------------ Estados: carregando / vazio / erro */
.skeleton { pointer-events: none; box-shadow: none; }
.sk-body { flex: 1; display: flex; flex-direction: column; gap: 9px; }
.sk-line {
  display: block;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: brilho 1.2s ease-in-out infinite;
}
.sk-w70 { width: 70%; height: 14px; }
.sk-w40 { width: 40%; }
@keyframes brilho { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 8px var(--pad-r) 0 var(--pad-l);
  padding: 36px 22px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: 18px;
}
.empty-icon {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.empty.is-error .empty-icon { background: var(--danger-soft); color: var(--danger-text); }
.empty-title { font-size: 17px; font-weight: 700; }
.empty-text { max-width: 320px; font-size: 14.5px; color: var(--muted); overflow-wrap: anywhere; }
.empty .btn { margin-top: 8px; }

/* ------------------------------------------------------------------ Arrastar (SortableJS) */
/* Lista vazia continua aceitando o drop (min-height) e mostra uma dica */
.drop-list { position: relative; transition: background-color .15s ease, box-shadow .15s ease; }
.drop-list:empty::before {
  content: attr(data-vazio);
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  padding: 12px;
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.35;
  text-align: center;
}

/* Card escolhido (após segurar 180 ms no toque) */
.card.card-chosen {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft-2), var(--shadow-md);
}

/* Espaço reservado onde o card vai cair (vem depois de .card-chosen para prevalecer) */
.card.card-placeholder {
  background: var(--accent-soft);
  border: 2px dashed var(--accent);
  box-shadow: none;
  scale: 1 !important;
}
.card.card-placeholder > * { visibility: hidden; }

/* Cópia que acompanha o dedo ("pegando") */
.card.card-fallback,
.card.card-dragging {
  opacity: .97 !important;
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  rotate: 1.5deg;
  scale: 1.04;
  cursor: grabbing;
  pointer-events: none;
}

body.arrastando,
body.arrastando * { cursor: grabbing !important; -webkit-user-select: none; user-select: none; }
body.arrastando .drop-list:has(> .card-placeholder) {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent-soft-2);
}

/* ------------------------------------------------------------------ Aba Engenheiros */
.eng-board {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 var(--pad-r) 0 var(--pad-l);
}
.eng-section { min-width: 0; }
.eng-head {
  position: sticky;
  top: var(--header-h);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 8px 6px 8px 2px;
  border: 0;
  background: var(--bg);
  color: var(--text);
  text-align: left;
  box-shadow: 0 1px 0 var(--border);
}
.eng-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.eng-sem .eng-name { color: var(--text-2); }
.count-pill {
  min-width: 26px;
  height: 24px;
  padding: 0 8px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 700;
}
.eng-chevron { color: var(--muted); transition: rotate .2s ease; }
.eng-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 64px;
  padding: 10px 0 14px;
  border-radius: 14px;
}
.card-eng { min-height: 60px; }
body.arrastando .eng-section:has(.card-placeholder) .eng-head { color: var(--accent-text); }
body.arrastando .eng-section:has(.card-placeholder) .count-pill { background: var(--accent-soft-2); color: var(--accent-text); }

/* Seções recolhíveis só no celular (< 768 px) */
@media (max-width: 767.98px) {
  .eng-section.recolhida .eng-chevron { rotate: -90deg; }
  .eng-section.recolhida .eng-list { display: none; }
  .eng-section.recolhida .eng-list > .card:not(.card-placeholder) { display: none; }
  /* Durante o arraste, seções recolhidas viram uma faixa para soltar.
     As faixas acima do card empurram o conteúdo: iniciarArraste() no app.js
     compensa a rolagem na hora para o card continuar sob o dedo. */
  body.arrastando .eng-section.recolhida .eng-list {
    display: flex;
    min-height: 50px;
    margin: 6px 0 8px;
    padding: 4px;
    border: 2px dashed var(--border-strong);
  }
  body.arrastando .eng-section.recolhida .eng-list::before {
    content: attr(data-drop);
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 0 8px;
    border: 0;
    color: var(--muted);
    font-size: 13.5px;
    font-weight: 600;
  }
  body.arrastando .eng-section.recolhida .eng-list:has(> .card-placeholder)::before { display: none; }
}

/* Colunas lado a lado a partir de 768 px (rolagem horizontal interna) */
@media (min-width: 768px) {
  #btn-recolher { display: none; }
  .eng-board {
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 14px;
    scroll-padding: 0 var(--gutter);
  }
  .eng-section {
    flex: 0 0 300px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - var(--header-h) - var(--tabbar-h) - 90px);
    max-height: calc(100dvh - var(--header-h) - var(--tabbar-h) - 90px);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 18px;
  }
  .eng-head {
    position: static;
    padding: 10px 12px;
    background: transparent;
    box-shadow: none;
    cursor: default;
    border-bottom: 1px solid var(--border);
  }
  .eng-chevron { display: none; }
  .eng-list {
    flex: 1;
    min-height: 140px;
    overflow-y: auto;
    padding: 10px;
    border-radius: 0 0 18px 18px;
  }
}

/* ------------------------------------------------------------------ Aba Medições */
.med-top {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px var(--pad-r) 4px var(--pad-l);
}

.crumb {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin: -4px 0 -2px -8px;
}
.crumb-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding: 0 10px 0 4px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--accent-text);
  font-size: 16px;
  font-weight: 650;
  flex: none;
}
.crumb-back:active { background: var(--accent-soft); }
.crumb-sep { color: var(--muted); }
.crumb-title {
  min-width: 0;
  font-size: 18px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}
.month-label {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}
.month-name { font-size: 17px; font-weight: 750; letter-spacing: -0.01em; white-space: nowrap; }
.month-caption { font-size: 11.5px; font-weight: 650; color: var(--accent-text); text-transform: uppercase; letter-spacing: .05em; }
.month-nav .btn-sm { margin-left: 4px; }

.progress-card {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}
.progress-text { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 15px; }
.progress-text strong { font-weight: 700; }
.progress-pct { font-size: 13px; font-weight: 700; color: var(--muted); }
.progress-bar {
  height: 8px;
  margin-top: 9px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress-bar > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width .35s ease;
}
.progress-card.is-completo .progress-bar > span { background: var(--success); }
.progress-card.is-completo .progress-pct { color: var(--success-text); }
.progress-note { margin-top: 8px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

/* Kanban de duas colunas — lado a lado também no celular */
.kanban {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  padding: 4px var(--pad-r) 0 var(--pad-l);
}
.kcol { display: flex; flex-direction: column; min-width: 0; }
.kcol-head {
  position: sticky;
  top: var(--header-h);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 8px 4px;
  background: var(--bg);
  font-size: 14.5px;
  font-weight: 750;
}
.kcol-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.kcol-pend .kcol-dot { background: var(--warning); }
.kcol-env .kcol-dot { background: var(--success); }
.kcol-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcol-count {
  margin-left: auto;
  min-width: 26px;
  height: 24px;
  padding: 0 8px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 750;
}
.kcol-pend .kcol-count { background: var(--warning-soft); color: var(--warning-text); }
.kcol-env .kcol-count { background: var(--success-soft); color: var(--success-text); }
.kcol-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 180px;
  padding: 6px;
  border-radius: 16px;
}
.kcol-pend .kcol-list { background: var(--warning-col); }
.kcol-env .kcol-list { background: var(--success-col); }
.kcol-list:empty::before { min-height: 160px; }

/* Card de medição (coluna estreita: ~170 px no celular) */
.mcard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px;
  min-height: 62px;
  padding: 8px 2px 8px 11px;
}
.mcard-body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.mcard-body.is-clickable { cursor: pointer; border-radius: 8px; }
.mcard-title {
  font-size: 14.5px;
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.mcard-sub { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: 12.5px; color: var(--muted); }
.mcard-sub.is-muted { font-style: italic; }
.mcard-sub-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcard-obras { font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.mcard-chev { color: var(--muted); width: 18px; height: 18px; margin-right: 6px; }
.mini-bar { display: block; height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: 2px; }
.mini-bar > span { display: block; height: 100%; border-radius: inherit; background: var(--success); }
.mcard-grupo { padding-right: 4px; }
.mcard-grupo.is-concluido { border-color: var(--success-soft); }

.check-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--text);
}
.check-circle {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  color: transparent;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.check-circle .i { width: 16px; height: 16px; stroke-width: 3; }
.check-btn:active .check-circle { border-color: var(--success); color: var(--success); }
.is-enviada .check-circle { background: var(--success); border-color: var(--success); color: var(--on-success); }
.is-enviada .check-btn:active .check-circle { background: transparent; color: var(--muted); }
@media (hover: hover) {
  .check-btn:hover .check-circle { border-color: var(--success); color: var(--success); }
  .is-enviada .check-btn:hover .check-circle { color: var(--on-success); }
}

/* ------------------------------------------------------------------ Barra de abas inferior */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 6px max(6px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(6px, env(safe-area-inset-left, 0px));
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 52px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  -webkit-user-select: none;
  user-select: none;
}
.tab-icon {
  width: 58px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  transition: background-color .2s ease, color .2s ease;
}
.tab-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent-text); }
.tab[aria-selected="true"] .tab-icon { background: var(--accent-soft-2); }
.tab:active .tab-icon { background: var(--accent-soft); }
@media (min-width: 768px) {
  .tabbar { padding-left: calc(50% - 260px); padding-right: calc(50% - 260px); }
}

/* ------------------------------------------------------------------ Bottom sheet */
.sheet-root { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  opacity: 0;
  transition: opacity .28s ease;
}
.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-width: 640px;
  max-height: calc(100% - 36px - env(safe-area-inset-top, 0px));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-lg);
  transform: translateY(105%);
  transition: transform .32s cubic-bezier(.22, .9, .24, 1);
  outline: none;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-root.is-open .sheet-backdrop { opacity: 1; }
.sheet-root.is-open .sheet { transform: translateY(0); }
.sheet.is-dragging { transition: none; }

.sheet-grab {
  flex: none;
  padding: 8px max(10px, env(safe-area-inset-right, 0px)) 2px max(20px, env(safe-area-inset-left, 0px));
  touch-action: none;
  cursor: grab;
}
.sheet-handle { display: block; width: 40px; height: 5px; margin: 0 auto 4px; border-radius: 999px; background: var(--border-strong); }
.sheet-header { display: flex; align-items: flex-start; gap: 8px; }
.sheet-titles { flex: 1; min-width: 0; padding-top: 8px; }
.sheet-title { font-size: 20px; font-weight: 800; line-height: 1.25; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.sheet-sub { margin-top: 3px; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px max(20px, env(safe-area-inset-right, 0px)) 22px max(20px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
body.sheet-aberto { overflow: hidden; }

.badge-row { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet-section { display: flex; flex-direction: column; gap: 8px; }
.section-label {
  font-size: 12.5px;
  font-weight: 750;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.sheet-text { font-size: 15.5px; color: var(--text-2); line-height: 1.5; }

.info-list {
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}
.info-row:first-child { border-top: 0; }
.info-row dt { color: var(--muted); font-size: 14.5px; flex: none; }
.info-row dd { margin: 0; font-weight: 650; text-align: right; min-width: 0; overflow-wrap: anywhere; }

.obs {
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.5;
}
.muted { color: var(--muted); font-size: 14.5px; }
.nota-rodape { font-size: 12.5px; color: var(--muted); text-align: center; }

.obra-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.obra-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.obra-icone {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.obra-icone .i { width: 18px; height: 18px; }
.obra-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.obra-nome { font-weight: 650; overflow-wrap: anywhere; line-height: 1.3; }
.obra-eng { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

/* Lista de opções ("Mover para…") */
.option-list { display: flex; flex-direction: column; gap: 6px; }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  transition: background-color .15s ease, border-color .15s ease;
}
.option:active { background: var(--surface-3); }
.option.is-current { border-color: var(--accent); background: var(--accent-soft); }
.option-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.option-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.option-sub { font-size: 13px; color: var(--muted); }
.option.is-current .option-sub { color: var(--accent-text); font-weight: 600; }
.option-check { color: var(--accent-text); }
@media (hover: hover) { .option:hover { border-color: var(--border-strong); } }

.btn-stack { display: flex; flex-direction: column; gap: 10px; }
.aviso-box {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--warning-soft);
  color: var(--warning-text);
  font-size: 14px;
  font-weight: 600;
}

/* ------------------------------------------------------------------ Toasts */
.toasts {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 var(--pad-r) 0 var(--pad-l);
  pointer-events: none;
}
body.logado .toasts { bottom: calc(var(--tabbar-h) + 12px); }
body.logado.sheet-aberto .toasts { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 460px;
  min-height: 48px;
  padding: 8px 8px 8px 14px;
  border-radius: 14px;
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow-lg);
  font-size: 14.5px;
  line-height: 1.35;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(14px) scale(.98);
  transition: opacity .22s ease, transform .22s ease;
}
.toast.is-visible { opacity: 1; transform: none; }
.toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; padding: 4px 0; }
.toast-ico { flex: none; width: 20px; height: 20px; }
.toast-sucesso .toast-ico { color: #34d27a; }
.toast-erro .toast-ico { color: #ff7b7b; }
.toast-info .toast-ico { color: var(--toast-action); }
@media (prefers-color-scheme: dark) {
  .toast-sucesso .toast-ico { color: #16a34a; }
  .toast-erro .toast-ico { color: #dc2626; }
}
.toast-acao {
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--toast-action);
  font-size: 14.5px;
  font-weight: 750;
}
.toast-acao:active { background: rgba(127, 127, 127, .18); }

/* ------------------------------------------------------------------ Telas largas */
@media (min-width: 768px) {
  :root { --gutter: 24px; }
  #lista-contratos .card-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
  }
  .kanban { gap: 14px; }
  .mcard { padding-left: 14px; }
  .select-filtro { max-width: 260px; }
}

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