/* logwiju — Betaflight blackbox viewer */

:root {
  --bg: #0e1117;
  --panel: #12151c;
  --panel-2: #171b24;
  --line: #262c38;
  --line-2: #323a4a;
  --text: #d6dEEB;
  --text-dim: #7d8aa1;
  --accent: #4ea3ff;
  --ok: #5ed17f;
  --err: #ff6b7f;
  --radius: 6px;
  --topbar-h: 46px;
  --statusbar-h: 26px;
  --scrollbar-h: 14px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: #a9c4e6;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 650;
  letter-spacing: 0.2px;
  color: var(--accent);
  margin-right: 6px;
}

.spacer { flex: 1; }

.file-name {
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status { font-size: 11.5px; color: var(--text-dim); }
#status.ok { color: var(--ok); }
#status.error { color: var(--err); }

/* ------------------------------------------------------------------ buttons */

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 5px 11px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: #1e2431; border-color: #43506a; }
.btn:active { background: #171c26; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06131f; font-weight: 600; }
.btn.primary:hover { background: #6bb4ff; }
.btn.icon { width: 30px; padding: 5px 0; text-align: center; font-size: 15px; line-height: 1; }
.btn.tiny { padding: 2px 7px; font-size: 10.5px; font-weight: 400; }

.zoom-group { display: flex; gap: 4px; }

.select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 5px 8px;
  font: inherit;
  font-size: 12px;
  max-width: 260px;
}

/* ------------------------------------------------------------------ layout */

.layout {
  display: flex;
  height: calc(100% - var(--topbar-h));
}

.sidebar {
  width: 290px;
  min-width: 290px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.panel { border-bottom: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.panel.grow { flex: 1; }

.panel h2 {
  margin: 0;
  padding: 9px 12px;
  font-size: 10.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.muted { color: var(--text-dim); }
.pad { padding: 12px; }

/* -------------------------------------------------------------- info panel */

.info { padding: 8px 12px 11px; font-size: 11.5px; }
.info .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 2.5px 0;
}
.info .row span { color: var(--text-dim); flex-shrink: 0; }
.info .row b {
  font-weight: 500;
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  word-break: break-word;
}

/* ------------------------------------------------------------- field list */

.fields { overflow-y: auto; flex: 1; padding-bottom: 20px; }

.fields details { border-bottom: 1px solid var(--line); }

.fields summary {
  padding: 7px 12px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #93a2bb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  list-style: none;
}
.fields summary::-webkit-details-marker { display: none; }
.fields summary::before {
  content: "▸";
  margin-right: 6px;
  font-size: 9px;
  color: var(--text-dim);
  transition: transform 0.12s;
  display: inline-block;
}
.fields details[open] summary::before { transform: rotate(90deg); }
.fields summary > span:first-of-type { flex: 1; }
.fields summary:hover { background: var(--panel-2); }
.fields .count {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 400;
  font-family: ui-monospace, monospace;
}

.field {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 7px;
  padding: 3.5px 12px 3.5px 20px;
  cursor: pointer;
  font-size: 11.5px;
}
.field:hover { background: var(--panel-2); }
.field.constant { opacity: 0.42; }
.field input { margin: 0; accent-color: var(--accent); cursor: pointer; }

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  border: 1px solid var(--line);
  background: transparent;
  flex-shrink: 0;
}

.field .name {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field .range {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ------------------------------------------------------------- chart area */

.chart-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

#chart {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
#chart.grabbing { cursor: grabbing; }

/* ------------------------------------------------------------ empty state */

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  text-align: center;
  background: var(--bg);
  pointer-events: none;
}
.empty > * { pointer-events: auto; }
.empty h3 { margin: 0; font-size: 17px; font-weight: 600; }
.empty p { margin: 0; color: var(--text-dim); font-size: 12.5px; }
.empty .hint { font-size: 11.5px; opacity: 0.75; margin-top: 4px; }
body.has-log .empty { display: none; }
.empty[hidden] { display: none; }

.boot-error { gap: 7px; max-width: 620px; margin: 0 auto; }
.boot-error h3 { color: #ffc94a; }
.boot-error pre {
  margin: 2px 0;
  padding: 9px 16px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
}
.boot-error pre code { background: none; padding: 0; color: var(--ok); font-size: 12.5px; }

/* -------------------------------------------------------------- scrollbar */

.scrollbar {
  height: var(--scrollbar-h);
  background: var(--panel);
  border-top: 1px solid var(--line);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: none;
}
.scrollbar .thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  width: 100%;
  background: #3c4a63;
  border-radius: 5px;
  transition: background 0.12s;
}
.scrollbar:hover .thumb { background: #4d5f7e; }
.scrollbar.full .thumb { background: #2a3241; }

/* -------------------------------------------------------------- statusbar */

.statusbar {
  height: var(--statusbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
}
.statusbar .keys { font-family: inherit; opacity: 0.8; }
.statusbar .keys b { color: #93a2bb; font-weight: 600; }

/* ---------------------------------------------------------------- haptics */

.haptics {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-dim);
}
.haptics.unsupported { opacity: 0.4; }
.tiny-select { padding: 4px 6px; font-size: 11px; }

/* ----------------------------------------------------------- import modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
.modal[hidden] { display: none; }

.modal-box {
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  width: min(940px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px 16px;
  overflow-y: auto;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.modal-box h3 { margin: 0; font-size: 15px; font-weight: 650; }
.modal-box h4 {
  margin: 0 0 6px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.imp-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 10px;
}
.imp-controls label { display: flex; flex-direction: column; gap: 4px; }
.imp-controls label > span { font-size: 11px; color: var(--text-dim); }
.imp-controls .select { max-width: none; width: 100%; }
.imp-controls .select:disabled { opacity: 0.45; }

.imp-preview-wrap { min-width: 0; }
#imp-preview { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }

.imp-table {
  border-collapse: collapse;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  width: 100%;
}
.imp-table th,
.imp-table td {
  padding: 4px 9px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.imp-table th {
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  position: sticky;
  top: 0;
}
.imp-table th .u { color: var(--accent); margin-left: 5px; font-weight: 400; }
.imp-table th .t {
  margin-left: 6px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ok);
  border: 1px solid var(--ok);
  border-radius: 3px;
  padding: 0 4px;
}
.imp-table td.conv { color: var(--ok); }
.imp-table td.bad {
  color: var(--err);
  background: rgba(255, 107, 127, 0.1);
  text-decoration: line-through;
}
.imp-table td.empty { color: var(--text-dim); }
.imp-table .skipped { color: var(--text-dim); opacity: 0.5; font-style: italic; }

.imp-error { padding: 14px; color: var(--err); font-size: 12px; }

#imp-notes { display: flex; flex-direction: column; gap: 5px; }
.note {
  font-size: 11.5px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border-left: 3px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text-dim);
}
.note.warn { border-left-color: #ffc94a; color: #e8d9a8; }
.note.info { border-left-color: var(--accent); }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions .btn { padding: 7px 18px; }
.modal-actions .btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* --------------------------------------------------------------- dropzone */

.dropzone {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 20, 0.86);
  z-index: 100;
  pointer-events: none;
}
.dropzone.active { display: flex; }
.dropzone > div {
  border: 2px dashed var(--accent);
  border-radius: 12px;
  padding: 40px 70px;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 820px) {
  .sidebar { width: 220px; min-width: 220px; }
  .field .range { display: none; }
  .statusbar .keys { display: none; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: #2e3646; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3d4759; }
