/* Diário de Obra — estilo base: sóbrio, denso, responsivo (item 66) */
:root {
  --bg: #f3f4f6; --surface: #fff; --border: #e2e5ea; --text: #1f2933; --muted: #6b7280;
  --primary: #1f4e79; --primary-dark: #173b5c; --sidebar: #1e293b; --sidebar-text: #cbd5e1;
  --success: #15803d; --warning: #b45309; --error: #b91c1c; --radius: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .6rem; font-weight: 600; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.muted { color: var(--muted); }

.shell { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; color: #fff; font-weight: 600; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 6px; background: var(--primary); font-size: 12px; letter-spacing: .05em; }
.nav { flex: 1; padding: 6px 0; }
.nav-item { display: block; padding: 10px 18px; color: var(--sidebar-text); border-left: 3px solid transparent; }
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.08); color: #fff; border-left-color: #60a5fa; }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.user-name { color: #fff; font-weight: 600; }
.user-email { color: var(--sidebar-text); word-break: break-all; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 22px; background: var(--surface); border-bottom: 1px solid var(--border); }
.page-title { font-size: 18px; margin: 0; }
.menu-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius); font-size: 18px; padding: 2px 8px; cursor: pointer; }
.content { padding: 20px 22px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat-value { font-size: 28px; font-weight: 600; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; background: #e5e7eb; font-size: 12px; }

label { display: block; margin-bottom: 12px; font-weight: 500; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid #cbd2d9; border-radius: var(--radius); font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }
.btn { display: inline-block; padding: 9px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 6px 0; color: #93c5fd; cursor: pointer; font: inherit; }

.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: var(--error); }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: var(--success); }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: var(--warning); }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: var(--primary); }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--sidebar); }
.login-box { width: 100%; max-width: 380px; background: #fff; border-radius: 8px; padding: 28px; margin: 16px; }
.brand-login { padding: 0 0 20px; color: var(--text); justify-content: center; }
.error-box { max-width: 480px; margin: 60px auto; text-align: center; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 32px; }
.error-code { font-size: 48px; font-weight: 700; color: var(--primary); }
body.blank .error-box { margin-top: 12vh; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-block; }
  .content { padding: 14px; }
}

/* ── Fase 2: cadastros ── */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; min-width: 160px; margin: 0; padding: 7px 9px; }
.filters input[type=search] { min-width: 240px; }
.form h2 { margin-top: 18px; }
.form h2:first-of-type { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.form-actions { display: flex; gap: 8px; margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.field-error { display: block; color: var(--error); font-size: 12px; margin-top: 3px; font-weight: 400; }
.label-text { display: block; font-weight: 500; margin-bottom: 6px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 6px 0; }
label.check input { width: auto; margin: 0; }
textarea { resize: vertical; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { color: var(--error); border-color: #fecaca; background: #fff; }
.btn-danger:hover { background: #fef2f2; }
.danger-zone { margin-top: 14px; display: flex; justify-content: flex-end; }
.badge-ativo, .badge-ativa, .badge-em_andamento { background: #dcfce7; color: #166534; }
.badge-inativo, .badge-inativa, .badge-cancelada { background: #f3f4f6; color: #6b7280; }
.badge-bloqueado, .badge-paralisada { background: #fee2e2; color: #991b1b; }
.badge-planejada { background: #dbeafe; color: #1e40af; }
.badge-concluida { background: #e0e7ff; color: #3730a3; }
.actions { text-align: right; white-space: nowrap; }
.actions a { margin-left: 8px; }
form.inline { display: inline; }
.dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.dl-item dt { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.dl-item dd { margin: 0 0 6px; }
.pre { white-space: pre-wrap; margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--border); }
.logo-preview { max-height: 80px; max-width: 240px; margin: 6px 0 12px; border: 1px solid var(--border); border-radius: 4px; padding: 4px; background: #fff; }
.pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 13px; }
.pagination .btn { margin-left: 6px; }
.mt { margin-top: 14px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 5px 0; border-bottom: 1px solid var(--border); }
a.user-name { color: #fff; font-weight: 600; display: block; }
tr.muted td { color: var(--muted); }
@media (max-width: 700px) {
  .form-grid, .form-grid-3, .dl { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .filters input, .filters select { width: 100%; }
}

/* ── Fase 3: registros ── */
.tabs { display: flex; gap: 4px; }
.tab { padding: 7px 14px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted); background: #fff; }
.tab.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.filters-card { margin-bottom: 14px; padding: 10px 12px; }
.btn-link-plain { border: 0; background: none; color: var(--muted); }
td.desc { max-width: 360px; }
.gps { font-size: 12px; padding: 2px 6px; border-radius: 4px; background: #ecfdf5; color: #065f46; }
.gps-low_accuracy { background: #fffbeb; color: #92400e; }
.gps-unavailable { background: #f3f4f6; color: #6b7280; }
.badge-created, .badge-synced { background: #dbeafe; color: #1e40af; }
.badge-validated { background: #dcfce7; color: #166534; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-archived, .badge-draft { background: #f3f4f6; color: #6b7280; }
.grid-tl { display: grid; grid-template-columns: 1fr 260px; gap: 14px; }
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.tl-item { display: flex; gap: 14px; padding: 8px 0 8px 14px; position: relative; }
.tl-item::before { content: ''; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.tl-time { font-weight: 600; min-width: 46px; font-variant-numeric: tabular-nums; }
.tl-title { font-weight: 600; }
.tl-desc { margin: 2px 0; }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.pre-plain { white-space: pre-wrap; margin: 0; }
.geo-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
@media (max-width: 900px) { .grid-tl { grid-template-columns: 1fr; } }

/* ── Fase 4: fotografias ── */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery-item { position: relative; display: block; aspect-ratio: 4/3; overflow: hidden; border-radius: 4px; border: 1px solid var(--border); background: #f3f4f6; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 6px; font-size: 11px; color: #fff; background: rgba(0,0,0,.55); }
.hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.upload-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.upload-form label { flex: 1; min-width: 260px; margin: 0; }
.lightbox { position: fixed; inset: 0; z-index: 50; }
.lb-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.8); }
.lb-panel { position: absolute; inset: 24px; display: grid; grid-template-columns: 1fr 300px; background: #111; border-radius: 8px; overflow: hidden; }
.lb-img { display: flex; align-items: center; justify-content: center; background: #000; }
.lb-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-meta { background: #fff; padding: 18px; overflow: auto; }
.lb-meta .dl-item { margin-bottom: 8px; }
.lb-close { position: absolute; top: 8px; right: 310px; z-index: 2; background: rgba(0,0,0,.5); color: #fff; border: 0; font-size: 26px; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; }
.lb-actions { display: flex; gap: 6px; margin: 12px 0; }
@media (max-width: 800px) { .lb-panel { inset: 8px; grid-template-columns: 1fr; grid-template-rows: 1fr auto; } .lb-close { right: 8px; } .lb-meta { max-height: 45vh; } }

/* ── Fase 7: diário ── */
.badge-rascunho { background: #f3f4f6; color: #6b7280; }
.badge-em_revisao { background: #fef3c7; color: #92400e; }
.badge-aprovado { background: #dcfce7; color: #166534; }
.badge-encerrado { background: #e0e7ff; color: #3730a3; }
.dr-item { padding: 10px 0; border-top: 1px solid var(--border); }
.dr-item:first-of-type { border-top: 0; }
.dr-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dr-desc { margin: 6px 0; }
.dr-notes { margin: 4px 0 6px; padding: 6px 10px; background: #f8fafc; border-left: 3px solid var(--primary); }
.gallery-sm { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.dr-edit summary { cursor: pointer; color: var(--primary); font-size: 13px; }
.form-inline-edit { margin-top: 8px; padding: 10px; background: #f9fafb; border-radius: var(--radius); }
.form-inline-edit label { margin-bottom: 8px; }

/* ── Fase 9: mapa ── */
.map-card { padding: 0; overflow: hidden; }
#mapa { height: calc(100vh - 230px); min-height: 420px; }
.mini-map { height: 220px; border-radius: var(--radius); border: 1px solid var(--border); margin-top: 8px; }
.leaflet-popup-content { font-size: 13px; line-height: 1.35; }

/* ── Fase 10: auditoria ── */
.table-audit { font-size: 12px; }
.table-audit .val { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.badge-act-create, .badge-act-upload, .badge-act-sync { background: #dbeafe; color: #1e40af; }
.badge-act-update { background: #fef3c7; color: #92400e; }
.badge-act-delete, .badge-act-login_failed { background: #fee2e2; color: #991b1b; }
.badge-act-validate, .badge-act-approve, .badge-act-finalize, .badge-act-login { background: #dcfce7; color: #166534; }
