/* Publication Tracker — observability-style dashboard */

:root,
html[data-theme="dark"] {
  --canvas: #111217;
  --panel: #181b1f;
  --panel-hover: #1f2227;
  --field: #111217;
  --border: rgba(204, 204, 220, 0.12);
  --border-strong: rgba(204, 204, 220, 0.2);
  --text: #ccccdc;
  --text-2: rgba(204, 204, 220, 0.65);
  --text-3: rgba(204, 204, 220, 0.45);
  --link: #6e9fff;
  --grid: rgba(204, 204, 220, 0.08);
  --menu: #22252b;
  --shadow: 0 8px 24px rgba(1, 4, 9, 0.75);

  --green: #73bf69;
  --yellow: #fade2a;
  --orange: #ff9830;
  --red: #f2495c;
  --blue: #5794f2;
  --purple: #b877d9;
  --grey: #8e8e8e;
  --cell-red: #c4162a;
  --cell-orange: #fa6400;
  --cell-green: #37872d;
  --cell-blue: #1f60c4;
  color-scheme: dark;
}

html[data-theme="light"] {
  --canvas: #f4f5f5;
  --panel: #ffffff;
  --panel-hover: #f7f8fa;
  --field: #ffffff;
  --border: rgba(36, 41, 46, 0.12);
  --border-strong: rgba(36, 41, 46, 0.3);
  --text: #24292e;
  --text-2: rgba(36, 41, 46, 0.75);
  --text-3: rgba(36, 41, 46, 0.5);
  --link: #1f62e0;
  --grid: rgba(36, 41, 46, 0.1);
  --menu: #ffffff;
  --shadow: 0 4px 12px rgba(24, 26, 27, 0.18);

  --green: #56a64b;
  --yellow: #e0b400;
  --orange: #ff780a;
  --red: #e02f44;
  --blue: #3274d9;
  --purple: #a352cc;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--canvas);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
code, .mono { font-family: "Roboto Mono", monospace; }

/* Top nav */
.topnav {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.logo svg { width: 24px; height: 24px; stroke: none; display: block; }
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; min-width: 0; white-space: nowrap; overflow: hidden; }
.crumbs strong { color: var(--text); font-weight: 500; }
.crumbs .sep { color: var(--text-3); }
.topnav-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.sync { font-size: 12px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.sync b { color: var(--text); font-weight: 500; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(115, 191, 105, 0.2); }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: #3d71d9; color: #fff; font-size: 10px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn { background: none; border: 0; padding: 4px; border-radius: 2px; color: var(--text-2); cursor: pointer; display: inline-flex; }
.icon-btn:hover { color: var(--text); background: var(--panel-hover); }
.star.on { color: var(--yellow); }
.star.on svg { fill: currentColor; }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  flex-wrap: wrap;
}
.vars { display: flex; flex-wrap: wrap; gap: 8px; }
.var { display: inline-flex; height: 32px; position: relative; }
.var-label {
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 500;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-right: 0;
  border-radius: 2px 0 0 2px;
  color: var(--text);
}
.var-value {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  min-width: 80px;
  justify-content: space-between;
  background: var(--field);
  border: 1px solid var(--border-strong);
  border-radius: 0 2px 2px 0;
  cursor: pointer;
}
.var-value:hover { border-color: var(--text-3); }
.var-value .caret, .tb-btn .caret { width: 14px; height: 14px; color: var(--text-2); }
.controls { display: flex; align-items: center; gap: 8px; }
.tb-group { display: inline-flex; }
.tb-group > .tb-btn, .tb-group > .dropdown > .tb-btn { border-radius: 0; margin-left: -1px; }
.tb-group > :first-child, .tb-group > :first-child .tb-btn { border-radius: 2px 0 0 2px; }
.tb-group > :last-child, .tb-group > :last-child .tb-btn { border-radius: 0 2px 2px 0; }
.tb-btn {
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.tb-btn:hover { background: var(--panel-hover); color: var(--text); }
.tb-range { min-width: 150px; }
#refreshBtn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.dropdown { position: relative; }
.menu {
  position: absolute;
  z-index: 50;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  max-height: 360px;
  overflow: auto;
  padding: 4px 0;
  background: var(--menu);
  border: 1px solid var(--border);
  border-radius: 2px;
  box-shadow: var(--shadow);
}
.menu-right { left: auto; right: 0; }
.menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 12px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.menu button:hover { background: var(--panel-hover); }
.menu button.selected { box-shadow: inset 2px 0 0 var(--orange); background: var(--panel-hover); }
.menu .menu-head { padding: 6px 12px 4px; font-size: 12px; color: var(--text-3); }
.menu kbd { margin-left: auto; font: 11px "Roboto Mono", monospace; color: var(--text-3); }

.error {
  margin: 0 16px 8px;
  padding: 10px 14px;
  background: rgba(242, 73, 92, 0.12);
  border-left: 3px solid var(--red);
  font-size: 13px;
}
.error button { margin-left: 12px; background: var(--red); color: #fff; border: 0; border-radius: 2px; padding: 3px 10px; cursor: pointer; }

/* Rows and grid */
.dashboard { padding: 0 16px 24px; }
.row { margin-bottom: 8px; }
.row-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  background: none;
  border: 0;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
}
.row-title svg { transition: transform 0.15s; }
.row.collapsed .row-title svg { transform: rotate(-90deg); }
.row.collapsed .grid { display: none; }
.row-title .var-ref { color: var(--text); }
.row-count { font-size: 12px; color: var(--text-3); font-weight: 400; }

.grid { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 8px; }
.grid > * { grid-column: span var(--w); min-width: 0; }
.stack { display: grid; grid-template-rows: repeat(3, 1fr); gap: 8px; height: 300px; }
.stack-2 { grid-template-rows: repeat(2, 1fr); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
.panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 8px;
  flex-shrink: 0;
}
.panel-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panel-header .menu-btn { margin-left: auto; opacity: 0; }
.panel:hover .menu-btn, .menu-btn[aria-expanded="true"] { opacity: 1; }
.hint {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1px solid var(--text-3); color: var(--text-3);
  font-size: 9px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; cursor: help;
}
.panel-body { flex: 1; min-height: 0; padding: 0 8px 8px; position: relative; }
.panel-body.chart { padding: 4px 8px 8px; }
.h-chart { height: 240px; }
.h-detail { height: 300px; }
.no-data { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text-3); font-size: 14px; }

/* Panel view mode */
body.viewing .panel.view {
  position: fixed;
  inset: 56px 16px 16px;
  z-index: 40;
  height: auto !important;
}
body.viewing .panel.view .panel-body { overflow: auto; }
body.viewing::after { content: ""; position: fixed; inset: 0; background: var(--canvas); z-index: 30; }

/* Table */
.table-wrap { overflow: auto; padding: 0; }
.gtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.gtable th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
  text-align: left;
  font-weight: 500;
  color: var(--link);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.gtable th.num, .gtable td.num { text-align: right; }
.gtable th .arrow { margin-left: 4px; color: var(--text); font-size: 11px; }
.gtable td {
  padding: 0 8px;
  height: 36px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.gtable tbody tr { cursor: pointer; }
.gtable tbody tr:hover td { background: var(--panel-hover); }
.gtable tbody tr:hover td.cell-bg { filter: brightness(1.1); }
.gtable td.cell-bg { color: #fff; font-weight: 500; }
.gtable a { color: var(--link); }
.gtable .muted { color: var(--text-3); }
.gtable.compact td { height: 32px; font-size: 13px; }
.status-text { display: inline-flex; align-items: center; gap: 6px; }
.status-text::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* Stat */
.stat { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding-bottom: 10px; }
.stat .value { font-size: 26px; font-weight: 500; line-height: 1.1; }
.stat .sub { font-size: 11px; color: var(--text-2); margin-top: 2px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Gauge */
.gauge { display: flex; align-items: center; justify-content: center; padding: 0 8px 6px; }
.gauge svg { width: 100%; height: 100%; max-height: 110px; stroke: none; overflow: visible; }
.gauge text { font-family: Inter, sans-serif; }

/* Bar gauge */
.bargauge { display: flex; flex-direction: column; gap: 10px; height: 100%; justify-content: center; }
.bg-row { display: grid; grid-template-columns: 64px 1fr 30px; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.bg-row .label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bg-track { height: 22px; background: var(--grid); border-radius: 2px; overflow: hidden; }
.bg-fill { height: 100%; border-radius: 2px; }
.bg-row .val { font-weight: 500; text-align: right; }

/* LED gauge */
.led { display: flex; flex-direction: column; justify-content: space-around; height: 100%; gap: 6px; }
.led-row { display: grid; grid-template-columns: 96px 1fr 58px; align-items: center; gap: 10px; cursor: pointer; }
.led-row .label { font-size: 13px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.led-cells { display: grid; grid-template-columns: repeat(20, 1fr); gap: 3px; height: 26px; }
.led-cells i { border-radius: 1px; }
.led-row .val { font-size: 16px; font-weight: 500; font-variant-numeric: tabular-nums; }

/* Status tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; height: 100%; }
.tile {
  border: 0;
  border-radius: 2px;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  background-image: linear-gradient(120deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0));
}
.tile:hover { filter: brightness(1.08); }
.tile span { font-size: 12px; font-weight: 500; opacity: 0.9; }
.tile b { font-size: 30px; font-weight: 500; line-height: 1; align-self: flex-end; }
.tile.dim { opacity: 0.45; }

/* Timeline */
.timeline svg { width: 100%; height: auto; display: block; stroke: none; overflow: visible; }
.timeline text { font-family: Inter, sans-serif; font-size: 12px; fill: var(--text-2); }
.timeline .row-label { fill: var(--text); font-size: 13px; }
.timeline .hit { cursor: pointer; }
.timeline .hit:hover rect.band-bg { fill: var(--panel-hover); }

/* Tooltip */
.tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: var(--menu);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 2px;
  padding: 6px 10px;
  font-size: 12px;
  max-width: 280px;
}
.tooltip b { display: block; margin-bottom: 2px; }

/* Drawer */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 60; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 70;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 16px 8px; }
.drawer-head h3 { margin: 0; font-size: 18px; font-weight: 500; }
.drawer-head p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.tabs { display: flex; gap: 16px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.tabs button { background: none; border: 0; padding: 8px 2px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-image: linear-gradient(90deg, #f05a28, #fbca0a) 1; border-bottom-width: 2px; border-bottom-style: solid; }
.drawer-body { padding: 16px; overflow: auto; flex: 1; }
.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv th, .kv td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv th { color: var(--text-2); font-weight: 500; width: 38%; }
.drawer pre { margin: 0; padding: 12px; background: var(--canvas); border: 1px solid var(--border); font: 12px/1.6 "Roboto Mono", monospace; overflow: auto; white-space: pre; }
.drawer .actions { margin-top: 16px; display: flex; gap: 8px; }
.btn-primary { background: #3d71d9; color: #fff; border: 0; border-radius: 2px; padding: 6px 14px; font-weight: 500; cursor: pointer; display: inline-block; }
.btn-primary:hover { background: #2e5fc4; color: #fff; }

/* Responsive */
@media (max-width: 1200px) {
  .grid > .h-chart { grid-column: span 8; }
  .grid > .h-chart[data-panel="priority"], .grid > .h-chart[data-panel="venues"] { grid-column: span 12; }
  .grid > .stack { grid-column: span 6; }
  .grid > .h-detail { grid-column: span 12; }
  .grid > .h-detail[data-panel="steps"] { grid-column: span 24; }
}
@media (max-width: 760px) {
  .grid > *, .grid > .h-chart, .grid > .h-chart[data-panel], .grid > .stack, .grid > .h-detail { grid-column: span 24; }
  .stack { height: auto; grid-template-rows: none; }
  .stack .panel { height: 110px; }
  .stack-2 .panel { height: 150px; }
  .crumbs span:not(:last-of-type), .crumbs .sep { display: none; }
  .sync { display: none; }
  .toolbar, .dashboard { padding-left: 8px; padding-right: 8px; }
  .tb-range { min-width: 0; }
  .tb-range span { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
  body.viewing .panel.view { inset: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
