/* ==========================================================================
   Tool kit — shared styles for /tools and every tool page (loaded by ToolPage).
   Builds on the tokens and base components in theme.css.
   ========================================================================== */

/* Layout helpers */
.tool-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.tool-cols-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.tool-cols-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tool-cols > *, .tool-cols-3 > *, .tool-cols-4 > * { min-width: 0; }
.tool-stack { display: flex; flex-direction: column; gap: 20px; }
.inline-fields { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.inline-fields .field { margin-bottom: 0; }
.inline-fields .select, .inline-fields .input { width: auto; }
.tool-subtitle { font-size: 1rem; font-weight: 700; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
.tool-subtitle:first-child { margin-top: 0; }
.field .hint { display: block; font-size: .8rem; color: var(--muted); }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mt-16 { margin-top: 16px; }
.nowrap { white-space: nowrap; }

/* Tabs (segmented control with a selected state) */
.segmented .btn.active, .segmented .btn.active:hover { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.tool-tabs { margin-bottom: 18px; }

/* Output with header row */
.out-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.out-head label { font-size: .875rem; font-weight: 600; color: var(--text-2); margin: 0; }
.out-head .btn-row { gap: 6px; }
.output-box.light { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.output-box .placeholder { color: #8b7d6b; }
.size-note { font-size: .82rem; color: var(--muted); margin-top: 8px; }
.size-note b { color: var(--success); }

/* Messages */
.form-msg.info { color: var(--text-2); }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; font-size: .9rem; background: var(--brand-soft); border: 1px solid var(--brand-soft-2); color: var(--text-2); margin-bottom: 16px; }
.notice i { color: var(--brand); margin-top: 3px; }
.notice.err { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.notice.err i { color: var(--danger); }
.notice.ok { background: var(--success-soft); border-color: transparent; color: var(--success); }
.notice.ok i { color: var(--success); }

/* Pills / badges */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 650; white-space: nowrap; background: var(--surface-2); color: var(--text-2); }
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: rgba(217, 154, 30, .16); color: #8a5d00; }
[data-theme='dark'] .pill.warn { color: var(--accent); }
.pill.info { background: var(--brand-soft); color: var(--brand-ink); }

/* Drop zone */
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 30px 16px; border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); cursor: pointer; color: var(--text-2); transition: border-color .15s, background .15s; }
.dropzone i { font-size: 1.9rem; color: var(--brand); }
.dropzone strong { font-weight: 650; }
.dropzone span { font-size: .85rem; color: var(--muted); }
.dropzone.over, .dropzone:hover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input { display: none; }

/* File lists & thumbnails */
.file-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.file-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.file-item img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; background: var(--surface-2); flex-shrink: 0; }
.file-item .file-icon { width: 44px; height: 44px; border-radius: 8px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex-shrink: 0; }
.file-item .grow { flex: 1; min-width: 0; }
.file-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item small { color: var(--muted); display: block; }
.file-item .btn-icon { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.thumb { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); font-size: .8rem; }
.thumb img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: var(--surface-2); }
.thumb > div { padding: 6px 8px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }

/* Preview surfaces */
.preview-stage { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: 24px; min-height: 240px; display: flex; align-items: center; justify-content: center; overflow: auto; position: relative; }
.checkerboard { background-color: #fff; background-image: linear-gradient(45deg, #e8e8e8 25%, transparent 25%), linear-gradient(-45deg, #e8e8e8 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e8e8e8 75%), linear-gradient(-45deg, transparent 75%, #e8e8e8 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }
.preview-frame { width: 100%; min-height: 320px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.prose-preview { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; background: var(--surface); max-height: 600px; overflow: auto; }
.img-preview { max-width: 100%; max-height: 420px; border-radius: 10px; border: 1px solid var(--border); display: block; }

/* Colour */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.swatch { border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: var(--surface); }
.swatch-color { height: 88px; display: flex; align-items: flex-end; justify-content: space-between; padding: 8px 10px; font-family: var(--font-mono); font-size: .8rem; font-weight: 650; cursor: pointer; border: 0; width: 100%; text-align: left; }
.swatch-meta { padding: 6px 10px; font-family: var(--font-mono); font-size: .76rem; display: flex; justify-content: space-between; align-items: center; gap: 6px; color: var(--text-2); }
.color-field { display: flex; gap: 8px; align-items: center; }
.color-field input[type='color'] { width: 46px; height: 42px; padding: 2px; border: 1.5px solid var(--border-strong); border-radius: 10px; background: var(--surface); cursor: pointer; flex-shrink: 0; }
.color-field .input { min-width: 0; font-family: var(--font-mono); }
.color-strip { display: flex; height: 64px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.color-strip > * { flex: 1; }

/* Range sliders */
.range-field input[type='range'] { width: 100%; accent-color: var(--brand); }
.range-field label { display: flex; justify-content: space-between; gap: 8px; }
.range-field label output { font-family: var(--font-mono); font-weight: 500; color: var(--muted); font-size: .82rem; }

/* Results */
.result-card { background: var(--brand-soft); border: 1px solid var(--brand-soft-2); border-radius: var(--radius); padding: 18px 20px; }
.result-card .big { font-size: clamp(1.6rem, 3vw, 2.3rem); font-weight: 800; color: var(--text); font-family: var(--font-display); line-height: 1.15; display: block; }
.result-card small { color: var(--muted); font-size: .85rem; }
.kv { width: 100%; border-collapse: collapse; font-size: .9rem; }
.kv th { text-align: left; width: 34%; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv td { padding: 8px 10px; border-bottom: 1px solid var(--border); word-break: break-word; }
.kv td code, .kv td.mono { font-family: var(--font-mono); font-size: .85rem; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: 0; }
.check-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.check-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: .92rem; }
.check-list li > i { margin-top: 4px; width: 16px; text-align: center; flex-shrink: 0; }
.check-list li > div { min-width: 0; flex: 1; }
.check-list li small { display: block; color: var(--muted); }
.check-list li code { font-family: var(--font-mono); font-size: .82rem; background: var(--surface-2); padding: 0 5px; border-radius: 4px; word-break: break-all; }
.check-list .ok > i { color: var(--success); }
.check-list .warn > i { color: var(--accent); }
.check-list .err > i { color: var(--danger); }
.check-list .info > i { color: var(--brand); }
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.meter span { display: block; height: 100%; border-radius: inherit; transition: width .3s, background-color .3s; }
.score-big { font-size: 3rem; font-weight: 800; line-height: 1; font-family: var(--font-display); }
.data-scroll { max-height: 520px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.data-scroll .re-table th { position: sticky; top: 0; z-index: 1; }
.re-table td.mono, .re-table td code { font-family: var(--font-mono); font-size: .82rem; }

/* Diff */
.diff-view { font-family: var(--font-mono); font-size: .84rem; border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-height: 600px; background: var(--surface); }
.diff-line { display: grid; grid-template-columns: 46px 46px 20px minmax(0, 1fr); white-space: pre-wrap; word-break: break-word; line-height: 1.6; }
.diff-line .ln { color: var(--muted); text-align: right; padding: 0 8px; user-select: none; border-right: 1px solid var(--border); font-size: .76rem; }
.diff-line .sign { text-align: center; color: var(--muted); user-select: none; }
.diff-line.add { background: rgba(63, 185, 80, .14); }
.diff-line.del { background: rgba(248, 81, 73, .14); }
.diff-line.hunk { background: var(--surface-2); color: var(--muted); grid-template-columns: 1fr; padding: 2px 10px; }
.diff-inline { white-space: pre-wrap; word-break: break-word; font-family: var(--font-mono); font-size: .88rem; line-height: 1.7; padding: 14px; }
ins.dw { background: rgba(63, 185, 80, .32); text-decoration: none; border-radius: 3px; }
del.dw { background: rgba(248, 81, 73, .3); border-radius: 3px; }

/* Grid editor (table / markdown generators) */
.grid-editor { border-collapse: collapse; width: 100%; font-size: .88rem; }
.grid-editor td, .grid-editor th { border: 1px solid var(--border); padding: 0; min-width: 90px; }
.grid-editor th { background: var(--surface-2); }
.grid-editor input { width: 100%; border: 0; background: transparent; padding: 7px 9px; font: inherit; color: inherit; }
.grid-editor input:focus { outline: 2px solid var(--brand); outline-offset: -2px; }
.grid-editor .row-head { width: 34px; min-width: 34px; text-align: center; color: var(--muted); font-size: .75rem; background: var(--surface-2); }

/* Characters */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.char-cell { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: 10px 4px 8px; text-align: center; cursor: pointer; color: var(--text); transition: border-color .15s, transform .15s; }
.char-cell:hover, .char-cell.active { border-color: var(--brand); transform: translateY(-2px); }
.char-cell b { display: block; font-size: 1.9rem; line-height: 1.25; font-weight: 400; min-height: 2.4rem; }
.char-cell small { font-family: var(--font-mono); font-size: .68rem; color: var(--muted); }
.ascii-out { font-family: var(--font-mono); line-height: 1; white-space: pre; overflow: auto; background: var(--code-bg); color: var(--code-text); padding: 14px; border-radius: 12px; max-height: 640px; margin: 0; letter-spacing: 0; }

/* Code snippets */
.code-block { font-family: var(--font-mono); font-size: .86rem; background: var(--code-bg); color: var(--code-text); border-radius: 12px; padding: 16px 18px; white-space: pre-wrap; word-break: break-word; margin: 0; max-height: 520px; overflow: auto; position: relative; }

/* Tool directory (/tools) */
.tools-hero-search { max-width: 620px; margin-top: 22px; }
.tools-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.tools-filter { display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px; border-radius: 999px; font-size: .86rem; font-weight: 550; background: var(--surface); border: 1.5px solid var(--border); color: var(--text-2); cursor: pointer; transition: border-color .15s, color .15s, background .15s; }
.tools-filter small { font-size: .74rem; color: var(--muted); font-weight: 600; }
.tools-filter:hover { border-color: var(--brand); color: var(--brand); }
.tools-filter.active { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.tools-filter.active small { color: inherit; opacity: .8; }
.tools-group { margin-top: 36px; }
.tools-group h2 { font-size: 1.35rem; display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.tools-group h2 small { font-family: var(--font-sans); font-size: .85rem; color: var(--muted); font-weight: 500; }
.tool-card .tool-cat { font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.related-tools { margin-top: 28px; }
.related-tools .grid { gap: 12px; }
.related-link { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--text); }
.related-link .topic-icon { width: 40px; height: 40px; font-size: 1rem; border-radius: 10px; flex-shrink: 0; }
.related-link span { font-weight: 600; font-size: .92rem; line-height: 1.3; }
.related-link small { display: block; color: var(--muted); font-weight: 400; font-size: .8rem; }

/* Git graph */
.git-graph { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 12px; }
.git-graph svg text { font-family: var(--font-mono); font-size: 11px; fill: var(--text-2); }

@media (max-width: 900px) {
  .tool-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tool-cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .tool-cols, .tool-cols-3 { grid-template-columns: minmax(0, 1fr); }
  .diff-line { grid-template-columns: 34px 34px 16px minmax(0, 1fr); }
  .kv th { width: 40%; }
}
