/* ── MODAIS — shell unificado (Fase 5) ─────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--overlay);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}
.modal.open { display: flex; }
.modal.modal--stack { z-index: calc(var(--z-modal) + 20); }

body.modal-open { overflow: hidden; }

/* Shell interno — aliases dos boxes legados */
.modal-shell,
.modal > .tc-box,
.modal > .tar-modal-box,
.modal > .mv-box,
.modal > .tl-box,
.modal > .mnl-box,
.modal > .mbe-box,
.modal > .adm-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: min(92vh, 720px);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  box-sizing: border-box;
  position: relative;
}

.modal-shell--wide,
.modal > .mbe-box,
.modal > .mnl-box,
.modal > .tl-box,
.modal > .tar-modal-box { max-width: 560px; }

.modal > .mbe-box {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 720px;
  border-radius: var(--radius-lg);
}

.modal > .tl-box,
.modal > .adm-box {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.modal > .tc-box,
.modal > .tar-modal-box,
.modal > .mv-box,
.modal > .mnl-box {
  overflow-y: auto;
  padding: 24px;
  -webkit-overflow-scrolling: touch;
}

.modal > .mv-box { max-width: 490px; padding: 26px; }

.modal-hdr,
.modal > .tl-box > .tl-hdr,
.modal > .mbe-box > .mbe-hdr,
.modal > .adm-box > .adm-hdr {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
  flex-shrink: 0;
}

.modal-hdr-title,
.tc-title,
.tar-modal-title,
.mv-title,
.mnl-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.25;
  flex: 1;
  min-width: 0;
}

.modal-ic {
  display: inline-flex;
  align-items: center;
  line-height: 0;
  color: var(--accent);
  flex-shrink: 0;
}

.tc-sub, .mv-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.modal-close,
.mbe-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.modal-close:hover,
.mbe-close:hover { color: var(--text); background: var(--bg-muted); }

.modal-body-scroll,
.modal > .mbe-box > .mbe-body,
.modal > .adm-box > .adm-body,
.modal > .tl-box > .tl-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

.modal-foot,
.modal > .tl-box > .tl-foot,
.modal > .mbe-box > .mbe-foot,
.modal > .adm-box > .adm-foot,
.mv-actions,
.mnl-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding-top: 4px;
  margin-top: 16px;
}

.modal > .tl-box > .tl-foot,
.modal > .mbe-box > .mbe-foot,
.modal > .adm-box > .adm-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-muted);
  margin-top: 0;
  flex-shrink: 0;
}

/* Tentativa — resultados */
.tc-res-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.tc-res-btn {
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.15s, background 0.15s;
  min-height: 44px;
}
.tc-res-btn:hover,
.tc-res-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-on-soft);
}
.tc-res-ic {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--text-muted);
}
.tc-res-btn.active .tc-res-ic { color: var(--accent); }

/* Prioridade — badges (tarefa) */
.modal-prio-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.modal-prio-btn {
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}
.modal-prio-btn:hover { border-color: var(--border-strong); color: var(--text); }
.modal-prio-btn.active { color: #fff; border-color: transparent; }
.modal-prio-btn.modal-prio-alta.active { background: var(--danger); }
.modal-prio-btn.modal-prio-media.active { background: var(--warning); color: #1e293b; }
.modal-prio-btn.modal-prio-baixa.active { background: var(--accent); }

/* Novo lead — grids responsivos */
.mnl-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.mnl-row-city {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
}

/* Bottom sheet — mobile (padrão orcamento.html) */
@media (max-width: 639px) {
  .modal {
    align-items: flex-end;
    justify-content: center;
    padding: 0;
  }
  .modal-shell,
  .modal > .tc-box,
  .modal > .tar-modal-box,
  .modal > .mv-box,
  .modal > .tl-box,
  .modal > .mnl-box,
  .modal > .mbe-box,
  .modal > .adm-box {
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 88vh;
    border-bottom: none;
  }
  .tc-res-grid { grid-template-columns: 1fr; }
  .mnl-row-2,
  .mnl-row-city { grid-template-columns: 1fr; }
  .mnl-destino { grid-template-columns: 1fr; }
  .modal .mv-row { grid-template-columns: 1fr; }
  .mnl-input,
  .mv-inp,
  .modal textarea.mv-inp { font-size: 16px; }
  .mnl-actions,
  .mv-actions {
    flex-direction: column;
    position: sticky;
    bottom: 0;
    background: var(--bg-surface);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    margin-top: 12px;
    z-index: 2;
  }
  .mnl-btn-cancel,
  .mnl-btn-save {
    flex: none;
    width: 100%;
    min-height: 44px;
  }
  .modal > .tc-box,
  .modal > .tar-modal-box,
  .modal > .mv-box,
  .modal > .tl-box,
  .modal > .mnl-box,
  .modal > .mbe-box,
  .modal > .adm-box {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

@media (min-width: 640px) {
  .tc-res-grid { grid-template-columns: repeat(2, 1fr); }
}

.tc-res-btn.tc-res-wide { grid-column: 1 / -1; }
.mnl-dest-badge { font-size: 12px; font-weight: 500; color: var(--accent); }
