/* Deepal E07 service manual viewer
   Built for workshop use: high contrast, large touch targets, readable tables,
   and diagrams that can be zoomed properly on a phone. */

:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #eef0f4;
  --border:    #d8dce4;
  --text:      #171a1f;
  --muted:     #5c6472;
  --accent:    #0b63d6;
  --accent-sf: #e7f0fd;
  --warn-bd:   #c0392b;
  --warn-bg:   #fdecea;
  --warn-tx:   #8c1d12;
  --caut-bd:   #d98200;
  --caut-bg:   #fff5e3;
  --caut-tx:   #8a5200;
  --note-bd:   #0b7a8c;
  --note-bg:   #e6f6f9;
  --note-tx:   #075a67;
  --green:     #e8f6ea;
  --topbar-h:  56px;
  --sidebar-w: 320px;
  --radius:    8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg:        #0f1115;
  --surface:   #161a21;
  --surface-2: #1d222b;
  --border:    #2b323d;
  --text:      #e6e9ef;
  --muted:     #98a1b0;
  --accent:    #5aa2ff;
  --accent-sf: #16243a;
  --warn-bd:   #e05c4b;
  --warn-bg:   #2a1614;
  --warn-tx:   #ff9d8f;
  --caut-bd:   #d99a2b;
  --caut-bg:   #2a2114;
  --caut-tx:   #ffc766;
  --note-bd:   #38a5ba;
  --note-bg:   #10252a;
  --note-tx:   #7fd6e6;
  --green:     #16301c;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0f1115; --surface:#161a21; --surface-2:#1d222b; --border:#2b323d;
    --text:#e6e9ef; --muted:#98a1b0; --accent:#5aa2ff; --accent-sf:#16243a;
    --warn-bd:#e05c4b; --warn-bg:#2a1614; --warn-tx:#ff9d8f;
    --caut-bd:#d99a2b; --caut-bg:#2a2114; --caut-tx:#ffc766;
    --note-bd:#38a5ba; --note-bg:#10252a; --note-tx:#7fd6e6;
    --green:#16301c; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* A class that sets `display` outranks the UA rule for [hidden], and several
   overlays below do exactly that -- keep the attribute authoritative. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9;
      stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; flex: none; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 30px; border-radius: 6px;
  background: var(--accent); color: #fff; font: 700 12px/1 var(--sans); letter-spacing: .04em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 14px; }
.brand-text small { font-size: 11px; color: var(--muted); }

.searchwrap { position: relative; flex: 1; max-width: 560px; margin-left: auto; }
.searchicon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: var(--muted); pointer-events: none;
}
#search {
  width: 100%; height: 36px; padding: 0 34px 0 34px;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
#search::-webkit-search-cancel-button { -webkit-appearance: none; }
.searchkbd {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  font: 11px/1 var(--mono); color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px; padding: 3px 5px; background: var(--surface);
}
#search:focus + .searchkbd { display: none; }

.iconbtn {
  display: grid; place-items: center; width: 36px; height: 36px; flex: none;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--text); cursor: pointer; text-decoration: none;
}
.iconbtn:hover { background: var(--surface-2); }
.navtoggle { display: none; }
.ico-sun { display: none; }
:root[data-theme="dark"] .ico-sun { display: block; }
:root[data-theme="dark"] .ico-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico-sun { display: block; }
  :root:not([data-theme="light"]) .ico-moon { display: none; }
}

/* ---------- layout ---------- */
.layout { display: flex; padding-top: var(--topbar-h); min-height: 100vh; }

.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow: hidden; z-index: 30;
}
.manualtabs { display: flex; gap: 4px; padding: 10px; border-bottom: 1px solid var(--border); }
.manualtabs button {
  flex: 1; padding: 7px 4px; font: 600 11.5px/1.25 var(--sans); cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--muted);
}
.manualtabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.tree { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 8px 40px; }
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree li > ul { margin-left: 10px; padding-left: 8px; border-left: 1px solid var(--border); }
.node {
  display: flex; align-items: flex-start; gap: 6px; width: 100%;
  padding: 6px 8px; border: 0; border-radius: 6px; margin: 1px 0;
  background: transparent; color: inherit; font: inherit; font-size: 13.5px;
  text-align: left; cursor: pointer; line-height: 1.35;
}
.node:hover { background: var(--surface-2); }
.node .tw { flex: none; width: 14px; margin-top: 3px; color: var(--muted); transition: transform .15s; }
.node[aria-expanded="true"] .tw { transform: rotate(90deg); }
.node.folder { font-weight: 600; }
.node.leaf { color: var(--muted); padding-left: 26px; }
.node.leaf:hover { color: var(--text); }
.node.leaf.active { background: var(--accent-sf); color: var(--accent); font-weight: 600; }
li.collapsed > ul { display: none; }

/* ---------- content ---------- */
.content {
  flex: 1; min-width: 0; margin-left: var(--sidebar-w);
  padding: 26px clamp(16px, 4vw, 48px) 120px;
}
.page { max-width: 900px; margin: 0 auto; }
.loading { display: flex; align-items: center; gap: 10px; justify-content: center;
           padding: 80px 20px; color: var(--muted); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border);
           border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.crumbs span:not(:last-child)::after { content: "›"; margin: 0 6px; opacity: .6; }

h1.pagetitle {
  font-size: clamp(20px, 3.2vw, 28px); line-height: 1.25; margin: 0 0 6px;
  letter-spacing: -.01em;
}
.pagemeta { font: 500 11.5px/1 var(--mono); color: var(--muted); margin-bottom: 22px; }

.page h2, .page h3, .page h4 {
  line-height: 1.3; margin: 30px 0 10px; letter-spacing: -.005em;
  scroll-margin-top: calc(var(--topbar-h) + 12px);
}
.page h2 { font-size: 19px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.page h3 { font-size: 16.5px; }
.page h4 { font-size: 15px; color: var(--muted); }
.page p { margin: 10px 0; }
.page b { font-weight: 650; }
.kw { font-family: var(--mono); font-size: .92em; background: var(--surface-2);
      padding: 1px 5px; border-radius: 4px; }

.page ol, .page ul { margin: 10px 0; padding-left: 26px; }
.page li { margin: 6px 0; }
.page li > p:first-child { margin-top: 0; }
.page li > p:last-child { margin-bottom: 0; }

a.xref { color: var(--accent); text-decoration: none; border-bottom: 1px solid currentColor; }
a.xref:hover { background: var(--accent-sf); }
a.ext::after { content: " ↗"; font-size: .85em; opacity: .7; }

/* callouts — safety information must be impossible to miss */
.callout {
  margin: 16px 0; padding: 12px 14px; border-left: 4px solid; border-radius: 0 var(--radius) var(--radius) 0;
}
.callout .cl-label { display: block; font: 700 11px/1 var(--sans); letter-spacing: .09em; margin-bottom: 6px; }
.callout p { margin: 4px 0; }
.callout.warning { border-color: var(--warn-bd); background: var(--warn-bg); }
.callout.warning .cl-label { color: var(--warn-tx); }
.callout.caution { border-color: var(--caut-bd); background: var(--caut-bg); }
.callout.caution .cl-label { color: var(--caut-tx); }
.callout.note    { border-color: var(--note-bd); background: var(--note-bg); }
.callout.note .cl-label { color: var(--note-tx); }

/* tables */
.tablewrap { overflow-x: auto; margin: 16px 0; border: 1px solid var(--border);
             border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { border: 1px solid var(--border); padding: 8px 10px; vertical-align: top; text-align: left; }
thead th { background: var(--surface-2); font-weight: 650; position: sticky; top: 0; }
td.green { background: var(--green); }
td p, th p { margin: 3px 0; }
td img { max-width: 220px; height: auto; border-radius: 4px; cursor: zoom-in; }

/* figures */
figure.fig { margin: 18px 0; text-align: center; }
figure.fig img {
  /* --srcw is the source's percentage-of-an-A4-page width. Honoured on a wide
     screen; the mobile block below drops it so diagrams fill the column. */
  width: var(--srcw, auto);
  max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; cursor: zoom-in;
}
figure.fig figcaption { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.figcap { font-size: 13px; color: var(--muted); text-align: center; margin: -8px 0 16px; }

/* untranslated marker */
.raw { border-bottom: 1px dotted var(--caut-bd); }

/* prev / next */
.pager { display: flex; gap: 12px; margin-top: 46px; padding-top: 20px; border-top: 1px solid var(--border); }
.pager a {
  flex: 1; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: inherit; background: var(--surface); min-width: 0;
}
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.pager strong { display: block; font-size: 13.5px; font-weight: 600;
                overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager .next { text-align: right; }

/* home screen: always a dark workshop bay, whatever the theme */
.page.home { max-width: 1040px; }
.bay {
  --ink: #e9edf3; --dim: #8b95a5; --line: rgba(255,255,255,.055); --hot: #ff7a1a;
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 28px; align-items: center; padding: 34px 32px; margin: 0 0 22px;
  background:
    radial-gradient(120% 90% at 85% 40%, rgba(90,162,255,.10), transparent 60%),
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 100% 32px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 32px 100%,
    #07090c;
  border: 1px solid #1c222b; border-radius: 6px; color: var(--ink); overflow: hidden;
}
.bay::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: repeating-linear-gradient(-45deg, var(--hot) 0 8px, #07090c 8px 16px);
}
.bay-tag { font: 600 11px/1 var(--mono); letter-spacing: .14em; color: var(--hot); }
.page .bay h1 {
  margin: 14px 0 12px; padding: 0; border: 0; color: var(--ink);
  font-size: clamp(30px, 4.6vw, 50px); line-height: .98; letter-spacing: -.035em; font-weight: 800;
}
.bay h1 em {
  font-style: normal; color: transparent; -webkit-text-stroke: 1.5px var(--ink);
  font-size: 1.35em; letter-spacing: -.02em;
}
.page .bay p { color: var(--dim); margin: 0; font-size: 14.5px; max-width: 44ch; }
.bay-cta {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 20px;
  font: 600 13.5px/1 var(--sans); color: #07090c; background: var(--ink);
  border: 0; border-radius: 3px; padding: 11px 12px 11px 16px; cursor: pointer;
  transition: background .15s ease;
}
.bay-cta:hover { background: var(--hot); }
.bay-cta:focus-visible { outline: 2px solid var(--hot); outline-offset: 3px; }
.bay-cta kbd { font: 600 11px/1 var(--mono); padding: 3px 6px; border: 1px solid rgba(0,0,0,.35); border-radius: 3px; }
.readout { margin: 24px 0 0; border-top: 1px dashed #2a313c; }
.readout div { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px dashed #2a313c; font-family: var(--mono); }
.readout dt { width: 64px; flex: none; font-size: 10.5px; color: var(--dim); text-transform: uppercase; letter-spacing: .1em; padding-top: 2px; }
.readout dd { margin: 0; font-size: 12.5px; color: var(--ink); }
.bay-scan { position: relative; margin: 0; padding: 14px; }
.bay-scan img {
  display: block; width: 100%; height: auto; border-radius: 2px;
  filter: grayscale(1) contrast(1.15) brightness(.9);
  -webkit-mask-image: radial-gradient(75% 80% at 50% 55%, #000 55%, transparent 100%);
          mask-image: radial-gradient(75% 80% at 50% 55%, #000 55%, transparent 100%);
  animation: develop 2.4s ease-out .2s both;
}
@keyframes develop { from { filter: grayscale(1) contrast(1.15) brightness(.25) blur(3px); } }
.bay:hover .bay-scan img { filter: grayscale(.15) contrast(1.05) brightness(1); transition: filter .6s ease; }
.corner { position: absolute; width: 22px; height: 22px; border: 2px solid var(--hot); }
.corner.tl { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.corner.tr { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.corner.bl { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.corner.br { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.scanline {
  position: absolute; left: 14px; right: 14px; top: 14px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--hot), transparent);
  box-shadow: 0 0 14px var(--hot); opacity: .8; animation: scan 3.2s ease-in-out .3s 2 both;
}
@keyframes scan { 0% { top: 14px; opacity: 0; } 10% { opacity: .85; } 90% { opacity: .85; } 100% { top: calc(100% - 16px); opacity: 0; } }
.bay-scan figcaption {
  position: absolute; right: 22px; bottom: 20px; font: 600 10.5px/1 var(--mono);
  letter-spacing: .14em; color: var(--hot); background: rgba(7,9,12,.75); padding: 5px 7px;
}
@media (prefers-reduced-motion: reduce) {
  .bay-scan img, .scanline { animation: none; } .scanline { display: none; }
}

.bays { display: grid; gap: 10px; }
.bayrow {
  position: relative; display: grid; grid-template-columns: 64px minmax(0, 1fr) 200px; align-items: stretch;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
  text-decoration: none; color: inherit; min-height: 112px; transition: border-color .15s ease;
}
.bayrow:hover { border-color: #ff7a1a; }
.bay-no {
  display: grid; place-items: center; font: 800 26px/1 var(--mono); color: var(--muted);
  border-right: 1px dashed var(--border); transition: color .15s ease;
}
.bayrow:hover .bay-no { color: #ff7a1a; }
.bay-body { padding: 16px 20px; display: flex; flex-direction: column; justify-content: center; }
.page .bayrow h3 { margin: 0 0 4px; font-size: 16.5px; letter-spacing: -.01em; }
.page .bayrow p { margin: 0; font-size: 13px; color: var(--muted); max-width: 60ch; }
.bay-meta { margin-top: 8px; font: 500 11.5px/1 var(--mono); color: var(--muted); }
.bay-meta b { color: var(--text); font-weight: 700; }
.bay-thumb {
  width: 100%; height: 100%; object-fit: cover; filter: grayscale(1) brightness(.75);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 45%);
          mask-image: linear-gradient(90deg, transparent, #000 45%);
  transition: filter .35s ease;
}
.bayrow:hover .bay-thumb { filter: grayscale(0) brightness(1); }
.home-credit { margin: 22px 0 0; font-size: 11px; color: var(--muted); }
.home-credit a { color: inherit; }

@media (max-width: 760px) {
  .bay { grid-template-columns: 1fr; padding: 26px 18px 22px 22px; gap: 10px; }
  .bay-scan { order: -1; }
  .bayrow { grid-template-columns: 48px minmax(0, 1fr); }
  .bay-no { font-size: 20px; }
  .bay-thumb { display: none; }
  .bay-body { padding: 14px 16px; }
}

/* ---------- search results ---------- */
.results {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0; z-index: 35;
  background: var(--bg); overflow-y: auto; padding: 18px clamp(16px, 4vw, 48px) 80px;
}
.results-inner { max-width: 900px; margin: 0 auto; }
.results h2 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 0 0 14px; }
.hit {
  display: block; padding: 13px 15px; margin-bottom: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: inherit;
}
.hit:hover, .hit.sel { border-color: var(--accent); background: var(--accent-sf); }
.hit-title { font-weight: 600; font-size: 14.5px; }
.hit-path { font-size: 11.5px; color: var(--muted); margin: 2px 0 5px; }
.hit-snip { font-size: 12.8px; color: var(--muted); line-height: 1.5; }
mark { background: #ffe066; color: #000; border-radius: 2px; padding: 0 1px; }
:root[data-theme="dark"] mark { background: #7a5c00; color: #ffe9a8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) mark { background: #7a5c00; color: #ffe9a8; }
}
.noresults { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------- image viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(8,10,14,.95);
          display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; color: #fff;
              background: rgba(0,0,0,.45); }
.viewer-bar .iconbtn { color: #fff; }
.viewer-bar .iconbtn:hover { background: rgba(255,255,255,.14); }
.viewer-name { flex: 1; font: 500 13px/1 var(--mono); opacity: .8;
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-zoom { font: 500 12px/1 var(--mono); opacity: .8; min-width: 46px; text-align: right; }
.viewer-stage { flex: 1; overflow: hidden; display: grid; place-items: center;
                cursor: grab; touch-action: none; }
.viewer-stage.grabbing { cursor: grabbing; }
.viewer-stage img { max-width: none; transform-origin: 0 0; will-change: transform;
                    background: #fff; user-select: none; -webkit-user-drag: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .navtoggle { display: grid; }
  .brand-text { display: none; }
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; width: min(86vw, 340px); }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .scrim { position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,.45); z-index: 29; }
  .content { margin-left: 0; padding: 20px 16px 100px; }
  th, td { padding: 7px 8px; }
  .pager { flex-direction: column; }

  /* A diagram drawn at "50% of an A4 page" lands at ~150px on a phone, which
     is useless in a workshop. Ignore the source width and use the column. */
  figure.fig img { width: 100%; }
  /* Procedures live inside tables, so a cell is effectively the page body --
     it must not be squeezed into a narrow column. */
  table, tbody, tr { display: block; width: 100%; }
  thead { display: none; }
  td, th { display: block; width: auto !important; border: 0; padding: 6px 2px; }
  tr + tr { border-top: 1px solid var(--border); }
  .tablewrap { border: 0; background: none; padding: 0; }
  /* ...but a genuine data table (torque figures, pin-outs) still needs its
     grid, so tables that carry a header row keep it and scroll sideways. */
  .tablewrap.grid { overflow-x: auto; border: 1px solid var(--border);
                    background: var(--surface); border-radius: var(--radius); }
  .tablewrap.grid table, .tablewrap.grid tbody, .tablewrap.grid tr { display: table; }
  .tablewrap.grid table { width: 100%; }
  .tablewrap.grid tbody { display: table-row-group; }
  .tablewrap.grid tr { display: table-row; }
  .tablewrap.grid thead { display: table-header-group; }
  .tablewrap.grid td, .tablewrap.grid th {
    display: table-cell; border: 1px solid var(--border); padding: 7px 8px;
  }
  .tablewrap.grid tr + tr { border-top: 0; }

  /* Bigger targets for gloved hands. */
  .node { padding: 10px 10px; font-size: 14.5px; }
  .node.leaf { padding-left: 28px; }
  .iconbtn { width: 40px; height: 40px; }
}
@media (max-width: 560px) {
  .searchkbd { display: none; }
  .brand-mark { width: 34px; }
  body { font-size: 15.5px; }
  .page { font-size: 15.5px; }
  h1.pagetitle { font-size: 21px; }
  .crumbs { font-size: 12px; }
  .results { padding: 14px 16px 80px; }
}

/* Touch devices: the hover-to-reveal affordances never fire, and the image
   viewer needs the whole screen. */
@media (hover: none) {
  figure.fig img, td img { cursor: default; }
  .viewer-bar { padding: 10px 12px; }
  .viewer-bar .iconbtn { width: 44px; height: 44px; }
}

@media print {
  .topbar, .sidebar, .pager, .results, .scrim { display: none !important; }
  .content { margin: 0; padding: 0; }
  .tablewrap { overflow: visible; }
  a.xref { color: inherit; border: 0; }
  figure.fig img { max-height: 16cm; }
}
