/* ================================================================
   Help Buddy Widget — Floating Feedback & Issue Tracker
   Self-contained styles with fallbacks for all CSS custom properties.
   Works with or without brand.css loaded.
   ================================================================ */

/* ============================================================
   FLOATING TRIGGER BUTTON
   ============================================================ */
.help-buddy-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--gwk-z-toast, 1060);
    width: 64px;
    height: 72px;
    border: none;
    background: none;
    cursor: pointer;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.25));
    transition: transform 0.2s ease, filter 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.help-buddy-trigger:hover {
    transform: scale(1.08);
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.3));
}

.help-buddy-trigger:active {
    transform: scale(0.96);
}

.help-buddy-trigger:focus-visible {
    outline: 3px solid var(--gwk-focus-ring, #E8A82E);
    outline-offset: 3px;
    border-radius: var(--gwk-radius-lg, 8px);
}

/* The badge SVG fills the button */
.help-buddy-trigger .badge-icon {
    width: 100%;
    height: 100%;
}

/* X close icon (shown when panel is open) */
.help-buddy-trigger .icon-close {
    width: 28px;
    height: 28px;
}

/* Toggle open/close icons */
.help-buddy-trigger.open .icon-open {
    display: none;
}

.help-buddy-trigger:not(.open) .icon-close {
    display: none;
}

/* When open, show X in a small green circle */
.help-buddy-trigger.open {
    width: 52px;
    height: 52px;
    background: var(--gwk-green-50, #F3F7F0);
    border-radius: var(--gwk-radius-full, 9999px);
    border: 2px solid var(--gwk-green-200, #C5E3B8);
}

/* ============================================================
   "NEED HELP?" LABEL
   ============================================================ */
.help-buddy-label {
    position: fixed;
    bottom: 34px;
    right: 92px;
    z-index: var(--gwk-z-toast, 1060);
    background: var(--gwk-card, #FFFFFF);
    color: var(--gwk-text-heading, #3F5F2A);
    font-size: var(--gwk-font-sm, 0.875rem);
    font-weight: var(--gwk-weight-semibold, 600);
    padding: 0.45rem 0.85rem;
    border-radius: var(--gwk-radius-md, 6px);
    box-shadow: var(--gwk-shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06));
    white-space: nowrap;
    pointer-events: none;
    animation: hb-nudge-label 3s ease-in-out 2s 3;
    transition: opacity 0.2s ease;
}

/* Small triangle pointing right toward the button */
.help-buddy-label::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -6px;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right: none;
    border-left-color: var(--gwk-card, #FFFFFF);
}

/* Hide the label once the widget is opened */
.help-buddy-trigger.open ~ .help-buddy-label,
.help-buddy-label.dismissed {
    opacity: 0;
    pointer-events: none;
}

@keyframes hb-nudge-label {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    50% { transform: translateX(2px); }
    75% { transform: translateX(-2px); }
}

/* ============================================================
   NOTIFICATION DOT
   ============================================================ */
.help-buddy-trigger .dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    background: var(--gwk-accent, #D49027);
    border-radius: var(--gwk-radius-full, 9999px);
    border: 2px solid white;
    animation: hb-pulse-dot 2s infinite;
}

.help-buddy-trigger.open .dot {
    display: none;
}

@keyframes hb-pulse-dot {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ============================================================
   PANEL (expanded widget)
   ============================================================ */
.help-buddy-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: var(--gwk-z-toast, 1060);
    width: 380px;
    max-height: 540px;
    background: var(--gwk-card, #FFFFFF);
    border-radius: var(--gwk-radius-xl, 12px);
    box-shadow: var(--gwk-shadow-xl, 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
    transform-origin: bottom right;
}

.help-buddy-panel.visible {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Panel header */
.hb-header {
    background: var(--gwk-primary, #3F5F2A);
    color: white;
    padding: 1.25rem 1.5rem;
}

.hb-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.hb-header h2 {
    font-size: var(--gwk-font-lg, 1.125rem);
    font-weight: var(--gwk-weight-semibold, 600);
    margin: 0 0 0.25rem;
    color: white;
}

.hb-header p {
    font-size: var(--gwk-font-sm, 0.875rem);
    opacity: 0.85;
    margin: 0;
    color: white;
}

.hb-close-btn {
    background: none;
    border: none;
    color: white;
    opacity: 0.7;
    cursor: pointer;
    padding: 4px;
    line-height: 0;
    border-radius: var(--gwk-radius-md, 6px);
    transition: opacity 0.15s ease;
}

.hb-close-btn:hover {
    opacity: 1;
}

.hb-close-btn:focus-visible {
    outline: 2px solid var(--gwk-focus-ring, #E8A82E);
    outline-offset: 2px;
}

/* Panel body */
.hb-body {
    padding: 1.25rem 1.5rem;
    flex: 1;
    overflow-y: auto;
    background: var(--gwk-card, #FFFFFF);
}

/* ============================================================
   HOME VIEW (category menu)
   ============================================================ */
.hb-home-view.hidden {
    display: none;
}

.hb-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--gwk-radius-lg, 8px);
    border: 1px solid var(--gwk-border, #E5E7EB);
    background: var(--gwk-card, #FFFFFF);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    text-align: left;
    font-family: inherit;
    font-size: var(--gwk-font-md, 1rem);
    color: var(--gwk-text-body, #374151);
}

.hb-menu-item:hover {
    border-color: var(--gwk-green-200, #C5E3B8);
    box-shadow: var(--gwk-shadow-sm, 0 1px 2px 0 rgba(0, 0, 0, 0.05));
}

.hb-menu-item:focus-visible {
    outline: 2px solid var(--gwk-focus-ring, #E8A82E);
    outline-offset: 2px;
}

.hb-menu-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--gwk-radius-md, 6px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.hb-menu-item[data-category="bug"] .hb-menu-icon,
.hb-menu-item[data-category="question"] .hb-menu-icon {
    background: var(--gwk-green-100, #E8F5E1);
}

.hb-menu-item[data-category="idea"] .hb-menu-icon,
.hb-menu-item[data-category="general"] .hb-menu-icon {
    background: var(--gwk-gold-100, #FFF4E6);
}

.hb-menu-text strong {
    display: block;
    color: var(--gwk-text-heading, #3F5F2A);
    font-size: var(--gwk-font-sm, 0.875rem);
    font-weight: var(--gwk-weight-semibold, 600);
}

.hb-menu-text span {
    color: var(--gwk-text-muted, #4B5563);
    font-size: var(--gwk-font-xs, 0.75rem);
}

/* ============================================================
   TICKET FORM VIEW
   ============================================================ */
.hb-form-view {
    display: none;
}

.hb-form-view.active {
    display: block;
}

.hb-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: none;
    color: var(--gwk-text-muted, #4B5563);
    font-size: var(--gwk-font-sm, 0.875rem);
    cursor: pointer;
    padding: 0;
    margin-bottom: 1rem;
    font-family: inherit;
}

.hb-back-btn:hover {
    color: var(--gwk-text-heading, #3F5F2A);
}

/* Form fields */
.hb-form-group {
    margin-bottom: 1rem;
}

.hb-form-group label {
    display: block;
    font-size: var(--gwk-font-sm, 0.875rem);
    font-weight: var(--gwk-weight-medium, 500);
    color: var(--gwk-text-heading, #3F5F2A);
    margin-bottom: 0.35rem;
}

.hb-form-group label .optional {
    color: var(--gwk-text-muted, #4B5563);
    font-weight: var(--gwk-weight-regular, 400);
}

.hb-input,
.hb-textarea,
.hb-select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--gwk-border, #E5E7EB);
    border-radius: var(--gwk-radius-md, 6px);
    font-family: inherit;
    font-size: var(--gwk-font-sm, 0.875rem);
    color: var(--gwk-text-body, #374151);
    background: var(--gwk-card, #FFFFFF);
    transition: border-color 0.15s ease;
}

.hb-input:focus,
.hb-textarea:focus,
.hb-select:focus {
    outline: none;
    border-color: var(--gwk-primary, #3F5F2A);
    box-shadow: 0 0 0 3px rgba(63, 95, 42, 0.12);
}

.hb-textarea {
    min-height: 80px;
    resize: vertical;
}

/* Validation error states */
.hb-form-group.has-error .hb-input,
.hb-form-group.has-error .hb-textarea,
.hb-form-group.has-error .hb-select {
    border-color: var(--gwk-error, #DC2626);
}

.hb-form-group.has-error .hb-input:focus,
.hb-form-group.has-error .hb-textarea:focus,
.hb-form-group.has-error .hb-select:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.hb-error-message {
    display: none;
    color: var(--gwk-error, #DC2626);
    font-size: var(--gwk-font-xs, 0.75rem);
    margin-top: 0.25rem;
}

.hb-form-group.has-error .hb-error-message {
    display: block;
}

/* Submission error banner */
.hb-submit-error {
    display: none;
    padding: 0.65rem 0.85rem;
    background: #FEF2F2;
    border: 1px solid var(--gwk-error, #DC2626);
    border-radius: var(--gwk-radius-md, 6px);
    color: var(--gwk-error, #DC2626);
    font-size: var(--gwk-font-sm, 0.875rem);
    margin-bottom: 1rem;
}

.hb-submit-error.visible {
    display: block;
}

/* Rate-limit notice */
.hb-rate-limit {
    display: none;
    padding: 0.65rem 0.85rem;
    background: var(--gwk-gold-50, #FFF9F0);
    border: 1px solid var(--gwk-gold-400, #E8A82E);
    border-radius: var(--gwk-radius-md, 6px);
    color: var(--gwk-text-body, #374151);
    font-size: var(--gwk-font-sm, 0.875rem);
    margin-bottom: 1rem;
}

.hb-rate-limit.visible {
    display: block;
}

/* Screenshot capture button */
.hb-screenshot-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    border: 1px dashed var(--gwk-border, #E5E7EB);
    border-radius: var(--gwk-radius-md, 6px);
    background: var(--gwk-gray-50, #F9FAFB);
    color: var(--gwk-text-muted, #4B5563);
    font-size: var(--gwk-font-sm, 0.875rem);
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
    width: 100%;
    justify-content: center;
}

.hb-screenshot-btn:hover {
    border-color: var(--gwk-primary, #3F5F2A);
    background: var(--gwk-green-50, #F3F7F0);
    color: var(--gwk-primary, #3F5F2A);
}

.hb-screenshot-btn.captured {
    border-style: solid;
    border-color: var(--gwk-success, #3F5F2A);
    background: var(--gwk-green-50, #F3F7F0);
    color: var(--gwk-success, #3F5F2A);
}

.hb-screenshot-btn.capturing {
    pointer-events: none;
    opacity: 0.7;
}

.hb-screenshot-preview {
    margin-top: 0.5rem;
    border-radius: var(--gwk-radius-md, 6px);
    overflow: hidden;
    display: none;
}

.hb-screenshot-preview.has-image {
    display: block;
}

.hb-screenshot-preview img {
    width: 100%;
    border: 1px solid var(--gwk-border, #E5E7EB);
    border-radius: var(--gwk-radius-md, 6px);
}

/* Context auto-captured badge */
.hb-auto-context {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--gwk-green-50, #F3F7F0);
    border-radius: var(--gwk-radius-md, 6px);
    font-size: var(--gwk-font-xs, 0.75rem);
    color: var(--gwk-text-muted, #4B5563);
    margin-bottom: 1rem;
}

.hb-auto-context svg {
    flex-shrink: 0;
}

/* Submit button */
.hb-submit-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--gwk-primary, #3F5F2A);
    color: white;
    border: none;
    border-radius: var(--gwk-radius-md, 6px);
    font-family: inherit;
    font-size: var(--gwk-font-md, 1rem);
    font-weight: var(--gwk-weight-semibold, 600);
    cursor: pointer;
    transition: background 0.2s ease;
}

.hb-submit-btn:hover {
    background: var(--gwk-hover-primary, #2E4020);
}

.hb-submit-btn:active {
    background: var(--gwk-active-primary, #263318);
}

.hb-submit-btn:focus-visible {
    outline: 3px solid var(--gwk-focus-ring, #E8A82E);
    outline-offset: 2px;
}

.hb-submit-btn:disabled {
    background: var(--gwk-gray-400, #9CA3AF);
    cursor: not-allowed;
}

/* ============================================================
   SUCCESS VIEW
   ============================================================ */
.hb-success-view {
    display: none;
    text-align: center;
    padding: 2rem 1rem;
}

.hb-success-view.active {
    display: block;
}

.hb-success-icon {
    width: 56px;
    height: 56px;
    background: var(--gwk-green-100, #E8F5E1);
    color: var(--gwk-primary, #3F5F2A);
    border-radius: var(--gwk-radius-full, 9999px);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 1.5rem;
}

.hb-success-view h3 {
    color: var(--gwk-text-heading, #3F5F2A);
    margin-bottom: 0.5rem;
}

.hb-success-view p {
    color: var(--gwk-text-muted, #4B5563);
    font-size: var(--gwk-font-sm, 0.875rem);
    line-height: var(--gwk-line-relaxed, 1.6);
    margin-bottom: 1.5rem;
}

.hb-success-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.hb-done-btn {
    background: var(--gwk-primary, #3F5F2A);
    color: white;
    border: none;
    padding: 0.55rem 1.25rem;
    border-radius: var(--gwk-radius-md, 6px);
    font-family: inherit;
    font-size: var(--gwk-font-sm, 0.875rem);
    font-weight: var(--gwk-weight-semibold, 600);
    cursor: pointer;
    transition: background 0.15s ease;
}

.hb-done-btn:hover {
    background: var(--gwk-hover-primary, #2E4020);
}

.hb-new-ticket-btn {
    background: none;
    border: 1px solid var(--gwk-border, #E5E7EB);
    color: var(--gwk-text-body, #374151);
    padding: 0.55rem 1.25rem;
    border-radius: var(--gwk-radius-md, 6px);
    font-family: inherit;
    font-size: var(--gwk-font-sm, 0.875rem);
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.hb-new-ticket-btn:hover {
    border-color: var(--gwk-primary, #3F5F2A);
    color: var(--gwk-primary, #3F5F2A);
}

/* ============================================================
   PANEL FOOTER
   ============================================================ */
.hb-footer {
    padding: 0.65rem 1.5rem;
    border-top: 1px solid var(--gwk-border, #E5E7EB);
    text-align: center;
    background: var(--gwk-card, #FFFFFF);
}

.hb-footer span {
    font-size: var(--gwk-font-xs, 0.75rem);
    color: var(--gwk-text-disabled, #9CA3AF);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 480px) {
    .help-buddy-panel {
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 85vh;
        border-radius: var(--gwk-radius-xl, 12px) var(--gwk-radius-xl, 12px) 0 0;
        transform: translateY(100%);
        transform-origin: bottom center;
    }

    .help-buddy-panel.visible {
        transform: translateY(0);
    }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .help-buddy-trigger,
    .help-buddy-panel,
    .help-buddy-label {
        transition: none;
    }

    .help-buddy-label {
        animation: none;
    }

    .help-buddy-trigger .dot {
        animation: none;
    }
}
