/* ==========================================================================
   Help Sidebar — SPEC.md v2.0.0
   Slides in from the right. Persists open/closed in localStorage.
   Renders as bottom drawer on screens < 768px.
   Light mode default per SPEC; dark mode via [data-theme="dark"].
   HMPM tokens: bg #FFFFFF / #0f1c32, accent #FFC000, navy #1B365D.

   Desktop fills the entire viewport (top: 0, bottom: 0, height: 100dvh).
   Mobile (< 768px) renders as a bottom drawer (height: 60dvh).

   --help-toggle-bot : bottom offset of the toggle button on mobile
   ========================================================================== */

:root {
    --help-toggle-bot: 72px;
}

/* ── Toggle button ──────────────────────────────────────────────────────── */
#helpToggle {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 95;
    width: 36px;
    height: 36px;
    border-radius: 8px 0 0 8px;
    border: none;
    background: #1B365D;
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, right 0.25s;
}
#helpToggle:hover { background: #FFC000; color: #1B365D; }
#helpToggle.open  { right: 320px; }

/* ── Sidebar panel ──────────────────────────────────────────────────────── */
#helpSidebar {
    position: fixed;
    top: 0;
    right: -320px;
    bottom: 0;
    width: 320px;
    height: 100vh;
    height: 100dvh; /* dynamic viewport for mobile */
    z-index: 150;   /* above navbar (100) so the panel truly fills the window */
    background: #FFFFFF;
    border-left: 4px solid #1B365D;
    /* Top border removed — the sidebar fills the entire viewport and the
       mark is no longer needed; the left border + shadow carry the edge. */
    border-top: 0;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
    overflow-y: auto;
    transition: right 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    scrollbar-width: thin;
}
#helpSidebar.open { right: 0; }

/* Custom thin scrollbar (WebKit) */
#helpSidebar::-webkit-scrollbar { width: 4px; }
#helpSidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 2px;
}
#helpSidebar::-webkit-scrollbar-track { background: transparent; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.help-sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px 12px;
    border-bottom: 1px solid #E7E6E6;
    position: sticky;
    top: 0;
    background: #FFFFFF;
    z-index: 1;
}
#helpSectionNr {
    font-size: 11px;
    font-weight: 600;
    color: #A5A5A5;
    flex-shrink: 0;
}
#helpSectionTitle {
    font-size: 0.95rem;
    font-weight: 600;
    color: #1B365D;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#helpPrev,
#helpNext,
#helpClose {
    background: none;
    border: none;
    color: #1B365D;
    cursor: pointer;
    border-radius: 4px;
    padding: 2px 5px;
    font-size: 14px;
    flex-shrink: 0;
    line-height: 1;
}
#helpPrev:hover:not(:disabled),
#helpNext:hover:not(:disabled),
#helpClose:hover { background: rgba(0, 0, 0, 0.06); }
#helpPrev:disabled,
#helpNext:disabled { opacity: 0.3; cursor: default; }

/* ── Body ───────────────────────────────────────────────────────────────── */
.help-sidebar-body {
    padding: 16px;
    transition: opacity 0.15s;
}
.help-sidebar-body.fading { opacity: 0; }

/* ── Purpose ────────────────────────────────────────────────────────────── */
.help-purpose {
    font-size: 13px;
    color: #44546A;
    line-height: 1.6;
    margin: 0 0 16px;
    font-style: italic;
}

/* ── Block label ────────────────────────────────────────────────────────── */
.help-block { margin-bottom: 16px; }
.help-block-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #A5A5A5;
    margin-bottom: 8px;
}

/* ── Tips ───────────────────────────────────────────────────────────────── */
.help-tips {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0;
    margin: 0;
}
.help-tip {
    font-size: 13px;
    color: #44546A;
    line-height: 1.55;
    padding: 7px 10px;
    border-left: 2px solid #FFC000;
    background: rgba(255, 192, 0, 0.07);
    border-radius: 0 4px 4px 0;
}
.help-tip.warning {
    border-left-color: #C41914;
    background: rgba(196, 25, 20, 0.06);
    color: #C41914;
}

/* ── Field hints ────────────────────────────────────────────────────────── */
.help-field-hints {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0;
    margin: 0;
}
.help-field-hint {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    background: #F5F5F5;
    border-radius: 4px;
    border-left: 2px solid #A5A5A5;
}
.help-field-name {
    font-size: 12px;
    font-weight: 700;
    color: #1B365D;
}
.help-field-text {
    font-size: 12px;
    color: #44546A;
    line-height: 1.5;
}

/* ── Mobile bottom drawer (< 768px) ─────────────────────────────────────── */
@media (max-width: 767px) {
    #helpToggle {
        top: auto;
        bottom: var(--help-toggle-bot);
        right: 12px;
        transform: none;
        border-radius: 50%;
        width: 40px;
        height: 40px;
    }
    #helpToggle.open { right: 12px; }

    #helpSidebar {
        top: auto;
        right: 0;
        bottom: -60vh;
        bottom: -60dvh;
        left: 0;
        width: 100%;
        height: 60dvh;
        max-height: 60dvh;
        border-left: none;
        border-top: 4px solid #FFC000;
        border-radius: 16px 16px 0 0;
        z-index: 150;
        transition: bottom 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }
    #helpSidebar.open { bottom: 0; }
}

/* ── Dark mode (project default — translucent surface, soft gold accent) ── */
/* Frosted-glass layer over the pure-black page. White-overlay alpha is
   raised vs. the page's --color-surface wash so the panel reads as a
   distinct surface, while backdrop-filter keeps content behind softly
   diffused. Borders and shadow carry the edge. */
[data-theme="dark"] #helpSidebar {
    background: rgba(255, 255, 255, 0.10);
    border-left-color: rgba(212, 180, 131, 0.5);
    /* Stronger shadow + frost compensate for the translucent surface */
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
[data-theme="dark"] #helpSidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
}
[data-theme="dark"] .help-sidebar-header {
    background: rgba(255, 255, 255, 0.10);
    border-bottom-color: rgba(255, 255, 255, 0.12);
}
[data-theme="dark"] #helpSectionTitle { color: #D4B483; }
[data-theme="dark"] .help-purpose     { color: rgba(255, 255, 255, 0.6); }
[data-theme="dark"] .help-tip {
    color: rgba(255, 255, 255, 0.75);
    background: rgba(212, 180, 131, 0.08);
    border-left-color: #D4B483;
}
[data-theme="dark"] .help-tip.warning {
    color: #FF5D5D;
    background: rgba(255, 93, 93, 0.08);
    border-left-color: #FF5D5D;
}
[data-theme="dark"] .help-field-hint {
    background: rgba(255, 255, 255, 0.05);
    border-left-color: rgba(255, 255, 255, 0.2);
}
[data-theme="dark"] .help-field-name { color: #D4B483; }
[data-theme="dark"] .help-field-text { color: rgba(255, 255, 255, 0.6); }
[data-theme="dark"] #helpPrev,
[data-theme="dark"] #helpNext,
[data-theme="dark"] #helpClose { color: rgba(255, 255, 255, 0.7); }
[data-theme="dark"] #helpPrev:hover:not(:disabled),
[data-theme="dark"] #helpNext:hover:not(:disabled),
[data-theme="dark"] #helpClose:hover { background: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] #helpToggle {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.85);
}
[data-theme="dark"] #helpToggle:hover {
    background: #D4B483;
    color: #0B1220;
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    #helpToggle,
    #helpSidebar,
    .help-sidebar-body {
        transition: none;
    }
}
