/* Floating Kolvera Help — bottom-left launcher + popover (partials/_help_launcher.html).
   Bottom-left on purpose: bottom-right holds the mini dialler pill, the
   background-task pill, report popups and the /app dock. Sits below modals
   (--z-modal 1000) so confirm dialogs and drawers always win. */

.kv-help-launcher {
    position: fixed;
    /* --kv-help-left is measured by help-launcher.js from the visible left
       rails (app sidebar, guide nav); the fallback is the default sidebar. */
    left: var(--kv-help-left, calc(var(--sidebar-w) + var(--sp-4)));
    bottom: var(--sp-5);
    z-index: 890;
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    min-height: 44px;
    padding: 0 var(--sp-4) 0 var(--sp-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: transform var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.kv-help-launcher svg { color: var(--flare); flex-shrink: 0; }
.kv-help-launcher:hover { border-color: var(--flare); transform: translateY(-1px); }
.kv-help-launcher:focus-visible { outline: 2px solid var(--flare); outline-offset: 2px; }
.kv-help-launcher[aria-expanded="true"] { border-color: var(--flare); color: var(--flare); }

.kv-help-panel {
    position: fixed;
    left: var(--kv-help-left, calc(var(--sidebar-w) + var(--sp-4)));
    bottom: calc(var(--sp-5) + 44px + var(--sp-3));
    z-index: 895;
    width: 400px;
    max-width: calc(100vw - var(--kv-help-left, var(--sidebar-w)) - var(--sp-4));
    height: min(600px, calc(100dvh - 120px));
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}
.kv-help-panel[hidden] { display: none; }

/* Theatre: the panel widens over the page so a walkthrough is easy to follow. */
.kv-help-backdrop {
    position: fixed;
    inset: 0;
    z-index: 989;
    background: var(--modal-backdrop);
}
.kv-help-backdrop[hidden] { display: none; }
.kv-help-panel.is-theatre {
    z-index: 990;
    left: 50%;
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    width: min(1040px, calc(100vw - var(--sp-8)));
    max-width: none;
    height: min(820px, calc(100dvh - var(--sp-8)));
}

.kv-help-head {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-1);
    padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-subtle);
}
.kv-help-head-text { flex: 1; min-width: 0; }
.kv-help-head h2 { margin: 0; font-size: var(--text-md); }
.kv-help-head p { margin: 2px 0 0; font-size: var(--text-xs); color: var(--text-muted); }
.kv-help-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
}
.kv-help-icon-btn:hover { color: var(--text); background: var(--bg-input); }
.kv-help-icon-btn:focus-visible { outline: 2px solid var(--flare); outline-offset: 1px; }

.kv-help-log {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--sp-4);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}
.kv-help-log:focus-visible { outline: 2px solid var(--flare); outline-offset: -2px; }

.kv-help-intro h3 { margin: 0 0 var(--sp-1); font-size: var(--text-md); }
.kv-help-intro > p { margin: 0 0 var(--sp-3); font-size: var(--text-sm); color: var(--text-muted); }
.kv-help-intro h4 {
    margin: 0 0 var(--sp-2);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}
.kv-help-page-videos { margin-bottom: var(--sp-4); display: grid; gap: var(--sp-2); }
.kv-help-page-videos[hidden] { display: none; }
.kv-help-suggest { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.kv-help-chip {
    min-height: 36px;
    padding: var(--sp-1) var(--sp-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: var(--text-xs);
    text-align: left;
    cursor: pointer;
}
.kv-help-chip:hover { border-color: var(--flare); }
.kv-help-chip:focus-visible { outline: 2px solid var(--flare); outline-offset: 1px; }
.kv-help-all { font-size: var(--text-xs); }

.kv-help-msg {
    max-width: 92%;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.kv-help-msg-user { align-self: flex-end; background: var(--flare); color: #fff; }
.kv-help-msg-assistant { align-self: flex-start; background: var(--bg-input); }
.kv-help-msg a { color: var(--link); }
.kv-help-msg-user a { color: inherit; text-decoration: underline; }

.kv-help-resources { align-self: stretch; display: grid; gap: var(--sp-2); }
.kv-help-guide-card {
    display: block;
    padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text);
    text-decoration: none;
}
.kv-help-guide-card:hover { border-color: var(--flare); }
.kv-help-guide-card strong { display: block; font-size: var(--text-sm); }
.kv-help-guide-card span { font-size: var(--text-xs); color: var(--text-muted); }

.kv-help-video {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg);
}
.kv-help-video-play {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    padding: 0;
    border: 0;
    background: #000 center / cover no-repeat;
    cursor: pointer;
}
.kv-help-video-play::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    transition: background var(--transition-fast);
}
.kv-help-video-play:hover::after { background: rgba(0, 0, 0, 0.1); }
.kv-help-video-play:focus-visible { outline: 2px solid var(--flare); outline-offset: -2px; }
.kv-help-video-play svg {
    position: absolute;
    z-index: 1;
    left: 50%;
    top: 50%;
    width: 48px;
    height: 48px;
    transform: translate(-50%, -50%);
    padding: 12px;
    border-radius: var(--radius-full);
    background: var(--flare);
    color: #fff;
}
.kv-help-video video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.kv-help-video-meta {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--text-xs);
}
.kv-help-video-meta strong { flex: 1; min-width: 0; font-size: var(--text-sm); }
.kv-help-video-meta .kv-help-dur { color: var(--text-muted); }
.kv-help-video-meta button {
    min-height: 32px;
    padding: 0 var(--sp-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
    font-size: var(--text-xs);
    cursor: pointer;
}
.kv-help-video-meta button:hover { border-color: var(--flare); }
.kv-help-video-meta button:focus-visible { outline: 2px solid var(--flare); outline-offset: 1px; }

.kv-help-status { margin: 0; padding: 0 var(--sp-4); font-size: var(--text-xs); color: var(--text-muted); min-height: 0; }
.kv-help-status:not(:empty) { padding-bottom: var(--sp-2); }
.kv-help-composer {
    display: flex;
    align-items: flex-end;
    gap: var(--sp-2);
    padding: var(--sp-3);
    border-top: 1px solid var(--border-subtle);
}
.kv-help-composer .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.kv-help-composer textarea {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    resize: none;
    padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
}
.kv-help-composer .btn { min-width: 44px; min-height: 40px; }

/* Guide pages: walkthrough above the article body. */
.gx-walkthrough { margin: 0 0 var(--sp-6); display: grid; gap: var(--sp-3); }
.gx-walkthrough .kv-help-video { max-width: 760px; }

@media (max-width: 1024px) {
    .kv-help-launcher, .kv-help-panel:not(.is-theatre) { left: var(--kv-help-left, calc(180px + var(--sp-4))); }
}
@media (max-width: 768px) {
    .kv-help-launcher { left: var(--sp-4); bottom: var(--sp-4); }
    .kv-help-launcher-label { display: none; }
    .kv-help-launcher { width: 48px; padding: 0; justify-content: center; }
    .kv-help-panel:not(.is-theatre) {
        left: var(--sp-2);
        right: var(--sp-2);
        bottom: calc(var(--sp-4) + 48px + var(--sp-2));
        width: auto;
        max-width: none;
        height: min(600px, calc(100dvh - 96px));
    }
}
@media (prefers-reduced-motion: reduce) {
    .kv-help-launcher { transition: none; }
    .kv-help-launcher:hover { transform: none; }
}
@media print {
    .kv-help-launcher, .kv-help-panel, .kv-help-backdrop { display: none !important; }
}
