/* Fault Lookup screen (lookup.js): entry button, search + filter controls,
   the custom module dropdown (lkd), grouped results, and the ISTA fault-detail
   modal (fm/fi). Split out of styles.css to keep both files readable. */

/* entry button on the chassis screen, below the grid */
.lookup-entry {
  margin-top: 18px; width: 100%; cursor: pointer;
  display: flex; align-items: center; gap: 16px; text-align: left;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 4px; padding: 16px 20px;
  transition: transform .18s cubic-bezier(.2,.7,.2,1), border-color .18s, box-shadow .18s;
}
.lookup-entry:hover { transform: translateY(-2px); border-color: var(--line-bright); box-shadow: var(--shadow); }
.lookup-entry-icon {
  font-size: 22px; color: var(--amber); width: 36px; height: 36px; flex: none;
  display: grid; place-items: center; border: 1px solid var(--line); border-radius: 4px;
  background: var(--raised);
}
.lookup-entry-text { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.lookup-entry-title { font-size: 16px; font-weight: 800; letter-spacing: .01em; color: var(--ink); }
.lookup-entry-desc { font-size: 12px; color: var(--ink-faint); }
.lookup-entry-arrow { color: var(--amber); font-size: 18px; opacity: 0; transform: translateX(-6px); transition: all .2s; }
.lookup-entry:hover .lookup-entry-arrow { opacity: 1; transform: none; }

/* controls: search + filters */
.lookup-controls {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  margin-bottom: 14px;
}
.lookup-search {
  position: relative; flex: 1 1 320px; min-width: 240px;
  display: flex; align-items: center;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--bg); transition: border-color .16s;
}
.lookup-search:focus-within { border-color: var(--amber); }
.lookup-search-icon { padding: 0 4px 0 12px; color: var(--ink-faint); font-size: 16px; }
.lookup-input {
  flex: 1; border: none; outline: none; background: none; color: var(--ink);
  font-family: var(--mono); font-size: 14px; padding: 11px 8px;
}
.lookup-input::placeholder { color: var(--ink-faint); }
.lookup-clear {
  border: none; background: none; cursor: pointer; color: var(--ink-faint);
  font-size: 20px; line-height: 1; padding: 0 12px; transition: color .15s;
}
.lookup-clear:hover { color: var(--ink); }

.lookup-filters { display: flex; gap: 10px; flex-wrap: wrap; }
.lookup-filter { display: flex; flex-direction: column; gap: 5px; }
.lookup-filter-lbl {
  font-family: var(--mono); font-size: 10px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-faint);
}
.lookup-filter-slot { display: block; }

/* custom Lookup dropdown (lkd) — rich rows: label + meta tag + count */
.lkd { position: relative; }
.lkd-btn {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 4px; background: var(--bg);
  color: var(--ink); font-family: var(--mono); font-size: 13px;
  padding: 10px 12px; min-width: 200px; outline: none; text-align: left;
  transition: border-color .16s;
}
.lkd-btn:hover { border-color: var(--line-bright); }
.lkd.open .lkd-btn { border-color: var(--amber); }
.lkd-val { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lkd-val.lkd-placeholder { color: var(--ink-faint); }
.lkd-caret { color: var(--ink-faint); font-size: 11px; flex: none; transition: transform .16s; }
.lkd.open .lkd-caret { transform: rotate(180deg); }

.lkd-pop {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  min-width: 300px; max-width: 420px;
  border: 1px solid var(--line-bright); border-radius: 6px; overflow: hidden;
  background: var(--panel); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
/* the [hidden] attribute must win over the flex display above, else the popup
   (with its search box) shows even when closed */
.lkd-pop[hidden] { display: none; }
.lkd.drop-up .lkd-pop { top: auto; bottom: calc(100% + 6px); }
/* search stays pinned while the list scrolls */
.lkd-search {
  flex: none; width: 100%; box-sizing: border-box;
  border: none; border-bottom: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-family: var(--mono); font-size: 13px;
  padding: 11px 14px; outline: none;
}
.lkd-list { max-height: 320px; overflow-y: auto; padding: 5px; }
.lkd-item {
  width: 100%; box-sizing: border-box; display: flex; align-items: center; gap: 12px;
  cursor: pointer; background: none; border: none; border-radius: 4px;
  padding: 9px 12px; min-height: 34px;
  font-family: var(--mono); font-size: 13px; line-height: 1.35; color: var(--ink); text-align: left;
}
/* subtle divider between rows so long lists read as distinct entries */
.lkd-item + .lkd-item { box-shadow: 0 -1px 0 var(--line); }
.lkd-item:hover { background: var(--raised); box-shadow: none; }
.lkd-item:hover + .lkd-item { box-shadow: none; }
.lkd-item.active { color: #1a1206; background: linear-gradient(180deg, var(--amber), var(--amber-soft)); box-shadow: none; }
.lkd-item.active + .lkd-item { box-shadow: none; }
html[data-theme="inpa"] .lkd-item.active { color: #fff; background: #000080; }
/* label takes the room and truncates; count is pinned to the right */
.lkd-item-label {
  flex: 1; min-width: 0; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lkd-item.active .lkd-item-label { font-weight: 800; }
.lkd-item-meta {
  flex: none; max-width: 45%; font-size: 11px; color: var(--ink-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right;
}
.lkd-item.active .lkd-item-meta { color: inherit; opacity: .8; }
.lkd-item-count {
  flex: none; font-size: 11px; color: var(--ink-faint); margin-left: auto;
  padding: 1px 7px; border-radius: 10px; background: var(--raised);
  font-variant-numeric: tabular-nums;
}
.lkd-item:hover .lkd-item-count { background: var(--bg); }
.lkd-item.active .lkd-item-count { color: inherit; opacity: .9; background: rgba(0,0,0,.12); }
.lkd-empty { padding: 16px; text-align: center; font-family: var(--mono); font-size: 12px; color: var(--ink-faint); }

/* INPA-mode module selector opens the two-pane popup; the button matches lkd-btn */
.lkd-inpa-btn { width: 100%; }

.lookup-count {
  font-family: var(--mono); font-size: 12px; color: var(--ink-dim);
  letter-spacing: .03em; margin-bottom: 12px;
}

/* results: grouped by module */
.lookup-results { display: flex; flex-direction: column; gap: 12px; }
.lookup-group {
  border: 1px solid var(--line); border-radius: 4px; overflow: hidden;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}
.lookup-group-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-bottom: 1px solid var(--line);
  background: var(--raised);
}
.lookup-chip {
  font-family: var(--mono); font-size: 11px; font-weight: 800; letter-spacing: .06em;
  color: #1a1206; background: linear-gradient(180deg, var(--amber), var(--amber-soft));
  padding: 3px 8px; border-radius: 3px; flex: none;
}
html[data-theme="inpa"] .lookup-chip { color: #fff; background: #000080; }
.lookup-group-name { font-weight: 700; font-size: 14px; flex: 1; min-width: 0; }
.lookup-group-sgbd {
  font-family: var(--mono); font-size: 11px; color: var(--ink-faint);
  padding: 2px 7px; border: 1px solid var(--line); border-radius: 3px; flex: none;
}
.lookup-group-count {
  font-family: var(--mono); font-size: 11px; color: var(--ink-faint); flex: none;
}
.lookup-rows { display: flex; flex-direction: column; }
.lookup-row {
  display: flex; align-items: baseline; gap: 14px;
  padding: 8px 16px; border-bottom: 1px solid var(--line);
}
.lookup-row:last-child { border-bottom: none; }
.lookup-row:hover { background: var(--raised); }
/* expandable rows (ISTA detail available) open a modal */
.lookup-row.lookup-expandable { cursor: pointer; }
.lookup-more { margin-left: auto; color: var(--ink-faint); font-size: 15px; line-height: 1;
  flex: none; transition: color .12s, transform .12s; }
.lookup-row.lookup-expandable:hover .lookup-more { color: var(--amber); transform: translateX(2px); }

/* --- fault detail modal (large) --- */
.fault-modal {
  width: min(920px, 92vw); max-height: 86vh; display: flex; flex-direction: column;
  padding: 0; overflow: hidden;
}
.fm-head {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--line);
}
.fm-code { font-family: var(--mono); font-size: 22px; font-weight: 800; color: var(--amber);
  letter-spacing: .02em; flex: none; }
.fm-title { font-size: 15px; color: var(--ink); flex: 1; line-height: 1.35; }
.fm-close { -webkit-app-region: no-drag; cursor: pointer; flex: none;
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-dim); font-size: 13px; }
.fm-close:hover { color: var(--ink); border-color: var(--ink-faint); }
.fm-pcodes { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 22px 0; }
.fm-pcode { font-family: var(--mono); font-size: 12.5px; font-weight: 700; color: #04140b;
  background: var(--green); border-radius: 4px; padding: 3px 9px; }
.fm-sub { padding: 12px 22px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-faint);
  font-family: var(--mono); }
.fm-showall { -webkit-app-region: no-drag; cursor: pointer; background: none; border: none;
  font: inherit; text-transform: none; letter-spacing: 0; color: var(--cyan); padding: 0; }
.fm-showall:hover { text-decoration: underline; }
html[data-theme="inpa"] .fm-showall { color: #000080; }
.fm-body { overflow-y: auto; padding: 6px 22px 22px; }
.fm-loading { color: var(--ink-dim); padding: 24px 0; text-align: center; }

.fm-variant { border: 1px solid var(--line); border-radius: 8px; margin-top: 12px;
  padding: 14px 16px; }
.fm-vhead { display: flex; gap: 12px; align-items: baseline; margin-bottom: 4px; }
.fm-vsgbd { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--cyan);
  flex: none; min-width: 96px; }
.fm-vname { font-size: 14px; color: var(--ink); }
.fm-noinfo { font-size: 12px; color: var(--ink-faint); font-style: italic; margin-top: 6px; }
.fi-grid { display: grid; grid-template-columns: 132px 1fr; gap: 8px 16px; margin-top: 10px;
  padding-top: 10px; border-top: 1px dashed var(--line); }
.fi-k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-faint); text-align: right; padding-top: 1px; }
.fi-v { font-size: 13px; color: var(--ink-dim); line-height: 1.5; }
html[data-theme="inpa"] .fm-vsgbd { color: #000080; }
html[data-theme="inpa"] .fm-pcode { background: #00a000; color: #fff; }
/* code column: hex/P-code, monospace, amber, fixed-width for alignment */
.lookup-code {
  font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--amber);
  flex: none; min-width: 66px; letter-spacing: .02em;
}
.lookup-code-none { color: var(--ink-faint); font-weight: 400; opacity: .5; }
/* known SAE P-code stacked above the BMW hex */
.lookup-code-stack { display: flex; flex-direction: column; line-height: 1.25; }
.lookup-pcode { font-weight: 700; }
.lookup-hex { font-size: 10.5px; font-weight: 600; color: var(--ink-dim); }
/* original German phrase (text-scheme only), dimmed for cross-reference */
.lookup-key {
  font-family: var(--mono); font-size: 12px; flex: none;
  min-width: 130px; max-width: 240px; word-break: break-word;
}
.lookup-key-text { color: var(--ink-faint); }
.lookup-en { font-size: 13px; color: var(--ink); flex: 1; }
