/* KivTools Frontend Lab: compact controls, immediate visual feedback, copyable output. */
.kiv-frontend-tool {
    --fl-accent: var(--kt-accent, #178b58);
    --fl-accent-deep: #276b4c;
    --fl-accent-soft: #e9f5ee;
    --fl-surface: var(--kt-surface, #fff);
    --fl-soft: var(--kt-surface-soft, #f5f8f6);
    --fl-canvas: var(--kt-canvas, #f2f6f3);
    --fl-line: var(--kt-line, #d8e2dc);
    --fl-ink: var(--kt-ink, #273a40);
    --fl-muted: var(--kt-muted, #73827d);
    --fl-danger: #a94f4f;
}

.kiv-frontend-tool .fl-tabs {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(112px, .72fr);
    margin: 18px 0;
    padding: 0;
    border: 0;
    border-bottom: 1px solid var(--fl-line);
    background: rgba(255, 255, 255, .34);
}

.kiv-frontend-tool .fl-tabs::before,
.kiv-frontend-tool .fl-tabs::after { display: none; content: none; }

.kiv-frontend-tool .fl-tabs > li {
    float: none;
    min-width: 0;
    margin: 0;
}

.kiv-frontend-tool .fl-tabs > li > a {
    display: flex;
    min-height: 48px;
    margin: 0;
    padding: 11px 12px 9px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 0;
    color: #4e655b;
    font-size: 12px;
    font-weight: 720;
    line-height: 1.25;
    text-align: center;
    transition: background .16s ease, color .16s ease, box-shadow .16s ease;
}

.kiv-frontend-tool .fl-tabs > li > a:hover,
.kiv-frontend-tool .fl-tabs > li > a:focus {
    border: 0;
    background: rgba(23, 139, 88, .07);
    color: var(--fl-accent-deep);
    outline: 0;
}

.kiv-frontend-tool .fl-tabs > li.active > a,
.kiv-frontend-tool .fl-tabs > li.active > a:hover,
.kiv-frontend-tool .fl-tabs > li.active > a:focus {
    border: 0;
    background: var(--fl-surface);
    color: var(--fl-accent-deep);
    box-shadow: inset 0 3px 0 var(--fl-accent);
}

.kiv-frontend-tool .fl-tabs .dropdown-menu {
    min-width: 250px;
    padding: 6px;
}

.kiv-frontend-tool .fl-tabs .dropdown-menu > li > a {
    padding: 8px 11px;
    border-radius: 3px;
    font-size: 12px;
}

.kiv-frontend-tool .fl-rail {
    display: flex;
    min-height: 42px;
    margin: 0 0 13px;
    padding: 9px 12px;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-left: 3px solid var(--fl-accent);
    background: rgba(255, 255, 255, .5);
    color: var(--fl-ink);
    font-size: 12px;
}

.kiv-frontend-tool .fl-rail strong { font-weight: 780; }
.kiv-frontend-tool .fl-rail small { color: var(--fl-muted); text-align: right; }

.kiv-frontend-tool .fl-status {
    min-height: 0;
    margin: 0 0 12px;
    color: var(--fl-muted);
    font-size: 12px;
    font-weight: 680;
}

.kiv-frontend-tool .fl-status:not(:empty) {
    min-height: 38px;
    padding: 10px 12px;
    border-left: 3px solid var(--fl-accent);
    background: #eaf5ee;
    color: #315f49;
}

.kiv-frontend-tool .fl-status.is-error:not(:empty) {
    border-left-color: var(--fl-danger);
    background: #faeeee;
    color: #853f3f;
}

.kiv-frontend-tool .fl-workbench {
    display: grid;
    grid-template-columns: minmax(250px, .78fr) minmax(360px, 1.18fr) minmax(280px, .9fr);
    gap: 14px;
    align-items: start;
}

.kiv-frontend-tool .fl-workbench > section {
    min-width: 0;
    overflow: hidden;
    border-radius: 6px;
    background: var(--fl-surface);
    box-shadow: 0 10px 28px rgba(31, 55, 43, .065);
}

.kiv-frontend-tool .fl-workbench > section > header {
    display: flex;
    min-height: 45px;
    padding: 10px 13px;
    align-items: center;
    gap: 8px;
    background: var(--fl-soft);
}

.kiv-frontend-tool .fl-workbench > section > header strong {
    color: var(--fl-ink);
    font-size: 12px;
    font-weight: 780;
    letter-spacing: .01em;
}

.kiv-frontend-tool .fl-workbench > section > header small {
    margin-left: auto;
    color: var(--fl-muted);
    font-size: 10px;
    text-align: right;
}

.kiv-frontend-tool .fl-step {
    display: inline-flex;
    width: 24px;
    height: 24px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--fl-accent-soft);
    color: var(--fl-accent-deep);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10px;
    font-weight: 820;
}

.kiv-frontend-tool .fl-section-body { padding: 14px; }
.kiv-frontend-tool .fl-field { display: grid; gap: 5px; margin-bottom: 12px; }
.kiv-frontend-tool .fl-field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.kiv-frontend-tool .fl-field label,
.kiv-frontend-tool .fl-code-label,
.kiv-frontend-tool .fl-coordinate-grid label {
    color: #53675e;
    font-size: 10px;
    font-weight: 740;
    letter-spacing: .015em;
}

.kiv-frontend-tool input[type="number"],
.kiv-frontend-tool input[type="text"],
.kiv-frontend-tool select,
.kiv-frontend-tool textarea {
    width: 100%;
    height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--fl-line);
    border-radius: 4px;
    background: #fbfdfc;
    color: var(--fl-ink);
    font-size: 12px;
    outline: 0;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.kiv-frontend-tool input:focus,
.kiv-frontend-tool select:focus,
.kiv-frontend-tool textarea:focus {
    border-color: #71b992;
    box-shadow: 0 0 0 3px rgba(23, 139, 88, .11);
}

.kiv-frontend-tool .fl-range { width: 100%; accent-color: var(--fl-accent); }

.kiv-frontend-tool .fl-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 12px;
}

.kiv-frontend-tool .fl-button {
    min-height: 36px;
    padding: 8px 13px;
    border: 0;
    border-radius: 4px;
    background: var(--fl-accent);
    color: #fff;
    font-size: 11px;
    font-weight: 760;
    line-height: 1.2;
    transition: transform .12s ease, background .15s ease;
}

.kiv-frontend-tool .fl-button:hover,
.kiv-frontend-tool .fl-button:focus { background: #11794b; color: #fff; outline: 0; transform: translateY(-1px); }
.kiv-frontend-tool .fl-button.fl-secondary { background: #e8efeb; color: #40574c; }
.kiv-frontend-tool .fl-button.fl-secondary:hover,
.kiv-frontend-tool .fl-button.fl-secondary:focus { background: #dbe9e1; color: #285a42; }

.kiv-frontend-tool .fl-code {
    display: block;
    width: 100%;
    min-height: 156px;
    margin: 0;
    padding: 13px;
    overflow: auto;
    border: 0;
    border-left: 3px solid var(--fl-accent);
    border-radius: 0 4px 4px 0;
    background: #17231e;
    color: #d8eee2;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    line-height: 1.62;
    white-space: pre-wrap;
    word-break: break-word;
}

.kiv-frontend-tool textarea.fl-code { height: auto; resize: vertical; }
.kiv-frontend-tool .fl-code-compact { min-height: 70px; margin: 5px 0 12px; }

.kiv-frontend-tool .fl-viewport-readout {
    display: flex;
    margin-bottom: 8px;
    align-items: center;
    justify-content: space-between;
    color: var(--fl-muted);
    font-size: 10px;
    font-weight: 700;
}

.kiv-frontend-tool .fl-viewport-readout output { color: var(--fl-accent-deep); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.kiv-frontend-tool .fl-clamp-preview {
    display: flex;
    min-height: 190px;
    margin-top: 12px;
    padding: 24px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 5px;
    background: linear-gradient(145deg, #e6f4eb 0%, #f8fbf9 58%, #e9f1ed 100%);
    color: #24583f;
    font-weight: 780;
    line-height: 1.15;
    text-align: center;
}

.kiv-frontend-tool .fl-sample-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.kiv-frontend-tool .fl-sample-row span { padding: 7px; border-radius: 3px; background: var(--fl-soft); color: var(--fl-muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; text-align: center; }

.kiv-frontend-tool .fl-coordinate-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-bottom: 12px; }
.kiv-frontend-tool .fl-coordinate-grid label { display: grid; gap: 5px; }

.kiv-frontend-tool .fl-bezier-canvas {
    display: block;
    width: 100%;
    height: auto;
    max-height: 300px;
    border-radius: 5px;
    background: #f6faf7;
    cursor: crosshair;
    touch-action: none;
}

.kiv-frontend-tool .fl-motion-track {
    position: relative;
    height: 46px;
    margin: 14px 0 0;
    border-radius: 5px;
    background: linear-gradient(90deg, #eef4f0, #ddece3);
}

.kiv-frontend-tool .fl-motion-track::after { position: absolute; top: 8px; bottom: 8px; right: 12px; width: 2px; background: rgba(23, 139, 88, .35); content: ""; }
.kiv-frontend-tool .fl-motion-track span { position: absolute; top: 10px; left: 10px; width: 26px; height: 26px; border-radius: 50%; background: var(--fl-accent); box-shadow: 0 5px 12px rgba(23, 139, 88, .28); }
.kiv-frontend-tool .fl-motion-track.is-playing span { left: calc(100% - 38px); }

.kiv-frontend-tool .fl-grid-preview {
    display: grid;
    min-height: 310px;
    padding: 13px;
    gap: 16px;
    align-content: start;
    border-radius: 5px;
    background-color: #eef4f0;
    background-image: linear-gradient(rgba(39, 107, 76, .06) 1px, transparent 1px), linear-gradient(90deg, rgba(39, 107, 76, .06) 1px, transparent 1px);
    background-size: 20px 20px;
}

.kiv-frontend-tool .fl-grid-preview span {
    display: flex;
    min-width: 0;
    min-height: 58px;
    padding: 10px;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    background: #fff;
    color: #39604d;
    box-shadow: 0 5px 13px rgba(40, 70, 55, .08);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    font-weight: 750;
}

.kiv-frontend-tool .fl-code-tabs { display: flex; gap: 4px; margin-bottom: 7px; }
.kiv-frontend-tool .fl-code-tabs button { padding: 6px 10px; border: 0; border-radius: 3px; background: var(--fl-soft); color: var(--fl-muted); font-size: 10px; font-weight: 760; }
.kiv-frontend-tool .fl-code-tabs button.is-active { background: var(--fl-accent-soft); color: var(--fl-accent-deep); }

.kiv-frontend-tool .fl-stop-list { display: grid; gap: 7px; }
.kiv-frontend-tool .fl-stop-row { display: grid; grid-template-columns: 36px minmax(0, 1fr) 74px 28px; gap: 6px; align-items: center; padding: 7px; border-radius: 4px; background: var(--fl-soft); }
.kiv-frontend-tool .fl-stop-row input[type="color"] { width: 36px; height: 32px; padding: 2px; border: 0; border-radius: 3px; background: transparent; }
.kiv-frontend-tool .fl-stop-row input { height: 32px; }
.kiv-frontend-tool .fl-stop-remove { width: 28px; height: 28px; padding: 0; border: 0; border-radius: 3px; background: #ebe5e5; color: #875050; font-size: 15px; line-height: 28px; }
.kiv-frontend-tool .fl-gradient-preview { display: flex; min-height: 310px; padding: 24px; align-items: flex-end; border-radius: 5px; color: rgba(255,255,255,.92); box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); font-size: 11px; font-weight: 760; text-shadow: 0 1px 3px rgba(0,0,0,.35); }

.kiv-frontend-tool .fl-dropzone {
    position: relative;
    display: flex;
    min-height: 132px;
    margin-bottom: 12px;
    padding: 20px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px dashed #9bc6ad;
    border-radius: 5px;
    background: #f7fbf8;
    color: var(--fl-ink);
    cursor: pointer;
    text-align: center;
}

.kiv-frontend-tool .fl-dropzone::before { color: var(--fl-accent); font-size: 22px; content: "⇣"; }
.kiv-frontend-tool .fl-dropzone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.kiv-frontend-tool .fl-dropzone span { font-size: 12px; font-weight: 760; }
.kiv-frontend-tool .fl-dropzone small { color: var(--fl-muted); font-size: 10px; }

.kiv-frontend-tool .fl-placeholder-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kiv-frontend-tool .fl-placeholder-grid figure { min-width: 0; margin: 0; padding: 8px; border-radius: 5px; background: var(--fl-soft); }
.kiv-frontend-tool .fl-placeholder-grid canvas,
.kiv-frontend-tool .fl-placeholder-grid img { display: block; width: 100%; aspect-ratio: 8 / 5; object-fit: cover; border-radius: 3px; background: #dfe9e3; image-rendering: auto; }
.kiv-frontend-tool .fl-placeholder-grid figcaption { padding-top: 6px; color: var(--fl-muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; text-align: center; }
.kiv-frontend-tool .fl-image-meta { margin-top: 10px; color: var(--fl-muted); font-size: 10px; line-height: 1.6; }

html.kiv-shell-dark .kiv-frontend-tool {
    --fl-accent-soft: #19392a;
    --fl-accent-deep: #86cfa6;
    --fl-surface: #142019;
    --fl-soft: #19271f;
    --fl-canvas: #0f1712;
    --fl-line: #304139;
    --fl-ink: #dce8e1;
    --fl-muted: #8da198;
}

html.kiv-shell-dark .kiv-frontend-tool .fl-tabs,
html.kiv-shell-dark .kiv-frontend-tool .fl-rail { background: rgba(20, 32, 25, .62); }
html.kiv-shell-dark .kiv-frontend-tool .fl-tabs > li > a { color: #a8b8b0; }
html.kiv-shell-dark .kiv-frontend-tool input[type="number"],
html.kiv-shell-dark .kiv-frontend-tool input[type="text"],
html.kiv-shell-dark .kiv-frontend-tool select,
html.kiv-shell-dark .kiv-frontend-tool textarea { background: #101a14; color: var(--fl-ink); color-scheme: dark; }
html.kiv-shell-dark .kiv-frontend-tool .fl-field label,
html.kiv-shell-dark .kiv-frontend-tool .fl-code-label,
html.kiv-shell-dark .kiv-frontend-tool .fl-coordinate-grid label { color: #aebdb5; }
html.kiv-shell-dark .kiv-frontend-tool .fl-button.fl-secondary { background: #26362e; color: #c5d6cd; }
html.kiv-shell-dark .kiv-frontend-tool .fl-status:not(:empty) { background: #193326; color: #b5d8c4; }
html.kiv-shell-dark .kiv-frontend-tool .fl-clamp-preview { background: linear-gradient(145deg, #1b3628, #15241c 58%, #20342a); color: #cbe7d6; }
html.kiv-shell-dark .kiv-frontend-tool .fl-bezier-canvas,
html.kiv-shell-dark .kiv-frontend-tool .fl-grid-preview,
html.kiv-shell-dark .kiv-frontend-tool .fl-motion-track,
html.kiv-shell-dark .kiv-frontend-tool .fl-dropzone { background-color: #111c16; }
html.kiv-shell-dark .kiv-frontend-tool .fl-grid-preview span { background: #1d2d24; color: #bad5c6; box-shadow: none; }
html.kiv-shell-dark .kiv-frontend-tool .fl-placeholder-grid canvas,
html.kiv-shell-dark .kiv-frontend-tool .fl-placeholder-grid img { background: #263a30; }

@media (max-width: 1120px) {
    .kiv-frontend-tool .fl-workbench { grid-template-columns: minmax(270px, .82fr) minmax(390px, 1.18fr); }
    .kiv-frontend-tool .fl-output { grid-column: 1 / -1; }
    .kiv-frontend-tool .fl-output .fl-section-body { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; }
    .kiv-frontend-tool .fl-output .fl-code-tabs,
    .kiv-frontend-tool .fl-output .fl-code-label,
    .kiv-frontend-tool .fl-output textarea,
    .kiv-frontend-tool .fl-output .fl-actions { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
    .kiv-frontend-tool .fl-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kiv-frontend-tool .fl-tabs > li:last-child { grid-column: 1 / -1; }
    .kiv-frontend-tool .fl-workbench { grid-template-columns: 1fr; }
    .kiv-frontend-tool .fl-output { grid-column: auto; }
    .kiv-frontend-tool .fl-output .fl-section-body { display: block; }
}

@media (max-width: 480px) {
    .kiv-frontend-tool .fl-tabs > li > a { min-height: 44px; padding: 9px 8px; font-size: 11px; }
    .kiv-frontend-tool .fl-rail { align-items: flex-start; flex-direction: column; gap: 4px; }
    .kiv-frontend-tool .fl-rail small { text-align: left; }
    .kiv-frontend-tool .fl-field-row,
    .kiv-frontend-tool .fl-coordinate-grid,
    .kiv-frontend-tool .fl-placeholder-grid { grid-template-columns: 1fr; }
    .kiv-frontend-tool .fl-stop-row { grid-template-columns: 34px minmax(0, 1fr) 64px 28px; }
    .kiv-frontend-tool .fl-clamp-preview,
    .kiv-frontend-tool .fl-gradient-preview,
    .kiv-frontend-tool .fl-grid-preview { min-height: 220px; }
    .kiv-frontend-tool .fl-workbench > section > header { padding: 9px 10px; }
    .kiv-frontend-tool .fl-section-body { padding: 11px; }
}

@media (prefers-reduced-motion: reduce) {
    .kiv-frontend-tool *, .kiv-frontend-tool *::before, .kiv-frontend-tool *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
