/*
 * tool-app.css — shared shell for all DiscoverAI converter tool pages
 * Covers: reset, tokens, topbar, titlebar, converter grid, panels,
 *         divider (arrow + swap variants), mobile tabs/opts, how-footer, toast, scrollbars.
 *
 * Each tool page also loads the Google Fonts via this file's @import.
 * Proto-to-json URL-bar styles remain inline in that page only.
 */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;1,400&family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

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

:root {
    --bg-deep:       #0a0c10;
    --bg-base:       #0f1117;
    --bg-surface:    #161921;
    --bg-raised:     #1c1f2b;
    --bg-input:      #0d0f14;
    --border-dim:    #1e2230;
    --border-base:   #282d3e;
    --text-primary:  #e8eaf0;
    --text-secondary:#8b90a0;
    --text-dim:      #555a6e;
    --accent:        #3d6;
    --accent-muted:  #1a3320;
    --accent-glow:   rgba(51,221,102,0.12);
    --error:         #f55;
    --error-bg:      rgba(255,85,85,0.08);
    --error-border:  rgba(255,85,85,0.25);
    --font-mono:     'IBM Plex Mono','Fira Code',monospace;
    --font-sans:     'DM Sans',system-ui,-apple-system,sans-serif;
    --radius:        6px;
    --topbar-h:      52px;
    --titlebar-h:    36px;
    --transition:    150ms ease;
}

html, body { height: 100%; }

body {
    font-family: var(--font-sans);
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
}

body::after {
    content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 9999;
    background: repeating-linear-gradient(0deg,transparent,transparent 2px,rgba(0,0,0,0.03) 2px,rgba(0,0,0,0.03) 4px);
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: #5fa; }

/* ── Topbar ────────────────────────────────────────────────── */

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.25rem; height: var(--topbar-h);
    background: var(--bg-base); border-bottom: 1px solid var(--border-dim);
    position: sticky; top: 0; z-index: 100;
    backdrop-filter: blur(12px); flex-shrink: 0; gap: 0.75rem;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.topbar-home {
    font-family: var(--font-mono); font-size: 0.75rem; font-weight: 500;
    color: var(--text-secondary); letter-spacing: 0.02em; transition: color var(--transition);
}
.topbar-home:hover { color: var(--accent); }
.topbar-sep { width: 1px; height: 18px; background: var(--border-base); flex-shrink: 0; }
.topbar-title {
    font-family: var(--font-mono); font-size: 0.8rem; font-weight: 600;
    color: var(--text-primary); letter-spacing: 0.03em;
}
.topbar-badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px; border-radius: 3px;
    font-family: var(--font-mono); font-size: 0.62rem; font-weight: 500;
    text-transform: uppercase; letter-spacing: 0.08em;
    background: var(--accent-muted); color: var(--accent);
    border: 1px solid rgba(51,221,102,0.2);
}
.topbar-badge::before {
    content: ''; width: 5px; height: 5px; border-radius: 50%;
    background: var(--accent); animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

.topbar-right { display: flex; align-items: center; gap: 1rem; flex-shrink: 0; }
.topbar-opts  { display: flex; align-items: center; gap: 0.75rem; }

/* ── Options: checkbox + segmented buttons ─────────────────── */

.opt {
    display: flex; align-items: center; gap: 0.4rem;
    cursor: pointer; font-size: 0.74rem; font-family: var(--font-mono);
    color: var(--text-secondary); transition: color var(--transition);
    user-select: none; white-space: nowrap;
}
.opt:hover { color: var(--text-primary); }
.opt input[type="checkbox"] {
    appearance: none; -webkit-appearance: none;
    width: 14px; height: 14px;
    border: 1.5px solid var(--border-base); border-radius: 3px;
    background: var(--bg-input); cursor: pointer;
    position: relative; transition: all var(--transition); flex-shrink: 0;
}
.opt input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.opt input[type="checkbox"]:checked::after {
    content: ''; position: absolute; left: 3.5px; top: 1px; width: 4px; height: 7px;
    border: solid var(--bg-deep); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg);
}

.opt-label { font-family: var(--font-mono); font-size: 0.63rem; color: var(--text-dim); white-space: nowrap; }

.seg-btns {
    display: flex; align-items: center;
    background: var(--bg-raised); border: 1px solid var(--border-base);
    border-radius: 4px; overflow: hidden; flex-shrink: 0;
}
.seg-btn {
    padding: 3px 10px; font-family: var(--font-mono); font-size: 0.63rem; font-weight: 500;
    background: transparent; border: none; cursor: pointer;
    color: var(--text-dim); transition: all var(--transition); white-space: nowrap;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border-base); }
.seg-btn:hover { color: var(--text-secondary); background: rgba(255,255,255,0.04); }
.seg-btn.active { background: var(--accent-muted); color: var(--accent); }

/* ── Title bar ─────────────────────────────────────────────── */

.titlebar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.25rem; height: var(--titlebar-h);
    background: var(--bg-deep); border-bottom: 1px solid var(--border-dim);
    flex-shrink: 0; gap: 0.75rem;
}
.titlebar-name {
    font-family: var(--font-sans); font-size: 0.83rem; font-weight: 600;
    color: var(--text-primary); letter-spacing: -0.01em;
    display: flex; align-items: center; gap: 0; white-space: nowrap;
}
.titlebar-name .grad {
    background: linear-gradient(135deg, var(--accent), #5fa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.local-pill {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 3px 9px 3px 7px; border-radius: 100px;
    font-family: var(--font-mono); font-size: 0.6rem; font-weight: 500;
    color: var(--text-dim); border: 1px solid var(--border-dim);
    background: var(--bg-raised); letter-spacing: 0.02em;
    user-select: none; white-space: nowrap;
}
.local-pill svg {
    width: 10px; height: 10px; stroke: var(--text-dim); fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}

/* ── Workspace ─────────────────────────────────────────────── */

.workspace { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }

/* ── Error bar ─────────────────────────────────────────────── */

.error-bar {
    display: flex; align-items: flex-start; gap: 0.6rem;
    padding: 0.55rem 1.25rem;
    background: var(--error-bg); border-bottom: 1px solid var(--error-border);
    font-family: var(--font-mono); font-size: 0.73rem; color: var(--error);
    line-height: 1.5; animation: error-in 200ms ease-out; flex-shrink: 0;
}
@keyframes error-in { from { opacity: 0; transform: translateY(-4px) } to { opacity: 1; transform: translateY(0) } }
.error-bar svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 1px; stroke: var(--error); fill: none; stroke-width: 2; }

/* ── Converter grid ────────────────────────────────────────── */

.converter {
    flex: 1; display: grid; grid-template-columns: 1fr auto 1fr;
    min-height: 0; overflow: hidden;
}

/* ── Panels ────────────────────────────────────────────────── */

.panel { background: var(--bg-surface); display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.panel:first-child { border-right: 1px solid var(--border-dim); }

.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1rem; height: 40px; background: var(--bg-raised);
    border-bottom: 1px solid var(--border-dim); flex-shrink: 0;
}
.panel-label {
    font-family: var(--font-mono); font-size: 0.67rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-secondary);
    display: flex; align-items: center; gap: 0.5rem;
}
.panel-label .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.panel-label .dot.orange { background: #f90; box-shadow: 0 0 6px rgba(255,153,0,.2); }

.panel-actions { display: flex; align-items: center; gap: 0.15rem; }

.panel-btn {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.28rem 0.55rem; border: none; border-radius: 4px;
    font-family: var(--font-mono); font-size: 0.63rem; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
    background: transparent; color: var(--text-dim);
}
.panel-btn:hover { background: rgba(255,255,255,0.05); color: var(--text-secondary); }
.panel-btn:disabled { opacity: .3; cursor: not-allowed; pointer-events: none; }
.panel-btn.accent { color: var(--accent); }
.panel-btn.accent:hover { background: var(--accent-glow); color: #5fa; }
.panel-btn svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.editor-wrap { flex: 1; display: flex; min-height: 0; }
.editor-wrap textarea {
    flex: 1; padding: 1rem 1.15rem;
    border: none; outline: none; resize: none;
    background: var(--bg-input); color: var(--text-primary);
    font-family: var(--font-mono); font-size: 0.81rem; line-height: 1.7;
    tab-size: 2; letter-spacing: 0.01em;
}
.editor-wrap textarea::placeholder { color: var(--text-dim); }
.editor-wrap textarea::selection  { background: rgba(51,221,102,.18); }

.panel-status {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1rem; height: 28px; background: var(--bg-raised);
    border-top: 1px solid var(--border-dim);
    font-family: var(--font-mono); font-size: 0.6rem; color: var(--text-dim); flex-shrink: 0;
}
.status-ok     { display: flex; align-items: center; gap: .35rem; color: var(--accent); }
.status-ok-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }

/* ── Center divider ────────────────────────────────────────── */

.converter-divider {
    width: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: var(--bg-deep);
    border-left: 1px solid var(--border-dim); border-right: 1px solid var(--border-dim);
}
.divider-line {
    flex: 1; width: 1px;
    background: linear-gradient(to bottom,transparent,var(--border-dim) 20%,var(--border-dim) 80%,transparent);
}

/* One-way arrow (beautify, repair, proto-to-json) */
.divider-arrow {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--bg-raised); border: 1px solid var(--border-base);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin: 0.5rem 0; transition: all var(--transition);
}
.divider-arrow.converting { border-color: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
.divider-arrow svg { width: 12px; height: 12px; stroke: var(--text-dim); fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; transition: stroke var(--transition); }
.divider-arrow.converting svg { stroke: var(--accent); }

/* Bidirectional swap (bson, csv, toml, xml, yaml) */
.divider-swap {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--bg-raised); border: 1px solid var(--border-base);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin: 0.5rem 0; cursor: pointer; transition: all var(--transition);
}
.divider-swap:hover,
.divider-swap.active { border-color: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
.divider-swap svg { width: 13px; height: 13px; stroke: var(--text-dim); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: stroke var(--transition); }
.divider-swap:hover svg,
.divider-swap.active svg { stroke: var(--accent); }

/* ── Mobile tab bar ────────────────────────────────────────── */

.mobile-tabs { display: none; flex-shrink: 0; background: var(--bg-base); border-bottom: 1px solid var(--border-dim); }
.tab-bar { display: flex; width: 100%; }
.tab-btn {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 0.4rem;
    padding: 0; height: 42px;
    background: transparent; border: none; border-bottom: 2px solid transparent;
    font-family: var(--font-mono); font-size: 0.7rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-dim); cursor: pointer; transition: all var(--transition);
}
.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tab-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; transition: opacity var(--transition); }
.tab-btn.active .tab-dot { opacity: 1; }
.tab-btn:first-child .tab-dot { background: #f90; }
.tab-btn:first-child.active { border-bottom-color: #f90; color: var(--text-primary); }
.tab-check {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--accent-muted); border: 1px solid rgba(51,221,102,.3);
    font-size: 0.52rem; color: var(--accent); font-weight: 700; letter-spacing: 0;
    opacity: 0; transform: scale(0.6); transition: all 200ms ease;
}
.tab-check.show { opacity: 1; transform: scale(1); }

.mobile-opts {
    display: none; align-items: center; justify-content: center; gap: 0.75rem;
    padding: 0 1rem; height: 42px; flex-wrap: wrap;
    background: var(--bg-deep); border-bottom: 1px solid var(--border-dim);
    flex-shrink: 0;
}

@media (max-width: 800px) {
    .topbar-right  { display: none; }
    .mobile-tabs   { display: block; }
    .mobile-opts   { display: flex; }
    .converter { display: flex; flex-direction: column; grid-template-columns: unset; }
    .converter-divider { display: none; }
    .panel { flex: 1; min-height: 0; }
    .panel:first-child { border-right: none; }
}

/* ── How It Works footer ───────────────────────────────────── */

.how-footer { flex-shrink: 0; border-top: 1px solid var(--border-dim); background: var(--bg-base); }
.how-toggle {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.25rem; height: 36px; cursor: pointer;
    font-family: var(--font-mono); font-size: 0.63rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-dim);
    user-select: none; transition: color var(--transition);
    list-style: none; border: none; background: none; width: 100%; text-align: left;
}
.how-toggle:hover { color: var(--text-secondary); }
.how-toggle-icon { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; transition: transform 250ms ease; }
details[open] .how-toggle-icon { transform: rotate(180deg); }
.how-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 0; border-top: 1px solid var(--border-dim); }
@media (max-width: 640px) { .how-grid { grid-template-columns: 1fr; } }
.how-step { padding: 1rem 1.35rem; display: flex; align-items: flex-start; gap: 0.8rem; }
.how-step + .how-step { border-left: 1px solid var(--border-dim); }
@media (max-width: 640px) { .how-step + .how-step { border-left: none; border-top: 1px solid var(--border-dim); } }
.how-step-num {
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--accent-muted); color: var(--accent);
    font-family: var(--font-mono); font-size: 0.7rem; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin-top: 2px; border: 1px solid rgba(51,221,102,.15);
}
.how-step-text h3 { font-size: .8rem; font-weight: 600; color: var(--text-primary); margin-bottom: .15rem; }
.how-step-text p  { font-size: .72rem; color: var(--text-secondary); line-height: 1.5; }

/* ── Toast ─────────────────────────────────────────────────── */

.toast {
    position: fixed; bottom: 1.5rem; left: 50%;
    transform: translateX(-50%) translateY(12px);
    padding: 0.42rem 1rem;
    background: var(--bg-raised); border: 1px solid var(--border-base);
    border-radius: var(--radius); font-family: var(--font-mono); font-size: 0.72rem; color: var(--accent);
    box-shadow: 0 8px 32px rgba(0,0,0,.4);
    opacity: 0; transition: all 250ms ease; pointer-events: none; z-index: 200;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Scrollbars ────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-base); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Input / Switch / Output dropdown ────────────────────────── */
.app-switcher {
    display: flex; align-items: center; gap: 0.55rem;
    padding: 0.12rem 0.15rem;
}
.app-switcher-label {
    font-family: var(--font-mono); font-size: 0.62rem; font-weight: 600;
    color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em;
    white-space: nowrap;
}
.app-switcher-select {
    appearance: none; -webkit-appearance: none;
    background: var(--bg-raised);
    border: 1px solid var(--border-base);
    border-radius: 4px;
    color: var(--text-primary);
    height: 28px; line-height: 28px;
    padding: 0 0.55rem;
    font-family: var(--font-mono); font-size: 0.66rem; font-weight: 600;
    outline: none; cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.app-switcher-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(51,221,102,0.12);
}
.app-switcher-select:disabled {
    opacity: .6; cursor: not-allowed; box-shadow: none;
}

.app-switcher-switch {
    width: 30px; height: 28px;
    border-radius: 4px;
    border: 1px solid var(--border-base);
    background: var(--bg-deep);
    color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all var(--transition);
    flex-shrink: 0;
    font-family: var(--font-mono); font-weight: 800; font-size: 0.85rem;
}
.app-switcher-switch:hover {
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
    color: var(--accent);
}
.app-switcher-switch svg { width: 14px; height: 14px; }
