/* ==========================================================================
   Utilith — Tool workbench & tool page layout
   ========================================================================== */

/* ----------------------------------------------------------- Tool head -- */

.tool-head {
  padding-block: 1.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.75rem;
}

.tool-head__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
}

.tool-head__title {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  max-width: 44rem;
}

.tool-head__icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  flex: none;
  border-radius: 15px;
  border: 1px solid var(--border);
  background: var(--brand-soft);
  color: var(--brand);
}

.tool-head__icon svg { width: 26px; height: 26px; }

.tool-head h1 {
  font-size: clamp(1.55rem, 1.15rem + 1.7vw, 2.3rem);
  margin-bottom: 0.4rem;
}

.tool-head p {
  font-size: 1rem;
  margin-bottom: 0;
}

.tool-head__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.9rem;
}

/* the guide link sits at the end of the badge row */
.tool-head__guide {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--brand);
}

.tool-head__guide:hover { color: var(--brand-strong); }

/* ------------------------------------------------------------ Workbench -- */

.workbench {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
  align-items: start;
}

@media (min-width: 1000px) {
  .workbench { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .workbench--with-aside { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 260px; }
}

.wb-col { display: flex; flex-direction: column; gap: 0.85rem; min-width: 0; }

.wb-col__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.wb-col__foot .spacer { flex: 1; }

/* Shared editor shell used by most text tools */
.editor {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 300px;
}

.editor textarea {
  flex: 1;
  min-height: 300px;
  border: 0;
  border-radius: 0;
  background: transparent;
  resize: vertical;
}

.editor textarea:focus { box-shadow: none; }

.editor .char-count {
  position: absolute;
  right: 0.6rem;
  bottom: 0.5rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--text-3);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* --------------------------------------------------------------- Stats -- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 0.6rem;
}

.stat-tile {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.stat-tile b {
  display: block;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

.stat-tile span {
  font-size: 0.74rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-tile--brand b { color: var(--brand); }
.stat-tile--success b { color: var(--success); }
.stat-tile--warn b { color: var(--warning); }

/* ------------------------------------------------------------- Options -- */

.options {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}

.options__head {
  padding: 0.75rem 0.95rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-2);
}

.options__body { padding: 0.95rem; }

.options__group + .options__group {
  margin-top: 1.1rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
}

.options__legend {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 0.55rem;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--brand);
}

.slider-row output {
  min-width: 3.2rem;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--brand);
}

/* ------------------------------------------------------------ Dropzone -- */

.dropzone {
  display: grid;
  place-items: center;
  gap: 0.6rem;
  padding: 2.25rem 1rem;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-soft);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.dropzone:hover,
.dropzone[data-drag="true"] {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.dropzone svg { width: 30px; height: 30px; color: var(--brand); }
.dropzone strong { display: block; color: var(--text); font-size: 0.98rem; }
.dropzone span { font-size: 0.84rem; color: var(--text-3); }

.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.file-item__thumb {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-3);
}

.file-item__info { min-width: 0; flex: 1; }

.file-item__name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item__meta { font-size: 0.76rem; color: var(--text-3); }

.file-item__actions { display: flex; gap: 0.3rem; flex: none; }

.icon-btn--sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn--sm svg { width: 15px; height: 15px; }

/* ------------------------------------------------------------- Preview -- */

.preview {
  display: grid;
  place-items: center;
  min-height: 240px;
  padding: 1rem;
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%) 0 0 / 18px 18px,
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%) 0 9px / 18px 18px,
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%) 9px -9px / 18px 18px,
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%) -9px 0 / 18px 18px,
    var(--bg-soft);
}

.preview img {
  max-height: 340px;
  width: auto;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.preview--qr {
  background: #ffffff;
  padding: 1.25rem;
}

.preview--qr canvas,
.preview--qr img {
  border-radius: 4px;
}

/* --------------------------------------------------------------- Misc --- */

.result-box {
  min-height: 120px;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
}

.result-box--error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  white-space: pre-wrap;
}

.result-box--ok { border-color: var(--success); }

.kv-list {
  display: grid;
  gap: 0.4rem;
  margin: 0;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  gap: 0.75rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 0.86rem;
}

.kv-row dt { color: var(--text-3); }
.kv-row dd {
  margin: 0;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  word-break: break-all;
}

.heatmap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.heatmap__cell {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 0.8rem;
}

.heatmap__cell b {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--brand);
  margin-left: 0.3rem;
}

/* ------------------------------------------------------- Related tools -- */

.related {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.related a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.related a:hover { border-color: var(--brand); transform: translateY(-2px); }

.related__icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 9px;
  background: var(--brand-soft);
  color: var(--brand);
}

.related__icon svg { width: 17px; height: 17px; }

.related strong { display: block; font-size: 0.9rem; color: var(--text); }
.related span { font-size: 0.78rem; color: var(--text-3); }

/* ------------------------------------------------------- Article cards -- */

.article-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.article-card {
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 1.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.article-card:hover { transform: translateY(-3px); border-color: var(--brand); }

.article-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.76rem;
  color: var(--text-3);
}

.article-card h3 { margin-bottom: 0.4rem; }
.article-card p { font-size: 0.9rem; margin-bottom: 1rem; flex: 1; }
/* the card sets its own display, so the hidden attribute needs the same treatment */
.article-card[hidden] { display: none; }

.article-card h3 a { color: var(--text); transition: color 0.16s ease; }
/* the title link covers the whole card, so the card itself is clickable */
.article-card h3 a::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
.article-card h3 a:hover { color: var(--brand); }
.article-card .link-arrow { font-size: 0.86rem; font-weight: 600; color: var(--brand); }
/* keyboard focus is shown around the whole card, not only around the title */
.article-card:has(h3 a:focus-visible) {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
}

.article-card:has(h3 a:focus-visible) h3 a:focus-visible { outline: none; }

/* ------------------------------------------------------- Article filter -- */

.article-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.article-filter__count {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.05rem 0.4rem;
  border-radius: 99px;
  background: var(--surface-2);
  font-size: 0.72rem;
  color: var(--text-3);
}

.cat-nav a[aria-current="page"] .article-filter__count {
  background: var(--brand-soft);
  color: var(--text-2);
}

.article-filter__status {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-3);
}

/* ---------------------------------------------------------- Article page -- */

.article-head {
  max-width: 72ch;
  padding-top: 1.75rem;
}

.article-head__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
  font-size: 0.8rem;
  color: var(--text-3);
}

.article-head__meta .badge { text-decoration: none; }
.article-head__meta a.badge:hover { border-color: var(--brand); color: var(--text); }

.article-head h1 { margin-bottom: 0.75rem; }
.article-head .lede { margin-bottom: 1.4rem; }

.article-body {
  max-width: 72ch;
  font-size: 1.02rem;
  line-height: 1.78;
}

.article-body > p { margin-bottom: 1.15rem; }
.article-body h2 { margin-top: 2.75rem; margin-bottom: 0.9rem; }
.article-body h2:first-child { margin-top: 0; }
.article-body ul,
.article-body ol { margin-bottom: 1.3rem; padding-left: 1.25rem; }
.article-body li { margin-bottom: 0.6rem; line-height: 1.72; }
.article-body code {
  padding: 0.12rem 0.4rem;
  border-radius: 6px;
  background: var(--surface-2);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.88em;
}

.article-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  max-width: 72ch;
  margin-top: 3rem;
  padding: 1.5rem 1.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.article-cta__text h2 { margin: 0 0 0.35rem; font-size: 1.15rem; }
.article-cta__text p { margin: 0; color: var(--text-2); font-size: 0.94rem; }
.article-cta .btn { gap: 0.45rem; }

.article-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  max-width: 72ch;
  margin-top: 2.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.article-foot .link-arrow { font-size: 0.88rem; }

@media (max-width: 560px) {
  .article-cta { flex-direction: column; align-items: flex-start; }
  .article-body { font-size: 1rem; }
}

/* --------------------------------------------------------- Category nav -- */

.cat-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cat-nav a {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.86rem;
  font-weight: 550;
  transition: border-color 0.16s ease, color 0.16s ease, background-color 0.16s ease;
}

.cat-nav a:hover {
  border-color: var(--brand);
  color: var(--text);
  background: var(--brand-soft);
}

.cat-nav a[aria-current="page"] {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--text);
}

/* --------------------------------------------------------- Result table -- */
/* Tables produced by the audit tools live inside .table-wrap, which already
   gives them the rounded border and the horizontal scroll. */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.data-table th {
  padding: 0.55rem 0.75rem;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table td {
  padding: 0.55rem 0.75rem;
  color: var(--text-2);
  vertical-align: top;
}

.data-table td:first-child { color: var(--text); font-weight: 550; }

.data-table tbody tr:nth-child(even) { background: var(--surface-2); }

.data-table td.cell-mono {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-3);
  word-break: break-word;
}

.data-table td.cell-error {
  color: var(--danger);
  font-weight: 700;
}

.data-table td.cell-warn {
  color: var(--warning);
  font-weight: 700;
}

/* ------------------------------------------------------------- Findings -- */

.finding-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.finding {
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

.finding--error { border-left-color: var(--danger); }
.finding--warning { border-left-color: var(--warning); }
.finding--info { border-left-color: var(--accent); }

.finding__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.finding__title {
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--text);
}

.finding__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  margin-bottom: 0.4rem;
  font-size: 0.76rem;
  color: var(--text-3);
}

.finding__where { color: var(--text-3); }

.finding__value {
  padding: 0.05rem 0.35rem;
  border-radius: 6px;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-2);
  word-break: break-all;
}

.finding__detail {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.6;
  color: var(--text-2);
}

/* Severity badges used by the audit tools. */
.badge--warn {
  border-color: color-mix(in srgb, var(--warning) 45%, transparent);
  background: var(--warning-soft);
  color: var(--warning);
}

.badge--danger {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

/* ------------------------------------------------------------- Hex view -- */

.hexview {
  margin: 0;
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  line-height: 1.65;
  color: var(--text-2);
  overflow-x: auto;
}

.hexview__row {
  display: block;
  white-space: pre;
  word-break: normal;
}

@media (max-width: 560px) {
  .data-table th,
  .data-table td { padding: 0.45rem 0.55rem; font-size: 0.8rem; }
  .finding__top { gap: 0.4rem; }
  .hexview { font-size: 0.68rem; }
}
