/* ============================================================
   Agent Platform
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
}

.page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Auth container */
.auth-container {
    background: white;
    border-radius: 12px;
    padding: 48px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    text-align: center;
    max-width: 400px;
    width: 90%;
}
.auth-container h1 { font-size: 24px; font-weight: 600; margin-bottom: 8px; }
.subtitle { color: #666; margin-bottom: 32px; }
.auth-link { margin-top: 16px; font-size: 14px; color: #666; }
.auth-link a { color: #2563eb; text-decoration: none; }
.auth-link a:hover { text-decoration: underline; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 24px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #e5e7eb; color: #333; }
.btn-secondary:hover { background: #d1d5db; }
.btn-small { padding: 6px 16px; font-size: 13px; }
.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover { background: #dc2626; }

/* Spinner */
.spinner {
    width: 32px; height: 32px;
    border: 3px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Top bar */
.topbar {
    background: white;
    border-bottom: 1px solid #e5e7eb;
    min-height: 64px;
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar .btn-secondary {
    align-items: center;
    background: #ffffff;
    border: 1px solid #176b87;
    border-radius: 6px;
    color: #0f4f64;
    display: inline-flex;
    font-size: 14px;
    font-weight: 650;
    justify-content: center;
    min-height: 38px;
    padding: 0 16px;
}
.topbar .btn-secondary:hover {
    background: #f7f9fb;
}
.brand {
    color: #1f2937;
    font-weight: 700;
    text-decoration: none;
}
.user-profile {
    align-items: center;
    display: inline-flex;
    gap: 10px;
    min-width: 0;
}
.user-avatar {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 50%;
    height: 36px;
    object-fit: cover;
    width: 36px;
}
.user-avatar-placeholder {
    align-items: center;
    color: #2563eb;
    display: inline-flex;
    font-size: 14px;
    font-weight: 700;
    justify-content: center;
}
.user-copy {
    display: grid;
    gap: 1px;
    min-width: 0;
    text-align: right;
}
.user-copy strong,
.user-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-copy strong {
    color: #1f2937;
    font-size: 14px;
}
.user-copy span {
    color: #6b7280;
    font-size: 12px;
}
.app-footer {
    align-items: center;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    color: #6b7280;
    display: flex;
    flex-shrink: 0;
    font-size: 14px;
    justify-content: space-between;
    min-height: 64px;
    padding: 0 32px;
}

/* Dashboard layout */
#page-dashboard, #page-create-agent, #page-edit-agent, #page-agent {
    display: none;
    flex-direction: column;
    min-height: 100vh;
    align-items: stretch;
    justify-content: flex-start;
}

#page-agent {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

#page-dashboard {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

.dashboard {
    padding: 72px 24px 24px;
    max-width: 1180px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
}

#page-dashboard .dashboard {
    display: flex;
    flex-direction: column;
    flex: 1;
    margin: 0;
    max-width: none;
    min-height: 0;
    padding: 64px 0 0;
}

#page-dashboard .dashboard-header {
    background: #f5f5f5;
    margin-bottom: 0;
    min-height: 56px;
    padding: 8px 32px;
}

#page-dashboard .agent-list-panel {
    border-left: 0;
    border-radius: 0;
    border-right: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

#dashboard-agents-panel {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

#dashboard-personas-panel {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

#page-dashboard .agent-top-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 16px;
}
.dashboard-header h2 { font-size: 20px; }

.dashboard-tabs {
    align-items: center;
    display: inline-flex;
    gap: 4px;
}

.dashboard-tab {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #4b5563;
    cursor: pointer;
    font: inherit;
    font-size: 15px;
    font-weight: 650;
    min-height: 38px;
    padding: 8px 14px;
}

.dashboard-tab:hover {
    background: #e5e7eb;
}

.dashboard-tab.active {
    background: #ffffff;
    border-color: #d1d5db;
    color: #111827;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.dashboard-panel {
    width: 100%;
}

.persona-workbench {
    display: grid;
    gap: 16px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.persona-list-panel {
    background: #ffffff;
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    width: 100%;
}

.persona-top-list {
    display: grid;
    flex: 1;
    gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    min-height: 0;
    overflow: auto;
    padding: 16px;
}

.persona-editor-modal {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 24px 72px rgba(15, 23, 42, 0.28);
    display: flex;
    flex-direction: column;
    max-height: min(760px, calc(100vh - 72px));
    max-width: min(760px, calc(100vw - 48px));
    min-height: 0;
    overflow: hidden;
    width: 760px;
}

.persona-pane {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.pane-header {
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    min-height: 52px;
    padding: 10px 14px;
}

.pane-header h3 {
    font-size: 16px;
    font-weight: 700;
}

.config-table-wrap {
    min-height: 220px;
    overflow-x: auto;
}

.config-table {
    border-collapse: collapse;
    width: 100%;
}

.config-table th,
.config-table td {
    border-bottom: 1px solid #eef2f7;
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
}

.config-table th {
    background: #f9fafb;
    color: #6b7280;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.config-table tr {
    cursor: pointer;
}

.config-table tbody tr:hover,
.config-table tbody tr.selected {
    background: #eff6ff;
}

.config-table td strong,
.config-table td span {
    display: block;
    max-width: 420px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.config-table td span {
    color: #6b7280;
    font-size: 12px;
    margin-top: 2px;
}

.pagination-row {
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    color: #6b7280;
    display: flex;
    font-size: 13px;
    justify-content: space-between;
    min-height: 48px;
    padding: 8px 12px;
}

.pagination-row div {
    display: flex;
    gap: 8px;
}

.pagination-row button:disabled {
    cursor: default;
    opacity: 0.45;
}

.config-editor {
    min-height: 0;
    overflow: auto;
    padding: 16px;
}

.config-editor textarea {
    min-height: 240px;
}

@media (max-width: 900px) {
    .persona-workbench {
        grid-template-columns: 1fr;
    }
}

/* Agent fleet view */
.agent-list-panel {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}

.agent-list-toolbar {
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
    min-height: 48px;
    padding: 10px 16px;
}

.agent-top-list {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    min-height: 420px;
    padding: 16px;
}

.agent-row {
    align-content: center;
    align-items: center;
    aspect-ratio: 1;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #1f2937;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: center;
    padding: 16px;
    text-align: center;
    width: 100%;
}

.agent-row:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.agent-row-terminated {
    color: #9ca3af;
}

.agent-row-avatar-img,
.agent-row-avatar-placeholder {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    flex-shrink: 0;
}

.agent-row-avatar-img {
    object-fit: cover;
    background: #e5e7eb;
}

.agent-row-avatar-placeholder {
    background: #6366f1;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 20px;
    user-select: none;
}

.agent-row-terminated .agent-row-avatar-img,
.agent-row-terminated .agent-row-avatar-placeholder {
    filter: grayscale(1);
    opacity: 0.6;
}

.agent-row-main {
    display: grid;
    gap: 4px;
    min-width: 0;
    width: 100%;
}

.agent-row-name,
.agent-row-sub,
.agent-row-created {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-row-name {
    font-size: 16px;
    font-weight: 700;
}

.agent-row-sub,
.agent-row-created {
    color: #6b7280;
    font-size: 12px;
}

.persona-row-description {
    display: -webkit-box;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: initial;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

.agent-row-status {
    align-self: center;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    color: #4b5563;
    font-size: 11px;
    line-height: 1;
    max-width: 86px;
    overflow: hidden;
    padding: 4px 7px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-row-terminated .agent-row-status {
    border-color: #e5e7eb;
    color: #9ca3af;
}

.agent-row-create {
    border-style: dashed;
    color: #4f46e5;
}

.agent-row-plus {
    align-items: center;
    border: 1px solid #c7d2fe;
    border-radius: 50%;
    display: flex;
    font-size: 34px;
    font-weight: 300;
    height: 64px;
    justify-content: center;
    line-height: 1;
    width: 64px;
}

.agent-row-empty {
    color: #6b7280;
    cursor: default;
    font-size: 14px;
}

.agent-row-empty:hover {
    background: #ffffff;
    border-color: #e5e7eb;
    box-shadow: none;
}

/* Legacy agent cards */
.agent-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
}

.agent-card {
    background: white;
    border-radius: 10px;
    padding: 20px 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.1s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    aspect-ratio: 1 / 1;
    text-align: center;
}
.agent-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

.agent-card-avatar-img {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    background: #e5e7eb;
    flex-shrink: 0;
}

.agent-card-avatar-placeholder {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: #6366f1;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 28px;
    user-select: none;
    flex-shrink: 0;
}

.agent-card-name {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.badge {
    background: #eff6ff;
    color: #2563eb;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

/* Session cards */
.session-list { display: flex; flex-direction: column; gap: 8px; }

.session-card {
    background: white;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    transition: box-shadow 0.2s;
}
.session-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.session-card h4 { font-size: 14px; margin-bottom: 4px; }
.session-card-body { flex: 1; min-width: 0; }
.session-meta { font-size: 12px; color: #999; }

.session-delete {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: transparent;
    color: #9ca3af;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s, background-color 0.15s, color 0.15s;
}
.session-card:hover .session-delete { opacity: 0.7; }
.session-delete:hover {
    background: #fee2e2;
    color: #dc2626;
    opacity: 1 !important;
}

/* Agent info */
.agent-info {
    background: white;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.agent-info p { color: #666; margin-bottom: 8px; }
.agent-meta { font-size: 13px; color: #999; display: flex; gap: 16px; }

/* Forms */
.form-card {
    background: white;
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.form-card h2 { margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}
.form-group textarea { resize: vertical; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

.agent-workspace {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    margin-top: 64px;
    height: calc(100vh - 128px);
    min-height: 0;
    max-width: 100vw;
    overflow: hidden;
}

.agent-workspace-body {
    display: grid;
    flex: 1;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.agent-side-pane {
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.agent-page-header {
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
}

.agent-header-title {
    align-items: flex-start;
    display: flex;
    gap: 12px;
    min-width: 0;
    width: 100%;
}

.agent-header-avatar,
.agent-header-avatar-placeholder {
    border-radius: 50%;
    flex-shrink: 0;
    height: 44px;
    width: 44px;
}

.agent-header-avatar {
    background: #e5e7eb;
    object-fit: cover;
}

.agent-header-avatar-placeholder {
    align-items: center;
    background: #6366f1;
    color: white;
    display: flex;
    font-size: 16px;
    font-weight: 700;
    justify-content: center;
}

.agent-title-copy {
    display: grid;
    gap: 4px;
    min-width: 0;
    padding-top: 2px;
}

.agent-header-title h1 {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-status-row,
.agent-page-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.agent-page-actions {
    justify-content: flex-start;
    width: 100%;
}

.agent-side-tabs {
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 8px;
    gap: 6px;
}

.agent-side-tabs[hidden] {
    display: none;
}

.agent-side-tab {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
    color: #64748b;
    cursor: pointer;
    font-size: 13px;
    font-weight: 650;
    padding: 8px 10px;
}

.agent-side-tab:hover {
    background: #f8fafc;
    border-color: #e5e7eb;
}

.agent-side-tab.active {
    background: #111827;
    border-color: #111827;
    color: #ffffff;
}

/* Chat */
.chat-container {
    background: #f7f8fb;
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.chat-messages {
    flex: 1;
    padding: 24px;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}
.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    background: white;
    align-items: flex-end;
}
.chat-input-area textarea {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 44px;
    max-height: 200px;
}

.workspace-files-panel {
    background: #ffffff;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.workspace-files-header {
    align-items: flex-start;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 14px;
}

.workspace-files-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.workspace-files-path {
    color: #6b7280;
    font-size: 12px;
    margin-top: 2px;
    max-width: 185px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-files-panel.workspace-upload-dragging,
.workspace-files-panel.workspace-uploading {
    background: #eff6ff;
    outline: 2px dashed #3b82f6;
    outline-offset: -6px;
}

.workspace-files-panel.workspace-upload-dragging::after,
.workspace-files-panel.workspace-uploading::after {
    align-items: center;
    background: rgba(239, 246, 255, 0.88);
    border: 1px solid #93c5fd;
    border-radius: 8px;
    color: #1d4ed8;
    content: "Drop to upload";
    display: flex;
    font-size: 14px;
    font-weight: 700;
    inset: 56px 12px 12px;
    justify-content: center;
    pointer-events: none;
    position: absolute;
    z-index: 3;
}

.workspace-files-panel.workspace-uploading::after {
    content: "Uploading...";
}

.workspace-files-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px;
}

.agent-work-panel {
    background: #ffffff;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.agent-work-header {
    align-items: flex-start;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 14px;
}

.agent-work-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.agent-work-subtitle {
    color: #6b7280;
    font-size: 12px;
    margin-top: 2px;
}

.agent-work-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px;
}

.agent-work-node {
    display: grid;
    gap: 6px;
}

.agent-work-node + .agent-work-node,
.agent-work-children {
    margin-top: 6px;
}

.agent-work-children {
    border-left: 1px solid #e5e7eb;
    display: grid;
    gap: 6px;
    margin-left: calc(17px + (var(--agent-work-depth, 0) * 2px));
    padding-left: 10px;
}

.agent-work-row {
    align-items: flex-start;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #111827;
    cursor: pointer;
    display: flex;
    gap: 9px;
    padding: 9px;
    text-align: left;
    width: 100%;
}

.agent-work-row:hover {
    background: #f3f4f6;
    border-color: #e5e7eb;
}

.agent-work-row-selected {
    background: #eff6ff;
    border-color: #93c5fd;
}

.agent-work-row-selected:hover {
    background: #dbeafe;
    border-color: #60a5fa;
}

.agent-work-row-terminal {
    opacity: 0.72;
}

.agent-work-avatar {
    background: #e5e7eb;
    border-radius: 50%;
    flex-shrink: 0;
    height: 28px;
    object-fit: cover;
    width: 28px;
}

.agent-work-avatar-placeholder {
    align-items: center;
    background: #eff6ff;
    color: #2563eb;
    display: inline-flex;
    font-size: 12px;
    font-weight: 750;
    justify-content: center;
}

.agent-work-copy {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.agent-work-line {
    align-items: center;
    display: flex;
    gap: 6px;
    min-width: 0;
}

.agent-work-line strong {
    font-size: 13px;
    font-weight: 700;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-work-status {
    background: #eef2ff;
    border-radius: 999px;
    color: #3730a3;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    text-transform: lowercase;
}

.agent-work-task,
.agent-work-result,
.agent-work-meta {
    color: #64748b;
    font-size: 12px;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-work-task,
.agent-work-result {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.agent-work-result {
    color: #334155;
}

.agent-work-empty {
    color: #94a3b8;
    font-size: 12px;
    padding: 10px 9px;
    text-align: left;
}

.workspace-file-row {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #111827;
    cursor: pointer;
    display: grid;
    gap: 2px;
    padding: 9px 10px;
    text-align: left;
    width: 100%;
}

.workspace-file-row:hover {
    background: #f3f4f6;
    border-color: #e5e7eb;
}

.workspace-file-name {
    font-size: 14px;
    font-weight: 650;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-file-meta {
    color: #6b7280;
    font-size: 12px;
}

/* Empty state */
.empty-state { color: #999; text-align: center; padding: 32px; }

.file-preview-overlay {
    align-items: center;
    background: rgba(15, 23, 42, 0.52);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 32px;
    position: fixed;
    z-index: 1200;
}

.file-preview-overlay[hidden] {
    display: none;
}

.file-preview-modal {
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.32);
    display: flex;
    flex-direction: column;
    height: min(820px, calc(100vh - 64px));
    max-width: 1080px;
    min-height: 360px;
    overflow: hidden;
    width: min(1080px, calc(100vw - 64px));
}

.file-preview-header {
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    padding: 14px 16px;
}

.file-preview-title {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.file-preview-title strong,
.file-preview-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-preview-title strong {
    color: #0f172a;
    font-size: 15px;
}

.file-preview-title span {
    color: #64748b;
    font-size: 12px;
}

.file-preview-actions {
    display: flex;
    flex-shrink: 0;
    gap: 8px;
}

.file-preview-body {
    align-items: center;
    background: #f8fafc;
    display: flex;
    flex: 1;
    justify-content: center;
    min-height: 0;
    overflow: auto;
    padding: 18px;
}

.file-preview-text {
    align-self: stretch;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #111827;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
    margin: 0;
    overflow: auto;
    padding: 16px;
    white-space: pre-wrap;
    width: 100%;
}

.file-preview-markdown {
    align-self: stretch;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #111827;
    font-size: 14px;
    line-height: 1.65;
    overflow: auto;
    padding: 20px 24px;
    width: 100%;
}

.file-preview-image,
.file-preview-video,
.file-preview-audio,
.file-preview-pdf {
    max-height: 100%;
    max-width: 100%;
}

.file-preview-video {
    background: #000000;
}

.file-preview-audio {
    width: min(640px, 100%);
}

.file-preview-pdf {
    align-self: stretch;
    background: #ffffff;
    border: 0;
    height: 100%;
    width: 100%;
}

.file-preview-message {
    color: #475569;
    font-size: 14px;
    margin: 0;
    text-align: center;
}

/* Messages */
.message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 10px;
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
}
.msg-human { background: #eff6ff; margin-left: 40px; }
.msg-assistant { background: white; margin-right: 40px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
@media (max-width: 700px) {
    .chat-messages {
        padding: 16px;
    }
    .agent-workspace {
        height: calc(100vh - 128px);
        min-height: 0;
        overflow: hidden;
    }
    .agent-workspace-body {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(220px, 40%) minmax(0, 1fr);
        overflow: hidden;
    }
    .agent-side-pane {
        border-bottom: 1px solid #e5e7eb;
        border-right: 0;
        max-height: none;
        min-height: 0;
    }
    .workspace-files-panel {
        min-height: 0;
    }
    .agent-work-panel {
        min-height: 0;
    }
    .chat-container {
        min-height: 0;
    }
    .msg-human,
    .msg-assistant {
        margin-left: 0;
        margin-right: 0;
    }
}
.msg-origin { font-size: 12px; font-weight: 600; color: #666; margin-bottom: 4px; }
.msg-text {
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
    overflow-x: hidden;
    word-break: break-word;
}
.msg-text-human {
    white-space: pre-wrap;
}
.msg-text-assistant {
    white-space: normal;
}
.msg-text-assistant p,
.msg-text-assistant li,
.msg-thinking-body p,
.msg-thinking-body li {
    white-space: pre-wrap;
}
.msg-text-assistant table,
.msg-thinking-body table {
    border-collapse: collapse;
    display: block;
    margin: 12px 0;
    max-width: 100%;
    overflow-x: auto;
    white-space: normal;
}
.msg-text-assistant th,
.msg-text-assistant td,
.msg-thinking-body th,
.msg-thinking-body td {
    border: 1px solid #d1d5db;
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
}
.msg-text-assistant th,
.msg-thinking-body th {
    background: #f3f4f6;
    font-weight: 600;
}
.msg-text-assistant tr:nth-child(even) td,
.msg-thinking-body tr:nth-child(even) td {
    background: #f9fafb;
}
.msg-thinking { color: #999; font-style: italic; font-size: 13px; margin-top: 4px; }
.msg-tool-call {
    background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px;
    padding: 8px 12px; margin-top: 8px; font-size: 13px;
}
.msg-tool-call pre { margin-top: 4px; font-size: 12px; overflow-x: auto; }
.msg-tool-result {
    background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 6px;
    padding: 8px 12px; margin-top: 4px; font-size: 13px;
}
.msg-tool-result pre { font-size: 12px; overflow-x: auto; }

/* Turn status badge */
.turn-status {
    font-size: 12px; padding: 2px 10px; border-radius: 12px;
    background: #fef3c7; color: #92400e;
}
.turn-status:empty { display: none; }

.field-hint { font-size: 12px; color: #999; margin-top: 4px; }
.field-hint a { color: #2563eb; }
.timeout-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.timeout-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #4b5563;
    font-size: 13px;
}
.timeout-grid input {
    width: 100%;
}
@media (max-width: 700px) {
    .timeout-grid {
        grid-template-columns: 1fr;
    }
}
.dashboard-actions { display: flex; gap: 8px; }
.inline-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #4b5563;
    font-size: 14px;
}
.inline-toggle input {
    width: auto;
}
.agent-card-terminated {
    opacity: 0.62;
}

/* ============================================================
   Avatars
   ============================================================ */

.avatar-img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    background: #e5e7eb;
}

.avatar-img-lg {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    background: #e5e7eb;
}

.avatar-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #6366f1;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 20px;
    user-select: none;
}

.avatar-placeholder-lg {
    width: 96px;
    height: 96px;
    font-size: 36px;
}

/* Agent detail header */
.agent-detail-header {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.agent-detail-avatar {
    flex-shrink: 0;
}

/* Avatar selector (in forms) */
.avatar-selector {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.avatar-selector-none {
    display: flex;
    gap: 12px;
    align-items: center;
}

.avatar-section h4 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    margin-bottom: 8px;
    font-weight: 600;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
}

.avatar-option {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px;
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.1s, background-color 0.1s;
}

.avatar-option:hover {
    background: #eef2ff;
}

.avatar-option.selected {
    border-color: #4f46e5;
    background: #eef2ff;
}

.avatar-option .avatar-img,
.avatar-option .avatar-placeholder {
    width: 56px;
    height: 56px;
    font-size: 20px;
}

.avatar-label {
    font-size: 11px;
    color: #6b7280;
}

.avatar-plus {
    background: #e5e7eb;
    color: #6b7280;
    font-size: 28px;
    font-weight: 300;
}

.avatar-upload {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px;
    border: 2px dashed #d1d5db;
    border-radius: 10px;
    transition: border-color 0.1s, background-color 0.1s;
}

.avatar-upload:hover {
    border-color: #4f46e5;
    background: #eef2ff;
}

.avatar-delete {
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(220, 38, 38, 0.9);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.avatar-option:hover .avatar-delete {
    display: flex;
}

@media (max-width: 760px) {
    .topbar,
    .app-footer {
        padding: 0 16px;
    }

    .user-copy {
        display: none;
    }
}


/* ============================================================
   Message rendering (markdown + tool cards)
   ============================================================ */

/* Markdown content inside assistant messages */
.msg-text-assistant {
    line-height: 1.6;
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
}
.msg-text-assistant p {
    margin: 0 0 12px;
}
.msg-text-assistant p:last-child {
    margin-bottom: 0;
}
.msg-text-assistant h1,
.msg-text-assistant h2,
.msg-text-assistant h3,
.msg-text-assistant h4 {
    margin: 20px 0 8px;
    font-weight: 600;
    line-height: 1.25;
}
.msg-text-assistant h1 { font-size: 1.5em; }
.msg-text-assistant h2 { font-size: 1.3em; }
.msg-text-assistant h3 { font-size: 1.15em; }
.msg-text-assistant h4 { font-size: 1em; }

.msg-text-assistant ul,
.msg-text-assistant ol {
    margin: 0 0 12px;
    padding-left: 28px;
}
.msg-text-assistant li {
    margin: 2px 0;
}
.msg-text-assistant li > p {
    margin: 0 0 4px;
}

.msg-text-assistant blockquote {
    margin: 0 0 12px;
    padding: 6px 14px;
    border-left: 3px solid #d1d5db;
    color: #4b5563;
    background: #f9fafb;
    border-radius: 0 6px 6px 0;
}

.msg-text-assistant a {
    color: #4f46e5;
    text-decoration: none;
}
.msg-text-assistant a:hover {
    text-decoration: underline;
}

.msg-text-assistant hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 16px 0;
}

.msg-text-assistant table {
    border-collapse: collapse;
    display: block;
    margin: 0 0 12px;
    max-width: 100%;
    overflow-x: auto;
    font-size: 14px;
}
.msg-text-assistant th,
.msg-text-assistant td {
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    text-align: left;
}
.msg-text-assistant th {
    background: #f3f4f6;
    font-weight: 600;
}

/* Inline code */
.msg-text-assistant code {
    background: #f3f4f6;
    color: #be185d;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: ui-monospace, 'SF Mono', Monaco, Menlo, Consolas, monospace;
    font-size: 0.9em;
    overflow-wrap: anywhere;
    white-space: break-spaces;
    word-break: break-word;
}

/* Code block: highlight.js styles github-dark theme */
.msg-text-assistant pre {
    background: #0d1117;          /* matches github-dark */
    padding: 14px 16px;
    border-radius: 8px;
    margin: 0 0 12px;
    max-width: 100%;
    overflow-x: auto;
    white-space: pre;
    font-size: 13px;
    line-height: 1.5;
}
.msg-text-assistant pre code {
    background: transparent;
    color: #e6edf3;               /* matches github-dark foreground */
    padding: 0;
    border-radius: 0;
    font-size: 13px;
    overflow-wrap: normal;
    white-space: pre;
    word-break: normal;
}

/* Human messages: keep plain but readable */
.msg-text-human {
    line-height: 1.5;
    word-wrap: break-word;
}

/* Tool call card */
.msg-tool-call,
.msg-tool-result {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin: 8px 0;
    font-size: 13px;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}
.msg-tool-call summary,
.msg-tool-result summary {
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #374151;
    list-style: none;
    min-width: 0;
}
.msg-tool-call summary::-webkit-details-marker,
.msg-tool-result summary::-webkit-details-marker { display: none; }
.msg-tool-call summary::before,
.msg-tool-result summary::before {
    content: '▸';
    display: inline-block;
    transition: transform 0.15s;
    color: #9ca3af;
    font-size: 10px;
}
.msg-tool-call[open] summary::before,
.msg-tool-result[open] summary::before {
    transform: rotate(90deg);
}

.tool-icon {
    color: #6366f1;
    font-weight: 600;
}
.msg-tool-result .tool-icon {
    color: #059669;
}
.msg-tool-error .tool-icon {
    color: #dc2626;
}

.tool-label {
    font-weight: 500;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 11px;
}

.tool-name {
    background: #eef2ff;
    color: #4338ca;
    padding: 1px 8px;
    border-radius: 4px;
    font-family: ui-monospace, 'SF Mono', Monaco, Menlo, Consolas, monospace;
    font-size: 12px;
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tool-input,
.tool-output {
    margin: 0;
    padding: 10px 14px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    overflow-x: auto;
    font-family: ui-monospace, 'SF Mono', Monaco, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    color: #1f2937;
    max-width: 100%;
    max-height: 400px;
    overflow-y: auto;
}
.tool-input code,
.tool-output code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: 12px;
}

.msg-tool-error {
    background: #fef2f2;
    border-color: #fecaca;
}
.msg-tool-error .tool-output {
    background: #fef2f2;
    color: #991b1b;
}

/* Thinking block: muted styling */
.msg-thinking {
    background: #fafaf9;
    border: 1px solid #e7e5e4;
    border-radius: 8px;
    margin: 8px 0;
    font-size: 13px;
    overflow: hidden;
}
.msg-thinking summary {
    padding: 8px 12px;
    cursor: pointer;
    color: #6b7280;
    font-style: italic;
    font-size: 12px;
    user-select: none;
}
.msg-thinking-body {
    padding: 10px 14px;
    border-top: 1px solid #e7e5e4;
    color: #4b5563;
}


/* ============================================================
   Confirmation modal
   ============================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modal-fade-in 0.15s ease-out;
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal {
    background: white;
    border-radius: 12px;
    padding: 28px;
    max-width: 480px;
    width: calc(100% - 40px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    animation: modal-pop-in 0.18s ease-out;
}

@keyframes modal-pop-in {
    from { transform: scale(0.96); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.modal h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #1f2937;
}

.modal-body {
    color: #4b5563;
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 20px;
}

.modal-body p {
    margin: 0 0 10px;
}
.modal-body p:last-child {
    margin-bottom: 0;
}

.modal-body strong {
    color: #111827;
    font-weight: 600;
}

.modal-warning {
    padding: 10px 12px;
    background: #fef3c7;
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
    color: #78350f;
    font-size: 13px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
