/* MDBro -- native Windows look, on purpose.
 *
 * The reference is MXF Inspector and the Win32 controls it is built from: a
 * tree on the left, a two-column property grid on the right, a byte pane
 * under it, a status bar along the bottom. Nothing is styled that a standard
 * control would not style itself. Colour is used for one thing only --
 * marking a value the reader could not fully account for -- so that when
 * colour appears it means something.
 */

:root {
  --face:        #f0f0f0;   /* control face                */
  --face-2:      #e8e8e8;   /* headers, inactive tabs      */
  --pane:        #ffffff;   /* list and grid backgrounds   */
  --border:      #d0d0d0;
  --border-2:    #a0a0a0;
  --text:        #000000;
  --text-dim:    #555555;
  --text-faint:  #808080;
  --sel:         #0078d7;   /* focused selection           */
  --sel-text:    #ffffff;
  --sel-soft:    #cbe8ff;   /* secondary selection         */
  --link:        #0563c1;
  --alert:       #a31515;   /* unbound / undecoded         */

  --row-h:       22px;
  --ui: "Segoe UI", Tahoma, "DejaVu Sans", sans-serif;
  --mono: Consolas, "Cascadia Mono", "DejaVu Sans Mono", "Courier New", monospace;

  /* Column widths of the object tree.  Custom properties rather than fixed
     values so localStorage can restore per-user widths on load, and both the
     header row and the (separate) data rows read the same numbers. */
  --col-w-name:  360px;
  --col-w-class:  60px;
  --col-w-id:     44px;
  --col-w-umid:  340px;
  /* Property grid: label / value split of the right pane's grid. */
  --grid-w-k:    170px;
  /* Reference-list column in kvtable panels ("Referenced by"). */
  --kv-w-k:      140px;
}

* { box-sizing: border-box; }

html { height: 100%; }
body {
  margin: 0; height: 100%;
  display: flex; flex-direction: column;
  background: var(--face); color: var(--text);
  font: 12px/1.35 var(--ui);
  overflow: hidden;
  cursor: default;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ chrome */
#menubar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 2px;
  height: 22px; padding: 0 4px; background: var(--face);
  border-bottom: 1px solid var(--border); user-select: none;
}
#menubar .logo {
  font-weight: 600; letter-spacing: .02em; padding: 0 10px 0 4px;
  color: var(--text);
}
#menubar .logo b { color: var(--sel); font-weight: 600; }
#menubar .menu { padding: 2px 8px; }
#menubar .menu:hover { background: var(--face-2); }
#menubar .menu.on { background: var(--sel); color: var(--sel-text); }

#toolbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 4px;
  padding: 3px 6px; background: var(--face);
  border-bottom: 1px solid var(--border);
}
.tbtn {
  font: 12px var(--ui); color: var(--text);
  background: var(--face-2); border: 1px solid var(--border-2);
  padding: 2px 10px; height: 22px; border-radius: 2px;
}
.tbtn:hover { background: #e0eefc; border-color: var(--sel); }
.tbtn:active { background: #cbe4fa; }
.tbtn:disabled { color: var(--text-faint); background: var(--face);
                 border-color: var(--border); }
.tsep { width: 1px; height: 18px; background: var(--border-2); margin: 0 4px; }
.tspacer { flex: 1 1 auto; }

#pathbar {
  flex: 0 0 auto; padding: 3px 6px; background: var(--face);
  border-bottom: 1px solid var(--border);
}
.pathbox {
  flex: 1 1 auto; min-width: 0;
  font: 12px var(--ui); color: var(--text);
  background: var(--pane); border: 1px solid var(--border-2);
  padding: 2px 6px; height: 22px; line-height: 17px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pathbox .stats { color: var(--text-faint); margin-left: 14px; }

.search { position: relative; display: block; flex: 0 0 auto; }
.search input {
  width: 240px; height: 22px;
  background: var(--pane); color: var(--text);
  border: 1px solid var(--border-2);
  padding: 2px 52px 2px 6px; font: 12px var(--ui); outline: none;
}
.search input:focus { border-color: var(--sel); }
.searchcount {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font: 11px var(--ui); color: var(--text-faint); pointer-events: none;
}
.toggle {
  font-size: 12px; color: var(--text); display: flex;
  align-items: center; gap: 4px; user-select: none; white-space: nowrap;
}
.toggle input { margin: 0; }

/* ------------------------------------------------------------------ layout */
#layout { display: flex; flex: 1 1 auto; min-height: 0; padding: 4px; }
#left  { display: flex; flex-direction: column; min-width: 280px; flex: 1 1 auto; }
#right { display: flex; flex-direction: column;
         width: 720px; min-width: 320px; flex: 0 0 auto; }
.splitter { width: 5px; cursor: col-resize; flex: 0 0 auto; }
.hsplitter { height: 5px; cursor: row-resize; flex: 0 0 auto; }

/* ------------------------------------------------------------------- tabs */
.tabs {
  display: flex; padding-left: 2px;
  font-size: 12px; position: relative; top: 1px;
}
.tab {
  background: var(--face-2); border: 1px solid var(--border-2);
  border-bottom: none; color: var(--text);
  padding: 3px 12px 4px; margin-right: 2px;
  border-radius: 3px 3px 0 0; user-select: none;
}
.tab.on { background: var(--pane); padding-bottom: 5px; }
.tab .n { color: var(--text-faint); margin-left: 6px; }

/* --------------------------------------------------------------- listviews */
.pane {
  background: var(--pane); border: 1px solid var(--border-2);
  display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto;
}
.colhead, .row { display: flex; align-items: center; }
/* Header cells share one look regardless of the size a column's data uses:
   same font-size and color, so the header row reads as a header row rather
   than as a preview of the widths below it. */
.colhead {
  flex: 0 0 auto; height: 22px; font: 12px var(--ui); color: var(--text);
  background: var(--face); border-bottom: 1px solid var(--border);
  user-select: none;
}
.colhead > div {
  position: relative;
  height: 22px; line-height: 21px; padding: 0 6px;
  border-right: 1px solid var(--border);
  overflow: hidden; white-space: nowrap;
  color: var(--text); font-size: 12px; text-align: left;
}
/* Columns are fixed-width from custom properties (see :root) so the header
   grip and the data rows compute the same width.  Only the trailing column
   takes the slack, which means dragging any grip changes exactly one column
   and never quietly steals from another.  All columns share the UI font --
   the MobID drops a point in size because a full dotted UMID is long. */
.c-name   { flex: 0 0 var(--col-w-name);  min-width: 60px; }
.c-class  { flex: 0 0 var(--col-w-class); min-width: 40px; }
.c-id     { flex: 0 0 var(--col-w-id);    min-width: 30px; text-align: right; }
.c-umid   { flex: 0 0 var(--col-w-umid);  min-width: 60px; }
.c-tracks { flex: 1 1 80px; min-width: 60px; }

/* Draggable grip on the right edge of resizable header cells.  A visible
   thin bar sits inside the border so it is clearly a target. */
.c-grip {
  position: absolute; top: 0; right: -3px; width: 7px; height: 100%;
  cursor: col-resize; z-index: 2;
}
.c-grip:hover { background: rgba(0, 120, 215, .35); }
.colhead.dragging { cursor: col-resize; }

.scroller { flex: 1 1 auto; overflow: auto; outline: none; position: relative; }
.spacer-inner { position: relative; }
.rows { position: absolute; top: 0; left: 0; right: 0; }

.row {
  height: var(--row-h); line-height: var(--row-h);
  font: 12px var(--ui); white-space: nowrap;
}
.row > div { padding: 0 6px; overflow: hidden; text-overflow: ellipsis; }
.row .c-name { padding-left: 0; }
.row.alt { background: #f7f7f7; }
.row:hover, .row.alt:hover { background: #f2f7fd; }
.row.sel   { background: var(--sel); color: var(--sel-text); }
.row.sel .c-class, .row.sel .c-id, .row.sel .c-umid, .row.sel .c-tracks,
.row.sel .rolelabel, .row.sel .unnamed, .row.sel .jumpmark {
  color: var(--sel-text);
}
.row.sel .twisty { border-color: var(--sel-text); }
/* A selected row must keep looking selected when it is also hovered; the
   next-more-specific rule .row.alt:hover would otherwise paint pale-blue
   over the selection blue while the text stayed white. */
.row.sel:hover, .row.sel.alt:hover {
  background: #005a9e; color: var(--sel-text);
}
.row.group .c-name { font-weight: 600; }

/* classic TreeView expander: a small bordered box with + / - */
.twisty {
  display: inline-block; width: 9px; height: 9px;
  border: 1px solid #808080; background: var(--pane); color: #000;
  text-align: center; font: 9px/7px var(--mono); margin: 0 5px 2px 0;
  vertical-align: middle; user-select: none;
}
.twisty.leaf { visibility: hidden; }
.rowname { vertical-align: middle; }
.rowname .unnamed { color: var(--text-faint); }
.rolelabel { color: var(--text-dim); }
.c-id { color: var(--text-dim); }
/* A full 32-byte dotted UMID is 71 characters; a smaller face lets more of
   it show without stealing space from Object or Class. */
.c-umid { color: var(--text-dim); font-size: 10px; letter-spacing: .1px; }
.c-tracks { color: var(--text-dim); }
.jumpmark { color: var(--text-faint); }

.statusbar {
  flex: 0 0 auto; height: 21px; line-height: 20px;
  font-size: 11px; color: var(--text);
  background: var(--face); border-top: 1px solid var(--border);
  display: flex;
}
.statusbar span {
  padding: 0 8px; border-right: 1px solid var(--border);
  overflow: hidden; white-space: nowrap;
}
.statusbar span:last-child { border-right: none; flex: 1 1 auto; }

/* ---------------------------------------------------------- property grid */
#gridpane { flex: 1 1 auto; min-height: 120px; }
#hexpane  { flex: 0 0 250px; min-height: 60px; }

.panehead {
  flex: 0 0 auto; height: 21px; line-height: 20px; padding: 0 6px;
  background: var(--face); border-bottom: 1px solid var(--border);
  font-size: 12px; display: flex; align-items: center; gap: 8px;
  user-select: none; white-space: nowrap; overflow: hidden;
}
.panehead b { font-weight: 600; }
.panehead .right { margin-left: auto; color: var(--text-dim); font-size: 11px; }
.panehead .mono { font-family: var(--mono); }
.panehead .seg {
  border: 1px solid var(--border-2); background: var(--face-2);
  padding: 0 8px; height: 17px; line-height: 15px; margin: 0;
}
.panehead .seg.on { background: var(--pane); font-weight: 600; }

.panebody { flex: 1 1 auto; overflow: auto; background: var(--pane); }

.grid {
  width: 100%; border-collapse: collapse;
  font: 12px var(--ui); table-layout: fixed;
}
.grid td {
  padding: 1px 6px; border-bottom: 1px solid #f4f4f4;
  vertical-align: top; line-height: 17px;
}
.grid td.k {
  width: var(--grid-w-k); border-right: 1px solid var(--border);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* value sits next to its label; the type is reference material and goes last */
.grid td.v {
  font: 12px var(--ui); overflow-wrap: break-word; word-break: break-word;
  border-right: 1px solid var(--border); position: relative;
  padding-right: 20px;
}
.grid td.t {
  width: 27%; color: var(--text-dim); font: 12px var(--ui);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Rows the reader derived rather than read from a TOC entry (SMPTE ST 330
   MaterialNumber and InstanceNumber): dimmed type note, no other tell.  The
   distinction is a hover-tooltip concern, not a foreground one. */
.grid tr.computed td.t { color: var(--text-faint); }
.repeat {
  color: var(--text-faint); font-family: var(--mono); font-size: 11px;
}
.copybtn {
  position: absolute; right: 2px; top: 1px; width: 16px; height: 16px;
  line-height: 15px; text-align: center; font-size: 10px;
  border: 1px solid var(--border-2); background: var(--face);
  border-radius: 2px; visibility: hidden;
}
.grid tr:hover .copybtn { visibility: visible; }
.copybtn:hover { background: #e0eefc; border-color: var(--sel); }
.grid tr.alt td, .kvtable tr.alt td, .listview tr.alt td { background: #f7f7f7; }
.grid tr.sel td, .grid tr.sel.alt td { background: var(--sel-soft); }
.grid tr:hover td, .grid tr.alt:hover td { background: #f2f7fd; }
.grid tr.sel:hover td { background: var(--sel-soft); }

.grid tr.grouphdr td {
  background: var(--face); border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-weight: 600; padding: 2px 6px; user-select: none;
}
.grid tr.grouphdr:hover td { background: var(--face-2); }
.grid tr.grouphdr .chev {
  display: inline-block; width: 12px; color: var(--text-dim); font-size: 9px;
}
.grid tr.grouphdr .gcount { font-weight: 400; color: var(--text-faint); }

.grid tr.dup td { color: var(--text-faint); }
.grid td.k .pid { color: var(--text-faint); font-family: var(--mono); }

/* the one place colour carries meaning */
.grid tr.dark td.k .pname { color: var(--alert); }
.grid tr.dark td.k .pname::after { content: " *"; }
body.hide-dark .grid tr.dark { display: none; }

.vnote { color: var(--text-faint); }
a.ref { color: var(--link); text-decoration: none; }
a.ref:hover { text-decoration: underline; }
a.ref.unresolved { color: var(--alert); }
.reftarget { color: var(--text-dim); font-family: var(--ui); }
.v-empty { color: var(--text-faint); }
.v-blob  { color: var(--alert); }

/* ---------------------------------------------------------------- hex pane */
.hexwrap { display: flex; height: 100%; min-height: 0; }
/* the dump is a fixed-width thing -- 16 bytes a line -- so it takes the
   width it needs and the field list gets the rest */
.hex {
  flex: 1 1 46%; min-width: 0; overflow: auto; padding: 2px 6px;
  font: 12px/16px var(--mono); background: var(--pane);
}
.hexline { white-space: pre; }
.hexoff { color: var(--text-faint); }
.hexgap { color: #b06000; background: #fff4e0; }
.hexascii { color: var(--text-dim); }
.f:hover, .f.hl { background: var(--sel); color: var(--sel-text); }
.f.even { background: #eef2f6; }
.f.even:hover, .f.even.hl { background: var(--sel); color: var(--sel-text); }

.fieldlist {
  flex: 1 1 54%; min-width: 0; overflow: auto;
  border-left: 1px solid var(--border);
  background: var(--pane); font-size: 12px;
}
.fieldrow { display: flex; line-height: 17px; white-space: nowrap; }
.fieldrow > span { padding: 0 6px; overflow: hidden; text-overflow: ellipsis; }
.fieldrow:hover, .fieldrow.hl { background: var(--sel-soft); }
.fieldrow .fname { flex: 0 0 32%; }
.fieldrow .foff  { flex: 0 0 76px; color: var(--text-dim); font-family: var(--mono); }
.fieldrow .fval  { flex: 1 1 auto; font-family: var(--mono); }
.fieldhead {
  display: flex; background: var(--face); font-size: 11px;
  color: var(--text-dim); border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
.fieldhead > span { padding: 1px 6px; border-right: 1px solid var(--border); }
.fieldhead .fname { flex: 0 0 32%; }
.fieldhead .foff  { flex: 0 0 76px; }
.fieldhead .fval  { flex: 1 1 auto; border-right: none; }

.empty { padding: 12px; color: var(--text-faint); }

/* ------------------------------------------------------------- file panel */
.kvtable, .listview { width: 100%; border-collapse: collapse; font-size: 12px; }
.kvtable td { padding: 1px 6px; border-bottom: 1px solid #f4f4f4; line-height: 17px; }
.kvtable td.k { width: 38%; border-right: 1px solid var(--border); }
.kvtable td.v { font-family: var(--mono); }
.kvtable tr:hover td, .listview tr:hover td { background: #f2f7fd; }

.listview th {
  text-align: left; font-weight: 400; background: var(--face);
  border-bottom: 1px solid var(--border); border-right: 1px solid var(--border);
  padding: 2px 6px; position: sticky; top: 0; z-index: 1;
}
.listview td { padding: 1px 6px; border-bottom: 1px solid #f4f4f4;
               line-height: 17px; font-family: var(--mono); }
.listview td.txt { font-family: var(--ui); }
.listview td.num { text-align: right; }

.sectionhead {
  background: var(--face); border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 2px 6px; font-weight: 600; font-size: 12px;
}

/* --------------------------------------------------------------- footnote */
/* min-height:0 matters: a flex item defaults to min-height:auto and would
   otherwise refuse to be shorter than the table inside it */
.footnote {
  flex: 0 0 auto; min-height: 0; background: var(--face);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.footnote.collapsed { flex-basis: 22px; }
.footnote:not(.collapsed) { flex-basis: 32vh; }
.footnote-toggle {
  all: unset; height: 22px; line-height: 22px; padding: 0 6px;
  font-size: 11px; color: var(--text); display: flex; gap: 6px;
  align-items: center; user-select: none;
}
.footnote-toggle:hover { background: var(--face-2); }
.footnote-toggle .chev { font-size: 9px; color: var(--text-dim); }
.footnote-toggle .n { color: var(--text-faint); }
.footnote-body {
  flex: 1 1 auto; min-height: 0; overflow: auto;
  background: var(--pane); margin: 0 4px 4px;
  border: 1px solid var(--border-2);
}
.footnote.collapsed .footnote-body { display: none; }
.footnote-body p { margin: 6px 8px; color: var(--text-dim); max-width: 110ch; }

/* ----------------------------------------------------------------- menus */
.ctxmenu {
  position: fixed; z-index: 200; min-width: 190px;
  background: var(--pane); border: 1px solid var(--border-2);
  box-shadow: 2px 2px 5px #0003; padding: 2px 0;
  font: 12px var(--ui); user-select: none;
}
.ctxitem { padding: 3px 20px 3px 4px; display: flex; align-items: center; }
.ctxitem .tick { display: inline-block; width: 16px; color: var(--text); }
.ctxitem:hover { background: var(--sel); color: var(--sel-text); }
.ctxitem.disabled { color: var(--text-faint); }
.ctxitem.disabled:hover { background: transparent; color: var(--text-faint); }
.ctxsep { height: 1px; background: var(--border); margin: 3px 2px; }

/* ----------------------------------------------------------- busy overlay */
/* The busy-box is a modal indicator sized for the message it holds; the
 * overlay behind it is translucent rather than opaque, because the tree the
 * work is loading into stays visible and it is useful to see what you are
 * about to replace. */
body.busy .busy-overlay { display: flex; }
.busy-overlay {
  position: fixed; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(240, 240, 240, .55); z-index: 300;
  cursor: progress;
}
.busy-box {
  background: var(--pane); border: 1px solid var(--border-2);
  padding: 18px 26px; min-width: 240px; text-align: center;
  box-shadow: 0 4px 14px #0002;
}
.busy-spin {
  width: 24px; height: 24px; margin: 0 auto 10px;
  border: 3px solid var(--face-2); border-top-color: var(--sel);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.busy-msg { font: 12px var(--ui); color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- tooltip */
.tooltip {
  position: fixed; z-index: 100; pointer-events: none;
  background: #ffffe1; border: 1px solid #767676;
  padding: 3px 6px; max-width: 420px;
  font: 12px/1.4 var(--ui); color: #000;
}
.tooltip .tt-name { font-weight: 600; }
.tooltip .tt-meta { color: var(--text-dim); font-family: var(--mono); font-size: 11px; }
.tooltip .tt-val  { font-family: var(--mono); word-break: break-all; }
