/* Components shared by the browser-side tool families. Loaded only on those tool pages. */

.io-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.io-grid.single { grid-template-columns: 1fr; }
.io-grid .textarea, .tool-textarea { min-height: 220px; font-size: 14px; }
.textarea.mono, .input.mono { font-family: var(--mono); font-size: 13px; }
.tool-section + .tool-section { margin-top: 20px; }
.tool-stage { margin-top: 20px; }
.tool-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stats-grid .stat { padding: 14px 16px; }
.stats-grid .stat-value { font-size: 24px; margin-top: 4px; }

.canvas-preview { display: grid; place-items: center; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg);
    background: var(--bg-muted) repeating-conic-gradient(#eef0f3 0% 25%, #fff 0% 50%) 50% / 16px 16px; min-height: 200px; overflow: hidden; }
.canvas-preview canvas, .canvas-preview img { max-width: 100%; max-height: 520px; height: auto; width: auto; display: block; }
.canvas-preview.pickable canvas { cursor: crosshair; }

.crop-stage { position: relative; display: inline-block; max-width: 100%; user-select: none; touch-action: none; line-height: 0; }
.crop-stage img { max-width: 100%; max-height: 520px; display: block; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(17, 24, 39, .55); cursor: move; outline: 1px solid rgba(17, 24, 39, .4); }
.crop-box::before, .crop-box::after { content: ""; position: absolute; border: 0 dashed rgba(255, 255, 255, .6); pointer-events: none; }
.crop-box::before { inset: 0 33.33%; border-left-width: 1px; border-right-width: 1px; }
.crop-box::after { inset: 33.33% 0; border-top-width: 1px; border-bottom-width: 1px; }
.crop-handle { position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid var(--accent); border-radius: 3px; }
.crop-handle[data-h="nw"] { left: -8px; top: -8px; cursor: nwse-resize; }
.crop-handle[data-h="ne"] { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-handle[data-h="sw"] { left: -8px; bottom: -8px; cursor: nesw-resize; }
.crop-handle[data-h="se"] { right: -8px; bottom: -8px; cursor: nwse-resize; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.swatch { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--card); cursor: pointer; text-align: left; padding: 0; font: inherit; color: var(--text); }
.swatch:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.swatch:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-ring); }
.swatch .chip-color { height: 64px; }
.swatch .swatch-body { padding: 8px 10px; font-size: 12.5px; font-family: var(--mono); }
.color-readout { display: grid; grid-template-columns: 72px 1fr; gap: 16px; align-items: center; }
.color-big { width: 72px; height: 72px; border-radius: 14px; border: 1px solid var(--border); }
.value-row { display: flex; align-items: center; gap: 8px; }
.value-row code { flex: 1; padding: 8px 10px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }

.diff-view { border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: 560px; font-family: var(--mono); font-size: 13px; background: var(--card); }
.diff-line { display: grid; grid-template-columns: 48px 48px 22px 1fr; white-space: pre-wrap; word-break: break-word; }
.diff-line span { padding: 1px 6px; }
.diff-line .ln { color: var(--text-3); text-align: right; background: var(--bg-soft); user-select: none; }
.diff-line.add { background: #ecfdf3; }
.diff-line.del { background: #fef3f2; }
.diff-line.add .sign { color: var(--success-700); font-weight: 700; }
.diff-line.del .sign { color: var(--danger-700); font-weight: 700; }

.result-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.result-list li { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.result-list li:last-child { border-bottom: 0; }
.result-list .code { font-family: var(--mono); font-weight: 700; min-width: 48px; display: inline-block; }

.regex-output { white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 13px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); min-height: 80px; }
.regex-output mark { background: #fde68a; border-radius: 3px; padding: 0 1px; }
.regex-output mark:nth-of-type(even) { background: #bfdbfe; }

.demo-box { display: grid; place-items: center; min-height: 260px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-soft); padding: 24px; }
.demo-shape { width: 200px; height: 140px; background: #fff; border: 1px solid var(--border); }
.gradient-preview { height: 220px; border-radius: var(--radius-lg); border: 1px solid var(--border); }
.stop-row { display: grid; grid-template-columns: 56px 1fr 72px 40px; gap: 10px; align-items: center; }
.stop-row input[type=color] { height: 38px; }

.dyn-list { display: grid; gap: 12px; }
.dyn-item { position: relative; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-soft); display: grid; gap: 10px; }
.dyn-item .dyn-remove { position: absolute; top: 8px; right: 8px; }

.meter { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--success); transition: width .2s var(--ease); }
.meter.warn > span { background: var(--warning); }
.meter.bad > span { background: var(--danger); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; }

.serp { max-width: 600px; font-family: Arial, sans-serif; padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: #fff; }
.serp.mobile { max-width: 380px; }
.serp .serp-site { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #202124; }
.serp .serp-fav { width: 26px; height: 26px; border-radius: 50%; background: #f1f3f4; display: grid; place-items: center; font-size: 12px; color: #5f6368; }
.serp .serp-url { font-size: 12px; color: #4d5156; }
.serp .serp-title { display: block; font-size: 20px; line-height: 1.3; color: #1a0dab; margin: 6px 0 4px; overflow-wrap: anywhere; }
.serp.mobile .serp-title { font-size: 18px; }
.serp .serp-desc { font-size: 14px; line-height: 1.58; color: #4d5156; overflow-wrap: anywhere; }

.share-card { max-width: 520px; border: 1px solid #dadde1; border-radius: 12px; overflow: hidden; background: #fff; font-family: Arial, sans-serif; }
.share-card .share-img { aspect-ratio: 1.91 / 1; background: #f0f2f5 center / cover no-repeat; display: grid; place-items: center; color: #8a8d91; font-size: 13px; }
.share-card .share-body { padding: 10px 12px; background: #f0f2f5; border-top: 1px solid #dadde1; }
.share-card .share-domain { font-size: 12px; color: #65676b; text-transform: uppercase; }
.share-card .share-title { font-size: 16px; font-weight: 700; color: #050505; margin: 3px 0; overflow-wrap: anywhere; }
.share-card .share-desc { font-size: 14px; color: #65676b; overflow-wrap: anywhere; }
.share-card.x-small { display: grid; grid-template-columns: 130px 1fr; border-radius: 16px; }
.share-card.x-small .share-img { aspect-ratio: 1; }
.share-card.x-small .share-body { background: #fff; border-top: 0; border-left: 1px solid #dadde1; }
.share-card.x-large { border-radius: 16px; }
.share-card.x-large .share-body { background: #fff; }

.video-probe { width: 100%; max-height: 320px; border-radius: 12px; background: #0b0f19; }
.big-result { font-size: 30px; font-weight: 750; letter-spacing: -.02em; }

.md-preview { min-height: 220px; max-height: 640px; overflow: auto; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); line-height: 1.6; overflow-wrap: anywhere; }
.md-preview > :first-child { margin-top: 0; }
.md-preview pre { background: var(--bg-soft); padding: 12px; border-radius: 8px; overflow: auto; }
.md-preview code { font-family: var(--mono); font-size: 13px; }
.md-preview blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md-preview table { border-collapse: collapse; margin-bottom: 12px; }
.md-preview th, .md-preview td { border: 1px solid var(--border); padding: 6px 10px; }
.md-preview img { max-width: 100%; }
.md-preview li.task-list-item { list-style: none; }
.md-img-placeholder { display: inline-block; padding: 2px 8px; border: 1px dashed var(--border-strong); border-radius: 6px; font-size: 13px; color: var(--text-3); }
.md-grid td, .md-grid th { padding: 4px; min-width: 120px; }
.md-grid td:first-child, .md-grid th:first-child { min-width: 0; width: 1%; white-space: nowrap; }
.tool-workspace pre { max-width: 100%; overflow-x: auto; }
.compare-stage { position: relative; display: grid; justify-items: center; }
.compare-stage canvas { max-width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.compare-range { width: 100%; max-width: 100%; margin-top: 8px; }

@media (max-width: 760px) {
    .io-grid { grid-template-columns: 1fr; }
    .stop-row { grid-template-columns: 48px 1fr 64px 36px; }
    .share-card.x-small { grid-template-columns: 96px 1fr; }
}

/* On-device AI panel (AiTool template) */
.ai-panel { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-soft); }
.ai-privacy { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.ai-facts { display: grid; gap: 6px; margin: 12px 0 0; font-size: 13.5px; }
.ai-facts > div { display: grid; grid-template-columns: 110px 1fr; gap: 12px; }
.ai-facts dt { color: var(--text-3); font-weight: 550; }
.ai-facts dd { margin: 0; color: var(--text-2); overflow-wrap: anywhere; }
.ai-facts [data-ai-env][data-gpu="true"] { color: var(--success-700); }
.ai-panel .progress-panel { margin-top: 12px; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent-600); cursor: pointer; font: inherit; text-decoration: underline; }
[data-ai-busy] [data-run] { pointer-events: none; opacity: .6; }
@media (max-width: 640px) { .ai-facts > div { grid-template-columns: 1fr; gap: 0; } }
.ai-bar-row { display: grid; grid-template-columns: 90px 1fr 48px; align-items: center; gap: 10px; margin-bottom: 6px; }
.ai-bar-row .meter { margin-top: 0; }
.ai-bar-row strong { text-align: right; font-variant-numeric: tabular-nums; }
.audio-timeline { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-soft); padding: 8px; }
.audio-timeline canvas { display: block; width: 100%; }
.w-full { width: 100%; }

/* YouTube downloader */
.yt-video-card { display: flex; gap: 16px; align-items: center; }
.yt-video-card img { width: 240px; max-width: 40%; height: auto; border-radius: var(--radius); background: var(--bg-muted); }
.yt-quality-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.yt-quality { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; background: var(--card); }
.yt-quality:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.yt-quality span { display: flex; flex-direction: column; }
@media (max-width: 640px) { .yt-video-card { flex-direction: column; align-items: flex-start; } .yt-video-card img { max-width: 100%; } }

/* NER highlighting */
.ner-text p { line-height: 1.9; }
.ner-text mark.ner { padding: 1px 4px; border-radius: 4px; }
.ner-text mark.ner-per { background: rgba(99, 102, 241, .22); }
.ner-text mark.ner-org { background: rgba(34, 197, 94, .22); }
.ner-text mark.ner-loc { background: rgba(245, 158, 11, .28); }
.ner-text mark.ner-misc { background: rgba(236, 72, 153, .2); }

/* Local AI chat */
.chat-log { display: flex; flex-direction: column; gap: 10px; max-height: 480px; min-height: 160px; overflow-y: auto; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-soft); }
.chat-msg { max-width: 85%; padding: 10px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.chat-msg.chat-user { align-self: flex-end; background: var(--accent-50); border-color: var(--accent-100); }
.chat-role { display: block; font-size: 12px; color: var(--text-3); margin-bottom: 4px; }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-input .textarea { width: 100%; resize: vertical; }
