:root {
  --dark: #1c1c1c;
  --dark-2: #2c2c2c;
  --surface: #ffffff;
  --surface-alt: #f2f2f2;
  --text: #232323;
  --text-muted: #6b6b6b;
  --red: #cf2e2e;
  --red-dark: #a82323;
  --border: #e2e2e2;
  --success: #1a8f4c;
  --radius: 12px;
  --font-heading: 'Montserrat', system-ui, sans-serif;
  --font-body: 'Open Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--surface-alt);
  color: var(--text);
}

[hidden] { display: none !important; }

h1, h2, h3, strong { font-family: var(--font-heading); }

header.topbar {
  background: #fff;
  color: var(--dark);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 3px solid var(--red);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }

.topbar-logo { height: 28px; width: auto; display: block; flex: 0 0 auto; }
.topbar-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--dark);
  border-left: 2px solid var(--border);
  padding-left: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.login-logo { display: block; width: 100%; max-width: 260px; margin: 0 auto 16px; }

.status-pill {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--success);
  color: #fff;
  font-weight: 600;
}
.status-pill.offline { background: var(--red); }
.status-pill.pending { background: #d97706; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 90px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.08);
  border: 1px solid var(--border);
}

.card h3 { margin-top: 0; color: var(--dark); }

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  margin: 12px 0 4px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.hint { font-size: 0.82rem; color: var(--text-muted); margin: 4px 0 8px; text-transform: none; }

input, select, textarea {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: var(--font-body);
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(207,46,46,0.15);
}

textarea { min-height: 80px; resize: vertical; }

.two-col { display: flex; gap: 10px; }
.two-col > * { flex: 1; min-width: 0; }

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 13px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--font-heading);
  transition: transform 0.05s ease, opacity 0.15s ease;
}
button:active { transform: scale(0.98); }

.btn-primary { background: var(--red); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--red-dark); }
.btn-secondary { background: var(--surface-alt); color: var(--dark); border: 1px solid var(--border); width: 100%; }
.btn-secondary:hover { background: #ececec; }
.btn-danger { background: #fee2e2; color: var(--red-dark); }
.btn-small { padding: 8px 12px; font-size: 0.82rem; width: auto; }

.row-group { border: 1px dashed var(--border); border-radius: 8px; padding: 10px; margin-top: 10px; background: #fafafa; }
.row-group .row-item { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; }
.row-item > * { flex: 1 1 90px; min-width: 0; }
.row-item button { flex: 0 0 auto; }

.tabs {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  z-index: 10;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
}
.tabs button {
  flex: 1;
  background: none;
  border-radius: 0;
  padding: 12px 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 700;
}
.tabs button.active { color: var(--red); border-top: 3px solid var(--red); margin-top: -1px; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--dark);
  background-image: linear-gradient(160deg, var(--dark) 0%, #0b1219 100%);
}
.login-box { max-width: 380px; width: 100%; text-align: center; }
.login-box h1 { text-align: center; margin-bottom: 4px; color: var(--dark); }
.login-box p.subtitle { text-align: center; color: var(--text-muted); margin-top: 0; margin-bottom: 20px; text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.08em; font-weight: 700; }
.login-box label { text-align: left; }

.entry-list-item {
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.entry-list-item:last-child { border-bottom: none; }
.entry-list-item .fecha { font-weight: 700; font-family: var(--font-heading); color: var(--dark); }
.entry-list-item .meta { font-size: 0.85rem; color: var(--text-muted); }

.toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--dark);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}

.error-text { color: var(--red); font-size: 0.85rem; margin-top: 6px; }

.photo-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.photo-thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

.photo-thumb-wrap { position: relative; }
.photo-thumb-wrap img { width: 84px; height: 84px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.photo-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.simple-list { display: flex; flex-direction: column; gap: 6px; }
.simple-list .item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.simple-list .item-row:last-child { border-bottom: none; }
.simple-list .item-name { font-weight: 700; color: var(--dark); flex: 1; }
.simple-list .item-meta { font-size: 0.8rem; color: var(--text-muted); }

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--dark), var(--red));
  border-radius: 999px;
}

.badge-pct {
  font-family: var(--font-heading);
  font-weight: 800;
  color: var(--dark);
  min-width: 46px;
  text-align: right;
}

.plano-wrap {
  position: relative;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: crosshair;
  margin-top: 8px;
  background: #eee;
  touch-action: none;
}
.plano-wrap img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }

.plano-zone {
  position: absolute;
  border: 2px solid var(--red);
  background: rgba(207,46,46,0.2);
  box-sizing: border-box;
  pointer-events: none;
}
.plano-zone-label {
  position: absolute;
  top: -1px;
  left: -2px;
  transform: translateY(-100%);
  font-size: 0.62rem;
  font-weight: 700;
  color: #fff;
  padding: 1px 6px;
  border-radius: 3px 3px 3px 0;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex: 0 0 auto;
}

.selector-screen {
  min-height: 100vh;
  background: var(--surface-alt);
}
.selector-topbar {
  background: #fff;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--red);
}
.selector-body { max-width: 640px; margin: 0 auto; padding: 20px 16px 40px; }
.selector-body h1 { color: var(--dark); margin-bottom: 4px; }

.obra-cards { display: flex; flex-direction: column; gap: 12px; margin: 16px 0 24px; }
.obra-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.obra-card:hover { border-color: var(--red); }
.obra-card h3 { margin: 0 0 4px; color: var(--dark); }
.obra-card .meta-row { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.obra-card .meta-row strong { color: var(--text); }

.obra-actual-bar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.obra-actual-bar strong { color: var(--dark); font-family: var(--font-heading); }

.activity-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  background: #fff;
}
.activity-card:hover { border-color: var(--red); }
.activity-card .top-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.activity-card .top-row .name { font-weight: 700; color: var(--dark); }

/* ---------- Reporte imprimible (estilo bitácora física) ---------- */

.report {
  font-size: 0.85rem;
  border: 2px solid var(--dark);
  padding: 16px;
  background: #fff;
}
.report-logo-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--dark);
}
.report-logo-row img { height: 50px; }
.report-logo-row .titulo { text-align: right; }
.report-logo-row .titulo h2 { margin: 0; color: var(--dark); text-transform: uppercase; letter-spacing: 0.02em; }
.report-logo-row .titulo .fecha-grande { font-weight: 800; color: var(--red); font-family: var(--font-heading); }
.report-footer {
  margin-top: 20px;
  font-size: 0.68rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
}

.report-info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  border: 1px solid var(--border);
  margin-bottom: 14px;
  font-size: 0.78rem;
}
.report-info-grid .lbl, .report-info-grid .val {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.report-info-grid .lbl {
  background: #ececec;
  font-weight: 700;
  color: var(--dark);
  white-space: nowrap;
}
.report-info-grid .val { color: var(--text); }

.report-section-title {
  background: var(--dark);
  color: #fff;
  font-weight: 800;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 10px;
  margin: 16px 0 0;
  border-left: 4px solid var(--red);
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin-bottom: 4px;
}
.report-table th, .report-table td {
  border: 1px solid var(--border);
  padding: 5px 7px;
  text-align: left;
}
.report-table th {
  background: #f2f2f2;
  font-weight: 700;
  color: var(--dark);
}

.report-plano-wrap { position: relative; width: 100%; border: 1px solid var(--border); margin-top: 6px; }
.report-plano-wrap img { display: block; width: 100%; height: auto; }

.report-photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.report-photos-grid figure { margin: 0; }
.report-photos-grid img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
  border: 1px solid var(--dark);
}
.report-photos-grid figcaption {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
  font-weight: 700;
}

.report-firmas {
  display: flex;
  gap: 20px;
  margin-top: 30px;
}
.report-firmas .firma-box { flex: 1; text-align: center; }
.report-firmas .linea { border-top: 1px solid var(--dark); margin-top: 40px; padding-top: 4px; font-weight: 700; font-size: 0.78rem; }

@media print {
  header.topbar, .tabs, #view-nueva, #view-avance, #view-ajustes, #view-login, .card:has(#btn-buscar-historial) { display: none !important; }
  body { background: #fff; }
}
