/* ========================================
   Unified AI Agent — Stylesheet
   Fullscreen split layout, dark theme
   ======================================== */

/* ---- Theme Variables ---- */
:root {
    --agent-primary: var(--primary, #00d4aa);
    --agent-primary-dark: var(--primary-dark, #00a888);
    --agent-secondary: var(--secondary, #6366f1);
    --agent-accent: var(--accent, #f59e0b);
    --agent-dark: var(--dark, #1a1a2e);
    --agent-darker: var(--darker, #12122a);
    --agent-light: var(--light, #f8fafc);
    --agent-gray: var(--gray, #94a3b8);
    --agent-card-bg: rgba(255,255,255,0.06);
    --agent-card-border: rgba(255,255,255,0.1);
}

/* ---- Reset ---- */
.agent-app * { margin: 0; padding: 0; box-sizing: border-box; }

/* ---- Layout ---- */
.agent-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--agent-darker);
    color: var(--agent-light);
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    overflow: hidden;
}

/* ---- Top Bar ---- */
.agent-topbar {
    display: flex;
    align-items: center;
    height: 36px;
    padding: 0 1rem;
    background: var(--agent-dark);
    border-bottom: 1px solid var(--agent-card-border);
    flex-shrink: 0;
    gap: 8px;
}
.agent-topbar-logo {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--agent-light);
    font-size: 0.82rem;
    font-weight: 600;
}
.agent-topbar-logo:hover { opacity: 0.8; }
.agent-topbar-spacer { flex: 1; }
.agent-topbar-login {
    color: var(--agent-gray);
    text-decoration: none;
    font-size: 0.75rem;
    padding: 2px 10px;
    border-radius: 4px;
    transition: all 0.15s;
}
.agent-topbar-login:hover { color: var(--agent-light); background: rgba(255,255,255,0.06); }
.agent-topbar-user { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--agent-gray); }
.agent-user-avatar {
    width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--agent-primary);
    color: var(--agent-darker);
    font-size: 0.7rem; font-weight: 600;
}
.agent-user-name { max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-topbar-swap {
    background: none; border: 1px solid transparent;
    color: var(--agent-gray); cursor: pointer;
    font-size: 1rem; padding: 2px 6px;
    border-radius: 4px; transition: all 0.15s;
    font-family: inherit; line-height: 1;
}
.agent-topbar-swap:hover { color: var(--agent-light); border-color: var(--agent-card-border); }

/* ---- Resize Handle ---- */
.agent-resize-handle {
    width: 4px; cursor: col-resize;
    background: transparent;
    transition: background 0.15s;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}
.agent-resize-handle:hover,
.agent-resize-handle.active { background: var(--agent-primary); }

/* ---- Main Content (below topbar) ---- */
.agent-main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ---- Left Panel ---- */
.agent-left {
    width: 40%;
    min-width: 380px;
    max-width: 50%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--agent-card-border);
    background: var(--agent-dark);
    position: relative;
}

.agent-left-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--agent-card-border);
    flex-shrink: 0;
}

.agent-btn-icon {
    background: none;
    border: none;
    color: var(--agent-gray);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s;
}
.agent-btn-icon:hover {
    color: var(--agent-light);
    background: rgba(255,255,255,0.08);
}

/* ---- Conversation Selector ---- */
.agent-conv-selector { position: relative; }
.agent-conv-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    background: rgba(255,255,255,0.06);
    border: 1px solid transparent;
    color: var(--agent-light);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    max-width: 240px;
    transition: all 0.15s;
    font-family: inherit;
}
.agent-conv-btn:hover { border-color: var(--agent-card-border); }
.agent-conv-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}
.agent-conv-arrow {
    font-size: 0.6rem;
    opacity: 0.5;
    flex-shrink: 0;
}
.agent-conv-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 260px;
    background: var(--agent-dark);
    border: 1px solid var(--agent-card-border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 100;
    overflow: hidden;
}
.agent-conv-list { max-height: 280px; overflow-y: auto; }
.agent-conv-list::-webkit-scrollbar { width: 4px; }
.agent-conv-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}
.agent-conv-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.agent-conv-item:hover { background: rgba(255,255,255,0.04); }
.agent-conv-item.active { background: rgba(0,212,170,0.12); }
.agent-conv-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.82rem;
}
.agent-conv-item-date {
    font-size: 0.7rem;
    color: var(--agent-gray);
    flex-shrink: 0;
}
.agent-conv-item-delete {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    color: var(--agent-gray);
    font-size: 1rem;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.15s;
}
.agent-conv-item:hover .agent-conv-item-delete { opacity: 1; }
.agent-conv-item-delete:hover {
    background: rgba(239,68,68,0.15);
    color: #ef4444;
}
.agent-conv-new {
    display: block;
    width: 100%;
    padding: 10px;
    border: none;
    background: none;
    color: var(--agent-primary);
    font-size: 0.82rem;
    cursor: pointer;
    text-align: center;
    border-top: 1px solid rgba(255,255,255,0.04);
    transition: background 0.15s;
    font-family: inherit;
}
.agent-conv-new:hover { background: rgba(255,255,255,0.04); }

/* ---- Shortcuts ---- */
.agent-shortcuts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--agent-card-border);
    flex-shrink: 0;
    overflow-x: auto;
}
.agent-shortcuts::-webkit-scrollbar { height: 2px; }
.agent-shortcuts::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 1px;
}
.agent-shortcut-chip {
    background: var(--agent-card-bg);
    border: 1px solid var(--agent-card-border);
    color: var(--agent-light);
    font-size: 0.72rem;
    padding: 4px 10px;
    border-radius: 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    font-family: inherit;
    flex-shrink: 0;
}
.agent-shortcut-chip:hover {
    border-color: var(--agent-primary);
    background: rgba(0,212,170,0.1);
    color: var(--agent-primary);
}

/* ---- Messages ---- */
.agent-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.agent-messages::-webkit-scrollbar { width: 4px; }
.agent-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}

/* ---- Welcome ---- */
.agent-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem 1rem;
    color: var(--agent-gray);
    gap: 0.5rem;
    flex: 1;
}
.agent-welcome-icon { font-size: 2.5rem; opacity: 0.5; }
.agent-welcome h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--agent-light);
    margin-top: 0.5rem;
}
.agent-welcome p {
    font-size: 0.82rem;
    opacity: 0.7;
    line-height: 1.5;
}

/* ---- Chat Messages ---- */
.agent-message {
    display: flex;
    flex-direction: column;
    max-width: 100%;
}
.agent-message.user { align-items: flex-end; }
.agent-message.assistant {
    align-items: flex-start;
    flex-direction: row;
    gap: 8px;
}
.agent-message-avatar {
    font-size: 1.2rem;
    flex-shrink: 0;
    margin-top: 2px;
}
.agent-message-body {
    max-width: 100%;
    padding: 0.65rem 0.8rem;
    border-radius: 12px;
    font-size: 0.84rem;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: break-word;
}
.agent-message.user .agent-message-body {
    background: var(--agent-primary);
    color: #0a0a1a;
    border-radius: 14px 4px 14px 14px;
}
.agent-message.assistant .agent-message-body {
    background: var(--agent-card-bg);
    flex: 1;
    border-radius: 4px 14px 14px 14px;
}
.agent-message-body p { margin: 0 0 0.5rem; }
.agent-message-body p:last-child { margin-bottom: 0; }
.agent-message-body h2, .agent-message-body h3, .agent-message-body h4 {
    margin: 0.5rem 0 0.35rem;
    font-weight: 600;
}
.agent-message-body h2 { font-size: 0.95rem; }
.agent-message-body h3 { font-size: 0.85rem; }
.agent-message-body h4 { font-size: 0.8rem; }
.agent-message-body ul, .agent-message-body ol { margin: 0.25rem 0; padding-left: 1.2rem; }
.agent-message-body li { margin-bottom: 0.15rem; font-size: 0.82rem; }
.agent-message-body code {
    background: rgba(255,255,255,0.08);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.78rem;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
}
.agent-message-body pre {
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    overflow-x: auto;
    font-size: 0.78rem;
    margin: 0.5rem 0;
    border: 1px solid rgba(255,255,255,0.06);
}
.agent-message-body pre code { background: none; padding: 0; font-size: 0.78rem; }
.agent-message-body strong { font-weight: 600; }
.agent-message-body em { font-style: italic; }
.agent-message-body a { color: var(--agent-accent); text-decoration: underline; }
.agent-message-body a:hover { color: var(--agent-primary); }
.agent-message-body blockquote {
    border-left: 3px solid var(--agent-accent);
    margin: 0.4rem 0;
    padding: 0.3rem 0.6rem;
    color: var(--agent-gray);
}
.agent-message-body hr {
    border: none;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin: 0.5rem 0;
}
.agent-message-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5rem 0;
    font-size: 0.78rem;
}
.agent-message-body th, .agent-message-body td {
    border: 1px solid rgba(255,255,255,0.1);
    padding: 4px 8px;
    text-align: left;
}
.agent-message-body th { background: rgba(255,255,255,0.04); }

/* Typing indicator */
.agent-typing {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}
.agent-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--agent-gray);
    animation: agentTyping 1.4s ease-in-out infinite;
}
.agent-typing span:nth-child(2) { animation-delay: 0.2s; }
.agent-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes agentTyping {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-2px); }
}

/* ---- Plan Card ---- */
.agent-plan-card {
    border: 1px solid var(--agent-accent);
    border-radius: 10px;
    padding: 0.85rem;
    margin-top: 0.75rem;
    background: rgba(245,158,11,0.06);
}
.agent-plan-card.executing {
    border-color: var(--agent-primary);
    background: rgba(0,212,170,0.06);
}
.agent-plan-card.completed {
    border-color: var(--agent-secondary);
    background: rgba(99,102,241,0.06);
}
.agent-plan-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.agent-plan-title { flex: 1; }
.agent-plan-status {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}
.agent-plan-status.pending {
    background: rgba(245,158,11,0.2);
    color: var(--agent-accent);
}
.agent-plan-status.executing {
    background: rgba(0,212,170,0.2);
    color: var(--agent-primary);
}
.agent-plan-status.completed {
    background: rgba(99,102,241,0.2);
    color: var(--agent-secondary);
}
.agent-plan-steps { display: flex; flex-direction: column; gap: 6px; }
.agent-plan-step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    background: rgba(255,255,255,0.03);
    font-size: 0.78rem;
    transition: all 0.2s;
}
.agent-plan-step-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    flex-shrink: 0;
}
.agent-plan-step.pending .agent-plan-step-icon {
    background: rgba(255,255,255,0.08);
    color: var(--agent-gray);
}
.agent-plan-step.in_progress .agent-plan-step-icon {
    background: rgba(0,212,170,0.2);
    color: var(--agent-primary);
    animation: agentPulse 1.2s ease-in-out infinite;
}
.agent-plan-step.completed .agent-plan-step-icon {
    background: rgba(0,212,170,0.15);
    color: var(--agent-primary);
}
.agent-plan-step.failed .agent-plan-step-icon {
    background: rgba(239,68,68,0.15);
    color: #ef4444;
}
@keyframes agentPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
.agent-plan-step-desc { flex: 1; }
.agent-plan-actions {
    display: flex;
    gap: 8px;
    margin-top: 0.75rem;
}
.agent-plan-btn {
    font-size: 0.75rem;
    padding: 5px 14px;
    border-radius: 6px;
    border: 1px solid;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.agent-plan-btn.execute {
    background: rgba(0,212,170,0.15);
    border-color: var(--agent-primary);
    color: var(--agent-primary);
}
.agent-plan-btn.execute:hover { background: rgba(0,212,170,0.3); }
.agent-plan-btn.modify {
    background: rgba(99,102,241,0.1);
    border-color: var(--agent-secondary);
    color: var(--agent-secondary);
}
.agent-plan-btn.modify:hover { background: rgba(99,102,241,0.2); }
.agent-plan-btn.cancel {
    background: rgba(239,68,68,0.08);
    border-color: #ef4444;
    color: #ef4444;
}
.agent-plan-btn.cancel:hover { background: rgba(239,68,68,0.18); }

/* ---- Tool Call Card ---- */
.agent-tool-call {
    border: 1px solid var(--agent-secondary);
    border-radius: 8px;
    padding: 0.65rem 0.8rem;
    margin-top: 0.5rem;
    background: rgba(99,102,241,0.06);
    font-size: 0.78rem;
}
.agent-tool-call-header {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--agent-secondary);
    font-weight: 500;
    margin-bottom: 0.35rem;
}
.agent-tool-call-name { opacity: 0.7; font-size: 0.72rem; }

/* ---- Input Area ---- */
.agent-input-area {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 0.6rem 0.75rem;
    border-top: 1px solid var(--agent-card-border);
    flex-shrink: 0;
}
.agent-input {
    flex: 1;
    background: var(--agent-card-bg);
    border: 1px solid var(--agent-card-border);
    border-radius: 10px;
    color: var(--agent-light);
    font-size: 0.84rem;
    padding: 9px 12px;
    resize: none;
    font-family: inherit;
    line-height: 1.45;
    max-height: 120px;
    outline: none;
    transition: border-color 0.15s;
}
.agent-input:focus { border-color: var(--agent-primary); }
.agent-input::placeholder { color: var(--agent-gray); opacity: 0.5; }
.agent-send-btn, .agent-stop-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}
.agent-send-btn {
    background: var(--agent-primary);
    color: #0a0a1a;
}
.agent-send-btn:hover { background: var(--agent-primary-dark); }
.agent-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.agent-stop-btn {
    background: rgba(239,68,68,0.15);
    color: #ef4444;
}
.agent-stop-btn:hover { background: rgba(239,68,68,0.3); }

/* ---- Right Panel ---- */
.agent-right {
    flex: 1;
    min-width: 500px;
    display: flex;
    flex-direction: column;
    background: var(--agent-darker);
    overflow: hidden;
}
.agent-right-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}
.agent-right-content::-webkit-scrollbar { width: 4px; }
.agent-right-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}

/* ---- Welcome Panel (Right) ---- */
.agent-welcome-panel { text-align: center; }
.agent-welcome-panel h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}
.agent-welcome-panel > p {
    color: var(--agent-gray);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}
.agent-feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    text-align: left;
}
.agent-feature-card {
    background: var(--agent-card-bg);
    border: 1px solid var(--agent-card-border);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}
.agent-feature-card:hover {
    border-color: var(--agent-primary);
    background: rgba(0,212,170,0.06);
    transform: translateY(-1px);
}
.agent-feature-card-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}
.agent-feature-card-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.agent-feature-card-desc {
    font-size: 0.75rem;
    color: var(--agent-gray);
    line-height: 1.4;
}

/* ---- Right Panel Top Bar ---- */
.agent-right-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--agent-card-border);
    flex-shrink: 0;
    background: var(--agent-dark);
}
.agent-right-title {
    font-size: 0.82rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.agent-right-close {
    background: none;
    border: none;
    color: var(--agent-gray);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: all 0.15s;
}
.agent-right-close:hover { color: var(--agent-light); background: rgba(255,255,255,0.08); }

/* ---- Iframe Mode ---- */
.agent-iframe-container {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
}
.agent-iframe-container iframe {
    flex: 1;
    border: none;
    width: 100%;
    height: 100%;
}
.agent-right.has-iframe { position: relative; }
.agent-right.has-iframe .agent-right-content { padding: 0; }

/* ---- Empty State ---- */
.agent-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--agent-gray);
    gap: 0.5rem;
    text-align: center;
}
.agent-empty-icon { font-size: 3rem; opacity: 0.4; }
.agent-empty p { font-size: 0.9rem; opacity: 0.7; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .agent-left {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }
    .agent-right {
        display: none;
        position: fixed;
        inset: 36px 0 0 0;
        z-index: 200;
    }
    .agent-right.mobile-open { display: flex; }
    .agent-right-topbar { padding-left: 1rem; padding-right: 1rem; }
}
