:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #666;
  --red: #c0392b;
  --orange: #d35400;
  --yellow: #b8860b;
  --blue: #1a5490;
  --green: #2c5f2d;
  --border: #e0e0e0;
  --card-bg: #fafafa;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --fg: #f0f0f0;
    --muted: #aaa;
    --card-bg: #2a2a2a;
    --border: #333;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  padding-bottom: max(env(safe-area-inset-bottom), 16px);
}

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--red);
  color: white;
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  padding-top: env(safe-area-inset-top);
  height: calc(56px + env(safe-area-inset-top));
}
.topbar h1 {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .back,
.topbar .search-icon {
  color: white;
  text-decoration: none;
  text-align: center;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  min-width: 44px;
}

/* HOME PAGE */
.home-header {
  background: linear-gradient(160deg, #8e1d12 0%, var(--red) 100%);
  color: white;
  padding: 24px 16px 20px;
  padding-top: calc(24px + env(safe-area-inset-top));
}
.home-header h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 4px;
}
.home-header .subtitle {
  font-size: 14px;
  opacity: 0.85;
  margin: 0 0 16px;
}
.home-search-wrap {
  position: relative;
}
.home-search-wrap input[type="search"] {
  width: 100%;
  padding: 12px 16px 12px 42px;
  font-size: 17px;
  border: none;
  border-radius: 12px;
  background: rgba(255,255,255,0.95);
  color: #1a1a1a;
  -webkit-appearance: none;
  appearance: none;
}
.home-search-wrap::before {
  content: "🔍";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  pointer-events: none;
}
.home-search-wrap input:focus {
  outline: 3px solid white;
}

/* CARDS */
.cards {
  padding: 12px 0;
}
.card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 16px;
  margin: 8px 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 6px solid var(--red);
  border-radius: 12px;
  color: var(--fg);
  text-decoration: none;
  min-height: 80px;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, box-shadow 0.1s;
}
.card:active { transform: scale(0.98); }
.card.urgent { border-left-color: var(--red); }
.card.orange { border-left-color: var(--orange); }
.card.yellow { border-left-color: var(--yellow); }
.card.blue { border-left-color: var(--blue); }
.card-icon { font-size: 28px; flex-shrink: 0; width: 40px; text-align: center; }
.card-text { flex: 1; min-width: 0; }
.card .title { font-size: 17px; font-weight: 700; margin-bottom: 2px; }
.card .sub { font-size: 13px; color: var(--muted); line-height: 1.3; }
.card .arrow { color: var(--muted); font-size: 20px; flex-shrink: 0; }

/* EMERGENCY BLOCK */
.emergency-block {
  margin: 8px 12px;
  border-radius: 12px;
  overflow: hidden;
}
.tel-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: var(--red);
  color: white;
  font-weight: 700;
  font-size: 17px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tel-btn.secondary {
  background: #b03020;
  font-weight: 600;
  font-size: 15px;
}

/* FOOTER STRIP */
.footer-strip {
  margin: 12px 12px 0;
  padding: 14px 16px;
  background: #fff8dc;
  border: 1.5px solid var(--yellow);
  border-radius: 12px;
  font-size: 14px;
  color: #4a3a00;
  line-height: 1.4;
}
@media (prefers-color-scheme: dark) {
  .footer-strip { background: #2a2500; color: #e0c040; border-color: #6b5c00; }
}
.footer-strip strong { display: block; margin-bottom: 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.last-updated {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 16px;
}

/* DOC PAGES */
.doc-page .doc {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}
.doc h1 { font-size: 22px; color: var(--red); margin: 0 0 16px; }
.doc h2 { font-size: 19px; color: var(--red); margin: 28px 0 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.doc h2:first-child { border-top: none; }
.doc h3 { font-size: 16px; color: var(--orange); margin: 20px 0 8px; }
.doc h4 { font-size: 15px; color: var(--blue); margin: 16px 0 6px; }
.doc p { margin: 0 0 12px; }
.doc ul, .doc ol { margin: 0 0 12px; padding-left: 22px; }
.doc li { margin-bottom: 6px; }
.doc strong { color: var(--fg); }
.doc em { color: var(--muted); }
.doc blockquote {
  border-left: 4px solid var(--orange);
  margin: 12px 0;
  padding: 10px 14px;
  background: var(--card-bg);
  border-radius: 0 8px 8px 0;
  font-style: italic;
}
.doc code {
  background: var(--card-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
  font-family: "SF Mono", Menlo, monospace;
}
.doc hr { border: none; border-top: 2px solid var(--border); margin: 20px 0; }
.doc mark { background: #fff59d; padding: 2px 4px; border-radius: 3px; color: #1a1a1a; }
.doc table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.doc th { background: var(--red); color: white; padding: 8px 10px; text-align: left; }
.doc td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.doc tr:nth-child(even) td { background: var(--card-bg); }

/* INLINE SEARCH ON DOC PAGES */
.search-inline {
  position: sticky;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 50;
  background: var(--bg);
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.search-inline input {
  width: 100%;
  padding: 10px 14px;
  font-size: 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--fg);
  -webkit-appearance: none;
  appearance: none;
}
.search-inline input:focus { border-color: var(--red); outline: none; }
.search-highlight { background: #fff59d; border-radius: 2px; }

/* SEARCH PAGE */
.search-page {
  padding: 16px;
}
.search-page .search-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.search-page input[type="search"] {
  flex: 1;
  padding: 12px 14px;
  font-size: 17px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  color: var(--fg);
  -webkit-appearance: none;
  appearance: none;
}
.search-page input:focus { border-color: var(--red); outline: none; }
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.chip {
  padding: 7px 14px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  color: var(--blue);
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.chip:active { background: var(--border); }
.result-count { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.result-item {
  display: block;
  padding: 14px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  text-decoration: none;
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
}
.result-item:active { background: var(--border); }
.result-heading { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.result-source { font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.3px; }
.result-snippet { font-size: 14px; color: var(--fg); line-height: 1.4; }
.result-snippet mark { background: #fff59d; padding: 1px 3px; border-radius: 2px; color: #1a1a1a; }
.no-results { text-align: center; color: var(--muted); padding: 40px 20px; }
.no-results .hint { font-size: 14px; margin-top: 8px; }

/* INFOGRAPHIC PAGE */
.infographic-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}
@media (max-width: 480px) {
  .infographic-wrapper .page {
    transform-origin: top left;
    transform: scale(0.45);
    width: 222%;
    margin-bottom: -55%;
  }
}

/* PDF LINK */
.pdf-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin: 12px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
  min-height: 56px;
}
