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

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background);
    color: var(--text);
    line-height: 1.6;
}

.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo i {
    font-size: 1.5rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--secondary);
}

.status.connected .status-dot { background: var(--success); }
.status.error .status-dot { background: var(--error); }

.main-content {
    display: flex;
    flex: 1;
}

.sidebar {
    width: 280px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    color: var(--text-light);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
    font-weight: 500;
}

.nav-btn:hover {
    background: var(--background);
    color: var(--text);
}

.nav-btn.active {
    background: var(--primary);
    color: white;
}

.nav-btn i {
    width: 16px;
    text-align: center;
}

.tenant-info {
    margin-top: auto;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.tenant-info h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-light);
}

.tenant-card {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 15px;
}

.tenant-card .tenant-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.tenant-card .tenant-role {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 10px;
}

.tenant-card .tenant-stats {
    font-size: 12px;
    color: var(--text-light);
    display: flex;
    gap: 15px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.tenant-card input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.tenant-card button {
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}

.content-area {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

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

.tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.tab-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

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

.agents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.agent-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: all 0.2s;
}

.agent-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.agent-card.is-default {
    border-color: var(--primary);
    border-width: 2px;
}

.default-badge {
    display: inline-block;
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    margin-left: 0.5rem;
    font-weight: 500;
    vertical-align: middle;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
}

.agent-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.agent-info h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.agent-role {
    color: var(--primary);
    font-weight: 500;
    font-size: 0.875rem;
}

.agent-company {
    color: var(--text-light);
    font-size: 0.875rem;
}

.agent-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.stat {
    text-align: center;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

.agent-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-small {
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    transition: all 0.2s;
}

.btn-view { background: var(--background); color: var(--text); }
.btn-edit { background: var(--warning); color: white; }
.btn-test { background: var(--primary); color: white; }
.btn-delete { background: var(--error); color: white; }

.agent-form {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 2rem;
    box-shadow: var(--shadow);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: border 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group small {
    margin-top: 0.5rem;
    color: var(--text-light);
    font-size: 0.75rem;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.chat-container {
    background: var(--surface);
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    overflow: hidden;
    height: 600px;
    display: flex;
    flex-direction: column;
}

.chat-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.chat-controls select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--surface);
}

.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    display: flex;
    max-width: 80%;
}

.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.message.system { align-self: center; max-width: 100%; }

.message-content {
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message.user .message-content {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.assistant .message-content {
    background: var(--background);
    color: var(--text);
    border-bottom-left-radius: 0.25rem;
}

.message.system .message-content {
    background: var(--surface);
    color: var(--text-light);
    border: 1px solid var(--border);
    font-style: italic;
}

.chat-input-container {
    border-top: 1px solid var(--border);
    padding: 1rem 1.5rem;
}

.chat-input {
    display: flex;
    gap: 0.5rem;
}

.chat-input input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 2rem;
    font-size: 0.875rem;
}

.chat-input input:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-input button {
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 2rem;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-input button:hover:not(:disabled) {
    background: var(--primary-dark);
}

.chat-input button:disabled {
    background: var(--secondary);
    cursor: not-allowed;
}

.chat-info {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-light);
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.metric-icon {
    width: 48px;
    height: 48px;
    background: var(--primary);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.25rem;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
}

.metric-label {
    font-size: 0.875rem;
    color: var(--text-light);
}

.recent-activity {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
}

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.activity-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--background);
    border-radius: 0.5rem;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

.modal-content {
    background: var(--surface);
    margin: 5% auto;
    padding: 0;
    border-radius: 0.75rem;
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
}

.close:hover {
    color: var(--text);
}

.modal-body {
    padding: 1.5rem;
    max-height: 70vh;
    overflow-y: auto;
}

.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    color: white;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1001;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.info { background: var(--primary); }
.toast.warning { background: var(--warning); }

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-light);
}

.error-message {
    text-align: center;
    padding: 2rem;
    color: var(--error);
}

.detail-section {
    margin-bottom: 1.5rem;
}

.detail-section h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-item label {
    font-weight: 500;
    color: var(--text-light);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.detail-item span {
    color: var(--text);
    font-size: 0.875rem;
}

.prompt-preview {
    background: var(--background);
    padding: 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    font-size: 0.875rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--background);
    padding: 1rem;
    border-radius: 0.5rem;
    text-align: center;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-light);
}

.action-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.edit-agent-form {
    padding: 1rem 0;
}

.edit-agent-form h4 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text);
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .sidebar-nav {
        flex-direction: row;
        overflow-x: auto;
    }
    
    .nav-btn {
        white-space: nowrap;
    }
    
    .content-area {
        padding: 1rem;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .agents-grid {
        grid-template-columns: 1fr;
    }
    
    .chat-container {
        height: 500px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .agent-actions {
        flex-wrap: wrap;
    }
}

/* ========== TOOLS CONFIG ========== */
.tools-config {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}

.tool-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.tool-item:last-child {
    border-bottom: none;
}

.tool-info {
    flex: 1;
}

.tool-info strong {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text);
}

.tool-info p {
    font-size: 0.85rem;
    color: var(--text-light);
    margin: 0;
}

/* Toggle Switch */
.tool-toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
    flex-shrink: 0;
}

.tool-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.tool-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 26px;
}

.tool-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.tool-checkbox:checked + .tool-slider {
    background-color: var(--success);
}

.tool-checkbox:checked + .tool-slider:before {
    transform: translateX(24px);
}

.tool-checkbox:disabled + .tool-slider {
    background-color: #e0e0e0;
    cursor: not-allowed;
}

/* Config Panel */
.tool-config-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin: 0.5rem 0 0.5rem 66px;
}

.tool-config-panel label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    display: block;
}

/* Lista de agentes alvo para transferência */
.transfer-targets-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.transfer-target-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.transfer-target-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.transfer-target-item label {
    flex: 1;
    cursor: pointer;
    font-weight: 400;
}

.transfer-target-item .agent-role {
    font-size: 0.8rem;
    color: var(--text-light);
}

/* Regras de transferência */
.transfer-rules {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.transfer-rule {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.transfer-rule input[type="text"] {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
}

.transfer-rule select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
    min-width: 150px;
}

.transfer-rule .rule-arrow {
    color: var(--text-light);
    font-size: 1.2rem;
}

.transfer-rule .btn-remove-rule {
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
}

.transfer-rule .btn-remove-rule:hover {
    color: #dc2626;
}

.btn-add-rule {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 6px;
    color: var(--text-light);
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.btn-add-rule:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Tool desabilitada */
.tool-item.tool-disabled {
    opacity: 0.6;
}

.tool-item.tool-disabled .tool-info strong {
    color: var(--text-light);
}

.badge-soon {
    background: var(--warning);
    color: white;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    margin-left: 0.5rem;
    vertical-align: middle;
}

/* Modal com textarea maior */
.edit-agent-form textarea,
.agent-form textarea {
    min-height: 150px;
    resize: vertical;
}

#editSystemPrompt {
    min-height: 250px;
}

/* Modal maior para edição */
.modal-content {
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
}

.prompt-preview {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
}