/* Embedded harness chat widget — scoped under .hw-root (no global leakage). */
.hw-root {
    --hw-accent: #00f3ff;
    --hw-accent-soft: rgba(0, 243, 255, 0.14);
    --hw-bg: rgba(10, 14, 22, 0.96);
    --hw-bg-panel: rgba(13, 18, 28, 0.98);
    --hw-border: rgba(255, 255, 255, 0.12);
    --hw-text: #e6edf3;
    --hw-text-muted: #8b98a9;
    --hw-user-bubble: rgba(0, 243, 255, 0.12);
    --hw-font: "Inter", system-ui, -apple-system, sans-serif;
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 9000;
    font-family: var(--hw-font);
    color-scheme: dark;
}

.hw-root, .hw-root * { box-sizing: border-box; }

/* ── launcher button ── */
.hw-launcher {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--hw-accent) 60%, transparent);
    background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.12), transparent 60%),
                var(--hw-accent-soft);
    color: var(--hw-accent);
    cursor: pointer;
    display: grid;
    place-items: center;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    animation: hw-pulse 2.6s ease-in-out infinite;
}
.hw-launcher:hover { transform: translateY(-2px) scale(1.04); }
.hw-launcher.hw-open { display: none; }

@keyframes hw-pulse {
    0%, 100% { box-shadow: 0 8px 28px rgba(0,0,0,0.45), 0 0 0 0 color-mix(in srgb, var(--hw-accent) 45%, transparent); }
    50%      { box-shadow: 0 8px 28px rgba(0,0,0,0.45), 0 0 0 10px transparent; }
}

/* ── panel ── */
.hw-panel {
    display: none;
    flex-direction: column;
    width: min(390px, calc(100vw - 32px));
    height: min(600px, calc(100vh - 110px));
    background: var(--hw-bg-panel);
    border: 1px solid var(--hw-border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(18px);
}
.hw-root.hw-active .hw-panel { display: flex; }

.hw-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--hw-accent) 16%, transparent),
        transparent 70%);
    border-bottom: 1px solid var(--hw-border);
}
.hw-title { font-weight: 700; font-size: 0.98rem; color: var(--hw-text); letter-spacing: 0.2px; }
.hw-badge-admin {
    display: inline-block;
    vertical-align: middle;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: #04121a;
    background: var(--hw-accent);
}
.hw-badge-admin[hidden] { display: none; }
.hw-subtitle { font-size: 0.74rem; color: var(--hw-text-muted); margin-top: 2px; }

.hw-header-actions { display: flex; gap: 6px; }
.hw-icon-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--hw-text-muted);
    border-radius: 8px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.hw-icon-btn:hover {
    color: var(--hw-text);
    background: rgba(255, 255, 255, 0.07);
    border-color: var(--hw-border);
}

/* ── messages ── */
.hw-messages {
    position: relative;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.hw-msg {
    max-width: 88%;
    padding: 10px 13px;
    border-radius: 13px;
    font-size: 0.88rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.hw-msg.hw-user {
    align-self: flex-end;
    background: var(--hw-user-bubble);
    border: 1px solid color-mix(in srgb, var(--hw-accent) 35%, transparent);
    color: var(--hw-text);
    border-bottom-right-radius: 4px;
}
.hw-msg.hw-assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.055);
    border: 1px solid var(--hw-border);
    color: var(--hw-text);
    border-bottom-left-radius: 4px;
}
.hw-msg.hw-assistant p { margin: 0 0 8px; }
.hw-msg.hw-assistant p:last-child { margin-bottom: 0; }
.hw-msg.hw-assistant ul, .hw-msg.hw-assistant ol { margin: 6px 0; padding-left: 20px; }
.hw-msg.hw-assistant code {
    background: rgba(255, 255, 255, 0.09);
    border-radius: 5px;
    padding: 1px 5px;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.82em;
}
.hw-msg.hw-error {
    align-self: flex-start;
    background: rgba(220, 53, 69, 0.12);
    border: 1px solid rgba(220, 53, 69, 0.4);
    color: #ffb3b3;
}

/* typing indicator */
.hw-typing { display: inline-flex; gap: 5px; align-items: center; padding: 4px 2px; }
.hw-typing i {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--hw-accent);
    opacity: 0.4;
    animation: hw-blink 1.2s infinite;
}
.hw-typing i:nth-child(2) { animation-delay: 0.2s; }
.hw-typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes hw-blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* live progress line under the typing dots */
.hw-status {
    display: block;
    margin-top: 6px;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.72rem;
    color: var(--hw-text-muted);
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* ── composer ── */
.hw-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 14px 0;
}
.hw-attachments[hidden] { display: none; }
.hw-attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.74rem;
    color: var(--hw-text);
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--hw-border);
    border-radius: 20px;
    padding: 4px 10px;
    cursor: pointer;
}
.hw-attach-chip:hover { border-color: var(--hw-accent); }
.hw-attach {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
}
.hw-file { display: none; }

.hw-composer {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--hw-border);
    background: rgba(0, 0, 0, 0.25);
}
.hw-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--hw-border);
    border-radius: 10px;
    color: var(--hw-text);
    padding: 10px 12px;
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.hw-input::placeholder { color: var(--hw-text-muted); }
.hw-input:focus { border-color: color-mix(in srgb, var(--hw-accent) 70%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hw-accent) 18%, transparent); }
.hw-send {
    background: var(--hw-accent);
    border: none;
    color: #04121a;
    font-weight: 700;
    font-size: 0.84rem;
    padding: 0 18px;
    border-radius: 10px;
    cursor: pointer;
    transition: filter 0.12s ease, transform 0.12s ease;
}
.hw-send:hover { filter: brightness(1.12); }
.hw-send:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.hw-footer {
    padding: 7px 0;
    text-align: center;
    font-size: 0.68rem;
    color: var(--hw-text-muted);
    border-top: 1px solid var(--hw-border);
    letter-spacing: 0.4px;
}

/* ── past conversations panel ── */
.hw-threads-panel {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    background: var(--hw-bg-panel);
}
.hw-threads-panel[hidden] { display: none; }
.hw-threads-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--hw-text-muted);
    border-bottom: 1px solid var(--hw-border);
}
.hw-threads-head .hw-threads-back { width: 26px; height: 26px; flex: 0 0 auto; }
.hw-threads-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.hw-thread-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 9px 11px;
    cursor: pointer;
    color: var(--hw-text);
    font-family: inherit;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.hw-thread-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--hw-border);
}
.hw-thread-title {
    font-size: 0.84rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hw-thread-meta {
    font-size: 0.7rem;
    color: var(--hw-text-muted);
    font-family: "JetBrains Mono", monospace;
}
.hw-thread-item.hw-thread-admin .hw-thread-meta { color: var(--hw-accent); }
.hw-threads-empty {
    padding: 24px 16px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--hw-text-muted);
}
.hw-threads-empty[hidden] { display: none; }

/* ── small screens ── */
@media (max-width: 480px) {
    .hw-root { right: 14px; bottom: 14px; }
    .hw-panel { width: calc(100vw - 28px); height: calc(100vh - 100px); }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
    .hw-launcher { animation: none; }
    .hw-typing i { animation: none; opacity: 0.6; }
}
