/* ============ Reset & tokens ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --border: #dde3ec;
  --text: #16233d;
  --text-dim: #5c6b84;
  --text-faint: #94a1b8;

  --primary: #1c3f73;
  --primary-dark: #0a1a33;
  --primary-light: #e8eef8;
  --accent: #4f7fc4;

  --danger: #dc2626;
  --danger-light: #fdecec;
  --success: #16a34a;
  --success-light: #eaf7ee;
  --warning: #b45309;
  --warning-light: #fef3e2;
  --info: #2563eb;
  --info-light: #eaf1fd;
  --muted: #6b7280;
  --muted-light: #eef1f6;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(10, 26, 51, .06), 0 4px 14px rgba(10, 26, 51, .07);
  --shadow-lg: 0 12px 32px rgba(10, 26, 51, .28);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-weight: 700; }
.hidden { display: none !important; }

/* ============ Login ============ */
.view-login {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  min-height: 100dvh;
  padding: 32px 20px;
  background: radial-gradient(circle at 30% 20%, #1c3f73 0%, #0a1a33 55%, #060f1f 100%);
}
.view-login.active { display: flex; }

.login-box {
  width: 100%;
  max-width: 380px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(6px);
  border-radius: 20px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  box-shadow: var(--shadow-lg);
}
.login-logo { margin-bottom: 6px; }
.login-box h1 { color: #fff; font-size: 21px; margin-bottom: 2px; }
.login-sub { color: #b7c4dc; font-size: 13px; line-height: 1.5; margin-bottom: 14px; }
.pendente-icon { font-size: 40px; margin-bottom: 4px; }

.login-alerta {
  width: 100%;
  background: rgba(220, 38, 38, .18);
  border: 1px solid rgba(220, 38, 38, .4);
  color: #ffd9d9;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}

#form-login, #form-cadastro { width: 100%; text-align: left; }
.login-box label {
  display: block;
  font-size: 12px;
  color: #c3cfe3;
  font-weight: 600;
  margin-bottom: 12px;
}
.login-box input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 11px 12px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.06);
  color: #fff;
  font-size: 14.5px;
}
.login-box input::placeholder { color: #7c8bab; }
.login-box input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn-full { width: 100%; padding: 12px; font-size: 14.5px; }
.login-hint { font-size: 11.5px; color: #93a3c0; margin-top: -4px; margin-bottom: 6px; text-align: center; }
.btn-link {
  border: none; background: none; color: #9db6e0; font-size: 13px; font-weight: 600;
  margin-top: 6px; text-decoration: underline; text-underline-offset: 2px;
}
.login-site { color: #7f92b8; font-size: 12.5px; text-decoration: none; letter-spacing: .02em; }
.login-site:hover { color: #b7c4dc; }

/* ============ Topbar ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--primary-dark);
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: #fff; }
.logo-mark { flex-shrink: 0; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.btn-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  position: relative;
}
.btn-icon:active { background: rgba(255,255,255,.18); }

.notif-wrap, .perfil-wrap { position: relative; }
.notif-badge {
  position: absolute; top: -2px; right: -2px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
}

.notif-dropdown {
  position: absolute;
  top: 44px;
  right: 0;
  width: 300px;
  max-width: 85vw;
  max-height: 400px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 30;
  color: var(--text);
}
.notif-dropdown-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 13.5px;
}
.btn-link-inline { border: none; background: none; color: var(--accent); font-size: 11.5px; font-weight: 600; }
.notif-lista { display: flex; flex-direction: column; }
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 12.5px; line-height: 1.4; }
.notif-item.nao-lida { background: var(--info-light); }
.notif-item .notif-tempo { display: block; color: var(--text-faint); font-size: 11px; margin-top: 3px; }

.perfil-info { padding: 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.perfil-info strong { font-size: 13.5px; }
.perfil-info span { font-size: 11.5px; color: var(--text-dim); }
.dropdown-item {
  display: block; width: 100%; text-align: left;
  border: none; background: none; padding: 11px 14px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.dropdown-item:active { background: var(--muted-light); }

/* ============ Main / views ============ */
main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 90px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

.section-title {
  font-size: 15px;
  margin: 22px 0 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.section-title:first-child { margin-top: 0; }

/* ============ Bottom nav ============ */
.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border: none;
  background: none;
  padding: 9px 4px 8px;
  font-size: 11.5px;
  color: var(--text-faint);
}
.nav-btn .nav-icon { font-size: 20px; }
.nav-btn.active { color: var(--primary); font-weight: 600; }

/* ============ Stat cards (dashboard) ============ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 12px; color: var(--text-dim); }
.stat-value { font-size: 22px; font-weight: 700; }

.alertas-wrap { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.alerta {
  display: flex; align-items: center; gap: 8px;
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #f6c9c9;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 600;
}
.alerta .emoji { font-size: 16px; }
.limite-aviso {
  background: var(--warning-light); color: var(--warning);
  border: 1px solid #f0d4ab; border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13px; font-weight: 600; margin-bottom: 12px;
}

/* ============ Cards grid (obras) ============ */
.cards-grid { display: flex; flex-direction: column; gap: 10px; }

.obra-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.obra-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}

.obra-card-nome { font-size: 15.5px; font-weight: 700; }
.obra-card-cliente { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; }

.progress-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.progress-bar-track {
  flex: 1;
  height: 8px;
  border-radius: 5px;
  background: var(--muted-light);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 5px;
  transition: width .3s ease;
}
.progress-row span { font-size: 12.5px; font-weight: 600; color: var(--text-dim); min-width: 34px; text-align: right; }

.obra-card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 8px;
}

.empty-state {
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
  padding: 30px 10px;
}

/* ============ Badges ============ */
.badge-status {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-planejamento { background: var(--info-light); color: var(--info); }
.badge-andamento { background: #e4edfb; color: var(--primary); }
.badge-pausada { background: var(--muted-light); color: var(--muted); }
.badge-concluida { background: var(--success-light); color: var(--success); }
.badge-cancelada { background: var(--danger-light); color: var(--danger); }
.badge-pendente { background: var(--warning-light); color: var(--warning); }
.badge-aprovado { background: var(--success-light); color: var(--success); }
.badge-bloqueado { background: var(--danger-light); color: var(--danger); }
.badge-admin { background: var(--primary-light); color: var(--primary); }
.badge-manha { background: var(--warning-light); color: var(--warning); }
.badge-tarde { background: var(--info-light); color: var(--info); }
.badge-dia_todo { background: var(--primary-light); color: var(--primary); }

/* ============ List items (generic) ============ */
.list-plain { display: flex; flex-direction: column; gap: 8px; }

.list-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-size: 14px; font-weight: 600; }
.list-item-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.list-item-value { font-size: 14.5px; font-weight: 700; white-space: nowrap; }
.value-despesa { color: var(--danger); }
.value-receita { color: var(--success); }
.value-previsto { opacity: .55; }

/* ============ View toolbar ============ */
.view-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.view-toolbar select,
.view-toolbar input[type="search"],
.view-toolbar input[type="date"] {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 13.5px;
}

/* ============ Buttons ============ */
.btn-primary, .btn-secondary, .btn-danger {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--muted-light); color: var(--text); }
.btn-danger { background: none; color: var(--danger); padding: 10px 4px; }
.btn-upload { display: inline-flex; align-items: center; justify-content: center; }

/* ============ Obra detail view ============ */
.view-detalhe { padding: 0 !important; }

.detalhe-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.detalhe-header .btn-icon { background: var(--primary-light); color: var(--primary); }
.detalhe-header-info { flex: 1; min-width: 0; }
.detalhe-header-info h1 {
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.detalhe-header-info .badge-status { margin-top: 4px; }

.subtabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 0;
}
.subtab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 11px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-faint);
  border-bottom: 2.5px solid transparent;
  white-space: nowrap;
}
.subtab-btn.active { color: var(--primary); border-color: var(--primary); }

.subtab-panel { display: none; padding: 16px; padding-bottom: 90px; max-width: 720px; margin: 0 auto; }
.subtab-panel.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 13.5px; color: var(--text-dim); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .03em; }

.card-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-header-row h3 { margin-bottom: 0; }

.rel-periodo-label { flex: 1; font-size: 12px; color: var(--text-dim); font-weight: 600; }

.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-row-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.bar-row-head strong { font-weight: 600; }
.bar-row-track { height: 8px; border-radius: 5px; background: var(--muted-light); overflow: hidden; }
.bar-row-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 5px; }

.info-list { display: flex; flex-direction: column; gap: 9px; margin-top: 10px; }
.info-list > div { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.info-list dt { color: var(--text-dim); }
.info-list dd { font-weight: 600; text-align: right; }
.observacoes { margin-top: 12px; font-size: 13px; color: var(--text-dim); line-height: 1.5; white-space: pre-wrap; }

.mini-stats { display: flex; justify-content: space-between; gap: 10px; }
.mini-stats > div { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.mini-label { font-size: 11.5px; color: var(--text-dim); }
.mini-value { font-size: 16.5px; font-weight: 700; }

/* ============ Timeline (cronograma) ============ */
.timeline .list-item { border-left: 3px solid var(--muted-light); }
.timeline .list-item.status-andamento { border-left-color: var(--primary); }
.timeline .list-item.status-concluida { border-left-color: var(--success); }
.timeline .list-item.status-atrasada { border-left-color: var(--danger); }

.etapa-progress-mini {
  width: 60px; height: 6px; border-radius: 4px; background: var(--muted-light); overflow: hidden; margin-top: 5px;
}
.etapa-progress-mini > div { height: 100%; background: var(--primary); }

/* ============ Equipe / presença ============ */
.equipe-item { display: flex; align-items: center; justify-content: space-between; }
.equipe-toggle {
  width: 46px; height: 26px; border-radius: 14px;
  background: var(--muted-light); border: 1px solid var(--border);
  position: relative; flex-shrink: 0;
}
.equipe-toggle .knob {
  position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: left .15s ease;
}
.equipe-toggle.on { background: var(--success); border-color: var(--success); }
.equipe-toggle.on .knob { left: 22px; }

.equipe-section-title { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .03em; margin: 18px 0 8px; }
.equipe-section-title:first-of-type { margin-top: 0; }
.equipe-hint { font-size: 12px; color: var(--text-faint); margin-bottom: 10px; }

.equipe-manual-item { align-items: flex-start; }
.equipe-obs-input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  font-size: 12.5px;
  color: var(--text);
}
.equipe-obs-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.agenda-badges { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.agenda-concluido-toggle {
  border: 1px solid var(--border);
  background: var(--muted-light);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.agenda-concluido-toggle.on { background: var(--success-light); color: var(--success); border-color: transparent; }
.agenda-concluido-toggle:disabled { opacity: .6; }
.list-item.agenda-concluido .list-item-title,
.list-item.agenda-concluido .list-item-sub { opacity: .55; text-decoration: line-through; }

/* ============ Galeria / fotos ============ */
.galeria-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}
.galeria-item {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--muted-light);
  position: relative;
  border: 1px solid var(--border);
}
.galeria-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.galeria-item .galeria-obra-tag {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.65));
  color: #fff; font-size: 10px; padding: 12px 6px 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.foto-modal-content {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.foto-modal-content img { max-width: 100%; max-height: 60vh; border-radius: var(--radius-sm); }
.foto-fechar { position: absolute; top: -6px; right: -6px; background: var(--primary-dark); color: #fff; font-size: 20px; }
#foto-legenda { font-size: 12.5px; color: var(--text-dim); text-align: center; }

/* ============ Modais ============ */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(10, 26, 51, .55);
  z-index: 40;
}
.modal-backdrop.active { display: block; }

.modal {
  display: none;
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow-lg);
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.modal.active { display: block; }

@media (min-width: 560px) {
  .modal {
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    border-radius: 18px;
    width: 90%;
  }
}

.modal h2 { font-size: 17px; margin-bottom: 16px; }
.modal label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 12px;
}
.modal input, .modal select, .modal textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 14.5px;
  color: var(--text);
}
.modal input:focus, .modal select:focus, .modal textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}
.modal textarea { resize: vertical; }
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 13.5px !important;
  color: var(--text) !important;
}
.checkbox-label input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--primary); flex-shrink: 0; }
.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; }

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  gap: 8px;
}
.modal-actions-right { display: flex; gap: 8px; margin-left: auto; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(20px);
  background: var(--primary-dark);
  color: #fff;
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 60;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ Larger screens ============ */
@media (min-width: 720px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .cards-grid { display: grid; grid-template-columns: 1fr 1fr; }
}
