/* ======================================================
   Agent Panel — FuncGen Design Agent sidebar
   Uses existing CSS variables from styles.css / theme-mist.css
   ====================================================== */
:root {
    --sidebar-width: clamp(340px, 28vw, 500px);
}

/* --------------------------------------------------
   A. Toggle Button (in header nav-right)
   -------------------------------------------------- */
.agent-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}
.agent-toggle-btn:hover {
    background: var(--hover);
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 12%, transparent);
}
.agent-toggle-btn.active {
    background: color-mix(in srgb, var(--primary) 10%, white);
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 16%, transparent);
}
.agent-toggle-btn svg {
    flex-shrink: 0;
}

/* --------------------------------------------------
   B. Panel Container
   -------------------------------------------------- */
.agent-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 20;
    background: var(--card);
    border-left: 1px solid var(--line);
    box-shadow: -4px 0 24px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}
.agent-panel.agent-panel--open {
    transform: translateX(0);
}

/* Backdrop (mobile overlay) */
.agent-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 19;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    pointer-events: none;
}
.agent-backdrop.agent-backdrop--visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* --------------------------------------------------
   C. Panel Header
   -------------------------------------------------- */
.agent-header {
    height: 52px;
    min-height: 52px;
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card);
}
.agent-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}
.agent-header-icon {
    color: var(--primary);
    flex-shrink: 0;
}
.agent-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.agent-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
    transition: background 0.3s ease;
}
.agent-status-dot.thinking {
    background: #f59e0b;
    animation: agent-dot-pulse 1.2s ease-in-out infinite;
}
.agent-status-dot.streaming {
    background: var(--primary);
    animation: agent-dot-pulse 1s ease-in-out infinite;
}
.agent-status-dot.error {
    background: #ef4444;
}
.agent-status-dot.awaiting-action {
    background: #f59e0b;
}

@keyframes agent-dot-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.agent-header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}
.agent-header-btn {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s ease;
}
.agent-header-btn:hover {
    background: var(--hover);
    color: var(--text);
}

/* --------------------------------------------------
   D. Thread Area
   -------------------------------------------------- */
.agent-thread {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Thin scrollbar */
.agent-thread::-webkit-scrollbar { width: 5px; }
.agent-thread::-webkit-scrollbar-track { background: transparent; }
.agent-thread::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 10px;
}
.agent-thread::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

/* --------------------------------------------------
   E. Empty State
   -------------------------------------------------- */
.agent-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    padding: 24px 16px;
    min-height: 200px;
}
.agent-empty-icon {
    margin-bottom: 16px;
}
.agent-empty-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 6px 0;
}
.agent-empty-hint {
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 20px 0;
    line-height: 1.5;
    max-width: 300px;
}
.agent-prompts {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    max-width: 320px;
}
.agent-prompt-chip {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 12.5px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.12s ease;
    font-family: inherit;
    line-height: 1.4;
}
.agent-prompt-chip:hover {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 5%, white);
    color: var(--primary);
}

/* --------------------------------------------------
   F. Message Base
   -------------------------------------------------- */
.agent-msg {
    animation: agent-msg-in 0.2s ease-out;
    max-width: 100%;
}
@keyframes agent-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* F.1  User message */
.agent-msg--user {
    align-self: flex-end;
    background: color-mix(in srgb, var(--primary) 10%, white);
    border: 1px solid color-mix(in srgb, var(--primary) 16%, var(--line));
    border-radius: 12px 12px 4px 12px;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    max-width: 88%;
    word-break: break-word;
}

/* F.2  Assistant message */
.agent-msg--assistant {
    padding: 6px 2px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
}
.agent-msg--assistant p {
    margin: 0 0 6px 0;
}
.agent-msg--assistant p:last-child {
    margin-bottom: 0;
}
.agent-msg--assistant strong {
    font-weight: 600;
}
.agent-msg--assistant code {
    background: var(--pill);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 12px;
}

/* F.3  Plan update */
.agent-msg--plan {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius2);
    padding: 10px 12px;
    font-size: 12.5px;
}
.agent-plan-title {
    font-weight: 600;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
}
.agent-plan-steps {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.agent-plan-step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--text);
    line-height: 1.4;
}
.agent-plan-check {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1.5px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    color: transparent;
    transition: all 0.15s ease;
}
.agent-plan-check.done {
    background: #22c55e;
    border-color: #22c55e;
    color: white;
}
.agent-plan-step.pending {
    color: var(--muted);
}

/* F.4  Proposed Job Card — waiting for user to review & submit */
.agent-msg--proposed-job {
    background: var(--card);
    border: 1px solid #fde68a;
    border-left: 3px solid #f59e0b;
    border-radius: var(--radius2);
    padding: 0;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}
.agent-job-action-banner {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #fffbeb;
    border-bottom: 1px solid #fde68a;
    border-radius: var(--radius2) var(--radius2) 0 0;
    font-size: 11px;
    font-weight: 600;
    color: #92400e;
    letter-spacing: 0.3px;
}
.agent-job-body {
    padding: 12px;
}
/* Submitted state — card dims, border turns green */
.agent-msg--proposed-job.submitted {
    border-color: var(--line);
    border-left-color: #22c55e;
    opacity: 0.7;
    pointer-events: none;
}
.agent-msg--proposed-job.submitted .agent-job-action-banner {
    background: #f0fdf4;
    border-bottom-color: #bbf7d0;
    color: #166534;
}
.agent-job-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.agent-job-mode-pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: color-mix(in srgb, var(--primary) 10%, white);
    color: var(--primary);
    border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--line));
}
.agent-job-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}
.agent-job-fields {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}
.agent-job-field {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 12px;
    line-height: 1.5;
}
.agent-job-field-key {
    color: var(--muted);
    white-space: nowrap;
    min-width: 70px;
}
.agent-job-field-val {
    color: var(--text);
    font-family: var(--mono);
    font-size: 11.5px;
    word-break: break-all;
}
.agent-job-actions {
    display: flex;
    gap: 8px;
    margin-top: 2px;
}
.agent-job-actions .btn {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 8px;
}
.agent-job-actions .btn.agent-submit-btn {
    font-size: 13px;
    padding: 8px 20px;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(59, 130, 246, 0.3);
    animation: agent-submit-nudge 0.8s ease-in-out 2s 6;
}
@keyframes agent-submit-nudge {
    0%, 100% {
        box-shadow: 0 1px 4px rgba(59, 130, 246, 0.3);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 2px 16px rgba(59, 130, 246, 0.7);
        transform: scale(1.06);
    }
}

/* F.4c  Motifs structured display */
.agent-job-field--block {
    flex-direction: column;
    gap: 4px;
}
.agent-job-field--block .agent-job-field-key {
    min-width: auto;
}
.agent-motifs-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.agent-motif-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 11px;
    line-height: 1.4;
}
.agent-motif-range {
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
}
.agent-motif-seq {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--primary);
    background: none;
    padding: 0;
}

/* F.4d  Job JSON Preview (inside proposed job card) */
.agent-job-json-preview {
    margin: 8px 0 4px;
    border-top: 1px solid var(--line);
    padding-top: 8px;
}
.agent-job-json-toggle {
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
    user-select: none;
}
.agent-job-json-toggle::-webkit-details-marker { display: none; }
.agent-job-json-toggle::before {
    content: '\25B8';
    font-size: 10px;
    transition: transform 0.15s ease;
    display: inline-block;
}
details.agent-job-json-preview[open] .agent-job-json-toggle::before {
    transform: rotate(90deg);
}
.agent-job-json-body {
    margin: 6px 0 0;
    padding: 8px;
    background: var(--bg);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1.5;
    color: var(--text);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
}

/* -- Draft Progress — Invalid variant -- */
.agent-msg--draft-invalid {
    border: 1px dashed #dc3545;
    background: #fff5f5;
    opacity: 1;
}
.agent-msg--draft-invalid .agent-draft-label {
    color: #dc3545;
}
.agent-draft-error-icon {
    color: #dc3545;
    font-weight: bold;
    font-size: 11px;
}

/* F.4b  Draft Progress Card */
.agent-msg--draft-progress {
    background: var(--bg);
    border: 1px dashed color-mix(in srgb, var(--primary) 30%, var(--line));
    border-radius: var(--radius2);
    padding: 10px 12px;
    opacity: 0.92;
}
.agent-draft-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.agent-draft-mode-pill {
    background: color-mix(in srgb, var(--primary) 6%, white);
    color: var(--muted);
    border-color: var(--line);
}
.agent-draft-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}
.agent-draft-status {
    font-size: 11.5px;
    color: var(--muted);
    margin-bottom: 8px;
    font-style: italic;
}
.agent-draft-fields {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.agent-draft-field {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 12px;
    line-height: 1.5;
}
.agent-draft-field-icon {
    width: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
}
.agent-draft-field-icon.resolved {
    color: #22c55e;
}
.agent-draft-field-icon.pending {
    color: var(--muted);
}
.agent-draft-spinner {
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 1.5px solid color-mix(in srgb, var(--primary) 25%, transparent);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: agent-spin 0.8s linear infinite;
}
.agent-draft-field-key {
    color: var(--muted);
    white-space: nowrap;
    min-width: 70px;
    font-weight: 500;
}
.agent-draft-field-val {
    color: var(--text);
    font-family: var(--mono);
    font-size: 11.5px;
    word-break: break-all;
}
.agent-draft-field-val.pending {
    color: var(--muted);
    font-style: italic;
    font-family: inherit;
}

/* Draft field — running state (tool actively executing) */
.agent-draft-field--running .agent-draft-field-icon {
    color: var(--primary);
}
.agent-draft-field--running .agent-draft-field-val {
    color: var(--primary);
    font-style: italic;
    font-family: inherit;
}
.agent-draft-field-icon.running {
    color: var(--primary);
}

/* Draft field — failed state */
.agent-draft-field--failed .agent-draft-field-icon {
    color: #ef4444;
}
.agent-draft-field--failed .agent-draft-field-val {
    color: #ef4444;
    font-style: normal;
}
.agent-draft-field-icon.failed {
    color: #ef4444;
}
.agent-draft-field-val.failed {
    color: #ef4444;
    font-style: normal;
    font-family: inherit;
}
.agent-draft-field-val.running {
    color: var(--primary);
    font-style: italic;
    font-family: inherit;
}

/* Draft footer status bar */
.agent-draft-footer {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--line);
    font-size: 11px;
    color: var(--muted);
    font-style: italic;
    transition: color 0.2s ease;
}
.agent-draft-footer--active {
    color: var(--primary);
    font-weight: 500;
}
.agent-draft-footer--complete {
    color: #22c55e;
    font-style: normal;
    font-weight: 500;
}
.agent-draft-footer--error {
    color: #ef4444;
}
.agent-draft-footer--stale {
    color: #f59e0b;
}

/* F.5  Confirmation Request */
.agent-msg--confirmation {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius2);
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.5;
    color: #92400e;
}
.agent-confirm-text {
    margin-bottom: 10px;
}
.agent-confirm-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.agent-confirm-actions .btn {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 8px;
}
.agent-confirm-actions .btn.ghost {
    background: transparent;
    border-color: transparent;
    color: var(--muted);
}
.agent-confirm-actions .btn.ghost:hover {
    background: var(--hover);
    color: var(--text);
}

/* F.6  Tool Event */
.agent-msg--tool-event {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    font-size: 11.5px;
    font-family: var(--mono);
    color: var(--muted);
}
.agent-tool-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
}
.agent-tool-icon.success { color: #22c55e; }
.agent-tool-icon.running { color: var(--primary); animation: agent-spin 1s linear infinite; }
.agent-tool-icon.error   { color: #ef4444; }
.agent-tool-name { color: var(--text-secondary, #cbd5e1); }
.agent-tool-detail { color: var(--muted); }

@keyframes agent-spin {
    to { transform: rotate(360deg); }
}

/* F.7  Job Status (Timeline Stepper) */
.agent-msg--job-status {
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius2);
}
.agent-timeline-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
}
.agent-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding-left: 8px;
}
.agent-timeline-step {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    position: relative;
    padding-bottom: 12px;
}
.agent-timeline-step:last-child {
    padding-bottom: 0;
}
/* Connecting line */
.agent-timeline-step:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 16px;
    bottom: 0;
    width: 1.5px;
    background: var(--line);
}
.agent-timeline-step.completed:not(:last-child)::before {
    background: #22c55e;
}
.agent-timeline-dot {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 2px solid var(--line);
    background: var(--card);
    flex-shrink: 0;
    margin-top: 1px;
    position: relative;
    z-index: 1;
    transition: all 0.2s ease;
}
.agent-timeline-step.completed .agent-timeline-dot {
    background: #22c55e;
    border-color: #22c55e;
}
.agent-timeline-step.running .agent-timeline-dot {
    background: var(--primary);
    border-color: var(--primary);
    animation: agent-running-pulse 1.2s ease-in-out infinite;
}
.agent-timeline-step.running .agent-timeline-label {
    color: var(--primary);
    font-weight: 600;
}
@keyframes agent-running-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); }
    50% { box-shadow: 0 0 0 5px rgba(59, 130, 246, 0); }
}
.agent-timeline-step.failed .agent-timeline-dot {
    background: #ef4444;
    border-color: #ef4444;
}
.agent-timeline-label {
    font-size: 12.5px;
    color: var(--text);
    line-height: 1.3;
}
.agent-timeline-step.pending .agent-timeline-label {
    color: var(--muted);
}
.agent-timeline-time {
    font-size: 11px;
    color: var(--muted);
    margin-left: auto;
    white-space: nowrap;
}

/* F.8  Result Summary */
.agent-msg--result-summary {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius2);
    padding: 12px;
}
.agent-result-title {
    font-size: 13px;
    font-weight: 600;
    color: #166534;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.agent-result-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.agent-result-stat {
    font-size: 12px;
    color: #166534;
}
.agent-result-stat strong {
    font-weight: 600;
}
.agent-result-next {
    margin-top: 8px;
}
.agent-result-next-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 6px;
}
.agent-result-next-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.agent-result-next-item {
    font-size: 12px;
    color: #166534;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.12s ease;
}
.agent-result-next-item:hover {
    background: rgba(22, 163, 74, 0.08);
}
.agent-result-next-item::before {
    content: '\2192 ';
    opacity: 0.5;
}

/* F.9  Trace Event (collapsed) */
.agent-msg--trace {
    font-size: 11px;
}
.agent-trace-toggle {
    cursor: pointer;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
    user-select: none;
}
.agent-trace-toggle::-webkit-details-marker { display: none; }
.agent-trace-toggle::before {
    content: '\25B8';
    font-size: 10px;
    transition: transform 0.15s ease;
    display: inline-block;
}
details.agent-trace-details[open] .agent-trace-toggle::before {
    transform: rotate(90deg);
}
.agent-trace-body {
    margin-top: 4px;
    padding: 8px;
    background: var(--bg);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1.5;
    color: var(--muted);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* --------------------------------------------------
   G. Thinking Indicator
   -------------------------------------------------- */
.agent-thinking {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 2px;
}
.agent-thinking-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    animation: agent-thinking-bounce 1.2s ease-in-out infinite;
}
.agent-thinking-dot:nth-child(2) { animation-delay: 0.15s; }
.agent-thinking-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes agent-thinking-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* --------------------------------------------------
   G2. Activity Line (in-place single-line indicator)
   -------------------------------------------------- */
.agent-activity-line {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 2px;
    font-size: 11.5px;
    font-family: var(--mono);
    color: var(--muted);
    min-height: 20px;
    animation: agent-msg-in 0.15s ease-out;
}
.agent-activity-spinner {
    width: 12px;
    height: 12px;
    border: 1.5px solid color-mix(in srgb, var(--primary) 25%, transparent);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: agent-spin 0.8s linear infinite;
    flex-shrink: 0;
}
.agent-activity-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --------------------------------------------------
   H. Composer
   -------------------------------------------------- */
.agent-composer {
    border-top: 1px solid var(--line);
    padding: 8px 10px 6px;
    background: var(--card);
}
.agent-input-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    background: var(--bg);
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 4px 4px 4px 12px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.agent-actions {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}
.agent-input-row:focus-within {
    border-color: color-mix(in srgb, var(--primary) 35%, var(--line));
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 8%, transparent);
}
.agent-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    resize: none;
    padding: 4px 0;
    line-height: 1.5;
    max-height: 100px;
    overflow-y: auto;
}
.agent-input::placeholder {
    color: #c0c7cf;
}
.agent-send-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.12s ease;
}
.agent-send-btn:hover:not(:disabled) {
    opacity: 0.85;
}
.agent-send-btn:disabled {
    background: var(--line);
    color: var(--muted);
    cursor: not-allowed;
}
.agent-composer-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 2px 0;
}
.agent-composer-hint {
    font-size: 11px;
    color: var(--muted);
    opacity: 0.7;
}
.agent-composer-shortcut {
    font-size: 10px;
    font-family: var(--mono);
    color: var(--muted);
    opacity: 0.5;
    background: var(--bg);
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid var(--line);
}

/* --------------------------------------------------
   H2. File Upload – Attach Button, Chips & Drag-drop
   -------------------------------------------------- */
.agent-attach-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.12s ease, background 0.12s ease;
}
.agent-attach-btn:hover:not(:disabled) {
    color: var(--text);
    background: color-mix(in srgb, var(--primary) 8%, transparent);
}
.agent-attach-btn:disabled {
    color: var(--line);
    cursor: not-allowed;
    pointer-events: none;
}

/* Attachment chips area */
.agent-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 2px 6px;
}
.agent-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--line);
    font-size: 11.5px;
    color: var(--text);
    line-height: 1.3;
    max-width: 220px;
    transition: border-color 0.15s ease;
}
.agent-chip-icon {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.agent-chip-icon svg {
    width: 14px;
    height: 14px;
}
.agent-chip-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--mono);
    font-size: 11px;
}
.agent-chip-meta {
    color: var(--muted);
    font-size: 10px;
    white-space: nowrap;
}
.agent-chip-remove {
    width: 16px;
    height: 16px;
    border: none;
    background: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.12s ease, background 0.12s ease;
}
.agent-chip-remove:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}

/* Upload state: uploading */
.agent-attachment-chip.uploading {
    border-style: dashed;
}
.agent-attachment-chip.uploading .agent-chip-icon {
    animation: agent-chip-spin 0.8s linear infinite;
}
@keyframes agent-chip-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* Upload state: ready */
.agent-attachment-chip.ready .agent-chip-icon {
    color: #22c55e;
}

/* Upload state: error */
.agent-attachment-chip.error {
    border-color: #fca5a5;
    background: #fef2f2;
}
.agent-attachment-chip.error .agent-chip-icon {
    color: #ef4444;
}

/* Drag-over visual feedback */
.agent-composer.dragover .agent-input-row {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 15%, transparent);
}

/* File chips in user messages */
.agent-msg-attachments {
    margin-top: 6px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.agent-msg-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(255,255,255,0.25);
    font-size: 11px;
    font-family: var(--mono);
    color: inherit;
    opacity: 0.85;
}
.agent-msg-file-chip::before {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: currentColor;
    opacity: 0.35;
    flex-shrink: 0;
}

/* --------------------------------------------------
   I. Desktop Layout Push (optional)
   -------------------------------------------------- */
body.agent-open .container {
    transition: margin-right 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    margin-right: var(--sidebar-width);
}

/* --------------------------------------------------
   J. Responsive
   -------------------------------------------------- */
@media (max-width: 1100px) and (min-width: 981px) {
    body.agent-open .container {
        margin-right: 0;
    }
    .agent-backdrop.agent-backdrop--visible {
        display: block;
    }
}
@media (max-width: 980px) {
    .agent-panel {
        width: 100%;
    }
    body.agent-open .container {
        margin-right: 0;
    }
    .agent-backdrop.agent-backdrop--visible {
        display: block;
    }
}
@media (max-width: 600px) {
    .agent-toggle-btn span {
        display: none;
    }
    .agent-toggle-btn {
        padding: 6px 8px;
    }
}

/* --------------------------------------------------
   K. Disable states during thinking/streaming
   -------------------------------------------------- */
.agent-panel.agent-state-thinking .agent-input,
.agent-panel.agent-state-streaming .agent-input {
    opacity: 0.6;
}
.agent-panel.agent-state-thinking .agent-send-btn,
.agent-panel.agent-state-streaming .agent-send-btn {
    background: var(--line);
    color: var(--muted);
    cursor: not-allowed;
    pointer-events: none;
}
.agent-panel.agent-state-thinking .agent-attach-btn,
.agent-panel.agent-state-streaming .agent-attach-btn {
    color: var(--line);
    cursor: not-allowed;
    pointer-events: none;
}
