:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --border: #2c3845;
  --text: #e7eef5;
  --muted: #8b9aab;
  --accent: #3d9cf0;
  --accent-dim: #1e4f7a;
  --ok: #3ecf8e;
  --err: #f07178;
  --hl: #f5c542;
  --mono: "Cascadia Mono", "Consolas", "Courier New", monospace;
  --sans: "Segoe UI", system-ui, sans-serif;
  --packets-h: 120px;
  --catalog-w: 340px;
  --hex-w: 50%;
  --split: 6px;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--sans);
  background: radial-gradient(1200px 600px at 10% -10%, #1a2a3a, var(--bg));
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.7rem;
  padding: 0.3rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand-ver {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  user-select: all;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  flex: 1;
  min-width: 0;
}

.tb-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  color: var(--muted);
  margin: 0;
  min-width: 0;
  flex: 0 0 auto;
}

.tb-label { white-space: nowrap; }

.tb-field select {
  width: auto;
  min-width: 0;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
}

#format { max-width: 11rem; }
#framing { max-width: 6.2rem; }

.input-hint {
  color: var(--muted);
  font-size: 0.75rem;
  font-family: var(--mono);
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  min-width: 0;
}

input, select, textarea {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text);
  background: #0c1117;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

input[type="checkbox"] {
  width: auto;
  min-width: 0;
}

textarea { resize: vertical; }

.seg { display: flex; gap: 0.3rem; }

.tab {
  background: #121820;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.primary {
  border: 0;
  border-radius: 6px;
  padding: 0.25rem 0.85rem;
  background: var(--accent);
  color: #041018;
  font-weight: 600;
  cursor: pointer;
  width: auto;
  white-space: nowrap;
  font-size: 0.8rem;
}

.primary:hover { filter: brightness(1.08); }

.hidden { display: none !important; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.parse-filter {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 720px) {
  .parse-filter { grid-template-columns: minmax(0, 1fr); }
}

.status-area {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1 1 12rem;
  min-width: 0;
}

.status-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.28rem;
  flex: 0 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.22rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.72rem;
  font-family: var(--mono);
  white-space: nowrap;
  background: #121820;
}

.stat-k { color: var(--muted); }
.stat-v { color: var(--text); }
.stat-chip.stat-ok .stat-v { color: var(--ok); }
.stat-chip.stat-err .stat-v { color: var(--err); }
.stat-chip.stat-warn .stat-v { color: var(--hl); }

.status {
  margin: 0;
  min-height: 0;
  font-size: 0.75rem;
  color: var(--muted);
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status:empty { display: none; }
.status.error { color: var(--err); }
.status.ok { color: var(--ok); }

.input-drawer {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
}

.input-drawer > summary {
  cursor: pointer;
  padding: 0.22rem 0.75rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.input-body {
  padding: 0 1rem 0.75rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem 1.25rem;
  max-height: 40vh;
  overflow: auto;
}

.input-body .panel { min-width: 0; }
.input-body .framing-opts { min-width: 0; }

.filter-note {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.check-label {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0;
}

input:disabled, select:disabled {
  opacity: 0.45;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0.6rem 0.5rem;
  gap: 0;
}

.packet-list-wrap {
  flex: 0 0 var(--packets-h);
  min-height: 88px;
  max-height: 50%;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.3rem 0.55rem 0.4rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.packet-list-head,
.catalog-head,
.pane-head {
  display: flex;
  align-items: center;
  gap: 0.45rem 0.65rem;
  margin-bottom: 0.2rem;
  flex: 0 0 auto;
}

.packet-list-head,
.catalog-head { flex-wrap: wrap; }

.packet-list-head h2,
.catalog-head h2,
.pane-head h2 {
  margin: 0;
  font-size: 0.9rem;
}

.packet-meta { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }

.locator-filter {
  flex: 1 1 10rem;
  min-width: 8rem;
  max-width: 22rem;
  width: auto;
  padding: 0.18rem 0.4rem;
  margin: 0;
  font-size: 0.75rem;
}

.goto-input {
  width: 4.4rem;
  flex: 0 0 auto;
  padding: 0.18rem 0.35rem;
  margin: 0;
  font-size: 0.75rem;
}

.goto-input::-webkit-outer-spin-button,
.goto-input::-webkit-inner-spin-button { appearance: none; margin: 0; }
.goto-input { appearance: textfield; }

.packet-table-scroll,
.pdu-table-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c1117;
}

.pdu-table-scroll:focus,
.packet-table-scroll:focus {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

#packet-table,
#pdu-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.75rem;
  white-space: nowrap;
}

#packet-table thead th,
#pdu-table thead th {
  position: sticky;
  top: 0;
  background: #121820;
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

#packet-table tbody td,
#pdu-table tbody td {
  padding: 0 0.5rem;
  border-bottom: 1px solid #1a2430;
  color: var(--text);
}

#packet-table tbody tr,
#pdu-table tbody tr { cursor: pointer; }

#packet-table tbody tr:not(.vpad),
#pdu-table tbody tr:not(.vpad) { height: 24px; }

#packet-table tbody tr:hover:not(.vpad),
#pdu-table tbody tr:hover:not(.vpad) { filter: brightness(1.12); }

#packet-table tbody tr.active,
#pdu-table tbody tr.active {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

#packet-table tbody tr.secondary {
  outline: 1px dashed color-mix(in srgb, var(--accent) 55%, var(--border));
  outline-offset: -1px;
  background: color-mix(in srgb, var(--accent-dim) 55%, transparent);
}

#packet-table tbody tr.vpad,
#pdu-table tbody tr.vpad {
  cursor: default;
  border: 0;
}

#packet-table tbody tr.vpad td,
#pdu-table tbody tr.vpad td {
  padding: 0;
  border: 0;
}

#packet-table .col-no,
#packet-table .col-len,
#pdu-table .col-num { text-align: right; color: var(--muted); }

#packet-table .col-time,
#pdu-table .col-off,
#pdu-table .col-stream { color: var(--muted); }

#packet-table .col-info { white-space: nowrap; }

#pdu-table tbody tr.bad { color: var(--err); }
#pdu-table tbody tr.left { color: var(--hl); }

.proto-tcp { background: #1a2438; }
.proto-udp { background: #1a3028; }
.proto-arp { background: #2a2818; }
.proto-icmp, .proto-icmpv6 { background: #2a1c28; }
.proto-ip, .proto-ipv6 { background: #1c2228; }
.proto-ethernet { background: #181818; }

.split-h {
  flex: 0 0 var(--split);
  cursor: row-resize;
  margin: 2px 0;
  border-radius: 3px;
  background: var(--border);
  user-select: none;
  touch-action: none;
}

.split-h:hover, .split-v:hover { background: var(--accent); }

.main-row {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
}

.catalog {
  flex: 0 0 var(--catalog-w);
  min-width: 200px;
  max-width: 70%;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.4rem 0.55rem 0.5rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.chips::-webkit-scrollbar { height: 6px; }

.chip {
  border: 1px solid var(--border);
  background: #121820;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.72rem;
  font-family: var(--mono);
  cursor: pointer;
  flex: 0 0 auto;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-dim);
}

.pdu-filters {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  margin-bottom: 0.4rem;
}

.pdu-filters input[type="search"] { flex: 1; padding: 0.22rem 0.4rem; margin: 0; }

.chip-n { color: var(--muted); }

.flag-toggle,
.err-toggle {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  white-space: nowrap;
  font-size: 0.75rem;
}

.split-v {
  flex: 0 0 var(--split);
  cursor: col-resize;
  margin: 0 3px;
  border-radius: 3px;
  background: var(--border);
  align-self: stretch;
  user-select: none;
  touch-action: none;
}

.viewer {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: row;
  --hex-w: 50%;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.4rem 0.55rem 0.5rem;
}

.hex-pane {
  flex: 0 0 var(--hex-w);
  min-width: 160px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.fields-pane {
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pane-head { justify-content: space-between; gap: 0.4rem; }

.pane-head h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 8rem;
}

.pane-tools {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex: 0 1 auto;
  min-width: 0;
}

.pane-find {
  width: 8.5rem;
  flex: 1 1 6rem;
  min-width: 5rem;
  max-width: 12rem;
  padding: 0.18rem 0.4rem;
  margin: 0;
  font-size: 0.75rem;
}

.pane-select {
  width: auto;
  flex: 0 0 auto;
  padding: 0.18rem 0.3rem;
  margin: 0;
  font-size: 0.75rem;
}

.hex-cursor {
  flex: 1 1 8rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.ghost {
  background: #121820;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  font-size: 0.78rem;
}

.ghost:hover { border-color: var(--accent); }
.ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.ghost:disabled:hover { border-color: var(--border); }

.catalog-head .pane-tools { margin-left: auto; }
.catalog-head .ghost { padding: 0.12rem 0.4rem; font-size: 0.72rem; }

.pdu-badge {
  font-size: 0.65rem;
  font-weight: 600;
  margin-left: 0.2rem;
}
.pdu-badge.err { color: var(--err); }
.pdu-badge.left,
.pdu-badge.inc { color: var(--hl); }

.payload-notice {
  margin: 0 0 0.4rem;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--hl) 45%, var(--border));
  background: color-mix(in srgb, var(--hl) 18%, #0c1117);
  color: var(--hl);
  font-size: 0.8rem;
}

.hex-view,
.tree-view {
  flex: 1;
  min-height: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  background: #0c1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem;
  overflow: auto;
}

.hex-view {
  line-height: 1.45;
  white-space: pre;
}

.hex-view .byte.mapped,
.hex-view .ascii.mapped {
  color: #e8f4ff;
  border-radius: 2px;
  cursor: pointer;
}

.hex-view .byte.mapped-0,
.hex-view .ascii.mapped-0 { background: #245a86; }
.hex-view .byte.mapped-1,
.hex-view .ascii.mapped-1 { background: #4a3d6e; }

.hex-view .byte.hl,
.hex-view .ascii.hl {
  background: #f5c542;
  color: #1a1400;
  border-radius: 2px;
}

.hex-view .byte.find,
.hex-view .ascii.find {
  outline: 1px solid var(--ok);
  outline-offset: -1px;
}

.hex-view .byte.find-cur,
.hex-view .ascii.find-cur {
  background: #1e4a38;
  color: #e8fff4;
  outline: 1px solid var(--ok);
  outline-offset: -1px;
}

.tree-node { margin-left: 0.85rem; }
.tree-node.root { margin-left: 0; }
.tree-node.collapsed > .tree-node { display: none; }

.tree-row {
  display: flex;
  gap: 0.45rem;
  padding: 0.12rem 0.2rem;
  border-radius: 4px;
  cursor: pointer;
  align-items: baseline;
  flex-wrap: wrap;
}

.tree-row:hover, .tree-row.active { background: var(--accent-dim); }
.tree-row.match { outline: 1px dashed color-mix(in srgb, var(--accent) 70%, var(--border)); outline-offset: -1px; }
.tree-row.match-cur { background: var(--accent-dim); }
.tree-name { color: var(--accent); }
.tree-val { color: var(--text); word-break: break-all; min-width: 0; }
.tree-val.is-short {
  word-break: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 18rem;
}
.tree-val.hidden { display: none; }
.tree-meta { color: var(--muted); }

.tree-more,
.tree-copy {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0 0.15rem;
  font-family: var(--sans);
}

.tree-more:hover,
.tree-copy:hover { color: var(--accent); }

.tree-twist {
  flex: 0 0 1rem;
  width: 1rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 0.7rem;
  line-height: 1;
}

.tree-twist.spacer { visibility: hidden; pointer-events: none; }

@media (max-width: 1100px) {
  body { overflow: auto; }
  .workspace { min-height: 70vh; }
  .main-row { flex-direction: column; }
  .catalog {
    flex: 0 0 auto;
    max-width: none;
    width: 100%;
    min-height: 180px;
  }
  .split-v { display: none; }
  .viewer { min-height: 320px; }
}
