:root {
  --bg-0: #ffffff;
  --bg-1: #f5f5f5;
  --fg-0: #000000;
  --fg-1: #212529;
  --fg-2: #333333;

  --nav-bg: #f1f1f1;
  --border: #e0e0e0;
  --view-bg: #ffffff;
  --table-bg-hover: #f8f9fa;
  --calm: #61284e;
  --cold: #093060;
  --mild: #184033;
  --warm: #5d3025;

  --gray-0: #666666;
  --red-0: #a60000;
  --green-0: #006800;
  --yellow-0: #936e05;
  --brown-0: #7d5654;
  --blue-0: #0543cb;

  --added: #ccffcc;
  --modified: #ffffcc;
  --deleted: #ffcccc;

  --accent: #023e8a;
  --accent-hover: #0077b6;

  --view-width: 1180px;
  --line-height: 1.5;
  --fsize-xxxs: round(0.6rem, 1px);
  --fsize-xxs: round(0.75rem, 1px);
  --fsize-xs: round(0.85rem, 1px);
  --fsize-s: round(0.95rem, 1px);
  --fsize-normal: round(1rem, 1px);
  --fsize-m: round(1.1rem, 1px);
  --fsize-l: round(1.2rem, 1px);
  --fsize-xl: round(1.35rem, 1px);
  --fsize-xxl: round(1.6rem, 1px);

  --vertical-0: calc(var(--line-height) * 0.9rem);
  --vertical-1: calc(var(--line-height) * 1.2rem);
  --space-0: 0.5rem;
  --space-1: 1rem;

  --font-text: "helvetica neue", "arial", sans-serif;
  --font-text2: "Noto Sans", sans-serif;
  --font-mono:
    SFMono-Regular, Menlo, Consolas, Monaco, "Liberation Mono",
    "Lucida Console", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-0: #1a1a1a;
    --bg-1: #252525;
    --fg-0: #ffffff;
    --fg-1: #e8e8e8;
    --fg-2: #d0d0d0;

    --nav-bg: #2a2a2a;
    --border: #404040;
    --view-bg: #1e1e1e;
    --table-bg-hover: #2d2d2d;
    --calm: #c77aaf;
    --cold: #5a9bd5;
    --mild: #5eb89a;
    --warm: #d4927e;

    --gray-0: #a0a0a0;
    --red-0: #ff6b6b;
    --green-0: #51cf66;
    --yellow-0: #ffd43b;
    --brown-0: #c9a89b;
    --blue-0: #4dabf7;

    --added: #1a4d1a;
    --modified: #4d4d1a;
    --deleted: #4d1a1a;

    --accent: #4da6ff;
    --accent-hover: #66b3ff;
  }
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  font-size: 100%;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
  margin-bottom: 1rem;
  font-weight: 700;
  font-family: var(--font-text2);
}

h1 {
  font-size: var(--fsize-xl);
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  width: 100%;
}

h2 {
  font-size: var(--fsize-xl);
}

h3 {
  font-size: var(--fsize-l);
}

h4 {
  font-size: var(--fsize-normal);
}

h5 {
  font-size: var(--fsize-s);
}

h6 {
  font-size: var(--fsize-xs);
}

p {
  text-wrap: pretty;
  margin: 0 0 var(--vertical-0);
}

ul,
ol {
  list-style-position: inside;
  padding-inline-start: 0;
}

body {
  font-family: var(--font-text);
  background: var(--bg-0);
  color: var(--fg-0);
  line-height: var(--line-height);
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
  height: 100dvh;
}

p {
  margin: 0 0 var(--vertical-0);
}

button {
  padding: 0.4rem 1.2rem;
  border: 2px solid var(--fg-1);
  border-radius: 0;
  background: var(--bg-0);
  color: var(--fg-0);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 3px 3px 0 var(--fg-1);
}

button:hover {
  background: var(--gray-0);
  color: var(--bg-0);
  transform: translate(-1px, -1px);
}

button:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--fg-1);
}

abbr {
  cursor: help;
}

pre {
  max-height: 45dvh;
  font-family: var(--font-mono);
  font-size: var(--fsize-s);
  margin: 4px 0;
  padding: 4px;
  padding-left: 2px;
  white-space: pre-wrap;
  white-space-collapse: preserve;
  overflow: auto;
  overflow-wrap: break-word;
  word-break: normal;
  word-wrap: inherit;

  background-color: var(--bg-1);
  color: var(--fg-0);
  padding: 16px 20px;

  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

:not(pre) > code {
  color: var(--warm);
  background: var(--bg-1);
  padding: 1px 2px 1px 2px;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.green {
  color: var(--green-0);
}

.red {
  color: var(--red-0);
}

.blue {
  color: var(--blue-0);
}

.brown {
  color: var(--brown-0);
}

.yellow {
  color: var(--yellow-0);
}

.s3xx {
  color: var(--fg-1) !important;
}

.s2xx {
  color: var(--green-0) !important;
}

.s4xx {
  color: var(--yellow-0) !important;
}

.s2xx,
.s3xx,
.s4xx,
.s5xx {
  font-weight: bold;
}

.errorRecord,
.s5xx {
  color: var(--red-0) !important;
}

.logMsg {
  color: var(--fg-1) !important;
  font-style: italic;
}

.strike {
  text-decoration: line-through !important;
}

.bold {
  font-weight: 600;
}

.inline-block {
  display: inline-block;
  vertical-align: top;
}

/* HTMX animation after element creation */
.fade-me-in.htmx-added {
  opacity: 0;
  transform: translateY(20px) scale(0.9);
}

/* Final state */
.fade-me-in {
  opacity: 1;
  transform: translateX(0) translateY(0) scale(1);
  transition:
    opacity 0.2s ease-out,
    transform 0.2s ease-out;
}

body {
  width: 100%;
  min-height: 100dvh;

  display: grid;

  grid-template-areas:
    "nav"
    "content"
    "footer";
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
}

#content {
  grid-area: content;
  display: flex;
  margin: 0 auto;
  width: 100%;
  justify-content: center;
}

footer {
  grid-area: footer;
  gap: 2px;
  font-size: var(--fsize-xxs);
  border-top: 1px solid var(--border);
  border-bottom: none;
  font-style: italic;
  color: var(--fg-1);
}

nav {
  grid-area: nav;
}

nav,
footer {
  display: flex;
  gap: 6px;
  flex-direction: row;
  align-content: center; /* vertical align */
  align-items: center;
  justify-content: center;
  justify-items: center;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  background-color: var(--bg-1);
  border-bottom: 1px solid var(--border);
}

nav div {
  color: var(--gray-0);
  width: 100%;
  max-width: var(--view-width);
  margin: 0 auto;
  padding-left: 0.8rem;
}

nav label {
  color: var(--fg-0);
  font-size: var(--fsize-s);
  font-family: var(--font-text2);
  font-weight: 500;
  cursor: pointer;
  padding: 2px;
}

nav label:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

input[type="radio"].nav {
  display: none;
}

.view,
.error {
  width: 100%;
  max-width: var(--view-width);
}

.view {
  display: none;
  width: 100%;
  max-width: var(--view-width);
}

.view-content {
  width: 100%;
  padding: 1rem;
}

#radio-parse:checked ~ nav div label[for="radio-parse"],
#radio-overview:checked ~ nav div label[for="radio-overview"],
#radio-timings:checked ~ nav div label[for="radio-timings"],
#radio-headers:checked ~ nav div label[for="radio-headers"],
#radio-vcllogtree:checked ~ nav div label[for="radio-vcllogtree"],
#radio-reqbuild:checked ~ nav div label[for="radio-reqbuild"] {
  color: var(--accent);
  text-decoration: underline;
}

#radio-parse:checked ~ #content #parse-view,
#radio-overview:checked ~ #content #overview-view,
#radio-timings:checked ~ #content #timings-view,
#radio-headers:checked ~ #content #headers-view,
#radio-vcllogtree:checked ~ #content #vcllogtree-view,
#radio-reqbuild:checked ~ #content #reqbuild-view {
  display: block;
}

.hdr-legend {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.4rem;
  padding: 0.5rem;
  font-size: var(--fsize-xs);
}

.hdr-legend-item {
  display: flex;
  align-items: center;
  justify-items: center;
  gap: 0.4rem;
}

.hdr-legend-color {
  width: 14px;
  min-width: 14px;
  height: 14px;
  min-height: 14px;
  border: 1px solid var(--fg-0);
}

table.headers-legend th {
  text-align: right;
  vertical-align: top;
  padding-right: 8px;
}

div.hdr-table {
  padding-bottom: 42px;

  display: grid;
  grid-template-columns: max-content max-content max-content;
  column-gap: 4px;
  row-gap: 4px;

  justify-items: left;
  align-items: center;

  & * {
    font-size: var(--fsize-xs);
    font-family: var(--font-mono);
  }

  & div.hdr-tx,
  & div.hdr-title {
    font-family: var(--font-text2);
  }

  & div.hdr-tx {
    width: 100%;
    grid-column: span 3;
    font-size: var(--fsize-normal);
    font-weight: bold;
    padding: 8px 0 8px 0;
    border-bottom: 1px solid var(--mild);
    color: var(--mild);
  }

  & div.hdr-title {
    justify-self: center;
    font-weight: bold;
    font-size: var(--fsize-xs);
    padding: 4px 0 4px 0;
  }

  & div.hdr-key {
    justify-self: center;
    padding: 4px 0 4px 0;
  }

  & abbr {
    text-decoration: none;
    cursor: help;
  }

  & abbr input {
    text-align: center;
    display: block;
    width: 33dvw;
    max-width: 60ch;
    border: none;
    outline: none;
    padding: 4px;
    cursor: help;
  }

  & .hdr-bytes {
    color: var(--gray-0);
    font-style: italic;
  }
}

.diff-received {
  background: var(--bg-1) !important;
}

.diff-added {
  background: var(--added) !important;
}

.diff-modified {
  background: var(--modified) !important;
}

.diff-deleted {
  background: var(--deleted) !important;
  text-decoration: line-through !important;
}

div.txtree {
  & * {
    font-size: var(--fsize-xs);
    font-family: var(--font-mono);
  }

  & tx-logs {
    max-width: 100%;
    color: var(--fg-0);
    border: 1px solid var(--gray-0);
    border-radius: 5px;
    box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2);

    margin: 8px 0 8px 32px;
    padding: 3px 0 3px 0;

    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 6px;
    row-gap: 0;

    /* when this element is a child, occupy 2 columns */
    grid-column: span 2;

    /* nested tx-logs */
    & tx-logs {
      max-width: 95%;
    }

    & tx-key,
    & tx-val {
      display: block;
      padding: 2px 6px 2px 6px;
    }

    & tx-val {
      overflow-wrap: break-word;
    }

    & tx-key {
      text-align: right;
      font-weight: 600;
    }
  }

  & > tx-logs:first-of-type {
    margin: 0;
  }

  & .tx-tree-tx {
    font-weight: normal;
    color: var(--gray-0);
  }
}

.form-row {
  display: flex;
  gap: 4px;
  margin-top: 2px;
  margin-bottom: 6px;
}

#parse-form {
  width: 100%;

  & fieldset {
    width: 100%;

    & fieldset {
      width: auto;
    }

    & textarea {
      width: 100%;
      max-width: 450px;
      height: 220px;
    }
  }
}

#parse-submit-btn {
  width: 100%;
  max-width: 450px;
  padding: 10px;
}

form {
  margin-bottom: 1rem;
  vertical-align: top;

  & fieldset {
    vertical-align: top;
    display: inline-block;
    margin: 0.3rem 0 0 0;
    padding: 0.6rem;

    background: var(--bg-0);
    border-radius: 8px;
  }

  & fieldset legend {
    padding: 4px;
    margin: 0;

    background: var(--bg-0);
  }

  & fieldset label {
    display: inline-block;
    font-family: var(--font-text);
    font-size: var(--fsize-s);
    font-weight: 500;
    background: var(--bg-0);
    color: var(--gray-0);
    align-items: center;
    gap: 0.3rem;
    margin: 4px 6px 4px 0;
    padding: 2px;
    white-space: nowrap;
  }

  & input,
  & textarea,
  & select {
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    box-sizing: border-box;
    font-size: var(--fsize-xs);
    font-family: var(--font-mono);
  }

  & select {
    font-family: var(--font-text);
  }

  & input[type="checkbox"] {
    margin-left: 0;
  }

  & input:focus,
  & textarea:focus,
  & select:focus {
    border-color: var(--warm);
    outline: none;
  }

  & button {
    align-self: flex-start;
    margin: 1rem 1rem 0 0;
  }
}

form .examples {
  margin: 20px 0 10px 0;

  button {
    font-size: var(--fsize-xs);
    padding: 4px 8px;
    margin: 8px 2px;
  }
}

fieldset {
  border: none;

  & legend {
    font-weight: 600;
    color: var(--cold);
  }
}

fieldset fieldset {
  font-size: 85%;
  margin: 0 0.4rem;
  border: 1px solid var(--border);

  & legend {
    color: var(--warm);
  }
}

div.timeline {
  display: inline-block;
  width: 100%;
  max-width: var(--view-width);
}

/* Default classes from svg-timeline */
.tl-bg {
  fill: #ffffff;
}

.tl-event {
  cursor: pointer;
}

.tl-event rect {
  fill: rgba(115, 105, 250, 0.8);
  stroke: #000000;
  stroke-width: 0;
}

.tl-event:hover rect {
  stroke: #000000;
  stroke-width: 1;
}

.tl-event text {
  fill: #ffffff;
}

.tl-era rect {
  fill: rgba(200, 240, 240, 0.35);
  stroke: rgba(200, 240, 240, 0.95);
  stroke-width: 0;
}

.tl-era text {
  fill: #444444;
}

.tl-axis,
.tl-ticks line {
  stroke: #333333;
  stroke-width: 1;
}

.tl-ticks text {
  fill: #333333;
}

/* Custom classes */

/* Eras */
.ctl-session rect {
  fill: rgba(180, 180, 180, 0.15);
  stroke: rgba(200, 200, 200, 0.5);

  &:hover {
    fill: rgba(180, 180, 180, 0.3);
    stroke-width: 1;
  }
}

.ctl-request rect {
  fill: rgba(252, 186, 3, 0.15);
  stroke: rgba(252, 186, 3, 0.5);

  &:hover {
    fill: rgba(252, 186, 3, 0.3);
    stroke-width: 1;
  }
}

.ctl-bereq rect {
  fill: rgba(252, 3, 3, 0.15);
  stroke: rgba(252, 3, 3, 0.5);

  &:hover {
    fill: rgba(252, 3, 3, 0.3);
    stroke-width: 1;
  }
}

/* Events */
.ctl-e-start rect {
  fill: rgba(212, 136, 3, 0.85);
}

.ctl-e-req rect {
  fill: rgba(3, 3, 212, 0.85);
}

.ctl-e-process rect {
  fill: rgba(3, 52, 212, 0.85);
}

.ctl-e-resp rect {
  fill: rgba(3, 113, 212, 0.85);
}

.ctl-e-connected rect {
  fill: rgba(212, 3, 52, 0.85);
}

.ctl-e-bereq rect {
  fill: rgba(212, 3, 3, 0.85);
}

.ctl-e-fetch rect {
  fill: rgba(212, 2, 3, 0.85);
}

.ctl-e-beresp rect {
  fill: rgba(212, 52, 3, 0.85);
}

.ctl-e-berespbody rect {
  fill: rgba(212, 112, 3, 0.85);
}

div.sequence {
  display: inline-block;
  width: 100%;
  max-width: var(--view-width);
}

#currentNumOfTxsParsed,
#firstParsedHostname {
  display: none;
}

#history {
  margin-top: 20px;

  & table {
    margin-top: 10px;
    width: 100%;
    max-width: var(--view-width);
  }

  & th,
  & td {
    text-align: left;
    vertical-align: middle;
  }

  & .btn-load,
  .btn-delete {
    display: block;
    cursor: pointer;
  }

  .btn-load {
    color: var(--accent);
  }

  .btn-delete {
    color: var(--red-0);
  }

  .btn-load:hover,
  .btn-delete:hover {
    text-decoration: underline;
  }

  & .name-cell {
    cursor: pointer;
    color: var(--accent);
  }

  & .name-cell:hover {
    text-decoration: underline;
    color: var(--accent-hover);
  }

  & .name-input {
    width: 100%;
    padding: 4px;
    border: 1px solid var(--accent);
    border-radius: 3px;
  }

  & .empty-state {
    text-align: left;
    color: var(--gray-0);
  }

  & .note {
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: var(--fsize-xxxs);
    font-style: italic;
  }

  & {
    .pagination {
      display: flex;
      justify-content: left;
      align-items: left;
      gap: 0.5rem;
    }

    .pagination a {
      color: var(--accent);
      text-decoration: underline;
      cursor: pointer;
    }

    .pagination a.disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    .pagination span {
      color: var(--fg-1);
    }
  }
}

table {
  border-collapse: collapse;
  margin-bottom: 18px;
  border: none;
}

th {
  font-size: var(--fsize-xs);
  color: var(--fg-0);
  font-weight: 600;
  text-decoration: underline;
  padding: 4px 10px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tbody tr {
  border-bottom: 1px solid var(--border);
}

tbody tr:hover {
  background-color: var(--table-bg-hover);
}

tbody tr:last-child {
  border-bottom: none;
}

td {
  padding: 6px 10px;
  color: var(--fg-1);
}

td {
  font-family: var(--font-mono);
  font-size: var(--fsize-xs);
}

.chr_bg { color: #f8f8f2; background-color: #272822; }
.chr_chroma { color: #f8f8f2; background-color: #272822; }
.chr_chroma .chr_err { color: #960050; background-color: #1e0010 }
.chr_chroma .chr_lnlinks { outline: none; text-decoration: none; color: inherit }
.chr_chroma .chr_lntd { vertical-align: top; padding: 0; margin: 0; border: 0; }
.chr_chroma .chr_lntable { border-spacing: 0; padding: 0; margin: 0; border: 0; }
.chr_chroma .chr_hl { background-color: #3c3d38 }
.chr_chroma .chr_lnt { white-space: pre; -webkit-user-select: none; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f }
.chr_chroma .chr_ln { white-space: pre; -webkit-user-select: none; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f }
.chr_chroma .chr_line { display: flex; }
.chr_chroma .chr_k { color: #66d9ef }
.chr_chroma .chr_kc { color: #66d9ef }
.chr_chroma .chr_kd { color: #66d9ef }
.chr_chroma .chr_kn { color: #f92672 }
.chr_chroma .chr_kp { color: #66d9ef }
.chr_chroma .chr_kr { color: #66d9ef }
.chr_chroma .chr_kt { color: #66d9ef }
.chr_chroma .chr_na { color: #a6e22e }
.chr_chroma .chr_nc { color: #a6e22e }
.chr_chroma .chr_no { color: #66d9ef }
.chr_chroma .chr_nd { color: #a6e22e }
.chr_chroma .chr_ne { color: #a6e22e }
.chr_chroma .chr_nx { color: #a6e22e }
.chr_chroma .chr_nt { color: #f92672 }
.chr_chroma .chr_nf { color: #a6e22e }
.chr_chroma .chr_fm { color: #a6e22e }
.chr_chroma .chr_l { color: #ae81ff }
.chr_chroma .chr_ld { color: #e6db74 }
.chr_chroma .chr_s { color: #e6db74 }
.chr_chroma .chr_sa { color: #e6db74 }
.chr_chroma .chr_sb { color: #e6db74 }
.chr_chroma .chr_sc { color: #e6db74 }
.chr_chroma .chr_dl { color: #e6db74 }
.chr_chroma .chr_sd { color: #e6db74 }
.chr_chroma .chr_s2 { color: #e6db74 }
.chr_chroma .chr_se { color: #ae81ff }
.chr_chroma .chr_sh { color: #e6db74 }
.chr_chroma .chr_si { color: #e6db74 }
.chr_chroma .chr_sx { color: #e6db74 }
.chr_chroma .chr_sr { color: #e6db74 }
.chr_chroma .chr_s1 { color: #e6db74 }
.chr_chroma .chr_ss { color: #e6db74 }
.chr_chroma .chr_m { color: #ae81ff }
.chr_chroma .chr_mb { color: #ae81ff }
.chr_chroma .chr_mf { color: #ae81ff }
.chr_chroma .chr_mh { color: #ae81ff }
.chr_chroma .chr_mi { color: #ae81ff }
.chr_chroma .chr_il { color: #ae81ff }
.chr_chroma .chr_mo { color: #ae81ff }
.chr_chroma .chr_o { color: #f92672 }
.chr_chroma .chr_ow { color: #f92672 }
.chr_chroma .chr_c { color: #75715e }
.chr_chroma .chr_ch { color: #75715e }
.chr_chroma .chr_cm { color: #75715e }
.chr_chroma .chr_c1 { color: #75715e }
.chr_chroma .chr_cs { color: #75715e }
.chr_chroma .chr_cp { color: #75715e }
.chr_chroma .chr_cpf { color: #75715e }
.chr_chroma .chr_gd { color: #f92672 }
.chr_chroma .chr_ge { font-style: italic }
.chr_chroma .chr_gi { color: #a6e22e }
.chr_chroma .chr_gs { font-weight: bold }
.chr_chroma .chr_gu { color: #75715e }

