:root {
  --red: #D3151C;
  --red-dark: #A30F14;
  --red-soft: #FDEBEC;
  --amber: #B5650A;
  --amber-soft: #FDF1E2;
  --blue: #1B5FA8;
  --blue-soft: #E9F1FB;
  --ink: #1C1C1E;
  --ink-soft: #5B5B5F;
  --line: #E4E2E0;
  --paper: #FBFAF8;
  --card: #FFFFFF;
  --focus: #0B6FD1;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; padding-bottom: 90px; }

a { color: inherit; }

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

/* ---------- Header ---------- */

header.top {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + var(--safe-top)) 16px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

header.top img.logo { height: 30px; width: auto; display: block; }

header.top .titles { flex: 1; min-width: 0; }
header.top h1 {
  font-size: 15px;
  font-weight: 800;
  margin: 0;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
header.top p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--ink-soft);
}

.back-btn {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  padding: 6px 8px 6px 0;
  cursor: pointer;
  color: var(--ink);
}

/* ---------- SOS strip ---------- */

.sos-strip {
  margin: 14px 16px 6px;
  background: linear-gradient(135deg, var(--red) 0%, var(--red-dark) 100%);
  border-radius: var(--radius);
  color: #fff;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 6px 18px rgba(163,15,20,0.28);
}
.sos-strip .flame { font-size: 30px; }
.sos-strip .txt { flex: 1; }
.sos-strip .txt .lbl { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.6px; opacity: 0.9; }
.sos-strip .txt .num { font-size: 22px; font-weight: 800; margin-top: 1px; }
.sos-strip .call {
  background: #fff;
  color: var(--red-dark);
  font-weight: 800;
  font-size: 13px;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  text-decoration: none;
  white-space: nowrap;
}

/* ---------- Search ---------- */

.search-wrap { margin: 14px 16px; }
.search-wrap input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  font-size: 15px;
  color: var(--ink);
}
.search-wrap input:focus { border-color: var(--focus); }

/* ---------- Section labels ---------- */

.section-label {
  margin: 20px 16px 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-label .dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }
.dot.blue { background: var(--blue); }

/* ---------- Category grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0 16px;
}

.proc-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 96px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.proc-card:active { transform: scale(0.97); }
.proc-card .emoji { font-size: 22px; }
.proc-card .name { font-size: 13px; font-weight: 700; line-height: 1.25; color: var(--ink); }

.proc-card.cat-vida { border-left: 4px solid var(--red); }
.proc-card.cat-seguridad { border-left: 4px solid var(--amber); }
.proc-card.cat-infra { border-left: 4px solid var(--blue); }

.proc-card.hidden { display: none; }

/* ---------- Directory list entry ---------- */

.dir-btn {
  margin: 14px 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
}
.dir-btn .left { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; }
.dir-btn .chev { color: var(--ink-soft); font-size: 18px; }

/* ---------- Detail page ---------- */

main.detail { padding: 18px 16px 40px; max-width: 720px; margin: 0 auto; }

.detail-hero {
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  color: #fff;
}
.detail-hero.cat-vida { background: linear-gradient(135deg, var(--red), var(--red-dark)); }
.detail-hero.cat-seguridad { background: linear-gradient(135deg, #C97A17, var(--amber)); }
.detail-hero.cat-infra { background: linear-gradient(135deg, #2C79C9, var(--blue)); }

.detail-hero .emoji { font-size: 30px; }
.detail-hero h2 { font-size: 19px; margin: 8px 0 0; line-height: 1.3; }
.detail-hero .desc { font-size: 13.5px; opacity: 0.95; margin-top: 8px; line-height: 1.5; }

.quick-call {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 999px;
  padding: 8px 14px;
  margin-top: 12px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  color: #fff;
}

.role-block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.role-block h3 {
  font-size: 13.5px;
  margin: 0 0 10px;
  color: var(--ink);
  font-weight: 800;
}
.role-block ul { margin: 0; padding-left: 20px; }
.role-block li { font-size: 14px; line-height: 1.55; margin-bottom: 8px; color: var(--ink); }
.role-block li:last-child { margin-bottom: 0; }
.role-block p.note { font-size: 14px; line-height: 1.55; margin: 0; color: var(--ink); }
.role-block p.note.emph { color: var(--red-dark); font-weight: 700; }

/* ---------- Directory page ---------- */

.dir-search { margin: 4px 0 16px; }
.dir-cat { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-soft); margin: 18px 0 8px; }
.dir-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px;
}
.dir-row .name { font-size: 13.5px; font-weight: 600; padding-right: 10px; }
.dir-row a.call {
  flex-shrink: 0;
  background: var(--red-soft); color: var(--red-dark); font-weight: 800; font-size: 13px;
  border-radius: 999px; padding: 7px 12px; text-decoration: none; white-space: nowrap;
}

/* ---------- Bottom nav ---------- */

nav.bottom {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: var(--safe-bottom);
}
nav.bottom button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
}
nav.bottom button .ic { font-size: 19px; }
nav.bottom button.active { color: var(--red-dark); }

/* ---------- Offline badge ---------- */

.offline-badge {
  display: none;
  margin: 0 16px 6px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 10px;
  text-align: center;
}
.offline-badge.show { display: block; }

.empty-state {
  margin: 30px 16px; text-align: center; color: var(--ink-soft); font-size: 14px;
}

@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  header.top, .sos-strip, .search-wrap, .section-label, .grid, .dir-btn, main.detail {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }
  .sos-strip, .search-wrap, .dir-btn { margin-left: auto; margin-right: auto; width: calc(720px - 32px); }
}
