/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2260cc;
    --primary-hover: #1a4ea8;
    --primary-light: #edf3fb;
    --bg: #f5f6f8;
    --sidebar-bg: #fafbfc;
    --sidebar-text: #3c4a5c;
    --sidebar-hover: #edf3fb;
    --sidebar-active: #e4edf7;
    --surface: #fff;
    --border: #e8eaef;
    --border-light: #f0f2f5;
    --text: #1d2129;
    --text-secondary: #77818c;
    --text-tertiary: #a1a9b3;
    --agent-msg: #f7f8fa;
    --radius: 8px;
    --radius-sm: 5px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,.06);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.app-container {
    display: flex;
    height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 272px;
    min-width: 272px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    transition: opacity .2s ease;
    z-index: 10;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    opacity: 0;
    overflow: hidden;
    border-right: none;
}

.sidebar-header {
    padding: 22px 20px 14px;
}

.sidebar-header h1 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.2px;
}

.sidebar-header p {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 3px;
}

.sidebar-section {
    padding: 8px 10px;
    flex: 1;
    overflow-y: auto;
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    padding: 0 8px 8px;
    letter-spacing: .3px;
}

/* ===== Task Buttons ===== */
.task-buttons {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.task-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .12s;
    border: none;
    background: transparent;
    color: var(--sidebar-text);
    font-size: 13px;
    text-align: left;
    width: 100%;
    font-family: inherit;
}

.task-btn:hover {
    background: var(--sidebar-hover);
}

.task-btn:active {
    background: var(--sidebar-active);
}

.task-btn.running {
    opacity: .55;
    pointer-events: none;
}

.task-btn .task-icon {
    font-size: 16px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
    line-height: 1;
}

.task-btn .task-label {
    font-weight: 500;
    font-size: 13px;
    line-height: 1.3;
}

.task-btn .task-desc {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 1px;
    line-height: 1.3;
}

.task-btn.skeleton {
    pointer-events: none;
    opacity: .35;
}

/* Sidebar category icon replacement — use text marker instead of emoji */
.section-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary);
    margin-right: 6px;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

.sidebar-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--border-light);
}

.btn-clear {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all .12s;
    font-family: inherit;
}

.btn-clear:hover {
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
}

/* ===== Exports List ===== */
.exports-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.export-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: background .12s;
    color: var(--sidebar-text);
    text-decoration: none;
}

.export-item:hover {
    background: var(--sidebar-hover);
}

.export-item .export-icon {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
    font-size: 14px;
}

.export-item .export-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.export-item .export-time {
    font-size: 10px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.export-item.empty {
    color: var(--text-tertiary);
    cursor: default;
    pointer-events: none;
    font-size: 12px;
}

/* ===== Chat Area ===== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-header span {
    font-weight: 600;
    font-size: 14px;
}

.back-to-agents {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: all .12s;
}

.back-to-agents:hover {
    background: var(--agent-msg);
    color: var(--text);
}

.btn-logout { font-family: var(--font); transition: all .12s; }
.btn-logout:hover { background: #fef2f2 !important; border-color: #fecaca !important; color: #dc2626 !important; }
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    line-height: 1;
    transition: background .12s;
}

.sidebar-toggle:hover {
    background: var(--agent-msg);
    color: var(--text);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    margin-left: auto;
    flex-shrink: 0;
}

/* ===== Messages ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.welcome-message {
    text-align: center;
    margin: auto;
    max-width: 400px;
    animation: fadeIn .4s ease-out;
}

.welcome-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: var(--primary);
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -1px;
}

.welcome-message h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
}

.welcome-message p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

.welcome-hint {
    font-size: 12px;
    margin-top: 8px;
    color: var(--text-tertiary);
    background: var(--agent-msg);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-family: var(--font-mono);
    font-size: 12px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Message Bubbles */
.message {
    max-width: 76%;
    animation: fadeIn .25s ease-out;
    display: flex;
    flex-direction: column;
}

.message.user { align-self: flex-end; align-items: flex-end; }
.message.agent { align-self: flex-start; align-items: flex-start; }

.message .bubble {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.user .bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 3px;
}

.message.agent .bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 3px;
    box-shadow: var(--shadow-sm);
}

/* Time label on messages */
.message .time-label {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 3px;
    padding: 0 2px;
}

/* Agent message table rendering */
.message.agent .bubble table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
    width: 100%;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.message.agent .bubble th,
.message.agent .bubble td {
    border: 1px solid var(--border);
    padding: 7px 10px;
    text-align: left;
}

.message.agent .bubble th {
    background: #f8f9fb;
    font-weight: 600;
    color: var(--text);
    font-size: 12px;
}

.message.agent .bubble td {
    color: var(--text);
    font-size: 13px;
}

/* ===== Chat Input ===== */
.chat-input-area {
    padding: 12px 20px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding-left: 2px;
}

.typing-indicator.hidden { display: none; }

.typing-indicator span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary);
    animation: pulse-dot 1.4s infinite ease-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -.16s; }

@keyframes pulse-dot {
    0%, 80%, 100% { opacity: .2; transform: scale(.6); }
    40% { opacity: 1; transform: scale(1); }
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

#chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
    background: var(--bg);
}

#chat-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(34,96,204,.08);
    background: var(--surface);
}

#chat-input:disabled {
    background: #fafbfc;
    color: var(--text-tertiary);
}

.btn-send {
    padding: 10px 20px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .12s, opacity .12s;
    white-space: nowrap;
    font-family: inherit;
    height: 42px;
}

.btn-send:hover { background: var(--primary-hover); }
.btn-send:disabled {
    opacity: .45;
    pointer-events: none;
}

.btn-cancel {
    padding: 10px 14px;
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    transition: all .12s;
    white-space: nowrap;
    font-family: inherit;
    height: 42px;
    display: none;
}

.btn-cancel.visible { display: inline-block; }

.btn-cancel:hover {
    border-color: #fecaca;
    color: #dc2626;
    background: #fef2f2;
}

/* Inline retry button on error messages */
.retry-btn {
    display: inline-block;
    margin-top: 6px;
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--primary);
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: all .12s;
}

.retry-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

/* ===== Confirm Dialog ===== */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn .15s ease-out;
}

.dialog-overlay.hidden { display: none; }

.dialog-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 340px;
    width: 90%;
    box-shadow: var(--shadow-md);
    animation: fadeIn .2s ease-out;
}

.dialog-box h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.dialog-box p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.dialog-actions button {
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all .12s;
}

.dialog-btn-cancel {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.dialog-btn-cancel:hover { background: var(--agent-msg); }

.dialog-btn-confirm {
    background: #dc2626;
    border: none;
    color: #fff;
}

.dialog-btn-confirm:hover { background: #b91c1c; }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: #fff;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    z-index: 200;
    animation: toastIn .25s ease-out;
    pointer-events: none;
}

.toast.fading {
    animation: toastOut .3s ease-out forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(8px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(-50%) translateY(0); }
    to { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

/* ===== Responsive ===== */
@media (max-width: 700px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        box-shadow: var(--shadow-md);
        width: 272px;
        min-width: 272px;
    }

    .sidebar.collapsed {
        width: 0;
        min-width: 0;
        opacity: 0;
    }

    .message { max-width: 90%; }
    .chat-messages { padding: 14px 12px; }
    .chat-input-area { padding: 10px 12px 14px; }
}

@media (min-width: 1200px) {
    .message { max-width: 60%; }
    .chat-messages { padding: 24px 40px; }
}
