[x-cloak] { display: none !important; }

:root {
  --app-max-width: 2000px;
  --app-pad-x: 32px;

  --bg: #fafafa;
  --surface: #fff;
  --surface-alt: #f2f2f2;
  --surface-header: #eceff1;
  --surface-hover: #dde3e6;
  --border: #cfd8dc;
  --text: #263238;
  --text-muted: #616161;
  --text-faint: #b0bec5;
  --link: #00695c;
  --shadow: rgba(0,0,0,.08);
  --shadow-popover: rgba(0,0,0,.18);
  --shadow-scroll: rgba(0,0,0,.22);
  --nav-bg: #00796b;      /* materialize teal darken-2 */
  --nav-fg: #ffffff;
  --chip-active-bg: #009688;  /* materialize teal — active filter + sort chips share this */
  --chip-active-fg: #ffffff;
}

html[data-theme="dark"] {
  --bg: #14181c;
  --surface: #1e232a;
  --surface-alt: #262c34;
  --surface-header: #262c34;
  --surface-hover: #303842;
  --border: #37414a;
  --text: #eceff1;
  --text-muted: #90a4ae;
  --text-faint: #607d8b;
  --link: #4db6ac;
  --shadow: rgba(0,0,0,.4);
  --shadow-popover: rgba(0,0,0,.55);
  --shadow-scroll: rgba(0,0,0,.6);
  --nav-bg: #14181c;        /* header goes truly dark, not just darker teal */
  --nav-fg: #4db6ac;         /* teal-300 — brand text/logo/toggle in accent */
  --chip-active-bg: #00695c;   /* matches the "normal green" accent */
  --chip-active-fg: #eceff1;
}

body { background: var(--bg); color: var(--text); }

/* Materialize's nav uses .teal.darken-2 as a fixed class — swap the paint via
 * the variable so dark mode can dim it without editing the markup. Same for
 * the foreground: light mode keeps the usual white; dark mode paints the
 * brand text/logo/toggle in the accent teal. */
nav.teal.darken-2 { background-color: var(--nav-bg) !important; color: var(--nav-fg); position: relative; }
nav.teal.darken-2 a.brand-logo { color: var(--nav-fg); }
nav .nav-wrapper { text-align: center; }
nav .brand-logo { position: static; font-family: 'Roboto Mono', monospace; font-weight: 500; display: inline-flex; align-items: center; gap: 10px; transform: none; }
nav .brand-logo .brand-mark { height: 40px; width: 40px; display: block; color: var(--nav-fg); }

/* Nav actions align with the app content's left/right edges so the icons
 * track the same visual bounds as the sidebar/table below. On viewports
 * narrower than --app-max-width the calc collapses to the app padding
 * (nav icons at --app-pad-x from each edge); on wider viewports the calc
 * pushes them inward to match the centered app-body's edges. */
.nav-actions {
  position: absolute;
  right: max(var(--app-pad-x), calc(50vw - var(--app-max-width) / 2 + var(--app-pad-x)));
  top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; gap: 8px;
}
.nav-actions-left {
  right: auto;
  left: max(var(--app-pad-x), calc(50vw - var(--app-max-width) / 2 + var(--app-pad-x)));
}
.nav-icon-btn {
  background: transparent; border: none; color: var(--nav-fg); cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background-color .15s;
  text-decoration: none;
}
.nav-icon-btn:hover, .nav-icon-btn:focus { background: rgba(255,255,255,.12); outline: none; color: var(--nav-fg); }
.nav-icon-btn .material-icons { font-size: 22px; }
.nav-icon-btn svg { display: block; }
html[data-theme="dark"] .nav-icon-btn:hover,
html[data-theme="dark"] .nav-icon-btn:focus { background: rgba(77,182,172,.14); }

/* Theme switch — visually distinct from the GitHub link so it reads as a
 * stateful toggle rather than another nav action. Uses Materialize's .switch
 * scaffold; overrides colors so it sits legibly on the nav paint. */
.theme-switch { display: inline-flex; align-items: center; margin: 0; }
.theme-switch label { display: inline-flex; align-items: center; gap: 4px; color: var(--nav-fg); }
.theme-switch label .material-icons { font-size: 18px; color: var(--nav-fg); opacity: .75; }
.theme-switch label .lever { margin: 0 6px; background-color: rgba(255,255,255,.35); }
.theme-switch label .lever:after { background-color: #fafafa; }
.theme-switch label input[type=checkbox]:checked + .lever { background-color: rgba(77,182,172,.55); }
.theme-switch label input[type=checkbox]:checked + .lever:after { background-color: var(--nav-fg); }
html[data-theme="dark"] .theme-switch label .lever { background-color: rgba(77,182,172,.35); }
html[data-theme="dark"] .theme-switch label .lever:after { background-color: var(--nav-fg); }

/* Cap the app content on ultrawide monitors so the sidebar + table panel
 * don't stretch to the viewport edges. Below --app-max-width this is a no-op
 * — the container fills naturally with --app-pad-x lateral padding. Above
 * it, auto margins keep the app centered with a comfortable gutter. */
.app-body {
  padding: 12px var(--app-pad-x) 48px;
  max-width: var(--app-max-width);
  margin: 0 auto;
}
.no-margin { margin: 0; }

/* Sidebar */
.sidebar {
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 4px;
  box-shadow: 0 1px 2px var(--shadow);
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  position: sticky;
  top: 76px;
}
.filter-group { margin-bottom: 18px; }
.filter-group h6 { font-size: 13px; font-weight: 500; color: var(--text-muted); margin: 4px 0 8px; text-transform: uppercase; letter-spacing: .5px; }
.chip-list { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 4px; }
.chip-list .chip { margin: 0; font-size: 12px; height: 28px; line-height: 28px; padding: 0 12px; cursor: pointer; }

/* Materialize's default .chip is a light grey pill with dark text — invisible
 * against dark surfaces. Override the neutral state; active chips keep their
 * .teal.white-text classes and are unaffected. */
html[data-theme="dark"] .chip:not(.teal) { background-color: #37414a; color: #eceff1; }

/* Search input in the sidebar — Materialize inherits body color for input
 * text, but the label and underline are hardcoded greys that need help. */
html[data-theme="dark"] .input-field input[type=text] { color: var(--text); }
html[data-theme="dark"] .input-field label { color: var(--text-muted); }
html[data-theme="dark"] .input-field .prefix { color: var(--text-muted); }
html[data-theme="dark"] .input-field input[type=text]:not(.browser-default) { border-bottom-color: var(--border); box-shadow: none; }

/* Main */
.main { padding: 12px 16px; }

/* .table-panel wraps sort-bar + table-split + table-footer so all three share
 * one width. fit-content makes that width follow the table's natural column
 * total on wide screens (no empty gutter to the right of the data); the
 * max-width caps it at .main's width so wider datasets fall back to the
 * internal horizontal scroll inside .table-split. align-items: stretch is
 * the flex default — it's what makes the sort bar and footer track the
 * table's width without an explicit width on each. */
.table-panel {
  display: flex;
  flex-direction: column;
  width: fit-content;
  max-width: 100%;
}

.sort-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 8px 12px; margin-bottom: 12px;
  background: var(--surface); border-radius: 4px; box-shadow: 0 1px 2px var(--shadow);
}
.sort-bar > span { font-size: 13px; }
.sort-chip-list { list-style: none; margin: 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; min-height: 32px; }
/* Both active filter chips and sort chips carry Materialize's .teal class in
 * the markup (plus .lighten-4 or .white-text modifiers). Route them through
 * shared variables so filter + sort share one paint per theme. Applies to
 * .chip.teal anywhere — currently just these two lists. */
.chip.teal { background-color: var(--chip-active-bg) !important; color: var(--chip-active-fg) !important; }
.chip.teal .material-icons { color: var(--chip-active-fg); }
.sort-chip-list .chip { display: inline-flex; align-items: center; gap: 4px; cursor: grab; margin: 0; user-select: none; }
.sort-chip-list .chip:active { cursor: grabbing; }
.sort-chip-list .chip a { display: inline-flex; align-items: center; color: inherit; cursor: pointer; }
.sort-chip-list .chip a .material-icons { font-size: 16px; }
.sort-chip-list .chip .close { cursor: pointer; }

/* Two side-by-side tables: fixed identity columns on the left (no
 * horizontal scroll), the rest inside a wrapper that scrolls
 * horizontally. Vertical scroll lives on the parent so both tables
 * scroll together. */
.table-split {
  display: flex;
  align-items: flex-start;
  max-height: calc(100vh - 260px);
  overflow: auto;                 /* BOTH axes on the parent so the horizontal
                                     scrollbar sits at the visible bottom edge
                                     instead of trailing far below the fold */
  background: var(--surface);
  border-radius: 4px;
  box-shadow: 0 1px 2px var(--shadow);
}
/* Materialize sets `table { width: 100% }` globally — override for both halves
 * so widths follow content and horizontal overflow surfaces at .table-split. */
.fixed-table {
  flex: 0 0 auto; width: auto;
  border-right: 1px solid var(--border);
  /* Sticky-left keeps the Manufacturer/Model pane visible while the rest of
   * the columns scroll horizontally. z-index above the scrollable table so
   * cells scrolling under it don't peek through. Background is required — a
   * sticky cell without one is transparent to what's behind. */
  position: sticky; left: 0; z-index: 2;
  background: var(--surface);
  transition: box-shadow .35s ease;
}
.fixed-table.is-scrolled { box-shadow: 6px 0 8px -3px var(--shadow-scroll); }
/* Sticky-left carries the fixed-table over the scrolling table during horizontal
 * scroll. Materialize's .striped applies alternating backgrounds to <tr>, but
 * even rows are transparent by default — that transparency would let the
 * scrolling table's cells peek through the fixed pane. Give every row an
 * explicit opaque background so nothing shows through. */
.fixed-table.striped > tbody > tr:nth-child(even) { background: var(--surface); }
.fixed-table.striped > tbody > tr:nth-child(odd)  { background: var(--surface-alt); }
/* Materialize's .striped applies its odd-row tint to the scrolling table too;
 * override to our theme's alt surface so both halves stay in sync. */
.compact-table.striped > tbody > tr:nth-child(odd)  { background: var(--surface-alt); }
.compact-table.striped > tbody > tr:nth-child(even) { background: var(--surface); }
.scroll-table-wrap { flex: 0 0 auto; min-width: 0; }
.scroll-table-wrap > table { width: auto; }
.compact-table { margin: 0; font-size: 13px; color: var(--text); }
.compact-table th, .compact-table td { padding: 6px 10px; white-space: nowrap; }
.compact-table thead th { position: sticky; top: 0; background: var(--surface-header); z-index: 1; color: var(--text); }
.compact-table .mono { font-family: 'Roboto Mono', ui-monospace, Menlo, monospace; }
.compact-table td a { color: var(--link); }
table.compact-table > tbody > tr.row-hover { background-color: rgba(0, 137, 123, 0.22); }
.null { color: var(--text-faint); }
/* Dagger sigil marking derived/inferred/override cells. Click opens a
 * popover (delegated handler on the table body, see app.js). */
.derived-mark { color: var(--text-faint); font-size: 10px; padding-left: 1px; cursor: pointer; font-weight: bold; }
.derived-mark:hover { color: var(--text); }
/* Legend rendering: same visual mark, but static (not clickable). */
.derived-mark.legend { cursor: default; }

/* Click-triggered popover explaining a specific field's spec source. Anchored
 * via inline top/left (viewport coords, position:fixed), then shifted up-left
 * so the tip of the caret hangs over the clicked dagger. */
.spec-popover {
  position: fixed;
  z-index: 200;
  transform: translate(-50%, -100%);
  max-width: 320px;
  padding: 8px 10px;
  background: var(--surface-header);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  font-size: 12px;
  line-height: 1.4;
  white-space: normal;
}
.spec-popover::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--surface-header);
}

/* Reorderable column headers — grab cursor + hover highlights signal the
 * drag affordance; drop-indicator inset shadow shows the insertion side
 * during a drag. Fixed identity columns (Manufacturer + Model) live in a
 * separate table so they render as static headers with a default cursor. */
.compact-table th.reorderable {
  cursor: grab;
  user-select: none;
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
  transition: background-color .12s, border-color .12s;
}
.compact-table th.reorderable:hover {
  background: var(--surface-hover);
  border-left-color: #90a4ae;
  border-right-color: #90a4ae;
}
.compact-table th.reorderable:active { cursor: grabbing; }
.compact-table th.reorderable.dragging { opacity: .35; }
.compact-table th.reorderable.drop-left  { box-shadow: inset  3px 0 0 #00695c; }
.compact-table th.reorderable.drop-right { box-shadow: inset -3px 0 0 #00695c; }
/* Sort chip drag/drop feedback — same visual language as the column headers. */
.sort-chip-list .chip.dragging   { opacity: .35; }
.sort-chip-list .chip.drop-left  { box-shadow: inset  3px 0 0 #00695c; }
.sort-chip-list .chip.drop-right { box-shadow: inset -3px 0 0 #00695c; }

/* Columns picker */
.picker { position: relative; }
.picker-btn { padding: 0 10px; height: 32px; line-height: 32px; color: var(--text); }
.picker-btn i.material-icons.left { margin-right: 6px; line-height: 32px; height: 32px; }
.picker-btn[disabled] { color: var(--text-faint); cursor: not-allowed; }
.units-toggle { min-width: 120px; text-align: left; }
/* Materialize btn-flat:focus paints a grey background that sticks after click.
   On picker buttons it doubles as "menu is open" feedback so we leave it; on
   the units toggle it's just visual noise. */
.units-toggle:focus { background-color: transparent; }
html[data-theme="dark"] .btn-flat:focus:not(.units-toggle) { background-color: rgba(255,255,255,.08); }
.picker-popover {
  position: absolute; left: 0; top: calc(100% + 4px);
  z-index: 20;
  min-width: 280px; max-height: 60vh; overflow-y: auto;
  white-space: nowrap;
  background: var(--surface); border-radius: 4px;
  box-shadow: 0 2px 8px var(--shadow-popover);
  padding: 8px 0;
}
.picker-hint { font-size: 11px; padding: 0 14px 6px; color: var(--text-muted); }
.picker-popover ul { list-style: none; margin: 0; padding: 0; }
.picker-popover li { padding: 2px 14px; }
.picker-popover label { display: flex; align-items: center; cursor: pointer; font-size: 13px; color: var(--text); min-height: 24px; }
.picker-popover label span { padding-left: 28px; }
.picker-item { display: block; padding: 4px 0; font-size: 13px; color: var(--text); }
.picker-item:hover { color: var(--link); }
.picker-item-active { color: var(--link); font-weight: 500; }
.col-picker-reset { display: block; padding: 8px 14px 2px; font-size: 12px; color: var(--link); }

.table-footer {
  padding: 8px 4px;
  font-size: 12px;
  display: flex; flex-wrap: wrap; justify-content: flex-start; align-items: baseline;
  gap: 8px;
  text-align: left;
}
.table-footer .sep { color: var(--text-faint); }
.padded { padding: 32px 16px; }

/* Materialize's .grey-text is a hardcoded #9e9e9e that reads as low-contrast
 * mud on dark surfaces. Bump it to our muted token in dark mode. */
html[data-theme="dark"] .grey-text { color: var(--text-muted) !important; }

/* Dark-mode scrollbars — browsers draw stock light scrollbars against our
 * dark surfaces otherwise. Scoped to the three scrollable regions rather
 * than a document-wide *::-webkit-scrollbar so we don't restyle scrollbars
 * on unrelated third-party embeds. Firefox uses the standard scrollbar-*
 * properties on the same elements; WebKit/Blink uses the pseudo-elements. */
html[data-theme="dark"] .table-split,
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .picker-popover {
  scrollbar-color: #4a5560 #262c34;
  scrollbar-width: thin;
}
html[data-theme="dark"] .table-split::-webkit-scrollbar,
html[data-theme="dark"] .sidebar::-webkit-scrollbar,
html[data-theme="dark"] .picker-popover::-webkit-scrollbar { width: 10px; height: 10px; }
html[data-theme="dark"] .table-split::-webkit-scrollbar-track,
html[data-theme="dark"] .sidebar::-webkit-scrollbar-track,
html[data-theme="dark"] .picker-popover::-webkit-scrollbar-track { background: #262c34; }
html[data-theme="dark"] .table-split::-webkit-scrollbar-thumb,
html[data-theme="dark"] .sidebar::-webkit-scrollbar-thumb,
html[data-theme="dark"] .picker-popover::-webkit-scrollbar-thumb { background: #4a5560; border-radius: 5px; }
html[data-theme="dark"] .table-split::-webkit-scrollbar-thumb:hover,
html[data-theme="dark"] .sidebar::-webkit-scrollbar-thumb:hover,
html[data-theme="dark"] .picker-popover::-webkit-scrollbar-thumb:hover { background: #5c6a78; }
/* The corner square where the horizontal and vertical scrollbars meet on
 * .table-split (both axes overflow) — untreated it stays white. */
html[data-theme="dark"] .table-split::-webkit-scrollbar-corner { background: #262c34; }

@media (max-width: 992px) {
  .sidebar { position: static; max-height: none; }
  .table-split { max-height: none; }
}
