/* ============ Cerlic Maintenance Site ============ */
:root {
  --navy: #0e3a5c;
  --navy-dark: #092840;
  --teal: #1180a8;
  --teal-light: #e3f2f8;
  --accent: #f5a623;
  --bg: #f4f7f9;
  --card: #ffffff;
  --text: #1c2b36;
  --text-dim: #44565f;
  --border: #d9e2e9;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(14, 58, 92, .12);
  --topbar-h: 60px;
  --topbar-total: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Hebrew", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
body.menu-open { overflow: hidden; }

/* ============ Top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-total);
  background: var(--navy);
  color: #fff;
  display: flex; align-items: center; gap: .6rem;
  padding-top: env(safe-area-inset-top, 0px);
  padding-inline: calc(.75rem + env(safe-area-inset-left, 0px)) calc(.75rem + env(safe-area-inset-right, 0px));
}
.menu-btn, .search-btn {
  display: none;
  background: none; border: none; color: #fff;
  font-size: 1.4rem; padding: .5rem .6rem; cursor: pointer;
  border-radius: 8px;
  min-height: 44px; min-width: 44px;
}
.menu-btn:active, .search-btn:active { background: rgba(255,255,255,.15); }
.brand { display: flex; align-items: center; gap: .55rem; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.brand-logo {
  width: 36px; height: 36px; flex: 0 0 36px;
  background: var(--teal); color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.2rem;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: .72rem; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .5rem; flex: 0 0 auto; }

.search-wrap { position: relative; }
#searchInput {
  width: 290px; max-width: 45vw;
  padding: .5rem .9rem;
  min-height: 40px;
  border-radius: 999px; border: none;
  background: rgba(255,255,255,.14); color: #fff;
  font-size: 16px; outline: none;
  transition: background .15s;
}
#searchInput::placeholder { color: rgba(255,255,255,.65); }
#searchInput:focus { background: #fff; color: var(--text); }
.search-results {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0;
  width: min(440px, 92vw); max-height: 65vh; overflow-y: auto;
  background: var(--card); color: var(--text);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.25);
  z-index: 100;
}
.search-result {
  display: block; width: 100%; text-align: start;
  padding: .65rem .9rem; border: none; background: none; cursor: pointer;
  border-bottom: 1px solid var(--border);
  font: inherit; color: inherit;
  min-height: 48px;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result:focus { background: var(--teal-light); }
.sr-path { font-size: .75rem; color: var(--teal); font-weight: 600; }
.sr-snippet { font-size: .8rem; color: var(--text-dim); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sr-snippet mark { background: #ffe9a8; border-radius: 3px; padding: 0 1px; }
.search-empty { padding: 1rem; color: var(--text-dim); font-size: .9rem; text-align: center; }

.lang-btn {
  background: rgba(255,255,255,.14); color: #fff;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px; padding: .42rem .85rem;
  min-height: 44px; min-width: 44px;
  font-size: .85rem; font-weight: 700; cursor: pointer;
  white-space: nowrap;
}
.lang-btn:hover { background: rgba(255,255,255,.25); }

/* ============ Layout ============ */
.layout { display: flex; min-height: calc(100vh - var(--topbar-total)); }

.sidebar {
  width: 280px; flex: 0 0 280px;
  background: var(--card);
  border-inline-end: 1px solid var(--border);
  padding: 1rem .75rem;
  display: flex; flex-direction: column;
  position: sticky; top: var(--topbar-total);
  height: calc(100vh - var(--topbar-total));
  overflow-y: auto;
}
.device-nav { display: flex; flex-direction: column; gap: .35rem; }
.nav-item {
  display: flex; align-items: center; gap: .7rem;
  padding: .7rem .8rem;
  border-radius: var(--radius);
  border: none; background: none; cursor: pointer;
  text-align: start; font: inherit; color: var(--text);
  min-height: 52px;
}
.nav-item:hover { background: var(--teal-light); }
.nav-item.active { background: var(--navy); color: #fff; }
.nav-item.active .nav-sub { color: rgba(255,255,255,.7); }
.nav-icon {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 9px; background: var(--teal-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
}
.nav-item.active .nav-icon { background: rgba(255,255,255,.15); }
.nav-text { display: flex; flex-direction: column; min-width: 0; }
.nav-name { font-weight: 700; font-size: .95rem; }
.nav-sub { font-size: .76rem; color: var(--text-dim); }
.sidebar-footer { margin-top: auto; padding: .9rem .5rem 0; font-size: .75rem; color: var(--text-dim); border-top: 1px solid var(--border); margin-top: 1rem; }
.sidebar-footer a { color: var(--teal); }

.overlay {
  position: fixed; inset: 0; z-index: 39;
  background: rgba(10, 25, 38, .5);
}

/* ============ Main ============ */
.main {
  flex: 1; min-width: 0;
  padding: 1.4rem 2rem calc(4rem + env(safe-area-inset-bottom, 0px));
  max-width: 980px; margin-inline: auto;
}

.device-header h1 { margin: 0 0 .2rem; font-size: 1.55rem; color: var(--navy); }
.device-header .device-sub { color: var(--text-dim); margin: 0 0 .4rem; }
.device-source {
  display: inline-block; font-size: .75rem; color: var(--text-dim);
  background: var(--card); border: 1px solid var(--border);
  padding: .15rem .6rem; border-radius: 999px; margin-bottom: .4rem;
}

.tab-bar {
  display: flex; gap: .4rem; margin: 1rem 0 1.2rem;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  position: sticky; top: var(--topbar-total); z-index: 10;
  background: var(--bg); padding: .5rem 0;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-bar.has-overflow {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
}
.tab {
  flex: 0 0 auto;
  scroll-snap-align: start;
  padding: .55rem 1.05rem;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--text);
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; min-height: 44px;
}
.tab.active { background: var(--teal); border-color: var(--teal); color: #fff; }

/* ============ Content ============ */
.content-area { animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none;} }

.content-area h2 { color: var(--navy); font-size: 1.25rem; margin: 1.6rem 0 .6rem; }
.content-area h2:first-child { margin-top: 0; }
.content-area h3 { color: var(--teal); font-size: 1.05rem; margin: 1.3rem 0 .4rem; }
.content-area h2, .content-area h3 { scroll-margin-top: calc(var(--topbar-total) + 64px); }
.content-area p { margin: .4rem 0 .8rem; }
.content-area ul, .content-area ol { padding-inline-start: 1.4rem; margin: .4rem 0 1rem; }
.content-area li { margin-bottom: .35rem; }
.content-area img { max-width: 100%; border-radius: var(--radius); }

.flash { animation: flashbg 2s ease; }
@keyframes flashbg { 0% { background: rgba(17,128,168,.22); } 100% { background: transparent; } }

/* on-this-page TOC chips */
.toc { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1.1rem; }
.toc a {
  font-size: .8rem; padding: .35rem .75rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--card); color: var(--navy);
  text-decoration: none; cursor: pointer;
}
.toc a:hover { border-color: var(--teal); background: var(--teal-light); }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem 1.2rem; margin-bottom: 1rem;
}

/* freq badges */
.freq {
  display: inline-block; font-size: .78rem; font-weight: 700;
  padding: .12rem .55rem; border-radius: 999px;
  vertical-align: middle; margin-inline-start: .4rem;
}
.freq-weekly { background: #e8f6ee; color: #14693f; }
.freq-monthly { background: #fff3da; color: #8a5a00; }
.freq-quarterly { background: #f3eafe; color: #5e2da0; }
.freq-halfyear { background: #e8eefe; color: #1d4396; }
.freq-yearly { background: #fde8e6; color: #9c2415; }

/* checklists */
.checklist { list-style: none; padding-inline-start: 0 !important; }
.checklist li {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .45rem .2rem;
  min-height: 48px; cursor: pointer;
  border-bottom: 1px dashed var(--border);
}
.checklist li:last-child { border-bottom: none; }
.checklist input[type="checkbox"] {
  width: 24px; height: 24px; flex: 0 0 24px;
  margin-top: .15rem;
  accent-color: var(--teal);
  cursor: pointer;
}

/* steps — tappable, persisted */
.steps { counter-reset: step; list-style: none; padding-inline-start: 0 !important; }
.steps > li {
  counter-increment: step;
  position: relative;
  padding: .35rem 0 .35rem;
  padding-inline-start: 2.5rem;
  margin-bottom: .3rem;
  cursor: pointer;
}
.steps > li::before {
  content: counter(step);
  position: absolute; inset-inline-start: 0; top: .35rem;
  width: 27px; height: 27px;
  background: var(--teal); color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 700;
}
.steps > li.done { opacity: .45; }
.steps > li.done::before { content: "✓"; background: var(--ok); }

/* tables */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: .6rem 0 1.2rem; border-radius: var(--radius); border: 1px solid var(--border); }
.tbl-wrap.has-overflow {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
table { border-collapse: collapse; width: 100%; background: var(--card); font-size: .9rem; }
th, td { padding: .6rem .75rem; text-align: start; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--navy); color: #fff; font-weight: 600; white-space: nowrap; }
td { unicode-bidi: plaintext; }
tr:last-child td { border-bottom: none; }
tr:nth-child(even) td { background: #f8fbfd; }

/* callouts */
.note, .warn, .tip {
  border-radius: var(--radius); padding: .8rem 1rem; margin: .8rem 0;
  border-inline-start: 4px solid;
  font-size: .92rem;
}
.note { background: var(--teal-light); border-color: var(--teal); }
.warn { background: #fdf0ef; border-color: var(--danger); }
.tip  { background: #e8f6ee; border-color: var(--ok); }

/* pdf links */
.pdf-links { display: flex; flex-wrap: wrap; gap: .6rem; margin: .8rem 0; }
.pdf-link {
  display: inline-flex; align-items: center; gap: .45rem;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: .5rem .95rem;
  color: var(--navy); text-decoration: none; font-size: .88rem; font-weight: 600;
  min-height: 44px;
}
.pdf-link:hover { border-color: var(--teal); background: var(--teal-light); }
.pdf-link::before { content: "📄"; }

.print-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--navy); color: #fff; border: none;
  border-radius: 999px; padding: .55rem 1.1rem;
  font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
  margin-bottom: 1rem; min-height: 44px;
}
.print-btn:hover { background: var(--navy-dark); }
.print-btn::before { content: "🖨️"; }

.clear-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  background: none; color: var(--navy); border: 1px solid var(--border);
  border-radius: 999px; padding: .55rem 1.1rem;
  font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
  margin-bottom: 1rem; margin-inline-start: .5rem; min-height: 44px;
}
.clear-btn:hover { border-color: var(--teal); background: var(--teal-light); }
.clear-btn::before { content: "🧹"; }

kbd {
  background: var(--navy); color: #fff;
  border-radius: 5px; padding: .1rem .45rem;
  font-family: inherit; font-size: .82em; font-weight: 600;
  white-space: nowrap;
}

/* offline banner + update toast */
.net-banner {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 70;
  background: var(--navy); color: #fff;
  font-size: .85rem; text-align: center;
  padding: .45rem .8rem calc(.45rem + env(safe-area-inset-bottom, 0px));
  display: none;
}
.net-banner.show { display: block; }
.update-toast {
  position: fixed; bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); inset-inline-start: 50%;
  transform: translateX(-50%);
  z-index: 71;
  background: var(--teal); color: #fff; border: none;
  border-radius: 999px; padding: .65rem 1.3rem;
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 18px rgba(0,0,0,.3);
  display: none;
}
.update-toast.show { display: block; }

/* ============ Desktop ============ */
@media (min-width: 769px) {
  .search-btn { display: none; }
}

/* ============ Tablet ============ */
@media (max-width: 1024px) {
  .sidebar { width: 240px; flex-basis: 240px; }
  .main { padding-inline: 1.3rem; }
  #searchInput { width: 220px; }
}

/* ============ Mobile ============ */
@media (max-width: 768px) {
  .menu-btn, .search-btn { display: block; }
  .brand-sub { display: none; }
  .brand-title { font-size: .92rem; }

  /* search becomes a full-width overlay opened by the 🔍 button */
  .search-wrap { display: none; }
  .topbar.search-open .search-wrap { display: block; }
  .topbar.search-open #searchInput {
    position: fixed; top: calc(env(safe-area-inset-top, 0px) + 8px);
    inset-inline: 8px; width: auto; max-width: none;
    height: 44px; z-index: 60;
    background: #fff; color: var(--text);
  }
  .topbar.search-open .search-results {
    position: fixed; top: calc(env(safe-area-inset-top, 0px) + 58px);
    inset-inline: 8px; width: auto;
    max-height: min(60dvh, calc(100dvh - var(--topbar-total) - 16px));
  }

  .sidebar {
    position: fixed; top: var(--topbar-total); bottom: 0;
    inset-inline-start: 0; z-index: 56;
    width: min(310px, 85vw);
    transform: translateX(calc(var(--dirflip) * -105%));
    transition: transform .22s ease;
    height: auto;
    box-shadow: 0 0 30px rgba(0,0,0,.2);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  html[dir="rtl"] { --dirflip: -1; }
  html[dir="ltr"] { --dirflip: 1; }
  .sidebar.open { transform: translateX(0); }
  .overlay { z-index: 55; }

  .main { padding: 1rem .9rem calc(4rem + env(safe-area-inset-bottom, 0px)); }
  .device-header h1 { font-size: 1.3rem; }
  .content-area { font-size: .95rem; }
  th { white-space: normal; }
  th, td { padding: .5rem .55rem; font-size: .9rem; }

  .freq { font-size: .8rem; padding: .18rem .6rem; }
  .sr-snippet { font-size: .875rem; }
  .sr-path { font-size: .8rem; }
  .checklist input[type="checkbox"] { width: 26px; height: 26px; flex: 0 0 26px; }
  .print-btn { display: none; }

  /* 3-column fault tables become stacked cards */
  .tbl-wrap.faults { border: none; overflow: visible; }
  .tbl-wrap.faults.has-overflow { -webkit-mask-image: none; mask-image: none; }
  .tbl-wrap.faults table, .tbl-wrap.faults tbody, .tbl-wrap.faults tr, .tbl-wrap.faults td { display: block; }
  .tbl-wrap.faults thead { display: none; }
  .tbl-wrap.faults table { background: transparent; }
  .tbl-wrap.faults tr {
    border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: .8rem; background: var(--card);
    padding: .4rem .6rem;
  }
  .tbl-wrap.faults tr:nth-child(even) td { background: transparent; }
  .tbl-wrap.faults td { border: none; }
  .tbl-wrap.faults td::before {
    content: attr(data-label);
    display: block; font-size: .72rem; font-weight: 700;
    color: var(--teal); margin-bottom: .15rem;
  }
}

@media (max-width: 420px) {
  .brand-logo { display: none; }
}

/* landscape phone */
@media (max-height: 480px) {
  :root { --topbar-h: 48px; }
  .tab-bar { position: static; }
  .brand-sub { display: none; }
}

/* ============ Print ============ */
@media print {
  .topbar, .sidebar, .tab-bar, .overlay, .print-btn, .clear-btn, .pdf-links, .search-results, .toc, .net-banner, .update-toast { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #bbb; break-inside: avoid; }
  .checklist input[type="checkbox"] { -webkit-appearance: none; appearance: none; border: 2px solid #333; border-radius: 4px; background: #fff; }
  .checklist input[type="checkbox"]:checked { background: #333; box-shadow: inset 0 0 0 3px #fff; }
  .tbl-wrap { overflow: visible; border: none; }
  a { color: inherit; text-decoration: none; }
  .device-header h1 { font-size: 1.4rem; }
}
