/* AVBrowse -- native Windows look, on purpose.
 *
 * The same reference MDBro takes: MXF Inspector and the Win32 controls it is
 * built from.  A tree on the left, a property grid on the right, 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.
 *
 * There is no byte pane here.  An AVB object is not a byte range the way a
 * Bento TOC entry is; pyavb hands over a decoded object and nothing else, so
 * a hex column would be a second, worse answer to a question the grid has
 * already answered.  The right-hand pane is the grid, full height.
 */

: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;   /* undecoded blob              */

  --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:  300px;
  --col-w-class:  56px;
  --col-w-val:   170px;
  --col-w-umid:  300px;
  /* Property grid: label / value split of the right pane. */
  --grid-w-k:    170px;
}

* { 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;
}

/* ------------------------------------------------------------------ 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: 620px; min-width: 320px; flex: 0 0 auto; }
.splitter { width: 5px; cursor: col-resize; flex: 0 0 auto; }

/* -------------------------------------------------------------------- tabs */
/* The two lenses.  A tab rather than a dropdown because there are two of
   them and there will not be a third without a redesign: one is the bin as
   an editor thinks of it, the other is the object graph as the file stores
   it, and everything else is a filter on one of those. */
.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 */
/* `overflow: hidden` is load-bearing, not tidiness.  The tree's columns are
   fixed-width and can add up to more than the pane is wide; without this the
   header row paints straight over the property grid next door. */
.pane {
  background: var(--pane); border: 1px solid var(--border-2);
  display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto;
  overflow: hidden;
}
.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 colour, so the header row reads as a header row rather
   than as a preview of the widths below it. */
/* The header sits outside the scroller, as a Win32 listview's does, and is
   scrolled to match it from the table's scroll handler.  Scrolling it with
   the rows is the whole reason a header can be wider than its pane. */
.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; overflow: hidden;
}
.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. */
.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-val    { flex: 0 0 var(--col-w-val);   min-width: 40px; }
.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); font: 12px var(--ui); white-space: nowrap;
}
/* The cell's line box is shorter than the row and centred in it by the
   row's `align-items: center`.  A line box exactly as tall as the row would
   clip its own descenders against `overflow: hidden` -- and the first
   casualty is the underscore, which every Avid clip name is full of. */
.row > div {
  padding: 0 6px; line-height: 18px;
  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-val, .row.sel .c-umid, .row.sel .c-tracks,
.row.sel .rolelabel, .row.sel .unnamed, .row.sel .jumpmark, .row.sel .vnote {
  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; }
/* With several rows selected, the dotted focus rectangle marks the one the
   property grid is showing -- the Win32 ListView's own convention. */
.row.sel.cur { outline: 1px dotted var(--sel-text); outline-offset: -2px; }

/* 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); }
/* 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-val { color: var(--text-dim); }
.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 */
.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); }

.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: 24%; color: var(--text-dim); font: 12px var(--ui);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.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, .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); }

/* Group headers are the inheritance chain pyavb declares: Component, then
   TrackGroup, then Composition.  That grouping is not decoration -- it is
   what turns a flat thirty-row list into four short readable ones. */
.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); }

.vnote { color: var(--text-faint); }
a.ref { color: var(--link); text-decoration: none; }
a.ref:hover { text-decoration: underline; }
.reftarget { color: var(--text-dim); }
.v-empty { color: var(--text-faint); }
/* the one place colour carries meaning: a value whose bytes pyavb kept but
   did not decode */
.v-blob  { color: var(--alert); }
.v-id { font-family: var(--mono); font-size: 11px; }
.v-num, .v-bool, .v-date { font-family: var(--mono); }

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

/* --------------------------------------------------------- listview panel */
.listview { width: 100%; border-collapse: collapse; font-size: 12px; }
.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; }
.listview tr:hover td { background: #f2f7fd; }

/* --------------------------------------------------------------- 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 overlay behind the box 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: 260px; 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; }
